This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

\labelformat

equation(#1) \labelformatsection(#1)

OpenQAOA — An SDK for QAOA

Vishal Sharma    Nur Shahidee Bin Saharan    Shao-Hen Chiew    Ezequiel Ignacio Rodríguez Chiacchio    Leonardo Disilvestro    Tommaso Federico Demarie    Ewan Munro Entropica Labs, 186b Telok Ayer Street, Singapore 068632 [email protected]
Abstract

We introduce OpenQAOA, a Python open-source multi-backend Software Development Kit to create, customise, and execute the Quantum Approximate Optimisation Algorithm (QAOA) on Noisy Intermediate-Scale Quantum (NISQ) devices and simulators. OpenQAOA facilitates the creation of QAOA workflows, removing the more tedious and repetitive aspects of implementing variational quantum algorithms. It standardises and automates tasks such as circuit creation across different backends, ansatz parametrisation, the optimisation loop, the formatting of results, and extensions of QAOA such as Recursive QAOA. OpenQAOA is designed to simplify and enhance research on QAOA, providing a robust and consistent framework for experimentation with, and deployment of, the algorithm and its variations. Importantly, a heavy emphasis is placed on the provision of tools to enable QAOA computations at the scale of hundreds or thousands of qubits.

preprint: APS/123-QED

I QAOA with hundreds of qubits

Variational quantum algorithms (VQAs) are a firmly established hybrid approach to using noisy intermediate scale quantum (NISQ) and classical computers in tandem to tackle problems of scientific and industrial interest [1, 2, 3]. In contrast to quantum algorithms such as Grover’s or Shor’s algorithms, which come with performance guarantees and even speed-ups over classical approaches, VQAs are heuristic methods whose performance has become a major line of investigation in recent years. Today’s quantum computers typically support only a few tens of qubits. However, this number is expected to rise to several hundred in the next few years. Hence, research and development with VQAs will soon enter a new phase, characterised by a marked shift in scale.

This upwards step in scale will likely precipitate significant changes in research, working methods, and priorities within the field. For example, classical simulations of VQAs currently constitute a large part of the algorithmic prototyping and experimentation process. Moving forward, a more significant proportion of this work will take place directly on quantum computers. Meanwhile, on the applications side, the focus will shift away from small and illustrative ‘toy’ problems towards ones that capture more of the complexity of valuable target use-cases.

One of the most prominent VQAs is the Quantum Approximate Optimisation Algorithm (QAOA) [4], which has attracted much attention for its potential application to combinatorial optimisation problems. A broad spectrum of research work on QAOA has emerged, attempting to clarify questions ranging from fundamental aspects of its mechanism and its limitations [5, 6, 7, 8, 9, 10, 11, 12] to its suitability for specific use-cases [13, 14, 15, 16, 17, 18, 19, 20]. Coupled with the imminent arrival of quantum computers with hundreds of qubits, the growth in research activity for QAOA motivates the need for robust, consistent supporting software tools.

Refer to caption
Figure 1: OpenQAOA is conceptually divided into two parts. The Core contains all the features needed to set up and manage a QAOA computation, from problem input to result retrieval. The Enabler contains tools to support workflow deployment and execution on quantum hardware, with the aim of providing the features necessary to execute QAOA at the scale of hundreds of qubits.

In this article, we introduce OpenQAOA, an open-source Python Software Development Kit (SDK) that aims to meet these needs by simplifying and enhancing research work for all user groups. OpenQAOA has a strong focus on integrating physical devices, providing support for multiple quantum computing backends, as well as simulators. Algorithmically, OpenQAOA provides robust implementations of multiple extensions to the original proposal of Farhi et al. [4], including alternative circuit parametrisations and mixer operators, as well as strategies such as Recursive QAOA [9].

OpenQAOA is more than a library to solve optimisation problems with QAOA: it strives to be a tool to bridge algorithms and hardware. Executing computations on real quantum hardware at scale introduces many challenges, such as the need for effective circuit compilation methods to minimise the impact of noise. OpenQAOA seeks to address these issues through custom QAOA-tailored solutions, as well as integration with existing tools in the quantum open source ecosystem.

The source code for OpenQAOA is licensed under Apache 2.0 and is available at https://github.com/entropicalabs/openqaoa. The latest documentation can be consulted at https://el-openqaoa.readthedocs.io/en/latest/.

II An SDK for QAOA at scale

The role of an SDK is to provide a set of software tools and programs to create specific applications, resulting in a faster development environment for building and designing reliable and performant code. Within the context of quantum optimisation in the NISQ era, this means abstracting repeated and tedious tasks, improving cross-platform development, and providing tools and features that enable computations at the scale of hundreds or thousands of qubits. To illustrate different types of obstacles on the path to large-scale QAOA, and how OpenQAOA seeks to address them, we give three specific examples.

Firstly, a QAOA circuit can rarely be executed directly, ‘as-is’ on a quantum processing unit (QPU). The abstract circuit must be compiled to conform to the specification of the target device, taking into account its connectivity and available native gates. Furthermore, this compilation should minimise metrics strongly associated with the proliferation of noise, such as the circuit depth and the number of two-qubit gates. This noise suppression challenge will become more acute as researchers focus on increasingly larger problems. Therefore, in the NISQ era, circuit construction must be ‘hardware-aware’, and should call on suitable optimisation methods to limit the impact of noise. A major goal of OpenQAOA is to achieve tight integration with powerful circuit compilation tools.

Secondly, a greater degree of algorithmic flexibility will be needed to tackle larger and more complex problems. QAOA has many customisable components, including the circuit initial state, the mixer operator, the ansatz parametrisation, the initial parameter values, and the classical optimiser. The ability to easily experiment with these components, individually and in combination, will facilitate research on a wide range of problem classes and provide extensive scope for optimising performance at scale. OpenQAOA aims to meet the need for algorithmic design flexibility through its highly modular structure.

Finally, the performance of QAOA may be improved for large problems by embedding the algorithm in a wider workflow. A prominent example is Recursive QAOA (RQAOA), which combines QAOA with a divide-and-conquer approach, whereby a series of successively smaller problems are defined by eliminating variables [9]. Eliminating variables (qubits) one by one – as contemplated in the original RQAOA proposal – may lead to impractically long runtimes, especially for problems initially defined on many hundreds or thousands of variables. Besides a standard RQAOA workflow, OpenQAOA provides a customisable adaptive strategy, Ada-RQAOA, allowing multiple qubits to be eliminated at a time [21].

Solving these challenges is an effort to lower the entry barrier to quantum computing, while maintaining a research-grade code base fit for executing QAOA at scale. The role of an SDK such as OpenQAOA can then be seen as a democratising force, bringing quantum applications closer to researchers and end users.

III QAOA – The basics

We now review the main aspects of QAOA, with a particular emphasis on the features most relevant to OpenQAOA. For the remainder of the article, we refer to the original implementation of QAOA in Ref. [4] as standard QAOA. Furthermore, given the extensions and modifications of the standard QAOA that have been developed, we will often refer to their collective as a family of QAOAs.

III.1 Algorithmic components

Given a cost Hamiltonian HcH_{c}, the objective of QAOA is to optimise the expectation value Ψ(γ,β)|Hc|Ψ(γ,β)\langle\Psi(\gamma,\beta)|H_{c}|\Psi(\gamma,\beta)\rangle. In the standard QAOA, the variational ansatz state |Ψ(γ,β)|\Psi(\gamma,\beta)\rangle is defined as

|Ψ(γ,β)=k=1peiβkHmeiγkHc|+n.|\Psi(\gamma,\beta)\rangle=\prod_{k=1}^{p}e^{-i\beta_{k}H_{\textrm{m}}}e^{-i\gamma_{k}H_{\textrm{c}}}|+\rangle^{\otimes n}. (1)

The circuit is initialised in the state |+n|+\rangle^{\otimes n}, where nn is the number of qubits. Sets of unitary operators are then alternately applied to the state in a layer-wise manner. A layer in the QAOA circuit denotes the application of the complete set of unitaries, and the parameter pp corresponds to the number of layers in the circuit ansatz. Each layer is composed of the alternate evolution under unitaries generated by the cost Hamiltonian HcH_{c} encoding the problem, and a mixer Hamiltonian HmH_{\textrm{m}}. These unitary operators are parametrised by the variational parameters {γk}\{\gamma_{k}\} and {βk}\{\beta_{k}\} respectively, with k=1,,pk=1,\ldots,p.

Cost Operator: The most commonly envisioned usage of QAOA is to tackle classical binary combinatorial optimisation problems. In this case, the elements of the cost Hamiltonian are derived directly from the cost function associated with the problem at hand. It is well known that these problems can be cast in the Ising form, i.e. as a set of interacting spin-1/21/2 particles or binary variables [22]. This means that the objective function can be encoded as the expectation value of a cost Hamiltonian HcH_{c} of the form

Hc=jhjZj+j,kJjkZjZk,H_{c}=\sum_{j}h_{j}Z_{j}+\sum_{j,k}J_{jk}Z_{j}Z_{k}, (2)

where ZjZ_{j} denotes the Pauli-Z operator acting on the jthj^{th} spin, hjh_{j} is a bias term for single spins indicating their preference for one of the two possible operator eigenvalues, and JjkJ_{jk} denotes the coupling strength between the spins jj and kk. Equation 2 may also contain linear and quadratic terms that enforce constraints relevant to the problem. These constraints give a significant positive contribution to the energy if violated, but zero otherwise. When the entire problem can be formulated this way, we say we have a problem in quadratic unconstrained binary optimisation (QUBO) form [23].

The unitary operator associated with the cost Hamiltonian can be generalised beyond its standard form – i.e., as it appears in Eq. 1 – by increasing the number of variational parameters in the ansatz. The corresponding ‘cost operator’ for the LthL^{th} layer, Uc(L)U_{c}^{(L)}, then takes the form

Uc(L)=exp(i[jγjLhjZj+j,kγjkLJjkZjZk]).U_{c}^{(L)}=\exp\Big{(}-i\Big{[}\sum_{j}\gamma_{j}^{L}h_{j}Z_{j}+\sum_{j,k}\gamma_{jk}^{L}J_{jk}Z_{j}Z_{k}\Big{]}\Big{)}. (3)

Here, the coefficients {hj}\{h_{j}\} and {Jjk}\{J_{jk}\} are as defined in Eq. 2, and {γjL,γjkL}\{\gamma_{j}^{L},\gamma_{jk}^{L}\} denote the variational circuit parameters for each term in the cost Hamiltonian for the LthL^{th} layer.

Mixer Operator: The mixer operator is responsible for exploring the solution space, and creating interference between the computational basis states. In standard QAOA, the mixer operator is constructed from the Hamiltonian Hm=iXiH_{m}=-\sum_{i}X_{i}, where XiX_{i} is the Pauli-X operator acting on the ithi^{th} qubit. As with the cost operator, this unitary ‘mixer operator’ for the LthL^{th} layer, Um(L)U_{m}^{(L)}, can also be generalised from its standard form as

Um(L)=exp(ijβjLXj),U_{m}^{(L)}=\exp\Big{(}i\sum_{j}\beta_{j}^{L}X_{j}\Big{)}, (4)

where {βjL}\{\beta_{j}^{L}\} are the variational parameters associated with each term in the mixer Hamiltonian for the LthL^{th} layer. Different applications may call for alternative mixer operators, for example in the context of constrained optimisation, where it is desirable to explore a limited subspace of the full Hilbert space [24, 17].

Parametrisation: It is possible to establish fixed relationships between different sets of the variational parameters, leading to many possible state ansätze. We refer to a particular specification of these relationships as a ‘parametrisation’. For example, in the standard QAOA, we fix all parameters associated with the cost operator within a given layer to be equal, and similarly for the mixer operator. That is, we set γjL=γkL=γjkLγL\gamma_{j}^{L}=\gamma_{k}^{L}=\gamma_{jk}^{L}\equiv\gamma^{L}, and βjLβL\beta_{j}^{L}\equiv\beta^{L}; we refer to this as the ‘standard parametrisation’. While this parameterisation is prevalent in much of the literature, alternative approaches have been proposed, and will be discussed further in Section IV.2.

Parameter initialisation: For a given parametrisation, one must select initial values for the corresponding parameters. We refer to this as ‘parameter initialisation’, or simply ‘initialisation’ when the context is clear. The initialisation strategy can strongly impact the performance of the algorithm. For example, assigning random initial values could lead to acute issues in the scalability of the optimisation procedure [25, 26].

Initial state: Before applying the cost and mixer operations, the quantum circuit must be prepared in some initial state. In standard QAOA, one uses the equal superposition state |+n|+\rangle^{\otimes n}, however this may be undesirable for certain applications, e.g. constrained optimisation problems.

III.2 Computational procedure

QAOA consists of a hybrid process where quantum and classical routines are performed in a loop. The algorithm itself can be divided into three main phases, summarised in Fig. 2.

  • Preparation phase — A circuit ansatz is selected by specifying fixed problem inputs and variational parameters. The inputs include the cost Hamiltonian, the number of layers, the structure of the mixer layer, the parametrisation, and the initialisation strategy.

  • Classical-quantum loop phase — The circuit is prepared and executed either on a QPU or on a simulator. After the execution, measurement data is obtained from a QPU or a simulator (the wavefunction is obtained if a wavefunction simulator is being used). The measurement outcomes are then used to compute the cost Hamiltonian expectation value corresponding to the current set of variational parameters. Based on this expectation value, the classical optimiser proposes an updated set of variational parameters to be used in the next iteration. The algorithm thus consists of a loop over the circuit’s creation-execution, followed by optimisation of the variational parameters. This loop exits when the optimiser’s stopping criterion is met, and the variational parameters are considered optimised. We refer to these final values of the parameters as the ‘optimised’ or ‘optimal’ parameters, and the corresponding output quantum state as the ‘optimised’ or ‘optimal’ state.

  • Result phase — The third and final stage is the collection of the results and their parsing and presentation to the user. The raw output of QAOA is a distribution over all the computational basis states {|z}\{|z\rangle\}, where |z|z\rangle denotes an eigenstate of HcH_{c}, and the set of associated optimal parameters, which we denote {β}\{\beta^{*}\} and {γ}\{\gamma^{*}\}. Therefore, finding a unique bitstring solution encoding the answer to the original QUBO problem involves using a post-selection scheme after completing the optimisation process. Common choices are either the most probable bitstring, or the one corresponding to the lowest expectation value measured, depending on the goals at hand.

Refer to caption
Figure 2: The functional phases of OpenQAOA, and their relation to the different components of QAOA workflows. The preparation phase constructs the quantum circuit for the specified problem, with chosen input specifications. When a particular QPU backend is selected, the preparation phase includes a compilation step taking account of the device topology and native gate set. The quantum-classical loop phase is responsible for orchestrating the computation between the classical optimiser and the QPU or simulator, and terminates when a stopping criterion is reached. Following termination, the result phase provides a structure to access the problem solution and intermediate data associated with the optimisation.

Several modifications, enhancements, and extensions of the standard QAOA have been proposed [27, 28, 9]. Intuitively, these modifications form a family of QAOAs, related in their structure through the layer-wise application of mixer and cost operations. Recursive QAOA (RQAOA) [9], which we introduce within the context of OpenQAOA in Section IV.6, is a prominent member of this family.

IV OpenQAOA - API reference

OpenQAOA provides APIs (application programming interfaces) between users and algorithms within the QAOA family. Interfaces are abstractions that help focus the user’s attention on the QAOA, its implementation on QPUs, and its customisation by removing the need to write repetitive code dependencies to implement the algorithm explicitly. OpenQAOA interfaces are not constructed from a new circuit library, but are a programmable, abstract and device-independent description of QAOAs.

In OpenQAOA, there are two types of interfaces: workflows and factory mode. Workflows have been designed to be the simplest way to execute an end-to-end QAOA. They consist of a series of logical steps enabling the user to select the type of QAOA and its properties, such as the parametrisation, compilation steps, or the choice of the classical optimiser. The factory mode trades simplicity for deeper manipulation of the objects used to build the workflows. Therefore, it is a way for users to either develop their own workflows or extract information that may not be directly exposed through the regular workflows.

IV.1 QAOA workflows

OpenQAOA comes with two pre-defined workflows: QAOA and RQAOA (see Section IV.6). Support for the Alternating Operator Ansatz [27] and ADAPT-QAOA [28] is planned for future releases. While workflows implement QAOAs with the hybrid structure highlighted in Section III, the API structure is slightly different. Given a QUBO problem, the simplest executable workflow is the following:

from openqaoa.workflows import QAOA
q = QAOA()
q.compile(qubo)
q.optimize()
For a given QUBO problem, this is the simplest OpenQAOA workflow. All variational parameters and other circuit properties here assume their default values.

A QAOA object is instantiated via the initialisation step q = QAOA(). In the simplest case, all the required variational parameters and circuit properties are set to default values. In the following sections, we will show how to customise these parameters and properties within the OpenQAOA workflow and implement different flavours of QAOA. This process includes customising circuit properties, choosing particular backends and devices, and configuring classical optimisers.

The compilation step q.compile(qubo) is where the internal abstract representation of the QAOA is generated. The QUBO problem qubo used in the compilation step is prepared either through the OpenQAOA problem classes located in openqaoa.problems.problem, or it can be directly specified in terms of Python primitives by the user. OpenQAOA natively supports a set of popular problem classes modelled as QUBO problems. Note that, until this stage, the description of the QAOA is device independent and solely defined in terms of OpenQAOA primitives.

The final stage is the optimisation step, where the backend-specific circuit is created and submitted to either a simulator or a QPU. Subsequently, the optimisation loop is performed, and when the desired exit criteria are satisfied, the results will be accessible as attributes q.result_information of the QAOA object.

The initialisation step is where the parameters of the QAOA can be modified to suit the user’s needs. Codeblock 4 illustrates an example of how a workflow can be customised, and Sections IV.2 — IV.5 are dedicated to explaining each customisation step in detail.

# Instantiate the QAOA object
q = QAOA()
\par# Define the circut ansatz
q.set_circuit_properties(
p=2,
param_type=’standard’,
init_type=’rand’,
mixer_hamiltonian=’xy
)
\par# Create and set the device
local_qasm_device = create_device(
location=’local’,
name=’qiskit.qasm_simulator
)
q.set_device(local_qasm_device)
\par# Set the backend properties
q.set_backend_properties(
n_shots=2000,
cvar_alpha=0.9,
init_hadamard=True
)
\par# Set the classical optimiser properties
q.set_classical_optimizer(
method=’nelder-mead’,
maxiter=500,
cost_progress=True
)
\parq.compile(qubo)
q.optimize()
A customised workflow where the user sets the circuit ansatz, the parameter of the optimisation loop, and the backend properties. This demonstrates how the user can customise the workflows extensively with minimal effort.

IV.2 The OpenQAOA Ansatz

In OpenQAOA, the circuit ansatz can be modified easily through the workflow routines. This is done by using the set_circuit_properties method.

The user can specify the type of circuit parametrisation and its initialisation through the keywords param_type and init_type, and the number of layers is set through p. OpenQAOA offers several classes of parametrisation.

q.set_circuit_properties(
p=2,
param_type=’standard’,
init_type=’rand’,
mixer_hamiltonian=’xy
)
The circuit properties dictate the number of layers in the QAOA, the parameter type and their initialisation strategy, and the type of desired mixer Hamiltonian.
  • The default is the Standard parametrisation. In a given layer, each qubit is assigned the same mixer rotation angle β\beta, and each term in the cost Hamiltonian is assigned the same angle γ\gamma.

  • The Fourier parametrisation is defined through the discrete cosine and sine transforms of the γ\gamma and β\beta parameters across several layers, as proposed in Ref. [7].

  • The Annealing parametrisation emulates a discretised adiabatic annealing schedule using a QAOA circuit.

  • Some parametrisations can further be generalised by increasing the number of free variational parameters. The With-Bias sub-class parametrises the linear terms independently from the quadratic terms in the Hamiltonian.

  • The Extended sub-class parametrises each term in the Hamiltonian individually. In a standard QAOA circuit, there are 2p2p variational parameters, where pp is the number of layers. In the extended parametrisation, the number of parameters equals the number of terms in the Hamiltonian of Eq. 2. For fully-connected cost Hamiltonians, where all variables appear together in quadratic terms, the total number of parameters is O(n2)O(n^{2}), where nn is the number of variables. In general, the connectivity of the cost Hamiltonian for classical optimisation problems is defined by the pairs of (i,j)(i,j) in the second term of Eq. 2.

More information on the construction of these parametrisations may be found in the OpenQAOA documentation [29].

Besides setting the parametrisation class, initial values for the parameters must also be provided at the beginning of the optimisation loop. OpenQAOA allows for three initialisation strategies: random, custom, and linear ramp. The linear ramp strategy draws inspiration from quantum annealing, and linearly increases the values of the γ\gamma parameters across the QAOA layers, while linearly decreasing the β\beta parameters [30, 31].

IV.3 The OpenQAOA Devices

OpenQAOA builds circuits compatible with many devices. The quantum computing cloud services supported are Amazon Braket, IBMQ, and Rigetti Computing’s Quantum Cloud Services. With access to different cloud providers, users can perform QAOA on a variety of simulators and QPUs supported by these organisations. Local simulators are also available. The user can select the desired backend devices through a workflow as follows:

# IBMQ credentials
ibm_credentials = {
api_token”: ”<ENTER API TOKEN HERE>”,
hub”: IBMQ HUB”,
group”: IBMQ GROUP”,
project”: IBMQ PROJECT
}
\par# instantiate the device
ibmq_cloud = create_device(
location=’ibmq’,
name=’ibm_nairobi’,
**ibm_credentials)
\par# Set the device
q.set_device(ibmq_cloud)
\par# Warm start QAOA with an initial\_circuit
def initial_circuit(*args) -> qiskit.QuantumCircuit:
\par# Set the backend properties
q.set_backend_properties(
n_shots=2000,
cvar_alpha=1,
init_hadamard=False,
prepend_state=initial_circuit(*args)
)
Users can obtain quick access to cloud-based hardware by passing the corresponding credentials. The workflows currently support devices provided by IBM Quantum, Amazon Braket, and Rigetti QCS.

The OpenQAOA backend is responsible for creating and executing the device-specific circuit, computing the expectation value, and interacting with the classical optimiser. The method set_backend_properties() can then be used to set common backend properties, such as the number of shots or the CVaR α\alpha-parameter [32]. It also enables the preparation of an arbitrary initial state through the prepend_state parameter.

OpenQAOA provides access to simulators from popular open-source libraries such as Qiskit’s QASM Simulator and PyQuil’s Statevector Simulator, as well as a alternative option referred to as vectorized. The vectorized backend is a fast, QAOA-specific simulator developed by Entropica Labs, primarily based on the common Python library NumPy [33].

IV.4 The OpenQAOA optimisation loop

OpenQAOA automatically runs the classical-quantum optimisation loop by invoking the method q.optimize() as shown in Codeblock 3. The choice of optimiser lies with the user, and OpenQAOA supports all optimisers found in SciPy’s minimize method [34].

# classical optimiser properties
q.set_classical_optimizer(
method=’nelder-mead’,
maxiter=500,
optimization_progress=True,
cost_progress=True,
parameter_log=True
)
The user can choose the optimiser and configure other properties of the quantum-classical optimisation loop. Additionally, this method can be used to log the optimisation results and history.

OpenQAOA features native implementation of custom optimisation methods, including gradient descent, root mean squared propagation (RMSProp), Newton descent, quantum natural gradient descent [35], and simultaneous perturbation stochastic approximation (SPSA) [36]. The codebase also provides both approximate and exact methods to implement derivative computations. These include finite difference, SPSA, and the recently developed parameter shift  [37, 38, 39] and stochastic parameter shift methods for quantum circuits [40].

Finally, we emphasise that the optimiser has flags for tracking and logging the optimisation status, which we anticipate to be useful for research and debugging purposes. We discuss the content of these logs in the next section.

IV.5 The OpenQAOA result

In its most basic form, the result of a QAOA computation consists of a list of measurement outcomes (or the optimal statevector, if a statevector simulator was employed), and the corresponding optimal variational parameters and optimal cost. In addition to these, OpenQAOA also returns the kk bitstrings associated with the kk most probable states in the optimised distribution, and the unique bitstring corresponding to the lowest cost function value observed in the entire optimisation process.

As an iterative algorithm, QAOA generates additional data during the optimisation loop, which can also be stored for later use. The OpenQAOA optimiser is thus equipped with logger methods to provide metrics from the classical optimisation process, such as the cost expectation value and the corresponding variational parameters for the ithi^{th} iteration, and the measurement counts for the observed bitstrings. A summary of the attributes of the result object is given in Figure 8.

Refer to caption
Figure 8: To facilitate research, OpenQAOA provides a result object to store and access information about the optimisation run. At a high level, the results can be divided into number of evaluations, information on the intermediate states and outcomes, and on the final optimised state. The user can also access the probability distributions of the both optimised and intermediate circuits.

IV.6 The RQAOA workflow

RQAOA consists of running QAOA recursively and using the output statistics at each step to eliminate variables from the problem. When the reduced problem reaches a pre-defined cutoff size, it is solved exactly via classical methods. The final answer is then reconstructed from the solution obtained from this classical computation by re-inserting the eliminated variables in the appropriate order. Notably, the final output of RQAOA is a unique bitstring.

In OpenQAOA, RQAOA is implemented through a workflow built on top of the QAOA workflow. In its simplest code formulation, it reads as follows:

# Define the QAOA properties
q = QAOA()
\par# Set type to custom, set steps to 1 and use the default QAOA
r = RQAOA(qaoa=q, rqaoa_type=’custom’)
\par# Set parameters for RQAOA. Here we fix the steps to 1 (default), the final cutoff value to 3
r.set_rqaoa_parameters(steps=1, n_cutoff=3)
\par# Compile and optimise
r.compile(qubo)
r.optimize()
To implement Recursive QAOA, one first creates an instance of the QAOA object containing all desired properties, and then passes it as argument to the RQAOA workflow. All RQAOA-specific parameters can be set in a similar fashion as for the QAOA object. RQAOA is then compiled and optimised.

OpenQAOA incorporates the RQAOA initially formulated in Ref [9], and two generalised versions, which enable multiple variable (qubit) eliminations during the recursive process. These strategies are called custom and adaptive [21]. The custom strategy allows the user to define the number of eliminations performed at each step. The adaptive strategy adaptively selects how many qubits to eliminate at each step based on a statistical criterion, with the user specifying the maximum number of eliminations allowed per step.

Note how the RQAOA workflow requires a QAOA object to be instantiated: this can be customised in the same way as a regular QAOA workflow, as described in the preceding sections.

IV.7 Factory mode

OpenQAOA workflows help orchestrate the entire QAOA routine on the user’s backend of choice. They automate sequential creation and initialisation of different components that make up a QAOA computation, based on the inputs provided by the user. These components include the problem statement, variational parameters, device-specific backends and authentication, and classical optimiser initialisation.

However, OpenQAOA also gives the user the option of building the QAOA computation manually, by-passing the pre-defined workflows. We refer to this as factory mode, and Codeblock 10 presents an example to demonstrate the required steps. Factory mode allows greater flexibility, with more room for experimentation for advanced users. Since one of the central goals of OpenQAOA is to enable research, we consider this a significant feature. We now briefly discuss a few instances wherein a user may wish to employ the factory mode.

Using a custom classical optimiser: OpenQAOA can facilitate creating the variational parameters and an authenticated backend with the ability to initialise QAOA circuits. The custom classical optimiser can subsequently call the expectation method of the backend, bypassing the need for the optimisers supported by OpenQAOA.

Plotting cost landscapes: OpenQAOA backends support computing the cost value with respect to a set of parameter values (under the specified circuit parametrisation) for a QAOA circuit. A user may choose to define a grid of values for the parameters – for example, β\beta and γ\gamma for a p=1p=1 standard QAOA circuit – and obtain a plot of the cost landscape over the specified region.

More workflows: Accessing the components directly, a user can build more complex workflows, for instance, a layerwise QAOA approach to optimise parameters for a depth-pp circuit.

Obtain the QAOA circuit: With a greater degree of control in the factory mode, users may also choose to export the QAOA circuit. Note, however, that the circuit will be defined in the language of the chosen device. For instance, a qiskit.QuantumCircuit if the selected device was an IBMQ QPU or simulator.

Once the optimisation loop has terminated, the result is available as optimizer_obj.qaoa_result, following a similar structure as the results obtained through a workflow.

# generate the cost and mixer Hamiltonian
terms = [(1,2),(2,3),(0,3),(4,0),(1,),(3,)]
coeffs = [1,2,3,4,3,5]
n_qubits = 5
\parcost_hamil = Hamiltonian.classical_hamiltonian(terms,coeffs)
mixer_hamil = X_mixer_hamiltonian(n_qubits)
\par# prepare the circuit parameters
qaoa_circuit_params = QAOACircuitParams(cost_hamil,mixer_hamil,p=10)
params = create_qaoa_variational_params(qaoa_circuit_params,
params_type=’fourier’,
init_type=’ramp’,
q=1)
\par# call the device to use
device_qiskit = create_device(location = local’, name = qiskit.qasm_simulator’)
\par# initialise the backend with the device and circuit\_params
backend_qiskit_p1 = get_qaoa_backend(circuit_params_p1, device_qiskit, n_shots = 500)
\par# prepare the optimiser
optimizer_dict = {’method’: cobyla’, maxiter’: 100}
optimizer_obj = ScipyOptimizer(backend_obj, params, optimizer_dict)
\par# run the optimisation loop
optimizer_obj()
OpenQAOA workflows provide a simple way to run QAOA problems on both simulators and QPUs. Underneath, they compile the problem following steps in factory mode as shown here. For some use cases, an advanced user may bypass the workflow abstraction layer to access the factory mode. Some examples are provided in the text.

V Conclusions

We have introduced OpenQAOA, an SDK to execute QAOA workflows on QPUs and simulators. OpenQAOA helps the user to focus more on optimisation problems and the algorithmic components behind the QAOA, rather than on the tedious and repetitive tasks of writing quantum circuits from scratch. Through its abstract representation of QAOA workflows, OpenQAOA allows for a great degree of customisability, and provides compilation tools to extract maximum hardware performance.

There are many challenges in scaling quantum algorithms to hundreds of qubits. Building cross-platform solutions that abstract complex algorithms into simple, human-friendly interfaces, is of paramount importance to the development of quantum computing. Scaling QAOAs to hundreds of qubits while lowering the entry barrier to run quantum applications are thus important steps towards making quantum computers easy to use, accessible, and useful. OpenQAOA aims to achieve exactly that, providing an open-source, community-oriented library to bring value to existing quantum devices, supporting a code base designed to empower researchers.

VI Acknowledgements

We would like to thank our former team members at Entropica who contributed to previous iterations of what has ultimately become OpenQAOA. In particular, we acknowledge Jan Lukas Bosse’s central role in the design and construction of the original EntropicaQAOA package [30].

References