Search code examples
quantum-computingqiskit

How to Initialize the Qubits in IBM Quantum Composer


Step 1 Qisqit : Here is the code of Qiskit. I have initialized the four qubits.

qr1 = QuantumRegister(4)
mea = ClassicalRegister(2) 
circuit = QuantumCircuit(qr1,mea) 
initial=[[1,0],[0,1]]

circuit.initialize(initial[1], 0)
circuit.initialize(initial[1], 1)

#  Uc 
circuit.x(qr1[1])
circuit.ccx(qr1[0],qr1[1],qr1[2])
circuit.x(qr1[0])
circuit.x(qr1[1])
circuit.ccx(qr1[0],qr1[1],qr1[3])
circuit.x(qr1[0])

Its Circut:

enter image description here

Step 2 IBM Qunatum Composer: Here is no such tool to initialize the qubis. Please guide me how to initilize here?

enter image description here


Solution

  • The OpenQASM language is the standard for exchange circuits among several quantum computing tools. You can use to move your Qiskit circuit to the IBM Quantum Composer.

    print(circuit.qasm())
    
    OPENQASM 2.0;
    include "qelib1.inc";
    gate multiplex1_reverse_dg q0 { ry(pi) q0; }
    ...
    

    You can take the output and paste it in the OpenQASM 2.0 box in IBM Quantum Composer.

    Note: At the moment, there is an issue in Qiskit that QASM-exports a circuit with initialize instructions as "gates". For your specific case, you need to do decompose first:

    print(circuit.decompose().qasm())
    

    Detailed explanation of initialize: Qiskit initialize is a reset followed by a state preparation. Take the following example:

    circuit = QuantumCircuit(1) 
    circuit.initialize([0,1], 0)
    print(circuit.decompose().qasm())
    
    OPENQASM 2.0;
    include "qelib1.inc";
    gate multiplex1_reverse_dg q0 { ry(pi) q0; }   #3
    gate disentangler_dg q0 { multiplex1_reverse_dg q0; }
    gate state_preparation(param0,param1) q0 { disentangler_dg q0; }
    qreg q[1];
    reset q[0];                  #1
    state_preparation(0,1) q[0]; #2
    

    In #1, the reset, followed by state_preparation in #2. After some nested calling, the standard ry is called in #3. In this case, circuit.initialize([0,1], 0) is equivalent to reset q0[0]; ry(pi) q0[0].