How do you create a random initial state by modifying the $2^{n}$ vector amplitudes instead of starting every simulation at $|0000...000\rangle$?


1 Answer 1


If you want a random computational basis state, set the input state to the integer random.randint(0, 2**qubits-1).

If you want a random superposition sampled from the Haar measure, there is a method cirq.testing.random_superposition(dim=2**qubits).

Once you have created your initial state, you pass it into the simulator like cirq.Simulator().simulate(circuit, initial_state=...). Note that run methods do not support an initial state, because they are supposed to more closely mimic the hardware.


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.