# Obtain the quantum state on partial wires

Hi, I am implementing quantum auto-encoder with pennylane. Is there a way to obtain the quantum state on partial wires? Or any suggestions to construct circuit below with pennylane API?

Hey @Yang !

It looks like you need to make use of mid-circuit measurements. The functions you should check out are qml.measure and qml.cond.

Here is an example of both in use:

>>> dev = qml.device("default.qubit", wires=2)
>>>
>>> @qml.qnode(dev)
... def circuit(x):
...     qml.RX(x, 0)
...     qml.CNOT([0, 1])
...     m0 = qml.measure(0)
...     qml.cond(m0, qml.RZ)(1.23, 1)
...     return qml.expval(qml.PauliZ(1))
...
>>> circuit(4.56)


Let me know if this helps!

Thanks for your advice. The functions qml.measure and qml.cond seems not to work in my case. Take the circuit shown in the figure as example. Denote the system consisting of the first two qubits by A, and denote the system consisting of the last two qubits by B. What I intend to implement is to obtain the state of subsystem B \rho_B=Tr_A(\rho_{AB}). Could I implement with pennylane?

Hi @Yang ,

It’s strange that qml.measure and qml.cond don’t work for you. It’s possible that you’re using an old version of PennyLane. Make sure you’re using version 0.28. You can check it by looking at the output of qml.about().

If you are using v0.28 and the error persists, could you please post your full error traceback and the output of qml.about()?

Thanks. The problem is solved by installing the latest Pennylane.

It’s great to hear that this solved your problem @Yang !