# Hello Quantum

So the previous blogs gave an introduction to what quantum computing is and further went on to give a basic idea on two single qubit gates, Hadamard and Pauli-X aka the bit flip, There are many companies currently researching and investing in quantum computing, big names like IBM, Microsoft, Google, and startups like Rigetti and Xanadu. Quantum Information Science Kit, Qiskit is IBM's quantum computing framework to create and manipulate quantum programs.

Over the past few blog posts I posted the physics and math behind operations on qubits, this blog will focus on writing some code, to be specific we'll create a Bell State, so what is a bell state?

A bell state is an entangled state  of two qubits

A bell state is achieved using a CNOT gate and a Hadamard gate, a Hadamard gate puts a qubit into a state of superposition, the CNOT gate, that is the controlled NOT is a gate which acts on two qubits, one qubit acts as the control bit while the other is the target qubit. Now on applying the CNOT gate to a 2 qubit register, if the control bit is |1> the target bit flips that is if the target bit is |0> it becomes a |1> and if it is |1> it becomes a |0> and if the control bit is |0> the target bit is unchanged.

Now with that settled let's write some code. I'll be using Qiskit for coding, you can find more details on Qiskit and how to install it here

The code below should be executed in a Jupyter Notebook

`from qiskit import QuantumCircuit,QuantumRegister`
`from qiskit import ClassicalRegister,Aer,execute%matplotlib inlinefrom qiskit.tools.visualization import plot_histogram`

`q = QuantumRegister(2) c = ClassicalRegister(2) circ = QuantumCircuit(q,c)`

`circ.h(q[0])circ.cx(q[0],q[1])circ.measure(q,c)circ.draw(output='mpl') `

`backend = Aer.get_backend('qasm_simulator')job = execute(circ,backend=backend,shots=1000)result = job.result()plot_histogram(result.get_counts()) `

Now what exactly happened here?

First we import QuantumCircuit, QuantumRegister, ClassicalRegister,Aer and execute from qisit

Aer is a high performance simulator for quantum circuits , next we create a 2 qubit quantum register and a 2 bit classical register, then we compose a circuit

Each qubit is accesed via indexing q[0] denotes the 0thqubit and so on. In the next step we put the qubit at 0 to a state of superposition by applying the Hadamard gate, so that the qubit has a 50% chance of collapsing into 1 and a 50% to collapse into a 0 while measuring. We also apply a CNOT with qubit0 as control and qubit1 as target ( in the circuit diagam q30 and q31
respectively). Now we measure the qubits. Here an interesting thing happens, if qubit0 on measurement yields 0 qubit1 will also be 0 and if qubit0 yields 1 qubit1 will also yield 1. This is what we get in the histogram below, we do this a 1000 times and we get a 46.6% chance of the classical register being in 00 and a 53.4% chance that it is in 11. Weird isn't it, somehow our two qubits have managed to communicate with each other so that when we measure qubit0 to be 0 qubit1 automatically becomes a 0 and if qubit0 is 1 qubit1 is a 1. This is an entangled state.

Due to the superposition, measurement of the qubit0 will collapse it into one of its basis states with a given probability.Because of the entanglement, measurement of one qubit will assign one of two possible values to the other qubit instantly.Bell states can be generalized to represent specific quantum states of multi-qubit systems, such as the GHZ state for 3 subsystems. Understanding of the Bell states is essential in analysis of quantum communication

Aug. 12, 2019, 11:37 p.m.