Aqua 0.4: Improved Programmatic Interface, Better Performance, Richer Finance Applications, and More

Marco Pistoia, Chun-Fu Chen, Shaohan Hu, Peng Liu,
Manoel Marques, Antonio Mezzacapo, Steve Wood

In the Qiskit ecosystem, Aqua is the element that encompasses cross-domain quantum algorithms and applications running on Noisy Intermediate-Scale Quantum (NISQ) computers. Aqua is an open-source library completely written in Python and specifically designed to be modular and extensible at multiple levels. Currently, Aqua supports four applications, in domains that have long been identified as potential areas for quantum computing: Chemistry, Artificial Intelligence (AI), Optimization, and Finance. In this story, we highlight the new features made available in Aqua 0.4 as well as in Qiskit Chemistry, AI, Optimization and Finance, specifying the changes that are not backwards compatible.

New Features in the Aqua Library of Algorithms

In this section, we describe the new features made available in Qiskit Aqua 0.4 at the level of the library of algorithms.

Compatibility with Terra 0.7 and Aer 0.1

Aqua 0.4 is fully compatible with the latest version of Qiskit Terra, 0.7, and with the newly released Qiskit Aer 0.1. This allows you to install and execute Aqua in the same Python environment as all the other Qiskit elements and components.

Improved Programmatic Interface

The Aqua wizard allows you to use Aqua as a tool; you can configure and execute quantum experiments without writing a line of code. However, Aqua has a more powerful use case. In fact, Aqua is an extensible library of quantum algorithms; users can extend it with new components and program experiments by calling the Aqua APIs. In Aqua 0.4, we have simplified the Aqua programmatic interface.

In previous versions of Aqua, in order to instantiate one of the algorithmic components — such as algorithms, optimizers, variational forms, oracles, feature maps and AI classifiers — you had to call either the empty constructor or factory method of that component’s class, followed by a call to init_args containing the parameters needed for that component to be initialized. That somewhat convoluted API structure was implemented in order to reconcile a pure programmatic approach with the declarative approach allowed by the Aqua wizard, which has the ability to automatically discover and dynamically load new components at run time. In order to simplify the programmatic approach, we have deprecated the init_args API. Component classes no longer have empty constructors. Rather, we now allow the constructor of each component to take as parameters all the objects needed for that component to be fully initialized. For example, this one line constructs and initializes an instance of Grover’s search algorithm:

algorithm = Grover(oracle)

where oracle is an instance of the Aqua Oracle interface.

It is also worth noting that, in previous versions of Aqua, a backend was made available to an algorithm in the form of a string, and it was the algorithm’s responsibility to create an instance of the backend by interpreting that string. Starting with this release, the Qiskit ecosystem includes a new element: Qiskit Aer, consisting of a collection of high-quality, high-performance and highly scalable simulators. Aer will help us understand the limits of classical processors by demonstrating to what extent they can mimic quantum computation. Furthermore, we can use Aer to verify that current and near-future quantum computers function correctly. Being fully integrated with the newly released Aer 0.1, Aqua 0.4 allows for an experiment’s backend to be constructed programmatically from the Aer APIs.

Furthermore, we have decoupled the Aqua algorithms from the Terra backends. An Aqua algorithm is now a pure implementation of a quantum algorithm, and as such it is orthogonal to the notion of the backend on which the algorithm-generated circuits will be executed. This decoupling is reflected by the fact that the construction of a QuantumAlgorithm object no longer requires setting up the backend. Rather, the backend is passed as a parameter to the run method of the QuantumAlgorithm object as is, or wrapped in a QuantumInstance object along with backend-configuration parameters.

The following program shows how to conduct a chemistry experiment using Aqua’s improved programmatic interface:

Fig. 1: Conducting a Chemistry Experiment Using Aqua’s Improved Programmatic Interface

Specifically, the program in Fig. 1 uses a quantum computer to calculate the ground state energy of molecular Hydrogen, H2, where the two atoms are configured to be at a distance of 0.735 angstroms. The molecular configuration input is generated using PySCF, a standard classical computational chemistry software package. First, Aqua transparently executes PySCF, and extracts from it the one- and two-body molecular-orbital integrals; an inexpensive operation that scales well classically and does not require the use of a quantum computer. These integrals are then used to create a quantum fermionic-operator representation of the molecule. In this specific example, we use a parity mapping to generate a qubit operator from the fermionic one, with a unique precision-preserving optimization that allows for two qubits to be tapered off; a reduction in complexity that is particularly advantageous for NISQ computers. The qubit operator is then passed as an input to the Variational Quantum Eigensolver (VQE) algorithm, instantiated with a Limited-memory Broyden-Fletcher-Goldfarb-Shanno Bound (L-BFGS-B) classical optimizer and the RyRz variational form. The Hartree-Fock state is utilized to initialize the variational form.

This example emphasizes the use of Aqua’s improved programmatic interface by illustrating how the VQE QuantumAlgorithm, along with its supporting components — consisting of the L-BFGS-B Optimizer, RyRz VariationalForm, and Hartree-Fock InitialState —are all instantiated and initialized via simple constructor calls. The Aer statevector simulator backend is passed as a parameter to the run method of the VQE algorithm object, which means that the backend will be executed with default parameters.

To customize the backend, you can wrap it into a QuantumInstance object, and then pass that object to the run method of the QuantumAlgorithm, as explained above. The QuantumInstance API allows you to customize run-time properties of the backend, such as the number of shots, the maximum number of credits to use, a dictionary with the configuration settings for the simulator, a dictionary with the initial layout of qubits in the mapping, and the Terra PassManager that will handle the compilation of the circuits. For the full set of options, please refer to the documentation of the Aqua QuantumInstance API.

Numerous new notebooks in the qiskit/aqua and community/aqua folders of the Qiskit Tutorials repository illustrate how to conduct a quantum-computing experiment programmatically using the new Aqua APIs.

Transparent Parallelization of Gradient-based Optimizers

Aqua comes with a large collection of adaptive algorithms, such as VQE (used in the example of Fig. 1), the Quantum Approximate Optimization Algorithm (QAOA), and the Quantum Support Vector Machine (SVM) Variational Algorithm for AI. All these algorithms interleave quantum and classical computations, making use of classical optimizers. Aqua includes nine local and five global optimizers to choose from. By profiling the execution of the adaptive algorithms, we have detected that a large portion of the execution time is taken by the optimization phase, which runs classically. Among the most widely used optimizers are the gradient-based ones; these optimizers attempt to compute the absolute minimum (or maximum) of a function f through its gradient ∇f.

Five local optimizers among those integrated into Aqua are gradient-based: the four local optimizers Limited-memory Broyden-Fletcher-Goldfarb-Shanno Bound L-BFGS-B (used in the code of Fig. 1), Sequential Least SQuares Programming (SLSQP), Conjugate Gradient (CG), and Truncated Newton (TNC) from SciPy, as well as Simultaneous Perturbation Stochastic Approximation (SPSA). Aqua 0.4 contains a methodology that parallelizes the classical computation of the partial derivatives in the gradient-based local optimizers listed above. This parallelization takes place transparently, in the sense that Aqua intercepts the computation of the partial derivatives and parallelizes it without making any change to the actual source code of the optimizers.

In order to activate the parallelization mechanism for an adaptive algorithm included in Aqua, it is sufficient to construct it with parameter batch_mode set to True. Our experiments have proven empirically that parallelizing the process of a gradient-based local optimizer cuts in half the execution time of the adaptive algorithms on a simulator.

Multiple-Controlled-NOT Operation

The Multiple-Controlled-NOT (cnx) operation, as the name suggests, is a generalization of the quantum operation where one target qubit is controlled by a number n of control qubits for a NOT (x) operation. The multiple-controlled-NOT operation can be used as the building block for implementing various different quantum algorithms, such as Grover’s search algorithm.

For the different numbers 0, 1, 2, … of controls, we have corresponding quantum gates x, cx, ccx, ... The first three are basic/well-known quantum gates. In Aqua, the cnx operation provides support for arbitrary numbers of controls, in particular, 3 or above.

Currently two different implementation strategies are included: basic and advanced. The basic mode employs a textbook implementation, where a series of ccx Toffoli gates are linked together in a V shape to achieve the desired multiple-controlled-NOT operation. This mode requires n - 2 ancillary qubits, where n is the number of controls. For the advanced mode, the cccx and ccccx operations are achieved without needing ancillary qubits. Multiple-controlled-NOT operations for higher number of controls (5 and above) are implemented recursively using these lower-number-of-control cases.

Aqua’s cnx operation can be invoked from a QuantumCircuit object
using the cnx API, which expects a list q_controls of control qubits,
a target qubit q_target, and a list q_ancilla of ancillary qubits.
An optional keyword argument mode can also be passed in to indicate whether the 'basic' or 'advanced' mode is chosen. If omitted, this argument defaults to 'basic'.

Random Distributions

A random distribution is an implementation of a circuit factory. It provides a way to construct a quantum circuit to prepare a state corresponding to a random distribution. More precisely, the resulting state, together with an affine map, can be used to sample from the considered distribution. The qubits are measured and then mapped to the desired range using the affine map. Aqua 0.4 introduces random distributions in the form of the RandomDistribution pluggable component, and provides numerous concrete implementations, such as BernoulliDistribution, LogNormalDistribution
MultivariateDistribution, MultivariateNormalDistribution, MultivariateUniformDistribution, NormalDistribution
UniformDistribution, and UnivariateDistribution.

Uncertainty Problems

Uncertainty is present in most realistic applications, and often it is necessary to evaluate the behavior of a system under uncertain data. For instance, in finance, it is of interest to evaluate expected value or risk metrics of financial products that depend on underlying stock prices, economic factors, or changing interest rates. Classically, such problems are often evaluated using Monte Carlo simulation. However, Monte Carlo simulation does not converge very fast, which implies that large numbers of samples are required to achieve estimations of reasonable accuracy and confidence. Uncertainty problems can be solved by the amplitude estimation algorithm, discussed below. Aqua 0.4 introduces the UncertaintyProblem pluggable component and provides implementations for several concrete uncertainty problems used in Aqua Finance, such as FixedIncomeExpectedValue, EuropeanCallExpectedValue and EuropeanCallDelta.

