After thinking, I have refined the problem. The first point is how to input the final state of the previous quantum circuit into the initial state of the next quantum circuit to continue to evolve; Second, the goal of the first step is to build such a quantum circuit.
@CatalinaAlbornoz @isaacdevlugt Hello, I’m sorry if I bothered you. I have also encountered similar problems in the process of learning, this is the middle way measurement, then if there is no need to measure, I just need to input the final quantum state of the circuit of the previous repeating part as the initial state of the next repeating quantum circuit, in Pennylane writing, then what should I do? Thank you in advance. I really hope to get your help.
I’m sorry to hear that you have been confused for several days.
You can take a look at our documentation on Measurements, and more specifically on mid-circuit and conditional measurements. By using qml.measure and qml.cond you can apply certain gates depending on the output of the measurement.
Below is a code example showing three conditional measurements being applied to the circuit.
import pennylane as qml
dev = qml.device("lightning.qubit", wires=3)
def circuit(x, y):
m_0 = qml.measure(0)
qml.cond(m_0, qml.RY)(x, wires=1)
m_1 = qml.measure(2)
qml.cond(m_1 == 0, qml.RX)(y, wires=1)
m_1 = qml.measure(4)
qml.cond(m_1 == 0, qml.Hadamard)(wires=1)
From the description of what you want to do you mentioned that you want to measure a quantum state and then plug it into a different circuit. While PennyLane allows you to measure qml.state(), this is not compatible with actual quantum hardware. You may instead use quantum teleportation, where you transfer a state from one qubit to another by using a pair of entangled qubits. You can learn more in our PennyLane demo on teleportation or in Module I.15 of the Xanadu Quantum Codebook.
I also recommend that you check our PennyLane tutorials on YouTube to learn more about the exciting world of quantum computing!
@CatalinaAlbornoz Thank you very much for your answer, I will try your guidance and suggestions. However, I need to find a suitable video course to continue my study, which is a bit difficult for me, because I am a student from other countries and I cannot get on YouTube. Do You know BiliBili? It is called Station B in our company. If it is convenient, you can upload the video to Station B, or I can try other channels to get on YouTube. Finally, thank you again for helping me answer my questions.
@CatalinaAlbornoz Hello, I have another question. When I learned programming, I learned that the measured quantum state density matrix can be used for the initialization of quantum states, but I have not yet found the relevant API. The quantum state preparation API as shown in the following figure requires 2*n-2n parameters. No sign of it on the website.
Yes, you can use qml.QubitDensityMatrix() as you can see in the documentation to prepare a subsystem using a given density matrix.
Please check out the documentation and let me know if this is what you were looking for!
@CatalinaAlbornoz Ok, thank you. I understand you are in the New Year recently? Happy New Year to you
Hi @gbc, thank you! Happy new year to you too!