0
$\begingroup$

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!

$\endgroup$

2 Answers 2

3
$\begingroup$

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)
qc.x(0)
qc.draw()

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.

$\endgroup$
2
$\begingroup$

How about using the data attribute, like this:

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

Your Answer

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

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