from qiskit import QuantumCircuit, Aer,execute, IBMQ,transpile
from qiskit.visualization import *
from qiskit.test.mock import FakeVigo

qc=QuantumCircuit(3)
qc.h(0)
qc.cx(0,1)
qc.cx(0,2)
qc.measure_all()
qc.draw(output="mpl")

qc.depth()

# on the ideal simulator
backend=Aer.get_backend('qasm_simulator')
job=execute(qc,backend,shots=1024)
result=job.result()
counts=result.get_counts()
print(counts)

backend = FakeVigo()
job=execute(qc,backend,shots=1024)
result=job.result()
counts=result.get_counts()
print(counts)

transpile_circuit=transpile(qc,backend)
job=backend.run(transpile_circuit)
result=job.result()
counts=result.get_counts()
print(counts)

transpile_circuit.draw(output="mpl")

transpile_circuit.depth()

plot_circuit_layout(transpile_circuit, backend)

transpile_circuit_new=transpile(qc,backend,optimization_level=2,initial_layout=[0,1,2])
job=backend.run(transpile_circuit_new)
result=job.result()
counts=result.get_counts()
print(counts)

transpile_circuit_new.draw(output="mpl")

transpile_circuit_new.depth()

plot_circuit_layout(transpile_circuit_new,backend)

