Is it possible to encapsulate a multi-qubit operator (not necessary a unitary, see below) as a new gate, so when I print circuit with qmp.draw() I’d see just big box with incoming & outgoing wires and some title, but no details? Below is an example of a 6-qubit circuit w/ feed forward measurement.
If I add more qubits or concatenate several such circuits it is very hard to see the overall logic.
And displaying circuit is a very good method of debugging. Here is a minimal exmple:
import pennylane as qml
from pennylane import numpy as np
num_qubit=6 ; shots=1000
dev = qml.device('default.qubit', wires=num_qubit,shots=shots)
@qml.qnode(dev)
def f3(X):
ninp=X.shape[0]
ang=np.arccos(X)
qout=ninp
mL=[None for i in range(ninp)]
#.... set and measure input qubits
for i in range(ninp):
qml.RX(ang[i],i)
mL[i]=qml.measure(i)
hw=sum(mL) #... compute hamming weights
qml.cond(hw == 1, qml.PauliX)(qout) # select 1 value of HW
return qml.probs(ninp)
nSamp=50
X=np.random.uniform(-0.99,0.99,size=(num_qubit-1,nSamp))
print(qml.draw(f3)(X[:,0]))
and the output
0: ──RX(2.00)──┤↗├────────────────────────────────────────────────────────────────┤
1: ─────────────║───RX(0.75)──┤↗├─────────────────────────────────────────────────┤
2: ─────────────║──────────────║───RX(2.46)──┤↗├──────────────────────────────────┤
3: ─────────────║──────────────║──────────────║───RX(0.54)──┤↗├───────────────────┤
4: ─────────────║──────────────║──────────────║──────────────║───RX(1.84)──┤↗├────┤
5: ─────────────║──────────────║──────────────║──────────────║──────────────║───X─┤ Probs
╚══════════════║══════════════║══════════════║══════════════║═══╣
╚══════════════║══════════════║══════════════║═══╣
╚══════════════║══════════════║═══╣
╚══════════════║═══╣
╚═══╝
I’d like to see just a box with 6 wires of length ~5 character, no classical (black) wires.
Is there a trick to do this in PennyLane?