from qiskit import *
from qiskit.visualization import plot_histogram

simulator = Aer.get_backend("qasm_simulator")

circuit = QuantumCircuit(1, 1)
circuit.measure(0, 0)
circuit.draw(output="mpl")

job = execute(circuit, backend=simulator, shots=2**15)
result = job.result()
counts = result.get_counts()
print(counts)

plot_histogram(counts)

circuit = QuantumCircuit(1, 1)
circuit.x(0)
circuit.measure(0, 0)
circuit.draw(output="mpl")

counts = execute(circuit, backend=simulator, shots=2**15).result().get_counts()
plot_histogram(counts)

circuit = QuantumCircuit(1, 1)
circuit.h(0)
circuit.measure(0, 0)
circuit.draw(output="mpl")

counts = execute(circuit, backend=simulator, shots=2**15).result().get_counts()
plot_histogram(counts)

# Circuit to generate -|0>
circuit = QuantumCircuit(1, 1)
circuit.x(0)
circuit.z(0)
circuit.x(0)
circuit.measure(0, 0)
circuit.draw(output="mpl")

counts = execute(circuit, backend=simulator, shots=2**15).result().get_counts()
plot_histogram(counts)

# Circuit to generate i|0>
circuit = QuantumCircuit(1, 1)
circuit.x(0)
circuit.y(0)
circuit.measure(0, 0)
circuit.draw(output="mpl")

counts = execute(circuit, backend=simulator, shots=2**15).result().get_counts()
plot_histogram(counts)