Quantum Gates

by TecnoProfesor in Teachers > Coding

3047 Views, 6 Favorites, 0 Comments

Quantum Gates

Captura.PNG

"In the late twentieth century it was discovered that quantum theory applies not only to atoms and molecules, but to bits and logic operations in a computer..."

"Our everyday computers perform calculations and process information using the standard (or classical) model of computation...In this model, all information is reducible to bits, which can take the values of either 0 or 1..."

"The power of the quantum computer, meanwhile, lies in its much richer repertoire of states. A quantum computer also has bits — but instead of 0 and 1, its quantum bits, or qubits, can represent a 0, 1, or linear combination of both ..."

"While today’s quantum processors are modest in size, their complexity grows continuously. We believe this is the right time to build and engage a community of new quantum learners, spark further interest in those who are curious, and foster a quantum intuition in the greater community. By making quantum concepts more widely understood — even on a general level — we can more deeply explore all the possibilities quantum computing offers, and more rapidly bring its exciting power to a world whose perspective is limited by classical physics."

(IBM Introduction to quantum computing)

In this instructable I try to show you an easy introduction to the quantum computing and how to create your first quantum circuits in the IBM Quantum Composer.

Moreover we will create several quantum gates and we will learn how to use an universal and reversible quantum gate, the Toffoli gate, to create in a easy way the OR, AND, NOR and NAND quantum gates to compute any arbitrary no reversible classsical boolean functions.

I hope you like it.

The Qubit

Captura.PNG
Captura.PNG

What we have described here is the abstract notion of a qubit. The quantum computers you interact with in IBM Quantum use a physical type of qubit.

For a superconducting qubit to behave as the abstract notion of the qubit, we must have the device at drastically low temperatures.

Once a system has cooled to the target temperature, which takes several days, the qubit reaches equilibrium at the ground state |0>.

In the image you can see a circuit with one qubit (q0) initialize to the ground state and its Q-sphere.

Open in IBM Quantum Composer

The Standard Measurement

Captura.PNG
Captura.PNG

Here, the reset operation prepares the qubit in the |0> state, and is followed by the standard measurement.

As you can see the probability our circuit was in the ground state is 100%

Open in IBM Quantum Composer

The NOT Quantum Gate

Captura.PNG
Captura.PNG

As you may have guessed, we need to be able to put the qubit in other states. To do this, we require the concept of a quantum gate.

Quantum gates must be reversible and preserve probability amplitudes

Quantum gates are a convenient way in which to describe the evolution of a quantum state. The action of a gate is to transform an initial state into a final state.

The simplest gate is the NOT gate: it flips the 0 to a 1, or vice versa

Open in IBM Quantum Composer

FAN-OUT Gate

Captura.PNG
Captura.PNG

After the execution of this gate, the qubit 1, initialized to the state |0>, will have the same value as qubit 0

Open in IBM Quantum Composer

The Toffoli Quantum Gate

Captura.PNG
Captura.PNG

A quantum gate or quantum logic gate is a rudimentary quantum circuit operating on a small number of qubits.

They are the analogues for quantum computers to classical logic gates for conventional digital computers.

Quantum logic gates are reversible, unlike many classical logic gates.

Some universal classical logic gates, such as the Toffoli gate, provide reversibility and can be directly mapped onto quantum logic gates.

The Toffoli gate has 3-qubits inputs and outputs.

Toffoli (q0,q1,q2) = (q0),(q1),(XOR (q2, AND (q0,q1))

INPUTS OUTPUTS
q0 q1 q2 q0 q1 q2
0 0 0 0 0 0
0 0 1 0 0 1
0 1 0 0 1 0
0 1 1 0 1 1
1 0 0 1 0 0
1 0 1 1 0 1
1 1 0 1 1 1
1 1 1 1 1 0

The inputs in the image are red colored and the outputs are green colored.

The barriers is just only for visualization purpose. To separate the initial inputs from the rest of the circuit.

Please, pay attention how this final state is represented in the probabilities graph.

Go to the composer and proof how the outputs change when you change the inputs

Open in IBM Quantum Composer

The NAND (AND) Gates From the Toffoli Gate

Captura.PNG
Captura.PNG

The classical NAND gate is not reversible, so we have to use the universal reversible Toffoli gate to create the quantum NAND gate.

Let us have a look to the truth table of the Toffoli gate.

INPUTS OUTPUTS
q0 q1 q2 q0 q1 q2
0 0 0 0 0 0
0 0 1 0 0 1
0 1 0 0 1 0
0 1 1 0 1 1
1 0 0 1 0 0
1 0 1 1 0 1
1 1 0 1 1 1
1 1 1 1 1 0

If you pay attention, the inputs q0 and q1 (red) are all the possibles values for two classical bits and the output q2 (blue) implements the NAND gate. The input q2 (red) always is 1 and the ouputs q0 and q1 (blue) replicate the inputs values.

In the circuit in the image you can see the qubit q2 initialized to the ground state and after that a NOT gate to flip its state to |1>.

So, the quantum circuit implements:

Toffoli (q0,q1,1) = (q0),(q1),(XOR (1, AND (q0, q1))) = (q0),(q1), (NAND (q0,q1))

To implement the AND gate just only apply a NOT gate to the qubit q2.

AND (q0,q1) = NOT (NAND (q0,q1))

Open in IBM Quantum Composer

The OR (NOR) Gates From the Toffoli Gate

Captura.PNG
Captura.PNG
Captura.PNG

Again, the classical OR gate is not reversible, so we have to use the universal reversible Toffoli gate to create the quantum OR gate.

We can obtain it in the following way:

Toffoli (1,q1,Toffoli (q2,q1,q2)) = (1),(q1),(XOR (q2, AND (q2, q1))) = (1),(q1), (OR (q2,q1))

In the circuit:

  • q0 is always |1>
  • The circuit implement1 OR (q1,q2) and the result is present in q3
  • In the image the gate is showing OR (1, 0) = 1

To implement the NOR gate just only apply a NOT gate to the qubit q3

NOR (q1,q2) = NOT (OR (q1,q2))

Open in IBM Quantum Composer

The XOR Gate From the Toffoli Gate

Captura.PNG
Captura.PNG

We can obtain the XOR gate from the Toffoli gate in the next way:

Toffoli (1,q1,q2) = (1),(q1),(XOR (q2, AND (1, q1))) = (1),(q1), (XOR (q2,q1))

In the circuit:

  • q0 is always |1>
  • The gate implement XOR (q1,q2) and the result is present in q3
  • In the image the gate is showing XOR (1, 1) = 0

Open in IBM Quantum Composer

Quantum Circuit to Implement a Boolean Function

Captura.PNG
Captura.PNG

One we have create the OR, AND and NOT gate we have a set of universal quantum gates to implement whatever logical boolean function.

In the image you can see the circuit that implements:

f = (q0 AND q1) OR q4

In the circuit:

  • q3 is always |1>
  • The circuit implements f (q0,q1,q4) and the result is present in q5
  • In the image the gate is showing f (1, 1, 0) = 1

Open in IBM Quantum Composer

Futures Projects

With this instructable you can implement whatever logical function using a quantum circuit because we have created at least three set of universal quantum gates: (NOT, AND OR), NAND, NOR.

But the real power of a quantum computer are the superposition and the entanglement.

Two properties we have not used for in this instructable.

It is still very difficult to create clear and intuitive quantum circuits to demostrate its powerful.