[Translation] How quantum computing can affect software development

[Translation] How quantum computing can affect software development


For about the past six months, the publishing house has been actively working on the topic of quantum computing and its practical applicability. For a long time it was not possible to find a decent article for translation on this interesting topic, until such an article appeared in the Oracle blog. The publication will serve as an excellent introduction to the software, and hardware, and to the purely natural-science problems of this new paradigm, therefore - be sure to read.

In recent months and years, interest in quantum computing has increased significantly. Constantly there are new materials from research institutes, companies or government organizations, telling about breakthrough achievements in this area. At the same time, articles with a weaker technical basis talk about the potential consequences of quantum computing, and the predictions range from hacking into most modern encryption techniques to promises to cure all diseases and complete work on creating a full-fledged AI. However, not all of these expectations are equally realistic.

If you are a practicing sober programmer, then you must be wondering where the boundary between facts and fiction is in these calculations, and how quantum computing will affect software development in the future.

Naturally, there are still many years to create working hardware for quantum computing. However, the general principles of this paradigm are clear today, there are abstractions that allow developers to create applications in which the possibilities of quantum computing are realized using simulators.

Is quantum computing going down to another CPU boost?

Traditional software development using classic computers is associated with the translation of a high-level programming language (for example, Java) into operations performed on a large number of (hardware) transistors.

In Figure 1, this process is schematized in the simplest form: Java source code is compiled into platform-independent byte code, which, in turn, is translated into platform specific machine code. The machine code uses a number of simplest operations (gates) performed in memory. The main hardware component used for this purpose is the well-known transistor.

Fig. 1. Translating a high-level programming language into operations performed on transistors .

The increase in productivity obtained in recent years has been achieved mainly due to improvements in hardware technology. The size of a single transistor has drastically decreased, and the more transistors you can put on each square millimeter, the more memory and computing power your computer will have.

Quantum computing is a disruptive technology, since here the simplest computational units are not classic transistors, but qubits, which we will talk about below.

It is not only the difference between these primary elements, but also a different valve device. Thus, the stack with fig. 1 is not applicable to quantum computing.

Will quantum computations destroy the entire stack up to the Java level?

In short - "not really." Scientists gradually agree that quantum computers will be especially good for solving specific problems, while other problems will be more rational with traditional computers. Sounds familiar, right? A similar situation is observed when comparing the GPU and CPU. Whereas transistors are also used in the GPU, they differ from the CPU in the way they work.However, many applications written in high-level language, under the hood use the capabilities of both the CPU and the GPU. GPUs are very good for vector processing, and in many applications and libraries the work of the CPU and the GPU is delimited.

For example, this is exactly the situation when using JavaFX or Deeplearning4j. If you are writing a user interface application using JavaFX, then you only work with Java code (maybe, even, with FXML to declare the user interface). When the JavaFX scene needs to be displayed on the screen, the internal JavaFX implementations use shaders and textures for this, directly contacting low-level GPU drivers, as shown in Figure 2. So you don’t have to worry which part of the code is better suited for working with CPUs, and which with GPU.

Fig. 2. JavaFX delegates the work of the GPU and CPU.

As shown in fig. 2, JavaFX implementation code delegates work by passing it to the GPU and CPU. Although, from the developer, these operations are hidden (not provided through the API), some knowledge of the GPU is often useful when you need to develop more productive JavaFX applications.

When using Deeplearning4j there is a similar situation. Deeplearning4j has a number of implementations for performing the required vector and matrix operations, and some of them use GPUs. However, as a final developer, it doesn’t matter to you what capacities your code will use — CPU or GPU.

It seems that quantum computers will do an excellent job with solving problems that, as a rule, grow exponentially as the task grows and, therefore, difficult to solve or almost impossible to solve using classic computers. In particular, experts talk about a hybrid version: a typical end-to-end application contains a classic code running on a CPU, but it can also contain a quantum code.

How can the system execute a quantum code?

Today, hardware for quantum computers is still very experimental. While large corporations and, presumably, some states are engaged in the development of prototypes, there is no such equipment in wide access. But when it appears, its shape can be different:

  • The quantum coprocessor can be integrated with the CPU in the system.
  • Quantum tasks can be delegated to quantum cloud systems.

Although, there remains a huge uncertainty about the practical background of such decisions, we are coming to a greater agreement on how the quantum code should look. At the lowest level should be the following building blocks: qubits and quantum gates . Based on them, you can create quantum simulators that implement the expected behavior.

Therefore, a quantum simulator is an ideal tool for such development.
The results given by him should be almost the same as would be obtained on real equipment of a quantum computer - but the simulator runs much slower, since quantum effects accelerating quantum equipment have to be simulated using traditional software.

What are the basic building blocks of quantum computing?

