0
$\begingroup$

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

How do I achieve my goal at fourth step?

enter image description here

$\endgroup$

1 Answer 1

2
$\begingroup$

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:

enter image description here

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$.

$\endgroup$
5
  • $\begingroup$ 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. $\endgroup$ Commented Oct 16, 2022 at 7:28
  • $\begingroup$ It works with the whole classical register only. You can't pick a specific classical bit. To my knowledge at least.. $\endgroup$
    – Ohad
    Commented Oct 16, 2022 at 7:39
  • $\begingroup$ 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]==1. That's mean the whole classical register is 10 in binary. Because the order of two bit by nature is c[1]c[0]. All you had to do is converting 10 from binary to decimal which is 2 because OpenQASM using decimal in its syntax. $\endgroup$ Commented Oct 16, 2022 at 7:46
  • $\begingroup$ Oh, of course its possible to parse the classical register's value as we like. But it is not possible (in OpenQasm 2.0) to create a conditional quantum gate that directly depends on a value of a specific classical bit. $\endgroup$
    – Ohad
    Commented Oct 16, 2022 at 7:51
  • $\begingroup$ 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. $\endgroup$ Commented Oct 16, 2022 at 7:59

Your Answer

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

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