from qiskit import *
from math import pi
from qiskit.visualization import plot_bloch_multivector
The single-qubit gates available are:
We have provided a backend: unitary_simulator
to allow you to calculate the unitary matrices.
# Let's do an X-gate on a |0> qubit
qc = QuantumCircuit(1)
qc.x(0)
qc.draw('mpl')
# Let's see the result
backend = Aer.get_backend('statevector_simulator')
out = execute(qc,backend).result().get_statevector()
print(out)
plot_bloch_multivector(out)
[0.+0.j 1.+0.j]
# Run the quantum circuit on a unitary simulator backend
backend = Aer.get_backend('unitary_simulator')
job = execute(qc, backend)
result = job.result()
# Show the results
print(result.get_unitary(qc, decimals=3))
[[0.+0.j 1.+0.j] [1.+0.j 0.+0.j]]
# Let's do an X-gate on a |0> qubit
qc = QuantumCircuit(1)
qc.y(0)
qc.draw('mpl')
# Let's see the result
backend = Aer.get_backend('statevector_simulator')
out = execute(qc,backend).result().get_statevector()
print(out)
plot_bloch_multivector(out)
[0.+0.j 0.+1.j]
# Run the quantum circuit on a unitary simulator backend
backend = Aer.get_backend('unitary_simulator')
job = execute(qc, backend)
print(out)
result = job.result()
# Show the results
print(result.get_unitary(qc, decimals=3))
[0.+0.j 0.+1.j] [[0.+0.j 0.-1.j] [0.+1.j 0.+0.j]]
qc = QuantumCircuit(1)
qc.z(0)
qc.draw(output='mpl')
# Let's see the result
backend = Aer.get_backend('statevector_simulator')
out = execute(qc,backend).result().get_statevector()
print(out)
plot_bloch_multivector(out)
[1.+0.j 0.+0.j]
# Run the quantum circuit on a unitary simulator backend
backend = Aer.get_backend('unitary_simulator')
job = execute(qc, backend)
print(out)
result = job.result()
# Show the results
print(result.get_unitary(qc, decimals=3))
[1.+0.j 0.+0.j] [[ 1.+0.j 0.+0.j] [ 0.+0.j -1.+0.j]]
# Let's do an X-gate on a |0> qubit
qc = QuantumCircuit(1)
qc.x(0)
qc.x(0)
qc.y(0)
qc.y(0)
qc.z(0)
qc.z(0)
qc.draw('mpl')
# Let's see the result
backend = Aer.get_backend('statevector_simulator')
out = execute(qc,backend).result().get_statevector()
print(out)
plot_bloch_multivector(out)
[1.+0.j 0.+0.j]
# Run the quantum circuit on a unitary simulator backend
backend = Aer.get_backend('unitary_simulator')
job = execute(qc, backend)
result = job.result()
# Show the results
print(result.get_unitary(qc, decimals=3))
[[1.+0.j 0.+0.j] [0.+0.j 1.+0.j]]
# Let's do an X-gate on a |0> qubit
qc = QuantumCircuit(2)
qc.x(0)
qc.y(1)
qc.draw('mpl')
# Let's see the result
backend = Aer.get_backend('statevector_simulator')
out = execute(qc,backend).result().get_statevector()
print(out)
plot_bloch_multivector(out)
[0.+0.j 0.+0.j 0.+0.j 0.+1.j]
Y⊗X
# Run the quantum circuit on a unitary simulator backend
backend = Aer.get_backend('unitary_simulator')
job = execute(qc, backend)
result = job.result()
# Show the results
print(result.get_unitary(qc, decimals=3))
[[0.+0.j 0.+0.j 0.+0.j 0.-1.j] [0.+0.j 0.+0.j 0.-1.j 0.+0.j] [0.+0.j 0.+1.j 0.+0.j 0.+0.j] [0.+1.j 0.+0.j 0.+0.j 0.+0.j]]
# Let's do an X-gate on a |0> qubit
qc = QuantumCircuit(2)
qc.x(0)
qc.y(1)
qc.z(0)
qc.x(1)
qc.draw('mpl')
# Let's see the result
backend = Aer.get_backend('statevector_simulator')
out = execute(qc,backend).result().get_statevector()
print(out)
plot_bloch_multivector(out)
[0.+0.j 0.+0.j 0.+0.j 0.+1.j]
(X⊗Z)×(Y⊗X)
# Run the quantum circuit on a unitary simulator backend
backend = Aer.get_backend('unitary_simulator')
job = execute(qc, backend)
result = job.result()
# Show the results
print(result.get_unitary(qc, decimals=3))
[[0.+0.j 0.+0.j 0.+0.j 0.-1.j] [0.+0.j 0.+0.j 0.-1.j 0.+0.j] [0.+0.j 0.+1.j 0.+0.j 0.+0.j] [0.+1.j 0.+0.j 0.+0.j 0.+0.j]]
# Let's do an X-gate on a |0> qubit
qc = QuantumCircuit(3)
qc.x(0)
qc.y(1)
qc.z(2)
qc.draw('mpl')
# Let's see the result
backend = Aer.get_backend('statevector_simulator')
out = execute(qc,backend).result().get_statevector()
print(out)
plot_bloch_multivector(out)
[0.+0.j 0.+0.j 0.+0.j 0.+1.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]
Z⊗Y⊗Z
# Run the quantum circuit on a unitary simulator backend
backend = Aer.get_backend('unitary_simulator')
job = execute(qc, backend)
result = job.result()
# Show the results
print(result.get_unitary(qc, decimals=3))
[[ 0.+0.j 0.+0.j 0.+0.j 0.-1.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 0.+0.j 0.-1.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 0.+1.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j] [ 0.+1.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+1.j] [ 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+1.j 0.+0.j] [ 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j -0.-1.j 0.+0.j 0.+0.j] [ 0.+0.j 0.+0.j 0.+0.j 0.+0.j -0.-1.j 0.+0.j 0.+0.j 0.+0.j]]