Qiskit – Practical open source framework for quantum computing
Smart Toolbox
Qiskit is an open source framework that aims to make quantum computing technology both understandable and ready for production.
IBM is working on increasing the performance of the interaction between hardware and software. The milestones [1] planned for this effort are shown in the IBM Quantum Development Roadmap (Figure 1). To benefit from IBM Quantum hardware, the software and infrastructure must support a wide range of requirements and experiences. This need for versatility requires tools for different types of developers.
Qiskit (think "kiss kit") is a freely available software development kit (SDK) for working with quantum computers at the level of pulses, circuits, or application modules. At least, that's what the SDK home page says. Since its first publication in 2017, the project has grown and undergone some fundamental changes.
Figure 2 provides an overview of Qiskit and the major projects within the Qiskit community. In addition to this main Qiskit effort are numerous other projects that include the Qiskit name and form an important part of the Quantum open source landscape [2]. (See the "Open Source in Quantum Computing" box.)
Open Source in Quantum Computing
Because Qiskit is open source software, other companies can implement an interface to their quantum computers. For example, Alpine Quantum Technologies (AQT [3]) is working on a generalpurpose quantum computer. To access its back end, you just need to create an account and install the Qiskit AQT provider (Listing 1). Dr. Albert Frisch, senior research engineer at AQT, likes the open source spirit surrounding quantum computing: "Building generalpurpose quantum computers is complex, but thanks to Qiskit, customers have easy access to our systems and can gain experience at different levels, from novice to expert."
Listing 1
Installing the AQT Provider
from qiskit_aqt_provider import AQTProvider aqt = AQTProvider('MY_TOKEN') print(aqt.backends()) sim_backend = aqt.backends.aqt_qasm_simulator
Many of the core Qiskit capabilities are implemented in the form of Qiskit Terra [4], the largest component in the Qiskit ecosystem. Many of the other components have dependencies on Terra. Table 1 lists some important Qiskit modules.
Table 1
Qiskit Modules at a Glance
Module  Description 


Quantum circuits for initializing and editing objects for flow control, registers, circuits, instructions, gates, and parameters. 

Library with numerous predefined circuits, directives, and gates as basic building blocks for circuitbased quantum computations. 

Collection of quantum algorithms, such as Grover's search algorithm [5], Variational Quantum Eigensolver (VQE) [6], or Quantum Approximate Optimization Algorithm (QAOA) [7]. 

Collection of operators as a lingua franca for the theory and implementation of quantum algorithms and applications. 

Collection of classes (such as Sampler and Estimator) to include basic operations provided by quantum hardware and simulators. 

Transpilers to help rewrite quantum circuits to match the topology of a particular quantum computer. 

