Skip to content

Removing Ambiguity by Adjusting c_if Gates in Quantum Circuit #18

@MattePalte

Description

@MattePalte

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions