Let's say I have normalized values of $\alpha$ and $\beta$ as

$\alpha =(0.27524094128159016+0.8257228238447705j)$

$\beta =(-0.22019275302527214+0.4403855060505443j)$

How do I initialize my circuit starting from these values instead of qubit q[0] to be in state $|0\rangle$.

  • $\begingroup$ Welcome to QCSE! Could you explain what $\alpha$ and $\beta$ are and what is q[0]? Also note that you can use mathjax to improve rendering of mathematical formulas. $\endgroup$ – Adam Zalcman Feb 28 at 4:17
  • $\begingroup$ Thank you for responding. let's say a qubit = alpha(ket_zero) + beta(ket_one) alpha and beta are probabilities of finding qubits in state zero or state one. in IBM Q they are initializing with qubit bit in state zero if we add Hadamard gate then we can convert a qubit into a superposition(will have equal probabilities). I would like to have those probabilities as alpha and beta which i mentioned earlier. $\endgroup$ – bhagi radh Feb 28 at 4:37

If you want to start at a specific initial state, you can use qiskit initialize function to help you. For example,

from qiskit import QuantumCircuit
provider = IBMQ.load_account()
num_qubits = 1
vector = [-0.22019275302527214, 0.4403855060505443j]
initial_state = vector/np.linalg.norm(vector)
circuit = QuantumCircuit(num_qubits,num_qubits)
circuit.initialize(initial_state, 0)  

q_0: ┤ initialize(-0.44721,0.89443j) ├
c: 1/═════════════════════════════════

Once you do this, you can perform gate operations as normal... for example:


q_0: ┤ initialize(-0.44721,0.89443j) ├┤ H ├┤ RY(1.5) ├
c: 1/═════════════════════════════════════════════════

If you want the QASM code as commented then you can do it as follow:

qasm_circuit = circuit.decompose().decompose().decompose() 

q_0: ─|0>─┤ RY(2.2143) ├┤ U1(-π/2) ├┤ U(π/2,0,π) ├┤ U(1.5,0,0) ├
c: 1/═══════════════════════════════════════════════════════════

include "qelib1.inc";
qreg q[1];
creg c[1];
reset q[0];
ry(2.2142974) q[0];
u1(-pi/2) q[0];
u(pi/2,0,pi) q[0];
u(1.5,0,0) q[0];


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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