The Amplitude Estimation Algorithm

The Aqua library of algorithms is fully extensible; new algorithms can easily be plugged in. Aqua 0.4 includes a new algorithm: Amplitude Estimation, which is a derivative of Quantum Phase Estimation applied to a particular operator A, assumed to operate on n + 1 qubits (plus possible ancillary qubits). Here, the first n qubits encode the uncertainty (in the form of a random distribution), and the last qubit, called the objective qubit, is used to represent the normalized objective value as its amplitude. In other words, A is constructed such that the probability of measuring a 1 in the objective qubit is equal to the value of interest. Amplitude estimation leads to a quadratic speedup compared to the classical Monte Carlo approach when solving an uncertainty problem. Thus, millions of classical samples could be replaced by a few thousand quantum samples.

Qiskit Finance

The Amplitude Estimation algorithm, along with the RandomDistribution and UncertaintyProblem components introduced in Aqua 0.4, enriches the portfolio of Finance problems that can be solved on a quantum computer. These now include European Call Option Pricing (expected value and delta, using univariate distributions) and Fixed Income Asset Pricing (expected value, using multivariate distributions). New Jupyter Notebooks illustrating the use of the Amplitude Estimation algorithm to deal with these new problems are available in the Qiskit Finance tutorials repository.

Qiskit Chemistry

The support of Aqua for Chemistry continues to be very advanced. Aqua now features a new mechanism allowing pluggable components to register themselves to Aqua even without being part of the original Aqua installation package or installation directory. A component that has registered itself to Aqua is dynamically loaded and made available at run time to any program executed on top of Aqua. Taking advantage of this feature, we have remodeled the boundary between Qiskit Aqua and its Chemistry application. For example, the code for the Unitary Coupled Cluster Singles and Doubles (UCCSD) variational form and Hartree-Fock initial state has been made part of the Qiskit Chemistry project to reflect the fact that these components are chemistry-specific and unlikely to make sense in any non-chemistry setting. At installation time, these components register themselves to Aqua as Aqua extensions. The program in Fig. 1 shows how to import and use the HartreeFock InitialState as an Aqua extension from Qiskit Chemistry as opposed to Qiskit Aqua.

We have also improved the way molecular configurations are input into Qiskit Chemistry. Specifically, Qiskit Chemistry interfaces four classical computational-chemistry software packages: Gaussian™ 16, PSI4, PySCF and PyQuante. Qiskit Chemistry is unique in the fact that it allows the end user to configure chemistry experiments using these classical software packages as the front end, without imposing any new programming language or APIs. Qiskit Chemistry then executes these software packages classically to compute some preliminary data necessary to form the input to the underlying quantum algorithms in Aqua. Directly exposing to the end user classical computational software configuration parameters maximizes the functionality available to the underlying quantum algorithms. In this release, we have unified some advanced configuration features across the various drivers currently supported by Qiskit Chemistry. For example, while all the supported drivers allow the user to configure a molecule’s geometry by specifying the x, y and z coordinates of each atom in the molecule, only Gaussian™ 16 and PSI4 allow the end user to enter a molecule’s configuration in Z-matrix format, which consists of describing each atom in a molecule in terms of its atomic number, bond length, bond angle, and dihedral angle (the angle between planes through two sets of three atoms having two atoms in common). A Z-matrix configuration assigns the second atom of a molecule along the z axis from the first atom, which is assumed to be at the origin. This representation is very intuitive and convenient, especially when the position and orientation in space of a molecule are irrelevant. Starting from V0.4, Qiskit Chemistry allows the configuration of a molecule to be entered in Z-matrix format even when the user has chosen PySCF or PyQuante as the classical computational chemistry software driver interfaced by Qiskit Chemistry, which transparently converts any Z-matrix configuration entered by the user to the corresponding Cartesian coordinates.

Qiskit AI

Aqua 0.4 introduces two new implementations of the FeatureMap pluggable component, PauliZExpansion and PauliExpansion.

The PauliZExpansion feature map is a generalization of the already existing FirstOrderExpansion and SecondOrderExpansion feature maps, allowing for the order of expansion k to be greater than 2.

The PauliExpansion feature map generalizes the existing feature maps even more. Not only does this feature map allows for the order of expansion k to be greater than 2, but it also supports Paulis I, X and Y, in addition to Z.

Additionally, we have improved both the Support Vector Machine Quantum Kernel (QSVM Kernel) and Support Vector Machine Quantum Variational (QSVM Variational) algorithms by allowing a training model to be serialized to disk and dynamically retrieved in subsequent experiments.

Qiskit Optimization

In Aqua 0.4, we introduce new Ising models for the following optimization problems: exact cover, set packing, vertex cover, clique, and graph partition. All this problems are solved with VQE. Jupyter Notebooks illustrating how to use a quantum computer to solve these problems are available in the Qiskit community Optimization tutorials repository.


Aqua was inspired, authored and brought about by the collective work of an international team of researchers. We would like to thank in particular Jay Gambetta and Stefan Woerner for their contributions to this release.