Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing Ambiguity by Adjusting c_if Gates in Quantum Circuit #18

Open
MattePalte opened this issue Mar 1, 2024 · 0 comments
Open

Removing Ambiguity by Adjusting c_if Gates in Quantum Circuit #18

MattePalte opened this issue Mar 1, 2024 · 0 comments

Comments

@MattePalte
Copy link

Environment

  • qiskit.version: 0.45.2
  • Python version: 3.10.12
  • Operating system: Ubuntu 20.04

What is happening?

In the Python file example_qiskit_conditional.py, the c_if gates are used without preceding measurements. This could lead to ambiguities as the c_if gates are conditional and depend on the state of the classical registers.

How can we reproduce the issue?

Run the following code in the Python file:

q = QuantumRegister(3, "q")
c0 = ClassicalRegister(1, "c0")
c1 = ClassicalRegister(1, "c1")
c2 = ClassicalRegister(1, "c2")
qc = QuantumCircuit(q, c0, c1, c2, name="conditional")

qc.h(q[0])
qc.h(q[1]).c_if(c0, 0)  # h-gate on q[1] is executed
qc.h(q[2]).c_if(c1, 1)  # h-gate on q[2] is not executed

qc.measure(q[0], c0)
qc.measure(q[1], c1)
qc.measure(q[2], c2)

What should happen?

I would have expected either to have preceding measurements, such as:

q = QuantumRegister(3, "q")
c0 = ClassicalRegister(1, "c0")
c1 = ClassicalRegister(1, "c1")
c2 = ClassicalRegister(1, "c2")
qc = QuantumCircuit(q, c0, c1, c2, name="conditional")

qc.h(q[0])
qc.measure(q[0], c0)
qc.h(q[1]).c_if(c0, 0)  # h-gate on q[1] is executed
qc.measure(q[1], c1)
qc.h(q[2]).c_if(c1, 1)  # h-gate on q[2] is not executed

qc.measure(q[0], c0)
qc.measure(q[1], c1)
qc.measure(q[2], c2)

Or to have the c_if gates removed, such as:

q = QuantumRegister(3, "q")
c0 = ClassicalRegister(1, "c0")
c1 = ClassicalRegister(1, "c1")
c2 = ClassicalRegister(1, "c2")
qc = QuantumCircuit(q, c0, c1, c2, name="conditional")

qc.h(q[0])
qc.h(q[1])
# qc.h(q[2]) <- removed

qc.measure(q[0], c0)
qc.measure(q[1], c1)
qc.measure(q[2], c2)

To avoid ambiguity.
Thanks in advance, I wish you a happy and productive day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant