Hello!
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, hardware, and purely natural-science problems of this new paradigm, so 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 line 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.
Are quantum computations reduced to another CPU gain?
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. Translation of high-level programming language in the 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 is drastically reduced, and the more transistors you can fit on each square millimeter - the more memory and computing power the computer will have.
Quantum computing is a disruptive technology, since here the simplest computational units are not classical transistors, but qubits, which we will talk about a little later.
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 computing 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 in principle from the CPU. However, many applications written in high-level language use the capabilities of both the CPU and the GPU under the hood. 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 these operations are hidden from the developer (not provided through the API), some knowledge of the GPU is often useful when you need to develop more efficient 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 embodiment: a typical end-to-end application contains a classic code running on a CPU, but it can also contain a quantum code.
How can a 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 form may 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. The lowest building blocks should be at the lowest level:
qubits and
quantum gates . On their basis, 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 hardware of a quantum computer - but the simulator runs much slower, since quantum effects accelerating quantum hardware 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 classical 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. 3. Gate NOTIn 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. four:
Fig. 4. Equality, where the qubit is in superposition.Note: qubits are often written in
bra-ket notation , where the variable name is placed between the characters "|" and ">".
The expression in fig. 4 reports that the qubit x is in a superposition of the states | 0> and | 1>. This does not mean that it is in the state | 0> OR in the state | 1>; 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> or | 1>. In the above expression, there is another limitation: 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>, it will have the value | 0>, and the probability b ^ 2 that the measured qubit will contain the value | 1>.
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. With eight classic bits, you can represent 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 quench each other (destructive interference).
How can one “transform” a qubit into a superposition state?
Just as classical gates manipulate bits, quantum gates manipulate qubits. Some quantum gates resemble classic; for example, the Pauli-X gate transfers the qubit from the state a | 0> + b | 1> to the state b | 0 | + a | 1>, which is similar to the principle of operation of the classical NOT gate. Indeed, when a = 1 and b = 0, the qubit was initially in the state | 0>. After the impact of the Pauli-X valve, this qubit enters the state | 1>, as shown in Fig. five.
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>: 1 / sqrt (2) * (| 0> + | 1>), 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 start it when quantum equipment appears in the access.
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, more secure technologies in them.
How can you learn to work with quantum algorithms in Java?
You can download and learn
Strange , an open source simulator of a quantum computer in Java. 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 transfer it from the state | 0 & gt to | 1 & gt, and the Hadamard valve will translate into a superposition with equal probabilities | 0 & gt and | 1 & 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, which changes 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 -> 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 a cloud service to run programs in some cloud, for example,
Oracle Cloud .
In the following example, we use a simple built-in simulator, run the program, and get the resulting qubits:
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 we measure the 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 the
entanglement that ensures the 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> = a | 0> + b | 1>, 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.