Skip to content

[BUG] Incorrect circuit diagrams for QNodes with loops and adjoints #3

@glassnotes

Description

@glassnotes

What mode are you using in CircInspect?

  • Real-time development
  • Debugger mode

Expected behaviour

Entire sequence of operations generated by a loop is printed, for both regular operation and their adjoints.

Actual behaviour

The number of operations is incorrect adjoints are applied. It is usually about 2 loop iterations less, but this is irregular. For example, the image below is missing CNOTs from wires 3 and 4, and the terminal qml.adjoint(qml.QFT).

Image

However, removing the adjoint results in the correct behaviour:

Image

I tested also in PennyLane in a Jupyter notebook, and the adjoint version is drawn correctly.

Here's the code for testing:

import pennylane as qml
dev = qml.device("default.qubit", wires=7)

@qml.qnode(dev)
def my_circuit():

    for wire in range(5):
        qml.QFT(wires=range(5))
        qml.CNOT(wires=[wire, 6])
        #qml.adjoint(qml.QFT)(wires=range(5))

    return qml.probs()

# Execute a QNode to render a circuit in the righthand pane
my_circuit()

System information

  • OS: Ubuntu 24.04
  • Browser (include version): Mozilla Firefox 142.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions