Building Quantum GateΒΆ
This is a note on the the building blocks of Quantum Circuit. Go through this, we will learn:
- the operation of a quantum gate on the qubit
- using simulator to get the result
- represent it as a bloch sphere
- represent it as unitary matrix rather than satevector
%%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
from qiskit import *
Using visualization tools in qiskit
from qiskit.tools.visualization import plot_bloch_multivector
create a quantum circuit with one qubit and one classical bit
circuit = QuantumCircuit(1,1)
Quantum will have one quantum operation on it X on that qubit
circuit.x(0)
Take it and simulate and see the output Use the statevector simulator
simulator = Aer.get_backend('statevector_simulator')
Execute the circuit on the backend which we the simulator Result will be stored from the execution
result = execute(circuit, backend = simulator).result()
Statevecor will be the result of that vector
statevector = result.get_statevector()
print(statevector)
%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)
circuit.draw(output = 'mpl')
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
plot_bloch_multivector(statevector)
Runnning a circuit through measurement and see what the measreuemnt outcomes are
circuit.measure([0],[0])
Execute that at the backend
backend = Aer.get_backend('qasm_simulator')
Do 1024 shots Result take out and put to the result
result = execute(circuit, backend = backend, shots = 1024).result()
Take it and count the result
counts = result.get_counts()
Plot by histogram
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
plot_histogram(counts)
Using matrix to represent the circuit We change statevector to unitary
circuit = QuantumCircuit(1,1)
circuit.x(0)
Using unitary simulator
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
print(unitary)
Matplotlib inline
circuit.draw(output = 'mpl')