It is often important to compare classical calculations with quantum ones. In classic calculations, we have bits and gates.

The bit contains a single bit of information, and its value can be 0 or 1.
The gate acts on one or more bits and can operate with them. For example, the NOT gate shown in Figure 3 changes the value of a bit to the opposite. If the input is 0, the output of the NOT gate will be 1 and vice versa.

Fig. 3Gate NOT

In quantum computing, we have the equivalent of bits and gates. The quantum equivalent of a bit is qubit. The qubit value can be 0 or 1, as in the classical bit, however, it can also be in the so-called superposition. This is a complex representation, according to which a qubit can simultaneously be in both states: 0 and 1.
When a qubit is in superposition, its value is a linear combination of states 0 and 1. It can be written as shown in Fig. 4:

Fig. 4. Equality where the qubit is in superposition.

Please note: qubits are often recorded in bracet notation , where the variable name is placed between the characters" | " and "& gt;".

The expression in fig. 4 reports that the qubit x is in a superposition of states | 0 & gt; and | 1 & gt; This does not mean that it is in the state | 0 & gt; OR able | 1 & gt ;; this means that we do not know its current state.

In fact, it is in both states at the same time, and in this form it can be manipulated. However, when we measure a qubit, it will be in one state, either | 0 & gt; or | 1 & gt ;. In the above expression, there is another restriction: a ^ 2 + b ^ 2 = 1.
The values ​​of a and b are probabilistic: there is a probability a ^ 2 that when we measure the qubit | x & gt; it will have the value | 0 & gt; and the probability b ^ 2 that the measured qubit will contain the value | 1 & gt;

There is an important limiting factor breaking off the joys of quantum computing: after a qubit is measured, all information about the potential superposition in which it was located is lost. The qubit value can be 0 or 1.

When calculating, a qubit in a superposition can simultaneously correspond to 0 and 1 (with different probabilities). If we have two qubits, then they can be used to represent four states (00, 01, 10, and 11), again, with different probabilities. Here we come to the essence of all the power of quantum computers. Having eight classic bits, you can imagine exactly one number in the range from 0 to 255. The values ​​of each of the eight bits will be 0 or 1. With eight qubits, you can simultaneously represent all numbers from 0 to 255.

What is the benefit of superposition, if you can measure only one state?

Often the result of the algorithm is simple (“yes” or “no”), but to come to it, a lot of parallel computations are required. By holding qubits in superposition during calculations, you can immediately take into account any number of different options. By not making decisions for each individual combination, a quantum computer can calculate all the options in one step.
Then, in many quantum algorithms, the following important stage begins: to associate the result of the algorithm with a measurement that gives a meaningful result. Often, this takes into account interference: interesting results overlap constructively, and uninteresting extinguish each other (destructive interference).

How can one “convert” a qubit to a superposition state?

Just as classical gates manipulate bits, quantum gates manipulate qubits. Some quantum gates resemble classic; for example, the Pauli-X gate takes a qubit from the state a | 0 & gt; + b | 1 & gt; in the state b | 0 | + a | 1 & gt ;, which is similar to the principle of the classical NOT gate. Indeed, when a = 1 and b = 0, the qubit was initially in the state | 0 & gt ;. After the impact of the Pauli-X gate, this qubit will go to the | 1 & gt; state, as shown in fig. 5.

Fig. 5. The result of using the valve Pauli-X.

In this context, the Hadamard valve is very interesting.It translates into a superposition a qubit that was in the state | 0 & gt ;: 1/sqrt (2) * (| 0 & gt; + | 1 & gt;), as shown in Fig. 6.

Fig. 6. The result of applying the Hadamard valve.

After we apply the Hadamard valve to the qubit and measure the qubit, there is a 50% chance that the qubit value will be 0 and 50% - that the qubit value will be 1. As long as the qubit is not measured, it remains in the superposition state .

How is all this possible?

If you are really interested in the answer to this question, you will have to study in detail quantum physics. But, fortunately, the entire theoretical basis of these phenomena is not required. While the phenomenon of superposition may seem incomprehensible, it is important to emphasize that it is precisely these properties that are characteristic of elementary particles in nature. Therefore, quantum computing is much closer to the basics of physical reality than it seems at first glance.

Should I wait a few years, and then look closely at quantum computing?

Not. In this case, you will be late. It is theoretically possible to first develop the hardware, and then proceed to the study of the software level and see what can be achieved with it. However, all concepts are already more or less clear, and it is already possible to write quantum simulators in popular languages, including Java, C #, Python, and others.
Then these simulators can be used to work on quantum algorithms. Although, these algorithms will not give such a performance increase, which is achievable with their help when working on real quantum equipment, functionally they should turn out to be completely valuable.

Thus, if you are currently developing a quantum algorithm, then you have time to improve it, and you can run it when quantum equipment is available.

Quantum algorithms require a different intellectual approach than the classical ones. Outstanding scientists began to develop quantum algorithms in the last century, and now more and more articles are published describing such algorithms, including, for multiplying whole numbers, searching lists, working on path optimization and much more.

There are other reasons why you might want to do quantum computing today. Refactoring the software system in a modern large company is not one of those things that can be done overnight. However, one of the areas in which quantum computing will produce a real revolution is encryption; because everything is based on the theory that on a classic computer it is almost impossible to decompose a large integer into prime factors.

Although it may take many years before quantum computers become large enough to easily solve the problem of integer factorization, developers know that it takes many years to change systems and implement new, safer technologies in them.

How can you learn how to work with quantum algorithms in Java?

You can download and learn Strange , an open-source Java quantum computer simulator. Strange allows you to simulate a quantum algorithm by creating a series of qubits and applying several quantum gates to them.

As the simplest example, let's create two qubits, q [0] and q [1], so that both of them are initially in state 0. Then we apply two simple gates to each of the qubits, so that this operation graphically corresponds to fig. 7.

The first qubit will first hit the Pauli-X valve, and then the Hadamard valve. The Pauli-X valve will bring it from the state | 0 & gt to | 1 & amp; gt, and the Hadamard valve will translate into a superposition with equal probabilities | 0 & amp; gt and | 1 & amp; gt.Therefore, if we perform the entire sequence 1000 times, and we measure the first qubit 1000 times at the end of this cycle, then on average we can expect that in 500 cases it will have a value of 0 and in 500 cases it will have a value of 1.

The second qubit is even simpler. We start with the Identity gate, which does not change the behavior of the qubit, and then pass it to the Pauli-X gate, changing its value from 0 to 1.

Fig. 7. An example of a quantum algorithm that can be simulated with Strange.

To make sure that our reasoning is correct, you can create a simple quantum program with Strange.

  public static void main (String [] args) {
  Program p = new Program (2);
  Step s = new Step ();
  s.addGate (new X (0));
  p.addStep (s);
  Step t = new Step ();
  t.addGate (new Hadamard (0));
  t.addGate (new X (1));
  p.addStep (t);
  SimpleQuantumExecutionEnvironment sqee = new SimpleQuantumExecutionEnvironment ();
  Result res = sqee.runProgram (p);
  Qubit [] qubits = res.getQubits ();
  Arrays.asList (qubits) .forEach (q - & gt; System.out.println ("qubit with probability on 1 =" + q.getProbability () + ", measured it gives" + q.measure ()));

This application creates a quantum program with two qubits:

  Program p = new Program (2);  

Within this program we go through two stages. At the first stage, we use the Pauli-X valve to q [0]. We do not apply the gate to q [1], and thus we assume that it will work with the Identity gate. Add this step to the program:

  Step s = new Step ();
  s.addGate (new X (0));
  p.addStep (s);  

Then we proceed to the second stage, where we apply the Hadamard valve to q [0] and the Pauli-X valve to q [1]; add to the program and this step:

  Step t = new Step ();
  t.addGate (new Hadamard (0));
  t.addGate (new X (1));
  p.addStep (t);  

So, our program is ready. Now let's do it. A quantum simulator is built into Strange, however, Strange can also use the cloud service to run programs in some cloud, for example, SimpleQuantumExecutionEnvironment sqee = new SimpleQuantumExecutionEnvironment ();   Result res = sqee.runProgram (p);   Qubit [] qubits = res.getQubits ();

Before we measure the qubits (and lose all the information), we display the probabilities. Now measure qubits and look at the values:

  Arrays.asList (qubits) .forEach (q -> System.out.println ("qubit with probability on 1 =" + q.getProbability () +, measured it gives  "+ q.measure ()));  

Running this application, we get the following output:

qubit with probability on 1 = 0.50, measured it gives 1
qubit with probability on 1 = 1, measured it gives 1

Note: for the first qubit, the value of 0 can also be measured, as we expected.
If you run this program many times, the value of the first qubit will be on average 0 in half the cases and 1 in half the cases.

Is that all you need to know about quantum computing?

Of course not. Here we did not touch on a number of important concepts, in particular, we did not discuss entanglement , which ensures interaction between two qubits, even if physically they are very far from each other. We didn’t talk about the most famous quantum algorithms, among which is Shor’s algorithm, which allows decomposing integers into prime factors.We also ignored a number of mathematical and physical facts, in particular, did not take into account that in the superposition | x & gt; = a | 0 & gt; + b | 1 & gt ;, both numbers, a and b, can be complex.

However, the main purpose of this article was to give you an impression of quantum computing and how it fits into the future of software development.

Source text: [Translation] How quantum computing can affect software development