Tools used to visualize quantum circuits and results of experiments. 
Qiskit comes with a number of components that focus on specific use cases. For instance, Qiskit Nature aims to solve scientific problems using quantum algorithms. You'll find tools intended to address basic and excited states of molecular structures.
Qiskit Machine Learning provides tools for a number of applications in the Quantum Machine Learning research area. These tools include quantum neural networks (QNNs), quantum generative adversarial networks (QGANs), and quantum kernels. The TorchConnector
class provides an interface to PyTorch and lets users combine classical artificial intelligence workflows with quantumbased approaches. Qiskit Finance, on the other hand, offers quantumbased approaches to solving typical problems in finance, for example portfolio optimization, risk analysis, and price evaluation of financial options. Qiskit Optimization is a collection of tools designed to address optimization problems using quantum algorithms.
Qiskit also includes components that operate at a lower level in the development stack. The Qiskit Experiments library, for instance, is used to run characterization, calibration, and verification experiments on real qubits. Qiskit Metal provides engineers and scientists with graphical support for developing chips for superconducting quantum computers. Another component called Qiskit Dynamics is used to build, transform, and solve timedependent quantum systems. Qiskit Aer delivers simulators that allow you to simulate quantum computations on classical computers.
Running quantum circuits on real quantum computers requires an interface between Qiskit and the appropriate hardware vendor. This hardware interface is already available from a number of vendors, including IBM, AQT, and IonQ.
Quantum Composer
IBM Quantum Composer provides an easy entry point to visually define quantum circuits online using drag and drop. All you need is a free IBM Quantum account [8]. You can export the result of your work directly as code. Figure 3 shows a GHZ state for three qubits, where all are maximally entangled (see the article entitled "Cat's Dilemma" elsewhere in this issue).
In the IBM Quantum Lab, you can write your code directly or edit previously exported code. Listing 2 shows how to create a GHZ state as an example: Superpose qubit 0 and then interleave the other qubits with qubit 0 using CX (controlledNOT) gates. The results from Figure 3 were computed using the Aer simulator and confirm that a GHZ condition exists.
Listing 2
Creating a GHZ State
from qiskit import QuantumCircuit, execute, Aer, QuantumRegister qc = QuantumCircuit( 3, 3 ) qc.h( 0 ) qc.cx( 0, 1 ) qc.cx( 0, 2 ) qc.measure_all() simulator = Aer.get_backend( 'qasm_simulator' ) job = execute( qc, simulator, shots=4000 ) result = job.result() counts=result.get_counts() print(counts)
Instead of simulating the circuit, you can run it on a quantum computer. One of the available IBM quantum computers can provide the back end for the example in Listing 3. The results are not quite as clear due to the noise on the physical system. The 4000 measurements also include some measurements that do not return either 000> nor 111> – even though the majority still show the correct states. We will see how to avoid such mistakes later on.
Listing 3
Quantum Computer as Back End
from qiskit import IBMQ # Query the freely available quantum computers provider = IBMQ.load_account() provider = IBMQ.get_provider( hub='ibmq' ) print(provider.backends()) # Run on a physical quantum computer device = provider.get_backend( 'ibmq_lima' ) job = execute( qc, backend=device, shots=4000 ) result = job.result() counts=result.get_counts() print(counts)
Qiskit Runtime
Quantum computers are ideal for solving a few specific types of problems, but they aren't designed to manage the whole process. Instead, a quantum computer typically works together with classical computer; the classical computer preprocesses input or postprocesses the result, sometimes managing several iterations of quantum processing steps. A typical scenario would be a legacy system running locally and accessing a quantum system in the cloud. However, connecting a cloudbased quantum system with a local classical computer is quite inefficient, because of the latency associated with communicating over the Internet. Qiskit Runtime [9] offers a new paradigm for running computations on quantum computers. The Qiskit Runtime execution environment allows hybrid algorithms that mix legacy and quantum computations to all run directly in the cloud
The runtime shows improvements for both hybrid and more general algorithms. You can access Qiskit Runtime using an IBM Quantum account. Alternatively, you can create a Qiskit Runtime instance in the IBM cloud.
To create an instance, run PIP to install both Qiskit (package qiskit) and the Qiskit Runtime IBM Client (qiskitibmruntime).
First, you need to create the general GHZ state for n qubits (Listing 4, lines 6 and 7) – the example with three qubits was given earlier in this article. Then apply a bitwise XOR with the number 1 to this state to flip the first qubit (line 8). Then use Sampler
(from line 6) to determine the quasiprobabilities of the circuit.
Listing 4
QuasiProbabilities of the Circuit
01 from qiskit.circuit.library import XOR 02 from qiskit_ibm_runtime import QiskitRuntimeService, Sampler 03 N = 5 04 qc2 = QuantumCircuit(N) 05 qc2.h( 0 ) 06 for x in range( 1, N ): 07 qc2.cx( 0, x ) 08 qc2.compose( XOR(N,1), inplace=True ) 09 qc2.measure_all() 10 program_inputs = { 11 "circuits": qc2, 12 "circuit_indices": [0], 13 } 14 service = QiskitRuntimeService( channel="ibm_quantum", token=IBMQuantumAPIKey) 15 options = { 'backend_name': 'ibmq_lima' } 16 job = service.run( 17 program_id="sampler", 18 options=options, 19 inputs=program_inputs, 20 ) 21 print(job.result())
Qiskit at Work
The Qiskit team is always looking for realworld examples that demonstrate quantum principles. See the box entitled "Games" for some Qiskitbased quantum computing games that are available online. A deeper example is the work of Team Quantimize [11], a group of five quantum technology students who have already participated in several quantum challenges, such as the Qiskit Global Hackathon 2021. However, their biggest project to date was the Deloitte Quantum Climate Challenge 2022. The task was to optimize flight routes in order to protect the earth's atmosphere to the greatest extent possible, since burning kerosene has a different effect at different locations. Team Quantimize used atmospheric data from the German Aerospace Center (DLR) and information on minimum distances from German Air Traffic Control (DFS) to find an optimized, quantumbased solution.
Games
Games are a helpful way to approach a new technology and build an understanding of it. One example is the quantum coin game, which makes use of the principles of superposition and interference. Actually, the quantum coin game isn't much of a game at all, although it is an excellent way to illustrate the use of quantum computing. On a classical computer, the coin game gives each of the two players a 50 percent chance of winning. On a quantum computer, the results are a bit more onesided. A qubit represents a coin that two players (Alice and Bob) take turns either flipping or leaving in its current position. Flipping corresponds to applying an Xgate to the qubit; leaving it corresponds to the state of an LDgate. The procedure is always the same: At the beginning, heads is on top, which is equivalent to the state 1>. Alice starts and three rounds are played without seeing the results. In the end, Alice wins for heads, and Bob wins for tails.
Classically, the game amounts to a series of coin flips, and each player has an equal chance. However, if you play the game on a quantum computer, the outcome is quite different. Alice can additionally apply a Hadamard (H) gate to put the qubit into a superposition, so that the coin is effectively both heads and tails at once. Bob's move then no longer has any effect, since neither the application of the Xgate nor the LDgate significantly changes the state of the qubit representing the coin. If Alice now applies an Hgate again in her last move, which resolves the superposition, she wins with a probability of 100 percent. Figure 4 shows the course of the game using the Bloch sphere.
Another, somewhat more complex example is the GHZ game, which takes advantage of the entanglement of a GHZ circuit. You'll find the details and exact instructions for both games, including Jupyter notebooks, on the GitHub page of one of the authors [10] if you are interested.
The idea was to map the atmospheric data onto a map of qubits, all in superposition. Using the Quantum Approximate Optimization Algorithm (QAOA), the students then determined the best flight path. QAOA is an iterative process that involves the interaction of a legacy computer with a quantum computer to solve an optimization problem (Figure 5). The algorithm sorts the qubits into 0> and 1> states, so that the dividing line between them results in the flight path.
For this challenge, the team was able to directly apply the existing QAOA algorithm to their problem and convert it into a quantum circuit. Listing 5 demonstrates the core element of the optimization, where cost_grid
represents the discretized atmospheric data.
Listing 5
QAOA to a Quantum Circuit
import qiskit def run_QAOA( cost_grid, backend=qiskit.Aer.get_backend( 'qasm_simulator' ) ): # Generate cost function from a cost matrix (cost_grid); # function written inhouse function, coeffs = construct_function( cost_grid ) # Create quadratic program; function written inhouse, # nutzt qiskit.optimization.QuadraticProgram qp = generate_QP( coeffs, len( cost_grid ) ) # Initialize backend and optimization algorithm qins = qiskit.utils.QuantumInstance( backend=backend, shots=1000, seed_simulator=123 ) meo = qiskit_optimization.algorithms.MinimumEigenOptimizer \ ( min_eigen_solver=qiskit.algorithms.QAOA( reps=1, quantum_instance=qins) ) # Solve problem with builtin QAOA algorithm result = meo.solve(qp)
Team Quantimize used Qiskit to simulate its quantum circuit and then run it on an IBM quantum computer. Using brute force, it was possible to confirm that both the simulation and the quantum computer produced matching results.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News

KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.

Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.

DebConf24 to be Held in South Korea
Busan will be the location of the latest DebConf running July 28 through August 4

Fedora Unleashes Atomic Desktops
Fedora has combined its solid distribution with rpmostree system to make it possible to deliver a new family of Fedora spins, called Fedora Atomic Desktops.

Bootloader Vulnerability Affects Nearly All Linux Distributions
The developers of shim have released a version to fix numerous security flaws, including one that could enable remote control execution of malicious code under certain circumstances.

Microsoft Says VS Code Will Work with Ubuntu 18.04
If you're a user of Microsoft's VS Code and you're still using Ubuntu 18.04, you can breathe a sigh of release that the IDE will continue working… for a while.

Purism Crowdfunding Launched
The first public offering on StartEngine crossed the US$ 100,000 mark within 48 hours of launch.

System76 Refreshes Serval WS Laptop
With more and more users turning to AI workloads, System76 decided to raise the bar with its Serval WS laptop by upping the specs on a few key components.

Docker Build Cloud Helps Speed Up Build Time
Docker has announced a new product that directly addresses the time spent waiting on builds to complete.

Firefox 122 Release Includes Official DEB for Ubuntu Distros
Finally, Mozilla has returned to Ubuntu's/Debian's roots to offer an official DEB package for those who prefer to not use the Snap package.