Quantum programming short introduction

Quantum computing, as well as the entire field of quantum mechanics, is currently a strongly researched branch of knowledge with high hopes. Cryptography, communication, scientific and research works, biological or chemical industries are just some of the fields that could revolutionize computers of this type.


And although currently the practical application of quantum computers is negligible, more and more startups are emerging exploring the possibilities of these devices. Also private companies like Google, IBM, Intel, or universities and governments like China are achieving more and more successes in this field. In addition, selected companies, such as Microsoft, in their Azure platform, provide users with a service that allows them to run their own source code on a real quantum computer. Therefore, for some it may be a good time to start learning quantum programming.


But what exactly is a quantum computer? Quantum computers are devices that use phenomena occurring in quantum mechanics and work on the smallest elements of our reality – quantum particles, most often electrons or photons. These is possible by making appropriate changes to the particles using precise lasers or microwave beams in a specially created environment (often the temperature in such computers can be kept close to absolute zero). In fact, a quantum computer actually works more like a coprocessor that is managed by a classical computer. A classical computer sends commands to a quantum computer to start calculations suitable for quantum tasks and awaits the result. Quantum computers are not always able to be faster than classical computers and their use makes sense only in selected algorithmic problems.


Bits and Qubits

The basic unit of information in any classical computer is one bit which can take the value of zero or one. These values are physically represented by transistors to which electrical voltage is sent. Zero occurs when there is no voltage across the transistor and one when there is voltage across the transistor. Properly combining transistors and voltage, we can perform all the operations known to today’s computers.


Quantum computers operate on analogous values called qubits. In these computers, the qubit is physically represented by a single electron or photon which can be influenced by using precise lasers or microwave beams. The qubit, as in classical computers, assumes the value of zero and one. Nevertheless, qubits, thanks to the phenomenon of superposition, can assume any proportion of the values 0 and 1, expressed in the probability of occurrence of the value 0 or 1 during the measurement. Superposition allows a qubit to be in several states at the same time until it is measured. Only the measurement causes the quantum to collapse and ‘forces’ it to determine its value during the measurement.



It is the phenomenon of superposition that allows for a significant acceleration of calculations using quantum computers. Because a properly prepared algorithm allows for ‘simultaneous’ calculations of all qubits. Which even the most powerful classical computer would take several hundred if not more years. And these possibilities grow exponentially with each qubit of information.


In very simple terms, with four bits of information in a classic computer, we would have to check 16 possibilities one by one to check every possible path. In the case of 4 qubits, these values are in superposition and a properly prepared system could check them all at once.


Graphical representation of qubits

The Bloch sphere or circular notation is often used to represent the state of a single qubit.

In the case of the Bloch sphere. Sphere is used to represent probability of getting value 0 or 1 after measurement. If point on bloch sphere is at the north pole then chances of getting value 0 after mesurment is 100%. If point on bloch sphere is at the south pole then chances of getting value 1 after mesurment is 100%. If a point on the surface of the Bloch sphere is somewhere between these two values, then the closer a point on the sphere is to 0, the greater the probability is of getting this value after measurement. The closer a point comes to value 1 on the sphere, the greater the chance of this value occurring after messuring.



If we want to see for ourselves how the values on the Bloch sphere behave, the following tools may turn out to be useful:




Another notation that is often used is the circular notation. For one qubit, it is represented by a circle. How much the circle is filled determines the probability of occuring value 0 or 1. On this notation, we can also see relative phase (Z-axis on the Bloch sphere) of particle. Taking a value from 0 to 360 degrees in the form of a line extending from the center to the circumference of the circle.



Quantum gates


As in classical computers, where logic gates are used which accept signals at the input and return values in the form of zeros and ones. Similarly, quantum computers use logic gates to make calculations. However, these gates operate on qubits whose values are non-deterministic and based on probability. Precision lasers or microwave beams are used to manipulate the probability of qubits (spin for electrons or polarization for photons). Quantum gates are fundamental tools for manipulating quantum particles. Quantum gates must cooperate with physical quantum events, which is why we will find many operations here that do not occur in classical computers.


The most important quantum gates include:


M – Measurement – The measurement act results in the immediate determination of the qubit value and the loss of previous data related to this qubit (phase, probability).



Hadamard Gate – One of the fundamental gates in quantum programming. The qubits that pass through this gate are placed in a coherent superposition where the chance of the value after measurment and collapse will be 50% for |0> and 50% for |1>. In fact, this gate rotates 90 degrees along the Y axis on the Bloch sphere and then rotates 180 degrees along the X axis.



Pauli X Gate (NOT) – Negation – is analogous to the well-known NOT gate in classical computers. This gate changes the value of the qubit from |0> to |1> and from the value |1> to |0>. On the Bloch sphere, this gate rotates 180 degrees along the X axis.



Pauli Gate Y – This gate makes a rotation on the Bloch sphere by 180 degrees along the Y axis


Pauli Gate Z – This gate makes a rotation on the Bloch sphere by 180 degrees along the Z axis



Rx, Ry, Rz -Gates that allow you to rotate the Bloch sphere by a given amount of degrees along the X, Y or Z axis


CNOT – Control NOT – It is a gate operating on two qubits and it is easiest to compare it to the if condition in classical computers. This gate indicates the control qubit and the conditional qubit. If the value in the first qubit is equal to 1, then on the second qubit a NOT gate will be used to negate the value of the qubit.



SWAP – A gate operating on two qubits, with the help of which, as the name suggests, it is possible to exchange values between qubits.



CCNOT Tofoli – A gate operating on three qubits. It is similar in its operation to the CNOT gate, however, it is necessary to obtain value one from first and seccond qubit, if these conditions are met, the value on the third qubit is negated.



There are also other gates but these are one of the basic ones.


Quantum circuts


Just like in classical computers, we can combine logic gates in quantum computers to obtain specialized quantum systems that perform the tasks set by the author.


An example graphical representation of such a quantum system may look like this:



Where each row represents a single qubit and all qubits are grouped into a single register. From left to right, we can see what single operations are performed on each qubit.


There are some interesting tools for designing quantum systems and simulating their behavior step by step. It is definitely worth getting acquainted with them in order to better understand the topic:



Leave a Comment

WordPress Video Lightbox Plugin