Error adding CRX gates

Hey!

I was trying to add CRX gates in the middle of a circuit considering the upper half as the target qubits and the lower half as the control qubits. (so in a circuit of 12 qubits, the CRX gates are between 0th and 6th qubit, 1st and 7th qubit, etc).
This throws up an error that the tensors in the stack are of unequal sizes. May you help me debug the same?

Thanks!

Hi @Lakshika_Rathi, welcome to the forum!

I think you have an error somewhere in your code.

I’ve created a small example that works. Here I’ve used the broadcast function from PennyLane which makes your life much easier.

# import your favourite libraries
import pennylane as qml
from pennylane import numpy as np

# define the number of wires
n_wires = 12

# define your device
dev = qml.device('default.qubit',wires=n_wires)

# define the pattern for your broadcast function
pattern = [[i+6,i] for i in range(6)]

# create a qnode
@qml.qnode(dev)
def circuit(pars):
    # use a broadcast function for ease of use
    qml.broadcast(unitary=qml.CRX, pattern=pattern,
              wires=range(n_wires), parameters=pars)
    # make a measurement
    return qml.expval(qml.PauliZ(0))

# create your parameters with the correct size
pars = np.random.random(len(pattern))

# view your circuit!
qml.draw_mpl(circuit,decimals=1)(pars)

Please let me know if you have any questions about using broadcast or any other questions in fact.

Also please let me know if this helps solve your problem!

If this doesn’t solve your problem please share your full code :grin:

I hope this helps!