I know I can make a random_circuit, but I see that Qiskit has random_statevector. I'd like to optimize computation time by initializing a state by that instead of putting a random circuit at the beginning. Is it possible and how do I do it? Thank you!


2 Answers 2


here is an example of how to initialize the random statevector then send it to the quantum circuit:

from qiskit.quantum_info import random_statevector, Statevector
from qiskit import QuantumCircuit
# import numpy as np

vec = random_statevector(2)
# vec = Statevector([1, 0])
print('before circuit: {}'.format(vec)) 

qc = QuantumCircuit(1)

new_vec = vec.evolve(qc)
print('after circuit: {}'.format(new_vec))

you should notice that the dim of state vector is 2 so the quantum circuit is 1 qubit.


How about using the data attribute, like this:

qc = QuantumCircuit(1)   
initial_state = qc.initialize(random_statevector(2).data, 0)

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.