Quantcast
Channel: Trending Questions - Quantum Computing Stack Exchange
Viewing all articles
Browse latest Browse all 2381

Drawing Quantum Circuit from a list of Operations and their Adjoints

$
0
0

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)

Quantum Circuit drawn with base_circ_adjoint missing original operations

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]

Quantum Circuit with just the base operations


Viewing all articles
Browse latest Browse all 2381

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>