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

TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.

XZ Gets the AllClear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.

Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcommpowered devices.

Kodi 21.0 OpenSource Entertainment Hub Released
After a year of development, the awardwinning Kodi crossplatform, media center software is now available with many new additions and improvements.

Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.

Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.

Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.

Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.

New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs

Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.