I'm learning how to use the cirq library. Every time I set up a circuit the starting state of the qubits is $|0000..0\rangle$. Is there any way to make the starting state different? I'm thinking of somehow giving as input some np.array (vector) to the circuit so that the system initializes with such state. I know I could build a circuit to prepare the state I want but I would like a shorter way to do this.



1 Answer 1


Cirq distinguishes between "running" a circuit, which is generally supposed to act like hardware would (e.g. only getting samples), and "simulating" a circuit, which has more freedom.

Most "simulate" methods, like cirq.Simulator().simulate(...) have a parameter initial_state which can either be a computational basis state (specified as an integer e.g. initial_state=0b000111000) or a state vector (specified as a numpy array e.g. initial_state=np.array([0.5, -0.5, 0.5j, 0.5])).

For "run" methods, like cirq.Simulator().run(...), there is no way to specify the initial state because that's how it works in hardware. If you want a specific state, you have to make it with gates.

  • $\begingroup$ Then how can we "force" the qubit in specific state ? $\endgroup$
    – jaddawyn
    Nov 25, 2021 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.