I am training a MNIST classification hybrid model, there are some parts that I would like to obtain a state from qiskit and embed it into Pennylane’s circuit.
def data_prepration(d):
for i,j in enumerate(d):
r = j
temp = get_state_fromqiskit(r*np.pi)
# temp = get_state_frompennylane(r*np.pi)
temp2 = torch.tensor(temp)
qml.AmplitudeEmbedding(temp2, wires=i)
The code for obtaining the state above is just a simple example,When i use get_state_pennylane, it works normally, when i use get_state_fromqiskit, it’s not.Could you answer my question? Thanks!
qml.about():
Platform info: macOS-13.3-arm64-arm-64bit
Python version: 3.10.13
Numpy version: 1.23.5
Scipy version: 1.11.3
Installed devices:
If I understand your question correctly, I think you’re after qml.from_qiskit: qml.from_qiskit — PennyLane 0.34.0 documentation. It allows you to take qiskit circuits and turn them into usable elements in pennylane . We also have some more pennylane-qiskit features and improvements coming with the next release (next week)!
By the way, the use of Ry in the code I presented above is just a simple example. My actual requirement is to measure several entangled bits , obtain the collapsed state of the remaining one and embed it in the circuit.
inverce_MERA is a vqc which contains trainable variables, and data_prepration is just a data-embeddding circuit(the initial demo used Angle Embedding):
#state prepration template
def data_prepration(d):
for i,j in enumerate(d):
r = j/510
qml.RY(r*np.pi, wires=i)
qml.Barrier(wires=(len(d)-1,0))
I just want to modify this ,not directly using qml.RY to embed data , but using qiskit or pennylane-qiskit to obtain the embedded state of Ry() data and setting it as the initial state of the circuit with qml.AmplitudeEmbedding or qml.QubitStateVector .
But with all my efforts, I couldn’t do it successfully. No matter what I do, as long as I don’t use Pennylane(get_state_pennylanein my first post) to obtain this state, the loss won’t decrease
Hey! I’m confused . I think I just need to see your code, try and run it, replicate the behaviour, etc. If you could attach something minimal here that still reproduces what you’re seeing, that would be lovely ! Sorry this is taking a while
Sorry for replying so late, sorry again that i couldn’t give the minimal, but you can see this.
What I want to do is just not use pennylane Ry embedding directly, but obtain the state of equivalent Ry embedding using qiskit then use Pennylane AmplitudeEmbedding to take it as the initial state.
I think these two methods are the same.But the latter’s loss does not decrease.