qiskit.quantum_info
has a useful random_statevector function that you can use to generate a random statevector that's sampled from the uniform measure.
For a 2-qubit state, you would call it as follows:
from qiskit.quantum_info import random_statevector
state = random_statevector(4) # note: the parameter you pass is the number of entries in the vector, not the number of qubits
Once you have this statevector, the initialize function lets you initialize your qubits to the state you just created. The documentation for initialize
is not very helpful so here's how you would use it:
from qiskit import QuantumCircuit
qc = QuantumCircuit(2)
qc.initialize(state.data, [0,1])
Note that you will have to use state.data
to get the underlying array representing the statevector, because initialize
doesn't accept an argument of type StateVector
.
Hope this helps!