I am working with quantum machine learning and want to generate a random initial state with n qubits. How can I do it in qiskit?
I am working with quantum machine learning and want to generate a random initial state with n qubits. How can I do it in qiskit?
You can use random_statevector
function in qiskit
quantum_info
.
Example:
from qiskit import quantum_info
num_qubits = 4 # number of qubit for this random statevector
dims = 2**num_qubits # calculate statevector dimension based on the number of qubits
random_state = quantum_info.random_statevector(dims = dims, seed = None) # One can also specify the random seed for this random statevector