from qiskit import IBMQ

#token = open('/Users/gshyam/projects/work_projects/machine_learning/ANPA_dataScience/Python2020/TOKEN_BMQ','r')
#print (token)
#IBMQ.save_account(token)


#IBMQ.save_account('dbf31c5ec55e2b7914fe280fe04980f4edd8efa6063471bd9bc4e3617e7cc8348819917b6a01a4e106d8ef02c33f9abbf2920ceb9bbe44056eaec59eb1e910d3')

from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit import Aer, execute, BasicAer
from qiskit.visualization import plot_bloch_multivector

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

import qiskit
print (qiskit.__version__)
print (qiskit.__qiskit_version__)

IBMQ.load_account()

provider = IBMQ.get_provider(hub='ibm-q')
provider.backends()

for backend in provider.backends():
    print(backend.status())

real_device = provider.get_backend('ibmq_16_melbourne')

properties = real_device.properties()
coupling_map = real_device.configuration().coupling_map

from qiskit.providers.aer.noise import NoiseModel
noise_model = NoiseModel.from_backend(properties)

qc = QuantumCircuit(2,2)
qc.x(1)  # CNOT gate converts (00)
qc.measure(0,0)
qc.measure(1,1)


simulator = Aer.get_backend('qasm_simulator')

job = execute(qc, simulator, shots=1024, noise_model=noise_model,
                    coupling_map=coupling_map,
                    basis_gates=noise_model.basis_gates)

job.result().get_counts()

n=8
qc_encode = QuantumCircuit(n)
qc_encode.x(7)

qc_encode.draw(output='mpl')

qc_output = QuantumCircuit(n, n)
for j in range(n):
    qc_output.measure(j,j)
qc_output.draw(output='mpl')

job = execute(qc_output, Aer.get_backend('quasm_simulator'))#.result().get_counts()

