! qbraid jobs enable qbraid_sdk

!pip install qiskit

from qiskit import QuantumCircuit, Aer, transpile, assemble
from qiskit.visualization import plot_histogram, plot_bloch_multivector
from numpy.random import randint
import numpy as np
import math

qc=QuantumCircuit(2,1)
qc.h(0)  #Apply Hadamard Gate to the first qubit
qc.cx(0,1) #Apply Control Unit Operation on the second qubit, in this case the control NOT gate (for the sake of simplicity
qc.h(0) #Apply the Hadamard Gate again before output on the first qubit
qc.measure(0,0)  #Mesaure the output value of the first Qubit
aer_sim = Aer.get_backend('aer_simulator')
qobj = assemble(qc, shots=1, memory=True)
result = aer_sim.run(qobj).result()
measured_bit = int(result.get_memory()[0])
measured_bit
print(qc) #we draw the circuit
print(measured_bit)

def hadamard_test_real(): ##We copy the code above to create the circuit, the output is only the measured real value
    qc=QuantumCircuit(2,1)
    qc.h(0)
    qc.cx(0,1)
    qc.h(0)
    qc.measure(0,0)
    aer_sim = Aer.get_backend('aer_simulator')
    qobj = assemble(qc, shots=1, memory=True)
    result = aer_sim.run(qobj).result()
    measured_bit = int(result.get_memory()[0])
    return measured_bit
    

print(hadamard_test_real())

def hadamard_test_imag(): ##We copy the code above to create the circuit, the output is only the measured Imaginary value
    qc=QuantumCircuit(2,1)
    qc.h(0)
    qc.p(-math.pi/2,0)
    qc.cx(0,1)
    qc.h(0)
    qc.measure(0,0)
    aer_sim = Aer.get_backend('aer_simulator')
    qobj = assemble(qc, shots=1, memory=True)
    result = aer_sim.run(qobj).result()
    measured_bit = int(result.get_memory()[0])
    return measured_bit

print(hadamard_test_imag())

def roll_the_dice_twice(): 
    k=0
    a=0
    b=0
    while(k<6):
        k=k+1
        a=hadamard_test_real()+a
        b=hadamard_test_imag()+b
    return a,b

a,b=roll_the_dice_twice()
print("Your Dice Rolled a: ",a," And Your Friend Rolled a: ",b)
if (a<b):
    print("You WIN!")
else:
    if(a==b):
        print("It's a TIE!")
    else:
        print("Your friend WINS!")


from qbraid import get_devices

get_devices()

IBMQ.save_account('YOUR_IBMQ_KEY')

from qbraid import device_wrapper, job_wrapper, get_jobs
from qbraid.api import ibmq_least_busy_qpu, verify_config

from qiskit import QuantumCircuit
import numpy as np

qiskit_circuit = QuantumCircuit(1, 1)

qiskit_circuit.h(0)
qiskit_circuit.ry(np.pi / 4, 0)
qiskit_circuit.rz(np.pi / 2, 0)
qiskit_circuit.measure(0, 0)

qiskit_circuit.draw()

shots=200
google_id = "google_cirq_dm_sim"
qbraid_google_device = device_wrapper(google_id)

aws_id = "aws_dm_sim"
qbraid_aws_device = device_wrapper(aws_id)  # Credential handled by qBraid Quantum Jobs

qbraid_google_job = qbraid_google_device.run(qiskit_circuit, shots=shots)
qbraid_aws_job = qbraid_aws_device.run(qiskit_circuit, shots=shots)

get_jobs()

jobs = [qbraid_google_job, qbraid_aws_job]
google_result, aws_result = [job.result() for job in jobs]

print(f"{qbraid_google_device.name} counts: {google_result.measurement_counts()}")
print(f"{qbraid_aws_device.name} counts: {aws_result.measurement_counts()}")

google_result.plot_counts()

aws_result.plot_counts()

