from initialize import *

my_algorithm = initialize(circuit_name = 'demo', qubit_number=2, bit_number=2, backend = 'local_qasm_simulator', shots = 1024)


#Append sequence of gates to the quantum circuit. 
#For each gate, the qubits on which it is acting must be specified along with other gate-dependent parameters

my_algorithm.q_circuit.x(my_algorithm.q_reg[0]) # apply the X gate to the first qubit
my_algorithm.q_circuit.x(my_algorithm.q_reg[1]) # apply the X gate to the second qubit
my_algorithm.q_circuit.h(my_algorithm.q_reg[0]) # apply the Hadamard gate to the first qubit
my_algorithm.q_circuit.cx(my_algorithm.q_reg[0],my_algorithm.q_reg[1]) # apply the CNOT gate using the first qubit as control and second qubit as target
my_algorithm.q_circuit.measure(my_algorithm.q_reg[0], my_algorithm.c_reg[0]) # measures the first qubit and store the result in the first bit
my_algorithm.q_circuit.measure(my_algorithm.q_reg[1], my_algorithm.c_reg[1]) # measures the second qubit and store the result in the second bit

print('List of gates:')
for circuit in my_algorithm.q_circuit:
    print(circuit.name)


#Execute the quantum algorithm
result = my_algorithm.Q_program.execute(my_algorithm.circ_name, backend=my_algorithm.backend, shots= my_algorithm.shots)

#Show the results obtained from the quantum algorithm 

counts = result.get_counts(my_algorithm.circ_name) ## you can declare/initiate q_name first at the time you initialize circuit,

print('\nThe measured outcomes of the circuits are:',counts)

from initialize import *

#initialize quantum program
my_alg = initialize(circuit_name = 'multi', qubit_number=7, bit_number=7, backend = 'local_qasm_simulator', shots = 1024)

#add gates to the circuit
my_alg.q_circuit.x(my_alg.q_reg[1]) # applies X gate to second qubit
my_alg.q_circuit.x(my_alg.q_reg[3]) # applies X gate to fourth qubit
my_alg.q_circuit.x(my_alg.q_reg[5]) # applies X gate to sixth qubit
my_alg.q_circuit.measure(my_alg.q_reg[0], my_alg.c_reg[0]) # measures the first qubit and store the result in the first bit
my_alg.q_circuit.measure(my_alg.q_reg[1], my_alg.c_reg[1]) # measures the second qubit and store the result in the second bit
my_alg.q_circuit.measure(my_alg.q_reg[2], my_alg.c_reg[2]) # measures the third qubit and store the result in the third bit
my_alg.q_circuit.measure(my_alg.q_reg[3], my_alg.c_reg[3]) # measures the fourth qubit and store the result in the fourth bit
my_alg.q_circuit.measure(my_alg.q_reg[4], my_alg.c_reg[4]) # measures the fifth qubit and store the result in the fifth bit
my_alg.q_circuit.measure(my_alg.q_reg[5], my_alg.c_reg[5]) # measures the sixth qubit and store the result in the sixth bit
my_alg.q_circuit.measure(my_alg.q_reg[6], my_alg.c_reg[6]) # measures the seventh qubit and store the result in the seventh bit

print('List of gates:')
for circuit in my_alg.q_circuit:
    print(circuit.name)

#Execute the quantum algorithm
result = my_alg.Q_program.execute(my_alg.circ_name, backend=my_alg.backend, shots= my_alg.shots)

#Show the results obtained from the quantum algorithm 
counts = result.get_counts(my_alg.circ_name)

print('\nThe measured outcomes of the circuits are:',counts)

from initialize import *

#initialize quantum program
my_alg = initialize(circuit_name = 'multi_super', qubit_number=2, bit_number=2, backend = 'local_qasm_simulator', shots = 1024)

#add gates to the circuit
my_alg.q_circuit.h(my_alg.q_reg[0]) # applies H gate to first qubit
my_alg.q_circuit.h(my_alg.q_reg[1]) # applies X gate to second qubit
my_alg.q_circuit.measure(my_alg.q_reg[0], my_alg.c_reg[0]) # measures the first qubit and store the result in the first bit
my_alg.q_circuit.measure(my_alg.q_reg[1], my_alg.c_reg[1]) # measures the second qubit and store the result in the second bit

print('List of gates:')
for circuit in my_alg.q_circuit:
    print(circuit.name)

#Execute the quantum algorithm
result = my_alg.Q_program.execute(my_alg.circ_name, backend=my_alg.backend, shots= my_alg.shots)

#Show the results obtained from the quantum algorithm 
counts = result.get_counts(my_alg.circ_name)

print('\nThe measured outcomes of the circuits are:',counts)

from initialize import *

#initialize quantum program
my_alg = initialize(circuit_name = 'bell', qubit_number=2, bit_number=2, backend = 'local_qasm_simulator', shots = 1024)

#add gates to the circuit
my_alg.q_circuit.h(my_alg.q_reg[0]) # applies H gate to first qubit
my_alg.q_circuit.cx(my_alg.q_reg[0],my_alg.q_reg[1]) # applies CX gate using the first qubit as control and the second qubit as target
my_alg.q_circuit.measure(my_alg.q_reg[0], my_alg.c_reg[0]) # measures the first qubit and store the result in the first bit
my_alg.q_circuit.measure(my_alg.q_reg[1], my_alg.c_reg[1]) # measures the second qubit and store the result in the second bit

print('List of gates:')
for circuit in my_alg.q_circuit:
    print(circuit.name)

#Execute the quantum algorithm
result = my_alg.Q_program.execute(my_alg.circ_name, backend=my_alg.backend, shots= my_alg.shots)

#Show the results obtained from the quantum algorithm 
counts = result.get_counts(my_alg.circ_name)

print('\nThe measured outcomes of the circuits are:',counts)

from initialize import *

#initialize quantum program
my_alg = initialize(circuit_name = 'x_gate', qubit_number=1, bit_number=1, backend = 'local_qasm_simulator', shots = 1024)

#add gates to the circuit
my_alg.q_circuit.x(my_alg.q_reg[0]) # applies X gate to first qubit
my_alg.q_circuit.measure(my_alg.q_reg[0], my_alg.c_reg[0]) # measures the first qubit and store the result in the first bit

print('List of gates:')
for circuit in my_alg.q_circuit:
    print(circuit.name)

#Execute the quantum algorithm
result = my_alg.Q_program.execute(my_alg.circ_name, backend=my_alg.backend, shots= my_alg.shots)

#Show the results obtained from the quantum algorithm 
counts = result.get_counts(my_alg.circ_name)

print('\nThe measured outcomes of the circuits are:',counts)

from initialize import *

#initialize quantum program
my_alg = initialize(circuit_name = 'y_gate', qubit_number=1, bit_number=1, backend = 'local_qasm_simulator', shots = 1024)

#add gates to the circuit
my_alg.q_circuit.y(my_alg.q_reg[0]) # applies Y gate to first qubit
my_alg.q_circuit.measure(my_alg.q_reg[0], my_alg.c_reg[0]) # measures the first qubit and store the result in the first bit

print('List of gates:')
for circuit in my_alg.q_circuit:
    print(circuit.name)

#Execute the quantum algorithm
result = my_alg.Q_program.execute(my_alg.circ_name, backend=my_alg.backend, shots= my_alg.shots)

#Show the results obtained from the quantum algorithm 
counts = result.get_counts(my_alg.circ_name)

print('\nThe measured outcomes of the circuits are:',counts)

from initialize import *

#initialize quantum program
my_alg = initialize(circuit_name = 'h_gate', qubit_number=1, bit_number=1, backend = 'local_qasm_simulator', shots = 1024)

#add gates to the circuit
my_alg.q_circuit.h(my_alg.q_reg[0]) # applies H gate to first qubit
my_alg.q_circuit.measure(my_alg.q_reg[0], my_alg.c_reg[0]) # measures the first qubit and store the result in the first bit

print('List of gates:')
for circuit in my_alg.q_circuit:
    print(circuit.name)

#Execute the quantum algorithm
result = my_alg.Q_program.execute(my_alg.circ_name, backend=my_alg.backend, shots= my_alg.shots)

#Show the results obtained from the quantum algorithm 
counts = result.get_counts(my_alg.circ_name)

print('\nThe measured outcomes of the circuits are:',counts)

from initialize import *

#initialize quantum program
my_alg = initialize(circuit_name = 'rx_gate', qubit_number=1, bit_number=1, backend = 'local_qasm_simulator', shots = 1024)

theta = 0.79 # angle of rotation pi/4

#add gates to the circuit
my_alg.q_circuit.rx(theta, my_alg.q_reg[0]) # applies x-rotation of angle theta to first qubit
my_alg.q_circuit.measure(my_alg.q_reg[0], my_alg.c_reg[0]) # measures the first qubit and store the result in the first bit

print('List of gates:')
for circuit in my_alg.q_circuit:
    print(circuit.name)

#Execute the quantum algorithm
result = my_alg.Q_program.execute(my_alg.circ_name, backend=my_alg.backend, shots= my_alg.shots)

#Show the results obtained from the quantum algorithm 
counts = result.get_counts(my_alg.circ_name)

print('\nThe measured outcomes of the circuits are:',counts)

from initialize import *

for _ in range(4): # run over all possible initial states of two qubits

    #initialize quantum program
    my_alg = initialize(circuit_name = 'cx_gate', qubit_number=2, bit_number=2, backend = 'local_qasm_simulator', shots = 1024)
    
    #add gates to the circuit
    if _ == 1:
        my_alg.q_circuit.x(my_alg.q_reg[0]) # applies X gate to first qubit (prepares state 10)
    if _ == 2:
        my_alg.q_circuit.x(my_alg.q_reg[1]) # applies X gate to second qubit (prepares state 01)
    if _ == 3:
        my_alg.q_circuit.x(my_alg.q_reg[0]) # applies X gate to first qubit
        my_alg.q_circuit.x(my_alg.q_reg[1]) # applies X gate to second qubit (prepares state 11)
    
    my_alg.q_circuit.cx(my_alg.q_reg[0],my_alg.q_reg[1]) ## applies CX gate using the first qubit as control and the second qubit as target
    my_alg.q_circuit.measure(my_alg.q_reg[0], my_alg.c_reg[0]) # measures the first qubit and store the result in the first bit
    my_alg.q_circuit.measure(my_alg.q_reg[1], my_alg.c_reg[1]) # measures the second qubit and store the result in the second bit

    print('List of gates:')
    for circuit in my_alg.q_circuit:
        print(circuit.name)

    #Execute the quantum algorithm
    result = my_alg.Q_program.execute(my_alg.circ_name, backend=my_alg.backend, shots= my_alg.shots)

    #Show the results obtained from the quantum algorithm 
    counts = result.get_counts(my_alg.circ_name)

    print('\nThe measured outcomes of the circuits are:',counts)

from initialize import *

#initialize quantum program
my_alg = initialize(circuit_name = 'evo_1', qubit_number=1, bit_number=1, backend = 'local_qasm_simulator', shots = 1024)

#add gates to the circuit
my_alg.q_circuit.iden(my_alg.q_reg[0]) # applies U1
my_alg.q_circuit.measure(my_alg.q_reg[0], my_alg.c_reg[0]) # measures the first qubit and store the result in the first bit


print('List of gates:')
for circuit in my_alg.q_circuit:
    print(circuit.name)

#Execute the quantum algorithm
result = my_alg.Q_program.execute(my_alg.circ_name, backend=my_alg.backend, shots= my_alg.shots)

#Show the results obtained from the quantum algorithm 
counts = result.get_counts(my_alg.circ_name)

print('\nThe measured outcomes of the circuits are:',counts)

from initialize import *

#initialize quantum program
my_alg = initialize(circuit_name = 'evo_2', qubit_number=1, bit_number=1, backend = 'local_qasm_simulator', shots = 1024)

#add gates to the circuit
my_alg.q_circuit.iden(my_alg.q_reg[0]) 
my_alg.q_circuit.x(my_alg.q_reg[0]) # applies U2
my_alg.q_circuit.measure(my_alg.q_reg[0], my_alg.c_reg[0]) # measures the first qubit and store the result in the first bit


print('List of gates:')
for circuit in my_alg.q_circuit:
    print(circuit.name)

#Execute the quantum algorithm
result = my_alg.Q_program.execute(my_alg.circ_name, backend=my_alg.backend, shots= my_alg.shots)

#Show the results obtained from the quantum algorithm 
counts = result.get_counts(my_alg.circ_name)

print('\nThe measured outcomes of the circuits are:',counts)

from initialize import *

#initialize quantum program
my_alg = initialize(circuit_name = 'evo_3', qubit_number=1, bit_number=1, backend = 'local_qasm_simulator', shots = 1024)

#add gates to the circuit
my_alg.q_circuit.iden(my_alg.q_reg[0]) 
my_alg.q_circuit.x(my_alg.q_reg[0])
my_alg.q_circuit.x(my_alg.q_reg[0]) # applies U3
my_alg.q_circuit.measure(my_alg.q_reg[0], my_alg.c_reg[0]) # measures the first qubit and store the result in the first bit


print('List of gates:')
for circuit in my_alg.q_circuit:
    print(circuit.name)

#Execute the quantum algorithm
result = my_alg.Q_program.execute(my_alg.circ_name, backend=my_alg.backend, shots= my_alg.shots)

#Show the results obtained from the quantum algorithm 
counts = result.get_counts(my_alg.circ_name)

print('\nThe measured outcomes of the circuits are:',counts)