import qiskit


qiskit.__qiskit_version__

from qiskit import IBMQ

IBMQ.save_account('Type in the id you get from your IBM account')

IBMQ.load_account()

from qiskit import *

qr = QuantumRegister(2)
cr = ClassicalRegister(2)

circuit = QuantumCircuit(qr,cr)

%matplotlib inline

circuit.draw()

circuit.h(qr[0])

circuit.draw(output='mpl')

circuit.cx(qr[0], qr[1])

circuit.draw(output='mpl')

circuit.measure(qr,cr)

circuit.draw(output='mpl')

simulator = Aer.get_backend('qasm_simulator')

result = execute(circuit,backend=simulator).result()

from qiskit.tools.visualization import plot_histogram


plot_histogram(result.get_counts(circuit))

IBMQ.load_account()

provider = IBMQ.get_provider('ibm-q')
qcomp = provider.get_backend('ibmq_16_melbourne')

job = execute(circuit, backend=qcomp)

from qiskit.tools.monitor import job_monitor

job_monitor(job)

result = job.result()

plot_histogram(result.get_counts(circuit))

from qiskit import *

from qiskit.tools.visualization import plot_bloch_multivector

circuit = QuantumCircuit(1,1)
circuit.x(0)
simulator = Aer.get_backend('statevector_simulator')
result  = execute(circuit, backend=simulator).result()
statevector = result.get_statevector()
print(statevector)
%matplotlib inline
circuit.draw(output = 'mpl')

plot_bloch_multivector(statevector)

circuit.measure([0],[0])
backend = Aer.get_backend('qasm_simulator')
result = execute(circuit, backend = backend, shots = 1024).result()
counts = result.get_counts()


from qiskit.tools.visualization import plot_histogram
plot_histogram(counts)

circuit = QuantumCircuit(1,1)
circuit.x(0)
simulator = Aer.get_backend('unitary_simulator')
result  = execute(circuit, backend=simulator).result()
unitary = result.get_unitary()
print(unitary)
%matplotlib inline
circuit.draw(output = 'mpl')

from qiskit import *
%matplotlib inline

circuit = QuantumCircuit(3,3)

circuit.draw(output='mpl')

circuit.x(0)
circuit.barrier()
circuit.draw(output='mpl')

circuit.h(1)
circuit.cx(1,2)
circuit.draw(output='mpl')

circuit.cx(0,1)
circuit.h(0)
circuit.draw(output='mpl')

circuit.barrier()
circuit.measure([0,1], [0,1])
circuit.draw(output='mpl')

circuit.barrier()
circuit.cx(1,2)
circuit.cz(0,2)
circuit.draw(output='mpl')

circuit.measure(2,2)
simulator = Aer.get_backend('qasm_simulator')
result = execute(circuit,backend=simulator, shots=1024).result()
counts  = result.get_counts()
plot_histogram(counts)

print(counts)

from qiskit import *
%matplotlib inline

from qiskit.tools.visualization import plot_histogram

secretnumber = '10000001'

circuit = QuantumCircuit(len(secretnumber)+1, len(secretnumber))
circuit.h(range(len(secretnumber)))
circuit.x(len(secretnumber))
circuit.h(len(secretnumber))

circuit.barrier()

circuit.draw(output='mpl')

for ii, yesno in enumerate(secretnumber):
    if yesno == '1':
        circuit.cx(ii,len(secretnumber))


# circuit.cx(5,6)
# circuit.cx(3,6)
# circuit.cx(0,6)

circuit.barrier()

# circuit.h([0,1,2,3,4,5])
circuit.h(range(len(secretnumber)))
circuit.draw(output='mpl')

circuit.barrier()

# circuit.measure([0,1,2,3,4,5],[0,1,2,3,4,5])
circuit.measure(range(len(secretnumber)), range(len(secretnumber)))

circuit.barrier()
circuit.draw(output='mpl')

simulator = Aer.get_backend('qasm_simulator')
result = execute(circuit, backend = simulator, shots = 1).result()

counts = result.get_counts()
plot_histogram(counts)

IBMQ.load_account()
provider = IBMQ.get_provider('ibm-q')
qcomp = provider.get_backend('ibmq_16_melbourne')
job = execute(circuit, backend=qcomp)
from qiskit.tools.monitor import job_monitor

job_monitor(job)

result = job.result()

plot_histogram(result.get_counts(circuit))

import qiskit
from qiskit import *

nqubits = 3
circuit = QuantumCircuit(nqubits, nqubits)
circuit.h(0)
circuit.cx(0,1)
circuit.cx(1,2)
circuit.measure([0,1,2], [0,1,2])

%matplotlib inline
from qiskit.tools.visualization import plot_histogram


circuit.draw(output='mpl')

simulator =  Aer.get_backend('qasm_simulator')
result = execute(circuit, backend=simulator, shots=1024).result()

plot_histogram(result.get_counts(circuit))

