TransWikia.com

How do I Initiate with my own alpha and beta values instead of starting form qubit in state zero in IBM Q?

Quantum Computing Asked on May 25, 2021

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 $|0rangle$.

One Answer

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)  
print(circuit)

     ┌───────────────────────────────┐
q_0: ┤ initialize(-0.44721,0.89443j) ├
     └───────────────────────────────┘
c: 1/═════════════════════════════════
                                      

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

circuit.h(0)
circuit.ry(1.5,0)
print(circuit)

     ┌───────────────────────────────┐┌───┐┌─────────┐
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() 
print(qasm_circuit)
print(qasm_circuit.qasm())

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

OPENQASM 2.0;
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];

Answered by KAJ226 on May 25, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP