%matplotlib inline
from qiskit import *
from qiskit.visualization import plot_histogram

circuit = QuantumCircuit(2)
circuit.x(0)
circuit.z(1)
circuit.draw(output="mpl")

unitary_simulator = Aer.get_backend("unitary_simulator")
unitary = execute(circuit, backend=unitary_simulator).result().get_unitary()
print(unitary)

circuit = QuantumCircuit(2)
circuit.h(0)
circuit.x(1)
circuit.cx(0, 1)
circuit.draw(output="mpl")

state_simulator = Aer.get_backend("statevector_simulator")
state_vector = execute(circuit, backend=state_simulator).result().get_statevector()
print(state_vector)

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

state_vector = execute(circuit, backend=state_simulator).result().get_statevector()
print(state_vector)

circuit = QuantumCircuit(3, 3)
circuit.h([0, 1])
circuit.ccx(0, 1, 2)
circuit.measure([0, 1, 2], [0, 1, 2])
circuit.draw(output="mpl")

simulator = Aer.get_backend("qasm_simulator")
counts = execute(circuit, backend=simulator, shots=2**16).result().get_counts()
plot_histogram(counts)

circuit = QuantumCircuit(3, 3)
circuit.x(0)
circuit.cx(0, 1)
circuit.ccx(0, 1, 2)
circuit.ccx(0, 1, 2)
circuit.cx(0, 1)
circuit.x(0)
circuit.measure([0, 1, 2], [0, 1, 2])
circuit.draw(output="mpl")

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