# General tools
import numpy as np
import matplotlib.pyplot as plt
import math
# Importing standard Qiskit libraries
from qiskit import execute,QuantumCircuit, QuantumRegister, ClassicalRegister, Aer, transpile, IBMQ
from qiskit.tools.jupyter import *
from qiskit.visualization import *
from ibm_quantum_widgets import *


# Loading your IBM Quantum account(s)
provider = IBMQ.load_account()

QuantumCircuit(4, 4)

qc = QuantumCircuit(1)
qc.ry(3 * math.pi/4, 0)
# draw the circuit
qc.draw()

# et's plot the histogram and see the probability :)
qc.measure_all()
qasm_sim = Aer.get_backend('qasm_simulator') #this time we call the qasm simulator
result = execute(qc, qasm_sim).result() # NOTICE: we can skip some steps by doing .result() directly, we could go further!
counts = result.get_counts() #this time, we are not getting the state, but the counts!
plot_histogram(counts) #a new plotting method! this works for counts obviously!

inp_reg = QuantumRegister(2, name='inp')
ancilla = QuantumRegister(1, name='anc')
qc = QuantumCircuit(inp_reg, ancilla)

# Insert code here
qc.h(inp_reg[0:2])
qc.x(ancilla[0])
qc.draw()

bell = QuantumCircuit(2)
bell.h(0)
bell.x(1)
bell.cx(0, 1)
bell.draw()

qc = QuantumCircuit(1,1)
# Insert code fragment here
qc.ry(math.pi / 2,0)


simulator = Aer.get_backend('statevector_simulator')
job = execute(qc, simulator)
result = job.result()
outputstate = result.get_statevector(qc)
plot_bloch_multivector(outputstate)

from qiskit import QuantumCircuit, Aer, execute
from math import sqrt
qc = QuantumCircuit(2)
# Insert fragment here
v = [1/sqrt(2), 0, 0, 1/sqrt(2)]
qc.initialize(v,[0,1]) 


simulator = Aer.get_backend('statevector_simulator')
result = execute(qc, simulator).result()
statevector = result.get_statevector()
print(statevector)

qc = QuantumCircuit(3,3)
qc.barrier() # B. qc.barrier([0,1,2]) 
qc.draw()

qc = QuantumCircuit(1,1)
qc.h(0)
qc.s(0)
qc.h(0)
qc.measure(0,0)

qc.draw()

qc = QuantumCircuit(2, 2)
qc.h(0)
qc.barrier(0)
qc.cx(0,1)
qc.barrier([0,1])
qc.draw()




qc.depth()


# Use Aer's qasm_simulator
qasm_sim = Aer.get_backend('qasm_simulator')
#use a coupling map that connects three qubits linearly
couple_map = [[0, 1], [1, 2]]


# Execute the circuit on the qasm simulator.
# We've set the number of repeats of the circuit
# to be 1024, which is the default.
job = execute(qc, backend=qasm_sim, shots=1024, coupling_map=couple_map)



from qiskit import QuantumCircuit, execute, BasicAer
backend = BasicAer.get_backend('qasm_simulator')
qc = QuantumCircuit(3)

# insert code here
execute(qc, backend, shots=1024, coupling_map=[[0,1], [1,2]])

qc = QuantumCircuit(2, 2)
qc.x(0)
qc.measure([0,1], [0,1])
simulator = Aer.get_backend('qasm_simulator')
result = execute(qc, simulator, shots=1000).result()
counts  = result.get_counts(qc)
print(counts)

