TLDR: Circuit Drawer function draws just the second half of the list of Pennylane operations.
I am trying to create a “circuit drawer” function that takes in a list of Pennylane operations, and then queues the operations then draws them.The code is:
@qml.qnode(qml.device('default.qubit'))def circuit_drawer(circ_ops): for op in circ_ops: # print(f"Queueing operation: {op}") op.queue() return qml.state()pennylane_circ_drawer = qml.draw_mpl(circuit_drawer, decimals=4)Given, I have a list of PennyLane operations and their adjoints to invert the circuit in the following manner:
base_circ_adjoint = base_circ_ops + [qml.adjoint(op) for op in base_circ_ops[::-1]] However, when I attempt to draw the circuit, I can only see the adjoint operations in the image.
pennylane_circ_drawer(base_circ_adjoint)Moreover, when I try to call the circuit_drawer function to review the states, I do not see a $| 0 \rangle$ state but the following:
[ 0.5+0.j 0. +0.j 0.5+0.j 0. +0.j 0. +0.j -0.5+0.j 0. +0.j 0.5+0.j 0. +0.j 0. +0.j 0. +0.j 0. +0.j 0. +0.j 0. +0.j 0. +0.j 0. +0.j]which follows the diagram circuit’s math.
I can confirm list of operations has all the operations, as seen from the print statement inside the queuing loop.
Queueing operation: CZ(wires=[1, 4])Queueing operation: CNOT(wires=[2, 1])Queueing operation: Z(0)Queueing operation: H(4)Queueing operation: Z(2)Queueing operation: Z(4)Queueing operation: CNOT(wires=[4, 1])Queueing operation: H(2)Queueing operation: Z(0)Queueing operation: Z(0)Queueing operation: Adjoint(Z(0))Queueing operation: Adjoint(Z(0))Queueing operation: Adjoint(H(2))Queueing operation: Adjoint(CNOT(wires=[4, 1]))Queueing operation: Adjoint(Z(4))Queueing operation: Adjoint(Z(2))Queueing operation: Adjoint(H(4))Queueing operation: Adjoint(Z(0))Queueing operation: Adjoint(CNOT(wires=[2, 1]))Queueing operation: Adjoint(CZ(wires=[1, 4]))Can you please help me understand what I am doing incorrectly here?
Thanks!
EDIT:This is not an issue if I give it just the base_circ_ops list. I can see and confirm the correct outputs.
print(circuit_drawer(base_circ_ops))pennylane_circ_drawer(base_circ_ops)Queueing operation: CZ(wires=[1, 4])Queueing operation: CNOT(wires=[2, 1])Queueing operation: Z(0)Queueing operation: H(4)Queueing operation: Z(2)Queueing operation: Z(4)Queueing operation: CNOT(wires=[4, 1])Queueing operation: H(2)Queueing operation: Z(0)Queueing operation: Z(0)[ 0.5+0.j 0. -0.j 0.5+0.j 0. -0.j 0. +0.j 0. -0.j 0. +0.j 0. -0.j 0. +0.j 0. -0.j 0. +0.j 0. -0.j -0.5+0.j 0. -0.j -0.5+0.j 0. -0.j]

