I would like to play with a quantum circuit local_qasm_simulator
in QISKit, but I do not want to implement a separate quantum circuit that would prepare an initial state.
The way I do it now is by falling back to NumPy. Specifically, first, I extract matrix u
from a quantum program qp
:
cname = 'circuit name'
results = qp.execute(cname, backend='local_unitary_simulator', shots=1)
data = results.get_data(cname)
u = data['unitary']
Then, I explicitly create the state I need (e.g., $|\psi\rangle = \frac{1}{2}(|00\rangle + |01\rangle + |10\rangle - |11\rangle)$):
num_qubits = 2
psi = np.ones(2**num_qubits) / 2.0
psi[3] = -psi[3]
Finally, I apply u
to psi
with NumPy:
u @ psi
The advantage of this approach is that I can explicitly obtain the state $U |\psi\rangle$. However, I cannot use local_qasm_simulator
and the measure()
function.
So, how could I prepare an arbitrary state, and supply it to a circuit, and run a local_qasm_simulator
?