# Pennylane: take qml.state of one function and use it as the initialization for another

In Pennylane, I created a function to set the initial parameters of my qubit, and then called qml.state() to return the output. I now want to feed this initialization into another circuit, but I'm not sure how I would go about doing that.

here's what I have:

random_init() initializes a set of qubits to particular states, and then returns qml.state()

@qml.qnode(dev1)
def random_init():
for i  in range(0, y, 3):
qml.RX(random_list[i], i//3)
qml.RY(random_list[i+1], i//3)
qml.RZ(random_list[i+2], i//3)
return qml.state()


I now want to take qml.state() and pass it through another circuit that does computations based on the initial states set by random_init().

Is this possible to do? Furthermore, is there a more effective way to achieve this goal?

Thanks in advance for any help people provide.

You can totally do this in PennyLane. Check out qml.QubitStateVector :)


import pennylane as qml
from pennylane import numpy as np

dev1 = qml.device("default.qubit", wires=1)

@qml.qnode(dev1)
def circuit():
qml.RX(np.pi/3, wires=0)
return qml.state()

@qml.qnode(dev1)
def new_circuit(state):
qml.QubitStateVector(state, wires=0)
return qml.state()

state = circuit()
print(new_circuit(state))

# Out: [0.8660254+0.j  0.       -0.5j]


Hope this helps!

• Elegant! Thanks so much. Nov 1 at 0:41
• Would QubitStateVector work for entangled states as well? Nov 1 at 19:25
• Yes! All QubitStateVector needs is a vector in the computational basis. It could be entangled, separable (not entangled), etc. For density matrices, see QubitDensityMatrix. Nov 2 at 14:24