Building Blocks of Quantum Circuit

Building Quantum Gate

Building Quantum GateΒΆ

This is a note on the the building blocks of Quantum Circuit. Go through this, we will learn:

  1. the operation of a quantum gate on the qubit
  2. using simulator to get the result
  3. represent it as a bloch sphere
  4. represent it as unitary matrix rather than satevector
In [3]:
%%HTML
<iframe width="560" height="315" src="https://www.youtube.com/embed/tBnWG_95F9c" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

Import the qiskit everyhting into workspace

In [3]:
from qiskit import *

Using visualization tools in qiskit

In [5]:
from qiskit.tools.visualization import plot_bloch_multivector

create a quantum circuit with one qubit and one classical bit

In [ ]:
circuit = QuantumCircuit(1,1)

Quantum will have one quantum operation on it X on that qubit

In [ ]:
circuit.x(0)

Take it and simulate and see the output Use the statevector simulator

In [ ]:
simulator = Aer.get_backend('statevector_simulator')

Execute the circuit on the backend which we the simulator Result will be stored from the execution

In [ ]:
result = execute(circuit, backend = simulator).result()

Statevecor will be the result of that vector

In [ ]:
statevector = result.get_statevector()
print(statevector)
In [ ]:
%matplotlib inline

We draw the circuit The result is the state (0,1) One X gate on it and it gives out (0,0)(1,0)

In [10]:
circuit.draw(output = 'mpl')
[0.+0.j 1.+0.j]
Out[10]:

Using bloch sphere as visualization to see how the state rotate by appling the gate on the state of the bloch vector in the sphere Statevector is the thing we want to describe From state 0 to state 1, pointing down Quantum state for individual qubit can be represneted on the sphere As any point throughout the sruface of the sphere

In [11]:
plot_bloch_multivector(statevector)
Out[11]:

Runnning a circuit through measurement and see what the measreuemnt outcomes are

In [ ]:
circuit.measure([0],[0])

Execute that at the backend

In [ ]:
backend = Aer.get_backend('qasm_simulator')

Do 1024 shots Result take out and put to the result

In [ ]:
result = execute(circuit, backend = backend, shots = 1024).result()

Take it and count the result

In [ ]:
counts = result.get_counts()

Plot by histogram

In [ ]:
from qiskit.tools.visualization import plot_histogram

We have 100% becasue we have state 1 represented by the output of the circuit Measure qubit 0 and put that result into classical bit 0

In [12]:
plot_histogram(counts)
Out[12]:

Using matrix to represent the circuit We change statevector to unitary

In [ ]:
circuit = QuantumCircuit(1,1)
circuit.x(0)

Using unitary simulator

In [ ]:
simulator = Aer.get_backend('unitary_simulator')
result = execute(circuit, backend = simulator).result()
unitary = result.get_unitary()

The printed result is exactly the X gate j is the impaginary part of the state

In [ ]:
print(unitary)

Matplotlib inline

In [13]:
circuit.draw(output = 'mpl')
[[0.+0.j 1.+0.j]
 [1.+0.j 0.+0.j]]
Out[13]: