# How to copy value from classical register to quantum register?

I have 1-qubit of quantum register and 2-bit of classical register.

I have this simple algorithm:

• First, I'm doing simple process for q with NOT.
• Second, I want copy current value of q to the c through measurement.
• Third, I put reset in q that forcing the state to the 0 with |0>.
• Fourth, I want copy current value of c to the q, how do I do it?.
• Fifth, I'm doing simple process for q with Hadamard.
• Six, I want copy current value of q to the c through measurement.

How do I achieve my goal at fourth step? I would suggest working with Qiskit rather than IBM Quantum Composer in that case, because Qiskit supports the feature you are asking for, and IBM Quantum Composer supports it only partially. The reason is that IBM Quantum Composer uses OpenQASM 2.0 - See this QCSE post.

Qiskit Solution:
Use the c_if instruction - It allows applying a quantum gate upon qubit/s conditioned by a value of a classical bit. The following Qiskit code constructs the circuit that you have asked for:

from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister

q = QuantumRegister(1, 'q')
c = ClassicalRegister(2, 'c')
qc = QuantumCircuit(q,c)

qc.x(0)
qc.measure(0,0)
qc.reset(0)
qc.x(0).c_if(0,1)
qc.h(0)
qc.measure(0,1)


And the corresponding circuit diagram: By writing qc.x(0).c_if(0,1) we order the program to apply a $$NOT$$ gate upon qubit $$0$$ if the value of bit $$0$$ is $$1$$.

• Nice answer I just learn something new about conditional CNOT. Btw I was testing it with QASM 2.0 that generated by IBM composer, it's worked too. Oct 16, 2022 at 7:28
• It works with the whole classical register only. You can't pick a specific classical bit. To my knowledge at least..
• You can't pick a specific classical bit. It's not true. You can, in my case two bit classical gate, if you want only specify c==1. That's mean the whole classical register is 10 in binary. Because the order of two bit by nature is cc. All you had to do is converting 10 from binary to decimal which is 2 because OpenQASM using decimal in its syntax. Oct 16, 2022 at 7:46
• Okay I just notice, the first argument in c_if was c_reg means the whole register when generated with IBM Composer. Yeah I got it. Oct 16, 2022 at 7:59