1
$\begingroup$

I'm working on a Hybrid classical-quantum linear solver. For this, they make a loop on a quantum circuit (ie. below), and each time they change the value of the classical register and apply a X gate on the quantum register conditioned on the state of the classical register. quantum circuit

Therefore, I ask myself, is there a way to initialize the classical register ?

$\endgroup$
1
  • 1
    $\begingroup$ You cant make classical bits as a controller and make qubits as a target. But you can use if conditional statement to apply x gate on the qubits. $\endgroup$
    – Aman
    Jul 22, 2019 at 18:12

3 Answers 3

2
$\begingroup$

Classical registers are typically used for capturing measurement results, and may also be used for conditionally applying quantum operation. See: https://github.com/Qiskit/openqasm/blob/master/spec/qasm2.rst

Given the problem you described, one approach would be to have a classical program that iteratively: 1) defines and executes a quantum circuit on a quantum processor or simulator 2) reads the results from the classical registers for guidance in defining the circuit for the next iteration

$\endgroup$
0
$\begingroup$

You might find this section of the documentation helpful, it goes over initializing and using registers.

https://qiskit.org/documentation/terra/quantum_circuits.html

$\endgroup$
4
  • $\begingroup$ I already read it, but they don't talk about classical register initialization. $\endgroup$
    – lufydad
    Jul 23, 2019 at 8:27
  • $\begingroup$ What about this post: quantumcomputing.stackexchange.com/questions/1413/… $\endgroup$
    – mico
    Jul 23, 2019 at 12:25
  • $\begingroup$ In this post, they initialize the quantum register not the classical register. $\endgroup$
    – lufydad
    Jul 24, 2019 at 15:03
  • $\begingroup$ Why dont u initialize qubits and measure them by the classical registers and finally reset the qubits. $\endgroup$
    – Aman
    Jul 24, 2019 at 16:50
0
$\begingroup$

Here comes an illustration code written by myself.

from qiskit import QuantumRegister,ClassicalRegister,QuantumCircuit,Aer,execute
from qiskit.providers.aer import QasmSimulator
qr=QuantumRegister(1)
cr0=ClassicalRegister(5)
circ=QuantumCircuit(qr,cr0)
circ.measure(qr,cr0[0])
circ.x(qr)
circ.measure(qr,cr0[2])
circ.measure(qr,cr0[3])
circ.x(qr)
circ.measure(qr,cr0[3])
circ.x(qr)
circ.measure(qr,cr0[4])
circ.h(qr)
circ.x(qr)
print(execute(circ,Aer.get_backend('qasm_simulator')).result().get_counts())

Quantum Circuit for the upper instruction

The upper code shows how to get varied values and assign them to different classical registers. Although this method still requires a qubit, at least it can save some time. Maybe you can use the partial trace method to improve this. I think you must be ok with how the c_if() function works.

$\endgroup$
1
  • $\begingroup$ Haven't noticed that this is a rather old question, I hope this answer is now not that helpful for you. $\endgroup$ Nov 1, 2020 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.