While reading the PennyLane blog on Measurement-Based Quantum Computation (MBQC), I came across the 3-qubit linear cluster example, where an RX
gate is applied with an angle conditioned on a previous measurement outcome. Specifically, the rotation angle depends on an expression like (1+s0). This introduces a classical feedback loop into the quantum circuit, which raised a question in my mind: how can such conditional-angle operations be implemented effectively in PennyLane?
Although I was able to construct a circuit of my own that reproduces the same output state, the structure of my implementation is different. I’m curious about the correct and elegant way to represent such feedback-dependent operations within PennyLane’s framework.

Hi @Rayhan740 ,
Can you please share what you have tried and what is not working? You mentioned that you can reproduce the output state, so what’s the key difference, or the element that you’re not being able to implement? If you have a minimal code example or even pseudocode it can help me understand what you’re looking for.
@qml.qnode(mbqc_dev, interface="autograd")
def RX_MBQC(theta, input_state):
# Prepare the input state
qml.StatePrep(input_state, wires=0)
# Prepare the cluster state
qml.Hadamard(wires=1)
qml.Hadamard(wires=2)
qml.CZ(wires=[0, 1])
qml.CZ(wires=[1, 2])
# Measure the qubits and perform corrections
qml.Hadamard(wires=0)
m1 = qml.measure(wires=[0])
qml.RZ(theta, wires=1)
qml.cond(m1 == 1, qml.RX)(-2 * theta, wires=2) % in this line
qml.Hadamard(wires=1)
m2 = qml.measure(wires=[1])
qml.cond(m2 == 1, qml.PauliX)(wires=2)
qml.cond(m1 == 1, qml.PauliZ)(wires=2)
# Return the density matrix of the output state
return qml.density_matrix(wires=[2])
In the above code suppose we want to do 1+s0 operation on the qml.cond like for RX gate. Then how do u do that?
Any idea how do I do this?
Hi @Rayhan740
You can add the variable in the conditional.
See for example the code below
mbqc_dev = qml.device("default.qubit")
@qml.qnode(mbqc_dev)
def RX_MBQC(theta, input_state, s0):
# Prepare the input state
qml.StatePrep(input_state, wires=0)
# Prepare the cluster state
qml.Hadamard(wires=1)
qml.Hadamard(wires=2)
qml.CZ(wires=[0, 1])
qml.CZ(wires=[1, 2])
# Measure the qubits and perform corrections
qml.Hadamard(wires=0)
m1 = qml.measure(wires=[0])
qml.RZ(theta, wires=1)
qml.cond(m1 == (1+s0), qml.RX)(-2 * theta, wires=2) # in this line
qml.Hadamard(wires=1)
m2 = qml.measure(wires=[1])
qml.cond(m2 == 1, qml.PauliX)(wires=2)
qml.cond(m1 == 1, qml.PauliZ)(wires=2)
# Return the density matrix of the output state
return qml.density_matrix(wires=[2])
theta = 0.1
input_state = 1/np.sqrt(2)*np.ones(2)
s0 = 0
RX_MBQC(theta, input_state, s0)
If the solution above doesn’t answer your question, you may need to use a different function.
If you’re ok with using an experimental PennyLane module, we have qml.ftqc which contain functions designed to make it easier to work with workflows such as MBQC.
One of the functions it contains is qml.ftqc.cond_measure, which allows you to do some things that qml.cond doesn’t allow.
Warning: since the ftqc module is experimental it will not maintain API stability between releases. This means that your code might break with the next PennyLane release.
I hope this helps though!