Complete Download Quantum Computing For Developers A Java Based Introduction MEAP V09 Johan Vos PDF All Chapters
Complete Download Quantum Computing For Developers A Java Based Introduction MEAP V09 Johan Vos PDF All Chapters
com
https://textbookfull.com/product/quantum-computing-for-
developers-a-java-based-introduction-meap-v09-johan-vos/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/quantum-computing-in-action-
meap-v09-johan-vos/
textboxfull.com
https://textbookfull.com/product/parallel-and-high-performance-
computing-meap-v09-robert-robey/
textboxfull.com
https://textbookfull.com/product/scala-for-java-developers-a-
practical-primer-1st-edition-toby-weston/
textboxfull.com
A First Introduction to Quantum Computing and Information
Bernard Zygelman
https://textbookfull.com/product/a-first-introduction-to-quantum-
computing-and-information-bernard-zygelman/
textboxfull.com
https://textbookfull.com/product/java-cookbook-problems-and-solutions-
for-java-developers-early-release-ian-f-darwin/
textboxfull.com
https://textbookfull.com/product/mastering-corda-blockchain-for-java-
developers-1st-edition-jamiel-sheikh/
textboxfull.com
https://textbookfull.com/product/introducing-maven-a-build-tool-for-
today-s-java-developers-second-edition-balaji-varanasi/
textboxfull.com
https://textbookfull.com/product/java-cookbook-problems-and-solutions-
for-java-developers-final-release-4th-edition-ian-f-darwin/
textboxfull.com
MEAP Edition
Manning Early Access Program
Quantum Computing for Developers
A Java-based introduction
Version 9
—Johan Vos
The amount of books, articles and blog posts about Quantum Computing is increasing. Even if
you read only very basic information about Quantum Computing, it is clear that this is not just an
incremental enhancement of classical computing. The core concepts of Quantum Computing are
fundamentally different, but also its application area is very different. In some areas, Quantum
computers are expected to be able to address problems that classical computers are unable to.
Furthermore, since Quantum Computing is based on quantum physics, there is often some
mystery associated with it. Quantum physics is not the simplest part of physics, and some aspects
of quantum physics are extremely difficult to understand.
All combined, Quantum Computing is often pictured as some mysterious new way of working
with data, that will change the world drastically. The latter is true, at least based on what we
know at this moment. Many analysts believe it will take between 5 and 10 years before real
useful Quantum Computing is possible, and most believe the impact will be huge.
In this book, we try to stay close to reality. We want to explain to existing and new Java
developers how they can leverage Quantum Computing in their existing and new applications.
As we will show, Quantum Computing has indeed a huge impact on a number of important
issues in the IT industry. We will also explain why it is important to prepare for the arrival of
real quantum computers, and how you can do that, using Java and your favourite toolset (i.e.
your IDE and build tools). While it is true that real quantum hardware is not yet available on a
wide scale, developers should realise that building software leveraging quantum computing takes
time as well. Thanks to quantum simulators and early prototypes, there is nothing that prevents
developers to start working on exploring quantum computing in their projects today. This
increases the chances that their software is ready by the day the hardware is available.
NOTE take-aways:
The potential impact of Quantum Computing is huge. Researchers are still trying to estimate the
impact, but at least in theory, there might be very large consequences for the IT industry,
security, healthcare and scientific research and thus for mankind in general. Because of this large
impact, a Quantum Computer is often incorrectly pictured as "a huge classical computer". This is
not true, and in order to be able to see the relevance of quantum computing, one must understand
why Quantum Computing is so fundamentally different from classical computing.
It has to be stressed that there are still many roadblocks that need to be addressed before the big
ambitions can be realised.
The potential success of Quantum Computing depends on a number of factors that can be put in
two categories:
1.1.1 Hardware
There are a number of uncertainties that prevent wide-scale usage of Quantum Computing at this
moment. Adding to those uncertainties, it should be stressed that Quantum Computers will not
fix every single problem.
The hardware needed for Quantum Computing is by no means ready for mass production.
Creating Quantum hardware, in the form of a Quantum Computer or a Quantum co-processor, is
extremely challenging.
The core principles of Quantum Computing, which we will explain in this book, are based on the
core principles of quantum mechanics. In quantum mechanics, the fundamental particles of
nature are studied. It is generally considered to be one of the most difficult aspects of physics,
and it is still in an evolving phase. Some of the brightest physicists, including Albert Einstein,
Max Planck and Ludwig Boltzmann have been worked on the theory of quantum mechanics.
One of the major problems in the research of quantum mechanics is that it is often extremely
hard to check whether the theory matches with the reality. It is no less than amazing that theories
were created predicting the existence of some particles that were not yet observed. Observing the
smallest elements of nature, and their behavior requires very special hardware.
It is already difficult to investigate and manipulate quantum effects in closed lab environments.
Leveraging those quantum effects in a controllable way in real-world situations is an even bigger
challenge.
Most of the experimental quantum computers that exist today are based on the principles of
superconducting, and operate at a very low temperature (e.g. 10 milli Kelvin, or close to -273
degrees Celcius). This has some practical restrictions that are not encountered with classical
computers, operating at room temperature.
In this book, we make abstraction of the hardware. Clearly, the hardware problem isn’t solved,
and it is generally expected to take "a number of years" before hardware is available that can be
leveraged to solve problems that are currently impossible to solve with classical computing. At
the time of this writing, a number of early quantum computer prototypes already exist. IBM has a
5 qubit quantum computer that is available for public usage through a cloud interface, and
quantum computer with more qubits in the research labs and for clients. Google has a quantum
processor containing 72 qubits, named Bristlecone. Specialised companies like D-Wave and
Rigetti have quantum computing prototypes as well. It has to be mentioned that it is not trivial to
compare different quantum computers. At first sight, the number of qubits may sound the most
important criterium, but it can be misleading. One of the major difficulties when building
quantum computers, is to keep the quantum states as long as possible. The slightest disturbance
can destroy the quantum states, and therefore quantum computers are subject to errors that need
to be corrected.
As we will discuss later, there is no reason for software developers to wait until the hardware is
ready before they can start thinking about software algorithms that should eventually run on
Quantum hardware. The principles of Quantum computing are understood, and can be simulated
via Quantum Computer simulators. It is expected that quantum software written for quantum
computer simulators will also work on real quantum computers, provided that the core quantum
concepts are similar.
1.1.2 Software
While there are a number of areas where Quantum Computing could, in theory, lead to a huge
break-through, it is generally agreed that Quantum Computers will not replace classical
computers.
There is a growing consensus where Quantum computers, or Quantum processors, can take over
some tasks from classical computers, but they won’t replace classical computers.
The problems that can be solved using Quantum Computing do not differ from problems that
today are tackled using classical computers. However, since Quantum Computing uses a
completely different underlying approach, the problems can be handled in a completely different
way, and for a set of problems a dramatic increase in performance can be achieved using
Quantum Computing. As a consequence, Quantum computers should be able to solve problems
that today are not practically solvable because there are not enough computing resources to solve
them now.
It turns out that quantum computers will be most helpful for tackling problems that can not be
solved by classical computers in polynomial time, but that can be solved by a quantum computer
in polynomial time.
encryption. The basic idea in integer factorization is to decompose a number into prime numbers
that, when multiplied together, yield the original number. For example, 15 = 3 x 5. While this
is easy to do without a computer, you can imagine a computer is helpful when the numbers
become bigger, e.g. 146963 = 281 x 523.
The larger the number we want to factor, the longer it will take to find the solution. This is the
basis of many security algorithms. They leverage the idea that it is close to impossible to factor a
number consisting of e.g. 1024 bits. It can be shown that the time required to solve this problem
is in the order of
EQUATION 1.1
where b is the number of bits in the original number. The e at the beginning of this equation is
the important part. In short, it means that by making b larger, the time required to factor the
number becomes exponentially larger. The diagram in Figure 1.1 shows the time it takes to factor
a number with b bits.
Note that the absolute time is not relevant. Even if the fastest existing computers are used, adding
a single bit makes a huge difference.
This problem is said to be non-polynomial, as there is no known classical algorithm that can
solve the problem in polynomial time. Hence, by increasing the number of bits, it will be almost
impossible for classical computers to find a solution to this problem.
However, this same problem can be handled by a quantum algorithm in polynomial time. As we
will show in Chapter 4, using Shor’s algorithm, the time to solve this problem using a Quantum
Computer is in the order of \b^3.
To show what that means, we overlay the required time using a quantum algorithm on a quantum
computer over the required time using a classical algorithm on a classical computer. This is
illustrated in Figure 1.2.
Starting from a number of bits, the quantum computer will be much faster than the classical
computer. Moreover, the larger the amount of bits, the larger the difference. This is because the
required time for solving the problem on a classical computer increases exponentially when the
amount of bits is growing, where the same increase of bits will "only" cause a polynomial
increase for the quantum algorithm.
These kinds of problems, that are said to be polynomial in Quantum, are the ones that makes
mose sense for Quantum Computers to deal with.
1.1.3 Algorithms
Shor’s algorithms is a great example of a computational problem that is hard to solve on a
classical computer (non-polynomial in time) and relative easy on a quantum computer
(polynomial in time). Where does the difference come from? As we will discuss in Chapter 4,
Shor’s algorithm transforms the problem of integer factorisation into the problem of finding the
periodicity of a function, i.e. find the value p for which the function evaluation f(x+p) = f(x)
for all possible values of x. This problem is still very hard to solve on a classical computer, but it
is relative easy to fix on a Quantum Computer.
Most algorithms that are known today to be very suitable for quantum computers are based on
the same principle: transform the original problem into a problem space that is easy to solve
using Quantum Computers.
The classic approach is shown in Figure 1.3. The best known algorithm is applied to the
problem, and the result is obtained.
If we can somehow transform the original problem to a different problem that can easier be
handled by a quantum computer, we can expect a performance improvement. This is shown in
Figure 1.4.
Figure 1.4 Transforming a problem to an area where quantum computers can make a big
difference
Note that we have to take into account the cost of transforming the original problem to a
different problem, and vice versa for the final result. However, when talking about real
compution-intensive algorithms, this cost should be neglectible.
NOTE When you see a Quantum algorithm being explained, you may wonder why
it seems to take a detour from the original problem. Quantum computers
are capable of solving particular problems very fast, so moving an original
problem to one of those particular problems allows for a much faster
algorithm, using quantum computing.
Coming up with those algorithms often involves a very deep mathematical background.
Typically, developers will not create new quantum algorithms for applications that will benefit
from quantum computers, but they will use existing algorithms. However, developers who know
the basics about quantum algorithms, why they are faster, and how to use them, will have an
advantage.
Any developer working on a project that requires encryption or secure communication benefits
from learning about quantum computing. Some existing classical encryption algorithms will
become insecure when quantum computers are available. It would be a bad idea to wait for the
first time a quantum computer breaks encryption before hardening the encryption software. At
the contrary, you want to be prepared before the hardware is available. Since quantum computing
is really disruptive, it can be expected that most developers need more time learning quantum
computing than they typically need when using a new library.
While we do not want to scare people with doom scenario’s, it is important to understand that
there is no need for a wide installed base of quantum computers before existing encryption
techniques can be compromised. Cyber attacks do not require a large amount of computers, and
can be carried out from any place.
The software examples we will discuss in this book are very basic applications. They illustrate
the core principles of quantum computing, and they make it clear what kind of problems can
really benefit from quantum computing. But the gap between basic algorithms and fully
functional software is large. Hence, while it will take years before the hardware is ready,
developers have to understand that it will probably also take a long time before they have
optimised their software projects so that they leverage quantum computing as much as possible,
where applicable.
In the mid of the previous century, when the first digital computers were built, software
languages needed to be created as well. The difference with today is that we can now use
classical computers to simulate quantum computers. We can work on software for quantum
computers, without having access to a quantum computer.
This is a very important benefit, and it stresses the importance of quantum simulators.
Developers starting today looking into quantum computing using simulators will have a huge
advantage on other developers when the quantum hardware becomes more widely available.
The potential performance gains that are expected to be realised using Quantum computers have
nothing to do with these improvements.
A Quantum computer is not a classical computer with smaller chips, more memory, or faster
communication.
Instead, Quantum Computing starts with a completely different fundamental concept, which is a
qubit. We will discuss the qubit in detail in Chapter XX but since it is a crucial concept, we
introduce it here.
All existing classical software development is based on the manipulations of those bits. Using
combinations of bits, and applying gate operations of bits is the essence of classical software
development. We will discuss this in more detail in Chapter 3.
In Quantum Computing, the fundamental concept is a qubit. Similar to a classical bit, a qubit can
hold the values 0 and 1. But the disruptive difference is that the value of a qubit can be a
combination of the values 0 and 1. When people first hear about this, they are often confused. It
sounds artificial to have the qubit, the elementary component of Quantum Computing to be more
complex than the elementary component of classical computing, the bit. It turns out, however,
that a qubit is closer to the fundamental concepts of nature than the classical bit.
The spin of an electron is just one sample of a physical phenomenon that allows for a property to
One of the goals in Quantum Computing is to take advantage of physical phenomenons that
happen at the scale of the smallest particles. Hence, Quantum Computing is more "natural" and
although it seems much more complex than classical computing at first sight, it can be argued
that it is at the contrary much simpler, as it requires less artificial constructs.
Understanding quantum phenomenons is one thing, being able to manipulate them is another. It
took lots of time and resources to be able to prove that quantum phenomenons really exist. In
order to allow computational representations on qubits, one must be able to manipulate the
elementary parts. While this is what is typically done in large scientific research centers, it is still
very hard to do this in a typical computer environment.
Actually, this approach is not entirely new. A very similar pattern is already being used in most
modern computer systems, where the Central Processing Unit (CPU) is accompanied by a
Graphics Processing Unit (GPU). GPU’s are good in some particular tasks (e.g. doing vector
operations that are needed in graphical applications, or in deep learning applications), but not in
all tasks.
Many modern UI frameworks, including JavaFX, leverage the availability of both CPU’s and
GPU’s, and optimize the tasks they have to perform by delegating parts of the work to the CPU
and other parts to the GPU, as shown in Figure 1.5.
The idea of using different co-processors for different tasks can be extended to Quantum
Computing. In the ideal scenario, a software application delegates some tasks to a CPU, other
tasks to a GPU and other tasks to a Quantum Processing Unit (QPU), as shown in Figure 1.6.
The best results can be achieved when the best tools are used for a specific job. In this case, it
means that the software application should use the GPU for e.g. vector computations, the QPU
for algorithms that are slow on classical systems but fast on quantum systems, and the CPU for
everything that doesn’t benefit from either the GPU or the QPU.
If every end-application has to judge what parts should be delegated to which processor, the job
of a software developer would be extremely difficult. We expect though that frameworks and
libraries will provide help here, and abstract this problem away from the end-developer.
If you are using the JavaFX API’s to create user interfaces in Java, you don’t have to worry
about what parts are executed on the GPU, and what parts are executed on the CPU. The internal
implementations of the JavaFX API already do that for you. The JavaFX framework detects the
information about the GPU, and will delegate work to it. While it is still possible for developers
to directly access either the CPU or the GPU, this is typically something high-level languages as
Java shield away.
In the picture above, we oversimplified the QPU. Where a GPU easily fits in modern servers,
desktop systems, but also in mobile and embedded devices, providing a Quantum Processor
might be more tricky, due to the specific requirements for quantum effects to be manipulated in a
controlled, noise-free environment.
It is very well possible that, at least initially, most of the real quantum computing resources will
be available via specific cloud servers, instead of via co-processors on embedded chips.
The principles stay the same though, since the end-software application can benefit from libraries
splitting the complex tasks, and delegate some tasks to a quantum system that is accessible via a
cloud service as shown in Figure 1.7.
However, this should not be a reason to not start working on the software. We learned a lot from
classical hardware, and from the software that is built on top of it. The high-level programming
languages that have been created in the past decades allow software developers to create
applications in a convenient way, such that they do not have to worry about, or even understand,
the underlying hardware. Java, being a high-level programming language, is particularly good in
making abstraction of the underlying low-level software and hardware. Ultimately, when a Java
application is executed, some very low-level, hardware-specific instructions are executed.
Depending on the hardware being used, specific machine instructions, for different processors
with different architectures are used.
Hardware for classical computers is still evolving. Software is evolving as well. Most of the
changes in the Java language, however, are not related to hardware changes. The decoupling of
hardware and software evolutions allows for much faster innovation. There are a number of
areas, though, where improvements in hardware ultimately lead to more specific evolutions in
software but for most developers, hardware and software can be decoupled from each other.
Figure 1.8 shows how a Java application ultimately results in operations on hardware, but
different abstraction layers shield the real hardware (and the evolutions in the hardwar) from the
end application
For a large part, software for Quantum Computing can be decoupled from the hardware
evolutions. While the hardware implementation "details" are far from clear, the general
principles are becoming very clear. We discuss those principles in Chapters 2 - 5. Software
development can be based on those general principles. Similar to how a classical software
developer doesn’t have to worry about how transistors (a low-level building block for classical
computers) are combined on a single chip, a developer of quantum software does not have to
think about the physical representation of a qubit (one of the low level building blocks in
quantum computing). As long as the quantum software conforms with and exploits the general
principles, it will be usable on real quantum computers or quantum processors when they
become available.
A major benefit while developing software for Quantum Computers, is the availability of
classical computers. The behavior of quantum hardware can be simulated via classical software.
This is a huge advantage, since it implies that quantum software can be tested today, using a
quantum simulator written in classical software, on a classical computer. Obviously there are
major differences between a quantum computer simulator and a real hardware quantum
computer. Almost by definition, a typical quantum algorithm will execute much faster on a
quantum computer than on a quantum simulator. But from a functional point, the results should
be the same.
Apart from real quantum computers and quantum computer simulators, cloud services should be
taken into account. By delegating the work to a cloud service, an application doesn’t even know
if it is running on a simulator, or on a real quantum computer. The cloud provider can update its
service from a simulator to a real quantum computer. The results should be obtained much faster
when a real quantum computer is used, but they should not be different from when a simulator is
used.
In this picture, we show that Java applications can leverage libraries that provide Quantum
API’s. The implementation of these library can do the work on a real quantum computer, use a
quantum computer simulator, or delegate the work to the cloud. For the end application, the
results should be similar.
As we already discussed, Quantum algorithms are particular useful when dealing with problems
that require exponential scaling when dealt by with classical computers. One of the typical
examples for this is integer factorization. A Quantum Computer will be capable of decomposing
large integers into their prime factors (at least, it will provide a part of the algorithm), something
that is not possible today even with all computing power in the world combined. As a
consequence, a quantum computer simulator written in classical software is also not able to
factor those large numbers.
The same Quantum Algorithm is of course also capable of factoring small integers. Quantum
simulators can thus be used to factor small integers. The Quantum Algorithm can be created,
tested and optimized using small numbers on a quantum simulator. Whenever the hardware
becomes ready for it, that same algorithm can then be used to factor numbers on real hardware (a
5 qubit system has already factored 21).
When the quantum hardware improves (more qubits are added, or less errors occur), the
algorithm will allow larger numbers to be factorised.
We explain some of the Quantum Computing principles by looking at the source code of the
algorithms in the library. While this is not stricly needed to write applications leveraging
Quantum Computing, it will give the reader more insight in how and when quantum algorithms
might lead to a real advantage.
In this chapter, you will be introduced to Strange, an Open Source Quantum Computing project
including a Quantum simulator, and a library that exposes a Java API that you can use in regular
Java applications.
Throughout the book, we will dicuss concepts of Quantum Computing, and their relevance to
Java developers. We will show how Java developers can benefit from these concepts.
Strange contains a pure Java implementation of the required quantum concepts. When discussing
the concepts, we point the interested reader to the relevant code implementation of the concept in
Strange. This is part of a low-level API.
Most Java developers will not have to deal with low-level quantum concepts at all. However,
they might benefit from algorithms that take advantage of these concepts. For this group, Strange
provide a set of high-level algorithms that can be used in regular Java applications. These
algorithms are what we call the high-level Java API.
The Java Quantum API provides an implementation for a number of typical quantum algorithms.
These are the high-level algorithms that can be used by Java developers in their regular Java
applications. No knowledge about quantum computing is required in order to use the algorithms.
The Quantum Core Layer contains the low-level API which provides deeper access to the real
quantum aspects. The high-level API does not contain a concept specific to quantum computing,
but its implementation leverages the low-level Quantum Core Layer. Where the high-level API
shields the user from the quantum concepts, the low-level API at the contrary exposes those
concepts to the user.
The high-level API provides developers with a ready-to-use interface to quantum algorithms. By
using it, you can benefit from the gains realised by quantum computing. However, if you want to
be able to create your own algorithms, or modify existing algorithms, the low-level API is the
starting point.
We use the gradle build tool for building and running the samples, but users familiar with maven
will be able to easily run the samples with maven.
We do recommend you run the samples using your favourite IDE (IntelliJ, Eclipse or NetBeans).
The instructions on how to run Java applications are different for each IDE. Therefore, in this
book, we use the gradle build system from the command line.
Using the provided gradle (or maven) scripts implicitly makes sure all required code
dependencies are downloaded. The code is compiled, and executed, as illustrated in Figure 2.2
The result of
./gradlew run
gradlew.bat run
BUILD SUCCESSFUL in 3s
Typically, you shouldn’t worry about the structure of the build.gradle file, unless you plan to
create applications or projects yourself. In that case, you can find great resoures about using
Gradle online.
repositories {
mavenCentral();
}
dependencies {
compile 'com.gluonhq:strange:0.0.5'
}
mainClassName = 'com.gluonhq.javaqc.ch02.hellostrange.Main'
declare what plugins gradle should use Gradle is a build system that allows third
parties to provide plugins in order to make it easier to build and deploy
applications. The demo application is an application, and therefore uses the
application plugin. Strange is using Java 11 and the modularity concepts that
have been introduced in Java 9. Our demo applications don’t require knowledge
about the modular system in Java though. However, in order for the build tools to
be able to leverage the modularity, we also declare the use of the javamodularity
plugin.
declare where to download dependencies . Since our demo application is using a
Java library, Gradle needs to know where to find this library in order to use it for
compiling and running the demo application. The Strange library is uploaded to the
mavenCentral repository, hence we declare that in the repositories section.
declare the dependencies. The HelloStrange demo application uses the Strange
library. In the dependencies section of the build.gradle, we declare that we need
version 0.0.3 of the Strange library, which is defined by the combination of a
package name com.gluonhq and an artifact name strange. The compile keyword
tells Gradle that this library is needed to compile the application, and by default it
will then also use this library to run the application.
declare the main class that should be executed when running the demo. Finally, we
need to tell Gradle where it can find the main entry point to our application. In this
case, the project has only a single Java source file with a main method, hence this
is the entry point.
The build.gradle file is interesting to developers and code maintainers who are working on
project development, deployment, testing and distribution.
The Java source files in a project are very relevant to all developers. Gradle requires by default
that Java source files are placed in a folder src/main/java, followed by the packagename and
the name of the Java source file. In the case of the HelloStrange application, the single source file
is thus located in src/main/java/com/gluonhq/javaqc/ch02/hellostrange/Main.java.
Before we show the code, we will briefly explain what we want to achieve. In this first sample,
we will invoke a method on the high-level Strange API. This method is called randomBit() and it
generates a classic bit which is either 0 or 1. We will discuss the randomBit() method call
shortly. Apart from this call, all Java code used in the sample only uses the standard API’s that
are part of the JDK. The flow for the sample is shown in Figure 2.3
From this flow, it can be seen that the Java class we create depends on the high-level Strange
API. We don’t have to worry about how it is implemented in the lower layers of Strange.
The complete source code for the application is shown in Listing 2.2. We will analyse this source
code right away.
import com.gluonhq.strange.algorithm.Classic;
This Java code follows the basic Java conventions, which we assume you are familiar with. For
this sample, we briefly mention the typical concepts in a Java application.
We rely on functionality provided by the Strange library, and we import the Java class that
provides the functionality we need:
import com.gluonhq.strange.algorithm.Classic
We will have a deeper look at this Classic class later. For now, we simply assume it provides
the functionality we need.
The name of this Java class is Main, as it has to match the name of the file.
In Java, entrypoints in files need to be declared with a method public static void
main(String[] args). Build tools like Gradle will invoke this method when asked to execute
an application.
When the main method is invoked, it will first print some information:
System.out.println("----------------------------------------------------");
In the next line of code, we call a method on the Classic class, that is part of the Strange library
that we imported. The method we call is the Classic.randomBit() method, and it returns a
Java integer that either holds the value 0 or the value 1.
NOTE The classname Classic indicates that Strange offers this class for classic
invocations. Code calling this class is not expected to contain any
quantum-specific implementations. However, the implementation of the
Classic class itself contains quantum implementations. Therefore, the
implementation of Classic.randomBit() is not simply returning a default Java
random bit, but it is using a quantum circuit to do so --- as we will show
later in this chapter.
In the next line, this value is printed. Note that when you execute the application, there is 50%
chance you will see a 0 printed, and 50% chance that you will see the 1 printed.
The Classic.randomBit() is a Java method that under the hood leverages quantum principles.
We will discuss the implementation later. For now, we assume that there is an equal change for
this method to return 0 and 1.
In order to demonstrate this, the next part in the Java source code will call this
Classic.randomBit() 10,000 times, and it will keep track on how many times a 0 is returned
and how many times a 1 is returned.
int cntZero = 0;
int cntOne = 0;
Clearly, cntZero will hold the number of times the returned value is 0 where cntOne holds the
count for the calls that return 1.
We then create a loop which inner code calls the randomBit() method and increments the
appropriate variable. This is done in this code snippet:
}
}
Finally, the results are printed. Since the random values are truly random, the final results will
very likely be different every time you run the application. The sum of the cntOne and cntZero
values will always be 10,000 and it is expected that the cntZero and cntOne values both are in
the neighbourhood of 5000.
Although Java developers don’t need to know the details about the underlying implementations,
it often helps to have at least some insight in those details. This is not only the case for
algorithms on Quantum Computing, it is applicable to many fields. While documentation (e.g.
JavaDoc) is typically very helpful for general cases, it might help to understand some of the
details if you want to keep track of performance, for example. In the case of Quantum
Computing, it is recommended for Java developers to at least have some basic knowledge about
the underlying implementation of the quantum API’s, as this provides useful information that can
be used to judge wether a quantum algorithm is applicable or not for a specific usecase, and what
the performance impact will be.
Also, without this basic knowledge, users might worry about the initial performance of some of
the algorithms. Indeed, if a quantum algorithm is executed on a Quantum Simulator, the
performance will probably be worse than if a classic algorithm was used. However, if the
quantum algorithm is well-written and if the problem is applicable for quantum speedup, the
performance will dramatically improve once real quantum hardware is used.
Henri Lavedan stands for the bright side of Parisian life of to-day
—for the witty dialogue and the delicate sentiment. He has
created a language of his own, sound, racy, with all the
abruptness and unexpected drollery of the boulevards.
He was born at Orléans in 1859, and began his literary career by
contributing to the journals satiric pictures of the manners and
customs of the Paris world. Those written between 1885 and
1892 form a series of chronicles, which he has gathered into
several volumes. Most of his works, however, are written for the
theatre. In 1899 he was elected a member of the Academy.
WHEN HE WAS A LITTLE BOY
BY HENRI LAVEDAN
Translated by Katharine Vincent.
Copyright, 1902, by The Current Literature Publishing Company.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com