import sys
print(sys.executable)


import qiskit

qiskit.__qiskit_version__

from qiskit import IBMQ

IBMQ.save_account('fb335ef56b1d6d43894ad997ae54daf329de8050cda1e2e7a795f9bcae2da2e84ad903bd320d6e1354214371bcf9af7a80c1ccc1e0a546947469913805528928')

IBMQ.load_account()




import qiskit as q
%matplotlib inline
circuit=q.QuantumCircuit(2,2)
circuit.h(0)
circuit.cx(0,1)
circuit.measure([0,1],[0,1])
circuit.draw()


circuit.draw(output="mpl")

from qiskit import IBMQ


provider=IBMQ.get_provider("ibm-q")
for backend in provider.backends():
    try:
        qubit_count=len(backend.properties().qubits)
    except:
        qubit_count="simulated"
        print(f"{backend.name()}has{backend.status().pending_jobs}queued and␣{qubit_count}qubits")

from qiskit.tools.monitor import job_monitor
backend=provider.get_backend("ibmq_lima")
job=q.execute(circuit,backend=backend,shots=1024)
job_monitor(job)

from qiskit.visualization import plot_histogram
from matplotlib import style
style.use("dark_background")
result=job.result()
count=result.get_counts(circuit)
plot_histogram([count])



backend=provider.get_backend("ibmq_qasm_simulator")
circuit=q.QuantumCircuit(2,2)
circuit.h(0)
circuit.cx(0,1)
circuit.measure([0,1],[0,1])
circuit.draw()

job=q.execute(circuit,backend=backend,shots=1024)
job_monitor(job)


from qiskit.visualization import plot_histogram
from matplotlib import style
style.use("dark_background")
result=job.result()
count=result.get_counts(circuit)
plot_histogram([count])



from qiskit import Aer
sim_backend=Aer.get_backend("qasm_simulator")
for backend in Aer.backends():
    print(backend)

job=q.execute(circuit,backend=sim_backend,shots=1024)
job_monitor(job)

from qiskit.visualization import plot_histogram
from matplotlib import style
style.use("dark_background")
result=job.result()
count=result.get_counts(circuit)
plot_histogram([count])




from qiskit import *
circuit=QuantumCircuit(3,3)
%matplotlib inline
from qiskit.tools.visualization import plot_histogram
from qiskit.tools.visualization import plot_bloch_multivector
from qiskit.tools.visualization import plot_state_qsphere

# QFT
# Initialize the 3-qubit quantum circuit
# Set the state '110'
s = '110'
num_qubits = len(s)
qc = QuantumCircuit(num_qubits)

# Set reverse ordering
s = s[::-1]

# Construct the state 110
for idx in range(num_qubits):
    if s[idx] == '1':
        qc.x(idx)
qc.barrier()
qc.draw()


circuit.draw(output='mpl')

# Import the value pi for our rotations
from numpy import pi
# Always start from the most significant qubit,
# in this case it's q2.
# Step 1, add a Hadamard gate
qc.h(2)

# Step 2, add CROT gates from most significant qubit
qc.cu1(pi/2,1,2)

# Step 3, add another CROT from 2 to the next qubit down,
# while doubling the phase denominator
qc.cu1(pi/4, 0, 2)
# Draw the circuit
qc.draw()

# Now that we finished from 2 down to 0
# We'll drop to the next least significant qubit and
# start again,
# Step 1, add a Hadamard gate
qc.h(1)


# Step 2, add Control Rotation (CROT) gates from most
# significant towards
# least significant starting a pi/2, and doubling the
# denominator
# as you go down each qubit.
qc.cu1(pi/2, 0, 1)
# Draw the circuit
qc.draw()
# Now that we finished from 1 down to 0
# We'll drop to the next least significant qubit and 
# Start again

# Step 1, add a Hadamard gate
qc.h(0)
# Since we are at the least significant qubit, we are
# done!
# Draw the circuit
qc.draw()

# Define a function which will add the swap gates to the 
# outer
# pair of qubits
def add_swap_gates(qc_swaps,qubits):
    for qubit in range(qubits//2):
        qc-swaps.swap(qubit, qubit-qubit-1)
    return qc_swaps

qft_circuit=add_swap_gates(qc, num, qubits)
qft_circuit.draw()

 # Get the state vector simulator to view our final QFT
# state
backend = Aer.get_backend("statevector_simulator")
# Execute the QFT circuit and visualize the results
statevector = execute(qft_circuit,backend=backend).result().get_statevector()
plot_bloch_multivector(statevector)

plot_state_qsphere(statevector)
