from qiskit import QuantumCircuit
from qiskit import Aer, transpile
from qiskit.tools.visualization import plot_histogram

Aer.backends()

simulator = Aer.get_backend('statevector_simulator')

# Create a Quantum Circuit acting on a quantum register of three qubits
circ = QuantumCircuit(3)
# Add a H gate on qubit 0, putting this qubit in superposition.
circ.h(0)
# Add a CX (CNOT) gate on control qubit 0 and target qubit 1
circ.cx(0, 1)
# Add a CX (CNOT) gate on control qubit 0 and target qubit 2, putting
# the qubits in a GHZ state.
circ.cx(0, 2)

circ.draw('mpl')

# Create a Quantum Program for execution
result = simulator.run(circ).result()

counts = result.get_counts(circ)
print(counts)

plot_histogram(counts)

simulator = Aer.get_backend('aer_simulator')

# Create a Quantum Circuit acting on a quantum register of three qubits
circ = QuantumCircuit(3)
# Add a H gate on qubit 0, putting this qubit in superposition.
circ.h(0)
# Add a CX (CNOT) gate on control qubit 0 and target qubit 1
circ.cx(0, 1)
# Add a CX (CNOT) gate on control qubit 0 and target qubit 2, putting
# the qubits in a GHZ state.
circ.cx(0, 2)

circ.measure_all()
circ = transpile(circ, simulator)

# Run and get counts
result = simulator.run(circ).result()
counts = result.get_counts(circ)
plot_histogram(counts, title='GHZ State counts')

result = simulator.run(circ, shots=10, memory=True).result()

memory = result.get_memory(circ)
print(memory)

# IBMQ.load_account()

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

# device = provider.get_backend('ibmq_16_melbourne')

# job = execute(circuit,backend = device,shots = 1024)

# print(job.job_id())

# device_result = job.result()

# plot_histogram(device_result.get_counts(circuit))