Quantum Computing. The phrase invokes images from popular science fiction. From the innumerable Qubit machine of Devs on FX to the foundational component of a whole new virtual world in Neal Stephenson’s “Fall”. The phrase Quantum Computing invokes visions of mythological computational feats. Discussions around Quantum Computing veer into many branches of computational theory, artificial intelligence, cryptography and compression.
What is Quantum Computing? How do we start taking advantage of Quantum Computing right now? Is it worth it, or are we just forcing a solution onto problems created for the solution because the tech is “neat”? The aim of this article is to answer these questions, show how to integrate with Quantum Computing hosted in the cloud with Amazon Braket and discuss the value of researching this technology within your business.
To scope this a bit tighter, this is specifically a post about Quantum Computing within Amazon Braket, not a detailed exploration into Quantum Mechanics or Quantum Theory. By keeping our focus specifically on Quantum Computing we can more readily learn how to program Quantum Circuits using nothing more complex than Linear Combinations. This is the equivalent of how Electrical Engineers first learned to program using logic gates on classical hardware.
To begin it is assumed you have pre-requisite knowledge in Computer Science and Linear Algebra. If you need a brush up on Linear Algebra, follow the links listed below.
Quantum Computing, Then, Now and Forward
Before moving forward, one should go back and understand where Quantum Computing originated and what is seen as its future. Quantum computing is young (in human terms) and has seen more growth in the past ten years than the last couple of decades. The indicator of this growth is the adoption and enablement of using quantum computing in the cloud.
The first quantum computer hardware was produced in the mid-1990s, 1998 to be exact, by Isaac Chuang of the Los Alamos National Laboratory, Neil Gershenfeld of the Massachusetts Institute of Technology (MIT) and Mark Kubinec of the University of California at Berkeley. That was a 2-Qubit system. That research opened to door to the reality of using Quantum Computers.
Fast forward to the now and we find ourselves at the stage of having 5K+ quantum systems, but we still do not have formal definitions for common scalar types such as integer and floating point values. This means we still do quantum operations by composing circuit configurations for the target hardware. This can be like the early days of classical computing using tubes and vacuums.
Quantum Computing is also not seen as the primary or general means of computation. Like the GPUs we use for video games and heterogenous computing, a Quantum Processing Unit (QPU) is most likely to be used as a co-processor for specific types of tasks. But the benefit of being a young technology is that barriers and original assumptions may be broken, and perhaps a truly general-purpose quantum computer will arise.
Why? We have computers that can synthesize circuits and simulate the quantum computers. The old classical computing model is ready and able to obsolete itself with the work of discovering more in the field of quantum computing. What is more, is that through Cloud services such as Amazon Braket we are all enabled to explore innovation within Quantum Computing. Furthermore, we are at a stage where the benefits are already enjoyed by the early adopters in the fields of product development, Chemistry, Finance, Cryptography, Machine Learning, Statistics and Energy.
To see benefits so early in an unknown technology is exciting. It leads to innovation now in preparation for the future state of computing. To prepare for this future state, there are two main hurdles to cross when one wishes to learn Quantum Computing. The barriers being an understanding of the symbols physicists, engineers, and mathematicians use to represent various states and operations; and an understanding of what a Qubit is.
The first step is understanding a Qubit and the computational basis. A Qubit It is something that represents the quantum state of particles such as Ions, Photons, and Electrons. Other types of quantum like materials may be used as well so this is not a fully inclusive list. A Qubit maintains either a |0> state, or a |1> state, or a state in between the infinite ranges of |0> and |1>.
Mathematically speaking, a Qubit is a unit vector [a,b] where |a|^2 + |b|^2 = 1.
Now that we have our understanding of state, we must do something with that state. To do so we operate on Qubits using logic gates.
The Bra and the Ket
The two symbols that are most important are the Bra and Ket. Both represent n-dimensional vectors of complex numbers. From experience, the Ket is more prevalent in documentation and scientific papers; therefore, the remainder of discussion will be terms of Kets. This means our algorithms for our Quantum Circuits will be applied to column vectors.
Kets are shorthand for a column vector. A single Ket of a computational basis state is shown below, a 0 Ket |0> is equal to the [1, 0] vector and a 1 Ket |1> is equal to the [0, 1] vector. We can also combine Kets, like how we build strings of bits to represent specific binary data. Here we can see that doing this is nothing more than representing the tensor product of all the vectors involved.
Quantum Logic Gates
Beyond a representation of our state, we must also figure out how to apply logic to our state. This is done via Quantum Logic Gates. The biggest qualifier for these, mathematically, is that they are unitary matrices that preserve the length of our inputs. From the Matrix form of each of these gates you can begin to work out how that is accomplished.
Also note, as in the case of two Qubit and three Qubit gates such as the Controlled Not, Controlled Z, SWAP and Toffoli, the gates become larger matrices in relation to the number of Qubits. This is where we begin to realize why it begins a complex and inefficient method of computation on a classical computer. Therefore, most simulators only simulate tens of Qubits at a time. Keep in mind these are not all the gates, but just like with some CPUS, only certain gates are supported, and these will be the most common for the time being.
Quantum Logic Gates are operations that manipulate the Qubit or system of Qubits in a manner that mathematically preserves length. Therefore, all the gates can be represented as unitary matrices, their elements contain 1, 0, or imaginary values. The preservation of length is an important characteristic that explains why we use a 2-element vector for Qubit state, as opposed to a quaternion, and a 2×2 matrix for our logic gates. If you are interested in the proof behind this, I would recommend reading “Quantum Computing since Democritus” by Scott Aaronson. The four most basic gates for any given quantum computer are the logic Not gate, the Hadamard gate, the Controlled Not gate, and the Toffoli gate. From these gates you can create any other logical gate and quantum system.
Single Qubit Gates
The beginning implementation of any Quantum Computer begins with single Qubit gate operations. These are operations that operate only upon a single Qubit at a time. The most basic of these gates are known as the I Gate, Pauli X, Pauli Y, Pauli Z and the Hadamard Gate. This is not a fully inclusive list but one containing the most common gates.
The I Gate is the Identity Gate. Given a State Vector, once the Identity Gate is applied, a State Vector equal to the previous State Vector will be produced. This is done by applying the 2×2 identity matrix to the 2-Dimensional State Vector. If you were to imagine the state vector as a sphere, the Paul X Gate simply spins that sphere around by pi. The Pauli X gate is the quantum version of a Binary Not gate. Sometimes the term Pauli X is used, others Not is used, both refer to the same type of gate.
The Pauli Y and Pauli Z gates act similar in nature as the Pauli X gate if the Qubit’s state vector is imagined as a 3-D sphere. Each of those gates spin the sphere along the relevant Y and Z axis.
Example of a Bloc Sphere. source: wikipedia.org
Using the beforementioned Pauli X, Y, and Z gates we get the same functionality on a Quantum Computer as we would find in a classical computer. To take advantage of Quantum Computing we must first put our Qubit into Superposition. This is where the real “magic” of quantum computing occurs. We will not digress into a detailed explanation of Superposition; we will just discuss how to use it within the context of Quantum Circuits.
The Hadamard Gate is the gate that enables us to achieve superposition for a Qubit. Again, visualizing the Qubit as a sphere, it will rotate the sphere about the X and Z axis. When a Qubit passes through a Hadamard Gate, it will re-enter itself into a quantum state. The classic example is that it will be like a spinning penny, the odds of falling heads or tails equal. Essentially, a Hadamard gate initializes a Qubit.
There are many more single-Qubit quantum gates available. However, they are mostly shortcut gates to reduce the depth of a quantum program. Just as a classical computer can be built with NOT, OR and AND binary gates, a fully functional quantum computer can be built with only a handful of Quantum Circuits similar in behavior.
Moving away from single Qubit logic gates, we enter multiple Qubit logic gates. These gates enable us to build something like the computers we know and consume today. The first gate, and the one we will be looking at today, is the Controlled Not Gate. This gate takes a control Qubit and a target Qubit. Much like classical computing, the target Qubit state will change in relation to the state of the control Qubit. Unlike classical computing, there is a potential for the target Qubit state to impact the control Qubit state.
The second important multi Qubit gate is the Toffoli gate, also known as the Controlled Controlled Not gate. This is a three-Qubit gate that uses two control Qubits to manipulate a single target Qubit. This is like an AND gate in classical computing. The third Qubit is also known as an ancillary Qubit. The reason this third Qubit exists is because we cannot copy the state of a Qubit, therefore we must apply state to a Qubit due to the state of two other Qubits. Another note is that if we do not have a Toffoli gate available, we can compose a quantum circuit from Unitary matrices and CNOT gates to replicate a Toffoli gate. Other gates of note are the Controllzed Z gate, T Gate and Swap Gate.
Closing the Gate
To summarize, here is a convenient image showing the name of the gate, its symbolic representation on a quantum wiring diagram, and its matrix form.
Common Single and N-Qubit Gates, source: wikipedia.org
If you are interested in learning more specifics and the mathematics behind quantum computing, I would recommend the following resources:
Now that we understand what is known as a Ket and the computational basis state, the state we are most familiar with seeing, we must now understand how quantum measurements apply here. For quantum computing to work we must apply the horizontal and vertical measurements of our quantum state to our Kets. This is typically denoted as alpha and beta. This is how we begin to realize the probabilities of our algorithms and the measurements of quantum state, in particular positions.
Typically, a Qubit is measured once we want to begin the process of converting the quantum information into binary information for analysis or additional processing.
Quantum Computing with Amazon Braket
There are several ways to run the following example. Locally, by installing Python and the Amazon Braket SDK for Python, or in the cloud by activating Amazon Braket in your account.
Right, after that cursory and crash course in Quantum Computing and setup, let us write some code and fire off some quantum circuits!
Within each of those there are many different implementations of the layout of the Qubits, number of Qubits, and Qubit volume. What we care most about is going to be the implementation based on our problem. For instance, if we know we are going to be solving for NP-Hard problems – problems at least as hard as non-deterministic polynomial problems – to determine decisions with a focus on combinatorial complexity, quantum annealers will be our friend. On the contrast, Universal Gate-Model QPUs (Quantum Processing Units) are as they sound, built to provide circuits for universal problem solving.
Amazon Braket is generally available for anybody who activates it within their AWS Account. They offer real hardware, provisioned based on a queue, and simulators for immediate testing. Simulators run on optimized instances. You can do a lot of development on AWS by provisioning a Jupyter notebook – something data scientists and machine learning professionals are familiar with. Amazon Braket is also a Python SDK that enables the compositions of circuits and executing that on locally simulated Qubits. Let us look at an example.
This code, and other examples, can be found on GitHub.
This is a simple sample of a bell state in quantum computing. This is analogous to the programmer’s “Hello World” application in classical computing.
For the most part it is straight forward in implementation, the SDK functions representing quantum computation circuit gates, seen at the top, build QASM (Quantum Assembly Language, an Assembly and C-Like language using the OpenQASM 2.0 specification) that will be sent as instructions, over the internet, to an awaiting quantum computer. However, in this sample we see we can also simulate quantum operations within our local environment up to a few tens of Qubits.
To create a bell state, which creates an entangled state between two Qubits, we apply a Hadamard gate on the control Qubit, and a controlled not gate onto a target Qubit. From here we can run a local simulation and launch an asynchronous request to execute the quantum circuit.
Integrating Applications with Amazon Braket
In the real world, this application would run on a classical computer, and when the run method is called, we are making a request to Amazon Braket to execute a given quantum circuit on the target hardware. We can then operate as normal and handle a response when it is complete.
There are several methods of integrating results from Amazon Braket into existing infrastructure. These methods are through the Amazon Braket SDK, handling events from AWS Event Bridge, or enabling S3 Bucket Notifications for when results are added as an S3 Object to an S3 Bucket.
One of the simplest methods for a developer to leverage Amazon Braket is to use the Amazon Braket SDK to issue requests for Quantum Computing. An existing Python Application can await asynchronously for request to code to complete and use the results to continue processing. The caveat to this is that Amazon Braket Quantum Computations are executed via a queue of requests shared across all AWS Accounts; therefore, you may have stalling code in your application as it awaits a response.
For this reason, there are two decoupled and cloud friendly methods for integrating with Amazon Braket results. The advantage is you are no longer limited to Python and just need to handle data when it comes it using an eventing model in your infrastructure.
Those familiar with Serverless application infrastructure may be delighted to discover Amazon Braket publishes execution results to AWS Event Bridge. An AWS Lambda Function, or other serverless application, or a long running server, can handle Amazon Braket results in an eventually consistent manner by leveraging AWS Event Bridge. The event contains, among other state data, the result state of the execution and the location of the data in S3.
Another approach to handling the results of Amazon Braket quantum computations is to integrate directly with the S3 Bucket that stores the results of computations. Developers can deploy an AWS Lambda function to handle an S3:ObjectCreated:* S3 Bucket Notification. This event will contain the data necessary to get the results stored in S3 by Amazon Braket.
Quantum Computing is still in a young state, so there is much to discover. What we do know is that we can start creating algorithms now in preparation for the future and apply the smaller ones on real hardware available to us in the cloud. There are many algorithms available to explore, each with different use cases and advantages. A comprehensive list can be found here on Quantum Algorithm Zoo.
The ideal application for Quantum Computing for businesses is to use it as a hybrid computational model. Developers can use classical computing and languages to build applications integrating Quantum Computing. When a difficult combinatorial problem presents itself, a cloud native or integrated hybrid infrastructure can call out to Amazon Braket to perform a Quantum Circuit.
There are many examples as to the use cases of Quantum Computing. Such use cases of Quantum Hybrid applications is material design, optimizing battery design through simulation, or chemical engineering. These all are real world examples within business, and there are many more other industries that can be explored with Quantum Computing. The real question is, when the Quantum Revolution comes, will your company be ready?
Additional Quantum Computing Resources
Here are a couple of other resources to help you get started in Quantum Computing with Amazon Braket.
- What is Amazon Braket
- Amazon Braket SDK
- Amazon Braket Examples Github
- Amazon Braket – Go Hands-On with Quantum Computing
- Amazon Braket – Get Started with Quantum Computing
Here are highly recommended readings for anybody looking to get serious with Quantum Computing.
- Quantum Computing since Democritus by Scott Aaronson, ISBN: 9780511979309
- Quantum Computation and Quantum Information by Isaac Chung and Michael Nielsen, ISBN: 9780511976667
About the Author:
Martin Hollstein is a Principal Consultant in Sparq’s Milwaukee Development Center with experience in Healthcare, IoT, Game, Insurance, Manufacturing, FinTech, AdTech and the eCommerce industries. He is well versed in the design of distributed, scalable and fault tolerant systems. His experience in programming languages range across industry standard OOP languages to exciting new functional languages and all those in-between. His experience with designing RESTful services and GraphQL APIs have resulted in panel appearances and webinars. His approach to developing software focuses on the best tech for the market that enables you to reach your business goals. He sports a healthy interest in gardening, cooking, bread baking and video games. When not looking for the next cool thing to learn, he spends time in Wisconsin with his wife and dog.
Five Ways User Feedback Can Transform Your Product Strategy
User feedback is a critical asset that can provide valuable insights into your users' wants and needs. It can also give important observations into your application's overall performance. In this article, Principal Product Strategist Toyia Smith shares five ways to better incorporate user feedback into your product strategy.
Balancing Technical Debt and New Features: A Product Owner’s Guide
The term "technical debt" frequently emerges in discussions about software development, product health and organizational effectiveness. However, its true meaning and the balance organizations must find between managing this debt and new feature innovation can be confusing. In this article, learn how to manage that delicate balance so you can create an exceptional product.
Navigating Digital Product Discovery: A Guide to Avoiding the 5 Common Pitfalls in Custom Product Development
In digital product development, a well-structured discovery phase is critical to a product’s long-term success. However, bringing a digital product from concept to reality can be challenging. In this article, Principal Product Strategist Josh Campbell shares his guide to avoiding five common pitfalls during digital product discovery.
Preparing Your Business for the Realities of AI and Machine Learning: Beyond the Hype
The buzz around artificial intelligence (AI) and machine learning (ML) has almost certainly reached a fever pitch. With benefits including increased efficiency and enhanced customer experiences, many businesses are eager to take advantage of these technologies. In this article by Chief Technology Officer Derek Perry, learn why organizations need a solid foundation to ensure they're ready to harness the benefits of AI and ML, before jumping in headfirst.