# Implementation of a Quantum Approximate Optimization Algorithm for Continuous Variables with Qiskit

Miguel Luna, Vedant Patare, Gamzepelin Aksoy, Grégoire Cattan

► To cite this version:

Miguel Luna, Vedant Patare, Gamzepelin Aksoy, Grégoire Cattan. Implementation of a Quantum Approximate Optimization Algorithm for Continuous Variables with Qiskit. 2025. hal-05295918

HAL Id: hal-05295918

https://hal.science/hal-05295918v1

Preprint submitted on 3 Oct 2025

**HAL** is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
Implementation of a Quantum Approximate
Optimization Algorithm for Continuous Variables
with Qiskit

Miguel Luna¹*, Vedant Patare², Gamzepelin Aksoy³,
Gregoire Cattan⁴,⁵

¹Andrés Bello Catholic University, Telecommunications Engineering, Caracas, Venezuela.

²Fr. Conceicao Rodrigues Institute of Technology, Electrical Engineering, Mumbai, India.

³Isparta University of Applied Sciences, Department of Computer Engineering, Isparta, Türkiye.

⁴IBM, Data and AI, Krakow, Poland.

⁵Hother, Krakow, Poland.

*Corresponding author(s). E-mail(s): migue.luna.molinares@gmail.com;
Contributing authors: vedantp1729@gmail.com;
gamzepelinaksoy@isparta.edu.tr; gregoire.cattan@ibm.com;

Abstract

In this paper, we propose a quantum approximate optimization algorithm (QAOA) for solving continuous-variable optimization problems on gate-based universal quantum computers. Our approach exploits the power of quantum computing to explore the solution space efficiently and find approximate optima. We demonstrate the effectiveness of our algorithm by solving a quadratic program, testing different combinations of mixer operators, numbers of repetitions and optimizers. The optimizer and the number of repetitions had the greatest effect size. The best performance was achieved using the SPSA optimizer, three repetitions, and the binary X mixer.

**Keywords:** QAOA, Continuous variables, Quantum computing, Optimization
# 1 Introduction

Quantum computing is a burgeoning field that harnesses the principles of quantum mechanics to solve problems for which classical computers cannot obtain optimal solutions within reasonable timeframes. Applications of quantum computing are found in domains such as cryptography, finding solutions for large linear systems, and solving search and optimization problems.

Optimization lies at the heart of challenges across fields such as finance, telecommunications, and molecular biology. Classical optimization methods often do not scale efficiently with problem complexity, particularly in high-dimensional or dynamically constrained systems. The quantum approximate optimization algorithm (QAOA) has emerged as a versatile hybrid quantum-classical framework for discrete combinatorial optimization, demonstrating success in finance for knapsack-based portfolio optimization under risk constraints [1], in telecommunications for lattice-based cryptography and network traffic management [2], and in biology for protein folding via energy landscape sampling [3]. However, this algorithm is only suitable for combinatorial optimization problems.

The idea of creating a quantum computer that can implement continuous variables has been studied for many years [4–7]. This has resulted in variational algorithms that can enhance optimization processes by taking advantage of the continuous nature of the underlying variables. There has been previous work on adapting QAOA for continuous variables in [8, 9], which demonstrated strong parallels with quantum photonic systems. However, other quantum technologies have not been considered in this context. For this reason, the current article investigates an adaptation of the QAOA for continuous variables on gate-based universal quantum computers.

Despite these advances, QAOA’s reliance on discrete variable encoding limits its applicability to problems requiring continuous parameter spaces. For instance, financial portfolios necessitate fractional asset allocations, lattice-based cryptography demands adaptive key generation with continuous noise thresholds, and protein folding requires atomic-resolution conformational sampling, all of which are beyond the capabilities of binary or integer-based QAOA formulations.

In this work, we use Qiskit to develop CV-QAOA, an extension of QAOA to continuous variables, addressing these gaps and enabling the solution of a broader range of optimization problems. Qiskit [10] is a ubiquitous quantum framework developed by IBM to build quantum circuits and algorithms on gate-based quantum computers.

The remainder of this article is structured as follows. Section 2 introduces the concepts needed to understand CV-QAOA. Section 3 describes our method. Section 4 presents the results and 5 discusses them. Section 6 considers the limitations of the work, and 7 concludes.

# 2 Background

## 2.1 Variational Quantum Algorithms

The problems in which quantum algorithms are shown to be more efficient than their classical counterparts include unstructured database search and integer factorization.
Grover's algorithm [11] achieves a quadratic speed-up for search tasks, while Shor's algorithm [12] provides an exponential speed-up for factorization when compared to the most efficient known classical algorithms. These two algorithms have significantly influenced the theoretical quantum information community, laying the groundwork for numerous subsequent quantum algorithms. This has led to efforts to build a quantum computer capable of executing a task that cannot be simulated using classical computers. This milestone has been termed quantum supremacy.

For an implementation of Shor's algorithm that could outperform classical methods, a quantum computer would be required with hundreds of millions of physical qubits to factor a two-thousand-digit integer [13]. This presents two key engineering challenges. The first one is related to the nature of qubits, which must be isolated from their environment in order to prevent the decoherence of the quantum states from corrupting the information they contain. The second is the implementation of quantum gates and measurements, which require qubits to be addressed through external physical operations. Due to these challenges, in practice decoherence is always present, causing bias and uncertainty in physical implementations without error mitigation. However, it is theoretically possible to perform quantum computing on a large scale using techniques such as quantum error-correction codes and fault-tolerant quantum computation. They allow the detection and correction of physical errors but with significant overheads in the number of qubits and the run-time. Therefore, achieving scalable error correction is a long-term goal. The short- and medium-term goals are rather to find applications for noisy quantum computers while increasing the number of qubits. This period of quantum technologies is described as the noisy intermediate-scale quantum (NISQ) era. Within this context, it is useful to design quantum algorithms that minimize the quantum resources required for current devices while developing techniques that may also be suitable for the long-term goal of fault-tolerant quantum computation [14].

Quantum simulation and quantum optimization are the most promising fields in which solutions can be explored with NISQ devices. Quantum algorithms developed in this context include the quantum variational eigensolver (VQE) and the quantum approximate optimization algorithm (QAOA) for performing quantum simulations and solving combinatorial optimization problems, respectively. VQE and QAOA do not need to be executed on a fully coherent quantum computer. Instead, the optimization problem is approximated using a set of parametrized (variational) quantum gates assembled into a flexible quantum circuit. This flexibility enables running these algorithms within the limits of current quantum hardware, without requiring error correction [15]. The algorithms developed using this approach are known as variational quantum algorithms.

Most variational quantum algorithms have certain basic elements in common despite their different algorithmic structures and levels of complexity. Therefore, we can use a general framework to analyse them and understand how they can solve a variety of problems [16]. First, we need to define the following concepts:

1. Cost function: a mathematical function that quantifies the difference between the desired output and the actual output for a set of training data inputs. It maps the
current values of the parameters $\theta$ to a cost (that is, a real number), that must be
minimized to solve the problem.

2. Ansatz: a quantum circuit whose execution depends on the value of the parameters $\theta$. The values of these parameters are determined (trained) to minimize the cost. In other words, the final form of the ansatz depends on the task at hand.

3. Optimizer: a classical optimization routine whose goal is to find the values of the parameters $\theta$ of the ansatz that minimize the cost function.

Now that we have established the main modular components of variational quantum algorithms, we can describe a simplified workflow [17] of their implementation:

1. Initialize problem: the quantum computer is initialized in a default state $|0\rangle$ and then transformed to some desired state $|\rho\rangle$, which we will call the reference state.

2. Prepare ansatz: to begin iteratively optimizing from the default state $|0\rangle$ to the target state $|\psi(\theta)\rangle$, we establish a variational form that defines a set of parameterized states for our variational algorithm to explore. We refer to any particular combination of reference state and variational form as an ansatz, which will ultimately take the form of parametrized quantum circuits capable of taking the default state $|0\rangle$ to the target state $|\psi(\theta)\rangle$.

3. Evaluate cost function: we can encode our problem with a cost function that is a linear combination of Pauli operators, run on a quantum system. This can contain information about a physical system, such as energy or spin, but can also encode non-physical problems.

4. Optimize parameters: evaluations are passed to a classical computer, in which a classical optimizer analyzes them and chooses the next set of values for the variational parameters.

5. Adjust ansatz parameters with results, and re-run: the entire process is repeated until the classical optimizer's finalization criteria are met, and an optimal set of parameter values $\theta^*$ is returned. The proposed solution state for our problem will then be $|\psi(\theta^*)\rangle$. Although this will not be an exact solution, it is possible to achieve solutions that are close to optimal.

In summary, the basic idea is to run a short sequence of gates, some of which are parametrized. The process then reads out the result, adjusts the parameters on a classical computer, and repeats the calculation with the new parameters on the quantum hardware. This constitutes an iterative loop between the quantum and classical processing units, forming a classical-quantum hybrid algorithm [18].

## 2.2 The Variational Method

A common goal of variational algorithms is to find the quantum state with the lowest or highest eigenvalue of a certain observable. To achieve this, we will use the variational method of quantum mechanics.

Consider a Hermitian operator $H$ describing a quantum system with ground state $|\psi^*\rangle$ and ground-state energy $E_0$ [19]. The variational method is a technique to approximate $|\psi^*\rangle$ and $E_0$. This is done by choosing a parametrized trial state $|\psi(\theta)\rangle$, where $\theta$ denotes a set or vector of parameters. Recall that the energy of the system in the
state $|\psi\rangle$ is given by its expectation value with respect to $H$:

$$E(|\psi\rangle) = \langle\psi|H|\psi\rangle \qquad (1)$$

Since the ground state of the system is the lowest-energy eigenstate, by definition, it holds that

$$E_0 = \langle\psi^*|H|\psi^*\rangle \le \langle\psi(\theta)|H|\psi(\theta)\rangle \qquad (2)$$

for any parameters $\theta$. Thus, by minimizing the expectation value of the trial state $\psi(\theta)$, that is, by finding parameters $\theta$ for which the expectation value $\langle\psi(\theta)|H|\psi(\theta)\rangle$ is as small as possible, we obtain an upper bound on the ground-state energy $E_0$ and an approximation of the ground state itself. The choice of a good trial state $\psi(\theta)$ is key to the success of the variational method.

## 2.3 Overview of the VQE Framework

The variational quantum eigensolver (VQE) proposed in [20] uses the variational method to compute approximations to the ground state $E_0$ of a Hamiltonian $H$ represented as a linear combination of Pauli terms, which encodes physical systems or combinatorial optimization tasks. It uses a quantum circuit that depends on a parameter $\theta$, which serves as an ansatz and is chosen taking into account information from the problem domain.

Here, the cost function is defined as in [16]

$$C(\theta) = \langle\psi(\theta)|H|\psi(\theta)\rangle \qquad (3)$$

The goal is to minimize the expectation value of $H$ over the next trial state,

$$|\psi(\theta)\rangle = U(\theta) |\psi_0\rangle \qquad (4)$$

for some ansatz $U(\theta)$ and initial state $|\psi_0\rangle$. According to the variational method described in Section 2.2, this cost function is acceptable as $C(\theta) \ge E_0$, with the equality holding if $|\psi(\theta)\rangle$ is the ground state of $H$.

The general structure of VQE is as follows: we prepare a parametrized quantum state, measure it, estimate its energy, and change the parameters to minimize it; then, we repeat this process several times until some stopping criteria are met. The preparation and measurement of the state are performed by the quantum computer, whereas the energy estimation and parameter minimization are handled by a classical computer. VQE can be seen as a generalization of QAOA but was introduced earlier.

## 2.4 Adiabatic Quantum Computing

Adiabatic quantum computing (AQC) is a computational model based on quantum phenomena. Unlike the universal quantum circuit model, which performs operations using quantum gates in discrete or sequential steps, it relies on continuous transformations of qubit states governed by the time-dependent Schrödinger equation
$$H(t) |\psi(t)\rangle = i\hbar \frac{\partial}{\partial t} |\psi(t)\rangle. \qquad (5)$$

AQC operates according to the adiabatic theorem, which states that a quantum system initially in its ground state will remain in the ground state if its Hamiltonian is changed slowly enough over time (formulation borrowed from [22]). This approach enables solving computational problems by reformulating them as equivalent tasks of finding the minimum energy of a function, whose optimal solutions correspond to the original problem.

The use of the adiabatic theorem in quantum computing can be described as follows: first, the problem is encoded as a target Hamiltonian, often represented as a quadratic unconstrained binary optimization (QUBO) problem, whose ground state corresponds to the solution we seek. Next, a simple Hamiltonian is prepared for the quantum system, with a ground state that is already known. Finally, the system undergoes an adiabatic evolution, meaning a slow transition from the simple Hamiltonian to the problem Hamiltonian. By the end of this process, the system remains in the ground state of the problem Hamiltonian, thus providing the solution to the original problem.

AQC is sometimes confused with quantum annealing. In fact AQC is a universal model of quantum computation capable of solving any problem that a quantum computer can address, given the proper Hamiltonian encoding. In contrast, quantum annealing is a subset of AQC restricted to solving specific optimization problems, as its final Hamiltonians are constrained to certain realizable forms. AQC assumes fully adiabatic evolution, ensuring that the system remains in its ground state throughout the computation. Quantum annealing, however, often does not guarantee adiabaticity, as practical implementations may allow for non-adiabatic transitions due to faster evolution or other factors.

## 2.5 Ising Model

Many optimization problems can be reformulated as finding the ground state (the minimum energy configuration) of the Hamiltonian of an Ising model. In AQC, the quantum system evolves from an initial Hamiltonian with a known ground state to a problem Hamiltonian that encodes the solution to the optimization task. The Ising model provides the mathematical structure for this problem Hamiltonian, enabling the use of quantum systems for optimization tasks.

The Ising model is a mathematical representation of a graph composed of Λ lattice sites (here representing qubits). Each qubit (or lattice site) has an associated binary variable, referred to as a spin, which can take values $s_i = \pm 1$. The value of the binary variable depends on the interactions between lattice sites. The interaction between two sites i and j is denoted by $J_{ij}$. Additionally, each site is influenced by an external magnetic field $h_i$. These factors together define the Ising Hamiltonian:

$$H(s) = -\sum_{\langle ij \rangle} J_{ij} s_i s_j - \mu \sum_i h_i s_i \qquad (6)$$
where $s_i$ and $s_j$ represent the states (spins) of sites i and j, $J_{ij}$ is the interaction strength between sites i and j, which determines whether the spins tend to align ($J_{ij} > 0$) or oppose ($J_{ij} < 0$), and $h_i$ represents the external field acting on site i, which can bias the spin direction.

The goal in the Ising model is to find the configuration of spins {$s_i$} that minimizes $H$, which corresponds to the system's ground state. This makes the Ising model a foundational tool for optimization problems. In AQC, the Ising model becomes the problem Hamiltonian ($H_{\text{problem}}$), and the process of adiabatic evolution allows the system to transition from a simple initial Hamiltonian ($H_{\text{initial}}$) to $H_{\text{problem}}$. This gradual evolution ensures that the system remains in its ground state; thus, the final state represents the optimal solution to the encoded problem.

In QAOA, this Ising Hamiltonian maps directly to the phase Hamiltonian $H_P$, and the mixer Hamiltonian $H_M$ is chosen to explore the solution space. Without external magnetic fields ($h_i = 0$), Eq. 6 simplifies to the max-cut problem:

$$H(s) = - \sum_{\langle ij \rangle} J_{ij} s_i s_j \qquad (7)$$

The max-cut problem seeks to divide a graph into two subsets such that the number of edges between the subsets is maximized. This is the combinatorial problem solved using QAOA in the work that introduced it [23].

## 2.6 Overview of the Original QAOA Framework

There is an analogous approach to solving optimization problems using AQC principles for quantum computers based on the quantum circuit model. This method is derived by truncating the adiabatic process of AQC.

Let us consider a Hamiltonian composed of a sum of individual Hamiltonians, such as $H = H_1 + H_2$. Using the Lie product formula, this Hamiltonian can be expressed as follows:

$$e^{-i(H_1+H_2)/t} = \lim_{n \to \infty} \left( e^{-iH_1t/n} e^{-iH_2t/n} \right)^n \qquad (8)$$

Since the limit of Eq. 8 is infinite, the series needs to be truncated when implementing this formula on a quantum computer. This process of truncation, known as Trotterization, is widely used to simulate non-commuting Hamiltonians on quantum computers. The general Trotterization formula is given by

$$e^{-iHt} = \left( e^{-iH_1t/n} e^{-iH_2t/n} \dots e^{-iH_Mt/n} \right)^n + O(\text{some polynomials}) \qquad (9)$$

This process is the inspiration for QAOA. Hence, this algorithm can be interpreted as a discretization or Trotterization of AQC with the goal of approximating the optimal solutions to combinatorial optimization problems.

We now give an overview of the original quantum approximation optimization algorithm proposed in [23]. The starting point and goal of QAOA are the same as those of quantum annealing. We begin with a combinatorial optimization problem that we want to solve, and we encode it into an Ising Hamiltonian $H_1$. To find its ground state
and solve our problem, we seek to apply a quantum state evolution similar to that of quantum annealing but using a quantum circuit instead of a quantum annealer.

More concretely, suppose we have a combinatorial optimization problem defined on n-bit binary strings z that is solved by maximizing (or minimizing) an objective function defined as

$$f(z) : \{0, 1\}^n \to \mathbb{R} \qquad (10)$$

To make this solvable by a quantum computer, we must encode the problem appropriately. The QUBO framework enables us to formulate many optimization problems in a way that maps directly to the quantum setting. Once a problem is expressed as a QUBO instance, it can be translated into quantum mechanical Hamiltonian operators by implementing the Ising model, which represents the problem's variables and constraints as interactions between spins in a quantum system [24].

Then, we can use a plethora of quantum algorithms to seek solutions that are optimal or close to optimal. The algorithm is specified by an initial state and two Hamiltonians $H_P$ (the phase Hamiltonian) and $H_M$ (the mixer Hamiltonian), known as the cost and mixer operators. These operators can be repeated $p$ ($p \in \mathbb{N}$) times in the circuit, in which case the circuit contains $2p$ real parameters (which determine the angles of rotation inside the quantum gates) $\gamma_1, \dots, \gamma_p, \beta_1, \dots, \beta_p$. This parametric circuit, or ansatz, is referred to as the QAOA ansatz.

The initial state is selected to be the equal superposition of all possible solutions:

$$|s\rangle = |+\rangle^{\otimes n} = \frac{1}{\sqrt{2^n}} \sum_{x=0}^{2^n-1} |x\rangle \qquad (11)$$

The phase Hamiltonian $H_P$ encodes the objective function $f$ and acts diagonally on the computational basis states of a $2^n$ dimensional Hilbert space (an n-qubit space) [25]:

$$H_P|z\rangle = f(z)|z\rangle \qquad (12)$$

In addition, a family of phase operators is defined as follows:

$$U_P(\gamma) = e^{-i\gamma H_P} \qquad (13)$$

where $\gamma \in [0, 2\pi)$ is a parameter. The mixing Hamiltonian $H_M$ is defined as follows:

$$H_M = \sum_{j=1}^{n} X_j \qquad (14)$$

where $X_j$ is the Pauli X operator and $n$ is identical to the $n$ in Eq. 10. In quantum mechanical systems, the Pauli X operator acts as a NOT operator or bit flip, that is, $X|0\rangle = |1\rangle$ and $X|1\rangle = |0\rangle$. In this case, $|+\rangle^{\otimes n}$ is the highest-energy eigenstate rather than the ground state. To make it the ground state you must flip the sign of the Hamiltonian.

In addition, a family of mixing operators is defined as follows:

$$U_M(\beta) = e^{-i\beta H_M} \qquad (15)$$
where $\beta \in [0, 2\pi)$ is a parameter.

Given the above definitions, we can define parametrized quantum states by alternately applying the phase and mixing operators for $p$ rounds, with the durations in round $j$ specified by the parameters $\gamma_j$ and $\beta_p$ [26], respectively:

$$|\beta, \gamma\rangle = e^{-i\beta_p H_M} e^{-i\gamma_p H_P} \dots e^{-i\beta_2 H_M} e^{-i\gamma_2 H_P} \dots e^{-i\beta_1 H_M} e^{-i\gamma_1 H_P} |s\rangle \quad (16)$$

The final step is to perform measurements of the state in the computational basis, which return a candidate solution $y$ with probability $|\langle y|\beta, \gamma\rangle|^2$. After repeating this process, we can determine the expectation value of $H_P$ as follows:

$$\langle H_P \rangle := \langle \beta, \gamma | H_P | \beta, \gamma \rangle = \langle f \rangle_{\text{QAOA}_p} \quad (17)$$

where $\langle f \rangle$ is the expectation value of the objective function. The minimum value of $H_P$ can be obtained by repeating the process of finding the optimal values of the parameters $\gamma$ and $\beta$. This iterative process for function minimization uses classical optimization methods, but, whenever it needs to compute a value of the function, it is supplied with an estimate obtained using a quantum computer. The process is repeated until the stopping criteria of the classical algorithm are satisfied. For this reason, QAOA is a hybrid algorithm: one in which a classical and a quantum computer work in tandem to solve a problem.

The classical optimization of QAOA parameters can employ various strategies depending on the computational resources and noise characteristics. Gradient-based methods such as ADAM or the parameter shift rule [27, 28] can be employed. However, shot noise from quantum measurements and the potential presence of barren plateaus often make gradient-free optimizers like COBYLA or SPSA more practical.

Once the classical optimizer converges to parameter estimates $\gamma^*$ and $\beta^*$, which typically represent local minima rather than the global minimum due to the non-convex optimization landscape, we can use the quantum computer once more to prepare the state $|\beta^*, \gamma^*\rangle$. This state should have improved overlap with the ground state of $H_P$ compared to the initial superposition state, so when we measure it in the computational basis, we should obtain an approximate solution to our original combinatorial problem.

## 2.7 Implementation of the Original QAOA with Qiskit

This subsection describes the implementation of QAOA using Qiskit 1.1, following the original article [23]. The authors also recommend [29, 30] for detailed overviews of the original QAOA at the theoretical and practical levels.

### 2.7.1 The Max-Cut Problem

A graph is a set of vertices or nodes $V$ connected by a set of edges $E$ (Fig. 1). These edges can be weighted or unweighted. For simplicity, the latter case can be represented as a weighted graph in which each edge has a weight of one.

A cut of a graph is a partition of its vertices into two disjoint subsets. The size of a cut is defined as the number of edges connecting vertices from different sets. We
<figure><img src="image_2.png" /><figcaption>Fig. 1: Example of a weighted graph.</figcaption></figure>

can visually represent a cut by colouring the two subsets of vertices using different colours, such as red and blue (Fig. 2).

<figure><img src="image_3.png" /><figcaption>Fig. 2: Visual representation of cuts with a graph containing four nodes.</figcaption></figure>

Let $G = (V, E)$ be a weighted graph with $n$ vertices. By numbering the vertices $V1, \dots, V_n$ and assigning the value 0 to red vertices and 1 to blue ones, we can identify any cut of the graph with a vector. The weight of a cut $x \in \{0, 1\}^n$ is then determined by the cost function

$$C(x) = \sum_{i,j=1}^{n} W_{ij}x_i(1-x_j) \qquad (18)$$

where $W_{ij} = W_{ji}$ determines the weight of the edge connecting vertices $V_i$ and $V_j$, with $W_{ij} = 0$ if $V_i$ and $V_j$ are not connected by an edge. Each edge weight contributes exactly once to the sum if and only if $x_i \neq x_j$.

The max-cut problem seeks to partition the vertices of a graph into two subsets such that the number of edges between the subsets is maximized. This problem can always be formulated as a QUBO problem, making it particularly well-suited for quantum optimization techniques. It is for this reason that the authors of the original QAOA paper selected max-cut as a benchmark problem, and it remains one of the most extensively studied QAOA applications in the literature. To demonstrate the max-cut problem discussed above, we create a graph using the rustworkx library (Listing 1). The output of Listing 1 is displayed in Fig. 3.

```python
1 import rustworkx as rx
2 from rustworkx vizualization import mpldraw
3
4 num_nodes = 4
5 edges = [(0, 1, 1), (0, 2, 1), (1, 2, 1), (2, 3, 1), (3, 0, 1)]
6 G = rx.PyGraph()
7 G.add_nodes_from(range(num_nodes))
```
8 G.add_edges_from( edges )
9 mpldraw( G, with labels = True, node color = "#EE5396", font color = "#F4F4F4")

<figure><img src="image_4.png" /><figcaption>Fig. 3: Max-cut graph.</figcaption></figure>

2.7.2 Problem Encoding

We convert the graph partition problem into an Ising Hamiltonian whose ground state corresponds to the solution, which minimizes the cost function (Listing 2). The operator obtained is a linear combination of terms with Z operators on nodes connected by an edge. In this case, we have four nodes with five connections between them, so we have five terms:

$$
\begin{align}
H_p ={}& (I_0 \otimes I_1 \otimes Z_2 \otimes Z_3) \nonumber \\
       & + (I_0 \otimes Z_1 \otimes I_2 \otimes Z_3) \nonumber \\
       & + (I_0 \otimes Z_1 \otimes Z_2 \otimes I_3) \tag{19} \\
       & + (Z_0 \otimes Z_1 \otimes I_2 \otimes I_3) \nonumber \\
       & + (Z_0 \otimes I_1 \otimes I_2 \otimes Z_3) \nonumber
\end{align}
$$

1 from qiskit.quantum_info import SparsePauliOp
2 def build_max_cut_paulis(graph: rx.PyGraph) -> list[tuple[str, float]]:
3 pauli_list = []
4 for edge in list(graph.edge_list()):
5 paulis = ["I"] * len(graph)
6 paulis[edge[0]], paulis[edge[1]] = "Z", "Z"
7 weight = graph.get_edge_data edge[0], edge[1])
8 pauli_list.append("".join(paulis)[:-1], weight))
9
10 return pauli_list
11
12 max_cut_paulis = build_max_cut_paulis(G)
13
cost_hamiltonian = SparsePauliOp.from_list(max_cut_paulis)

<caption>Listing 2: Converting the max-cut problem into a Hamiltonian cost function.</caption>
### 2.7.3 QAOA Ansatz Circuit

With the Hamiltonian $H_p$ that contains the quantum definition of the optimization problem, we can create a quantum circuit that could be executed by a quantum computer (Listing 3). The ansatz used in QAOA is called the quantum alternating operator ansatz, sharing the same abbreviation as the algorithm [31]. The output produced by Listing 3 is displayed below (Fig. 4).

```python
1 from qiskit.circuit.library import QAOAAnsatz
```

2

3 hamiltonian = cost_hamiltonian

4 ansatz = QAOAAnsatz(hamiltonian, reps=2)

<figure><img src="image_5.png" /><figcaption>**Fig. 4:** QAOA ansatz with two repetitions.</figcaption></figure>

QAOA is a discretization of quantum annealing, and it is achieved by applying alternating layers of operators in the quantum circuit; they are repeated twice in our case. We can illustrate how the ansatz can be expressed at a deeper level of decomposition, which allows us to check its inner structure (Fig. 5).

<figure><img src="image_6.png" /><figcaption>**Fig. 5:** Decomposition of the QAOA ansatz with two repetitions.</figcaption></figure>

We can see how the first layer is composed of Hadamard gates, producing a superposition state. Then, we can see that the cost and mixer operators are alternated twice.

### 2.7.4 Cost Function

We define a scalar cost function to be minimized. Using the Qiskit Runtime Estimator, which directly accepts any provided Hamiltonian and parametrized ansatz, an energy
estimate can be obtained. This process involves computing the expectation value of the state with respect to the given Hamiltonian (Listing 4). We injected the cost function into the SciPy minimization function to find the optimal parameters $\gamma$ and $\beta$. We use constrained optimization by linear approximation (COBYLA) [32] as the classical optimizer (Listing 5).

```python
def cost_func(params, ansatz, hamiltonian, estimator):
    pub = (ansatz, hamiltonian, params)
    job = estimator.run([pub])
    results = job.result()[0]
    cost = results.data.evs
    objective_func vals.append(cost)

    return cost
```

<caption>Listing 4: Cost function.</caption>

### 2.7.5 Optimized Parameters

```python
from qiskit.primitives import StatevectorEstimator

init_params = 2 * np.pi * np.random rand (ansatz .num_parameters)
estimator = StatevectorEstimator()
objective_func vals = []
res = minimize (
    cost_func,
    init_params,
    args=(ansatz, hamiltonian, estimator),
    method="COBYLA",
)
```

<caption>Listing 5: Finding the optimal parameters.</caption>

We can also now view the progress toward convergence as monitored by the cost history at each iteration (Listing 6). The output of Listing 6 is displayed in Fig. 6. We observe that the loss curve converges toward the optimal cost value corresponding to the ground state.

```python
import matplotlib .pyplot as plt

3 plt .figure (figsize=(12, 6))
4 plt .plot (objective_func vals)
5 plt .xlabel ("Iteration")
6 plt .ylabel ("Cost")
7 plt .show()
```

<caption>Listing 6: Displaying the loss function.</caption>

### 2.7.6 Running QAOA

We have now found the optimal parameters for the quantum circuit corresponding to our original optimization problem. Therefore, the next step is to sample the final distribution obtained with these new parameter values and add a measurement layer at the end of the circuit (Listing 7).
<figure><img src="image_7.png" /><figcaption>Fig. 6: Cost as a function of the number of iterations.</figcaption></figure>

1 # Assign solution parameters to ansatz
2 qc = ansatzassig parameters(res.x)
3 # Add measurements to our circuit
4 qc .measure_all()

<caption>Listing 7: QAOA.</caption>

Listing 7 produces the following quantum circuit (Fig. 7).

<figure><img src="image_8.png" /><figcaption>Fig. 7: Final parameters value of the QAOA ansatz.</figcaption></figure>

The QAOA box in the above circuit can further be decomposed into the following
alternating operators (Fig. 8).

To compute the probability distribution of the bit-string measurement, we use a
Sampler primitive (Listing 8). This probability distribution corresponds to the optimal
cut of the graph (Fig. 9). We can see that the bit strings "0101" and "1010" have the
<figure><img src="image_9.png" /><figcaption>Fig. 8: Final QAOA ansatz decomposed.</figcaption></figure>

highest probability and are indeed the assignments for the initial graph that result in four edges between the two partitions.

```python
1 from qiskit.primitives import Sampler
2
3 sampler = Sampler()
4 result = sampler.run([qc]).result()
5 print(result)
6 print(result.quasi_dists[0].binary probabilities())
7 samp_dist = result.quasi_dists[0].binary probabilities()
8 plot_distribution(samp_dist, figsize=(15, 5))
```

<figure><img src="image_10.png" /><figcaption>Fig. 9: Probability distribution.</figcaption></figure>

# 3 Methodology

We use the same scheme implemented for the original QAOA described in Section 2.7 as a starting model; thus, we dispense with details related to the quantum circuit but point out the differences to explain how the algorithm can function with continuous variables.

## 3.1 Problem Formulation

To simplify the explanation, we solve a quadratic program with three continuous variables, in which the goal is to minimize the objective function

$$ (x - 0.83 + y + 2z)^2 \qquad (20) $$
where $x \in [-1, 0]$, $y \in [0, 2]$, and $z \in [1.1, 1.2]$. This problem is straightforward to implement with Docplex (Listing 9), which is an IBM modeling framework that can be used to define optimization problems via constraint programming.

```python
from docplex.mp. model import Model
from qiskit_optimization. translators import from_docplex mp

mdl = Model("docplex model")
x = mdl.continuous_var(-1, 0, "x")
y = mdl.continuous_var(0, 2, "y")
z = mdl.continuous_var(1.1, 2.2, "z")
mdl.minimize((x - 0.83 + y + 2 * z)**2)
qp = from_docplex mp(mdl)
```

<caption>Listing 9: Creation of a quadratic program with Docplex.</caption>

The choice of this equation is arbitrary and serves only to illustrate the methodology. The equation is strictly increasing as the partial derivatives are strictly positive on the definition ranges. Therefore, the minimum of the equation on the domain of definition can easily be computed:

$$(-1 - 0.83 + 0 + 2 \times 1.1)^2 = 0.1369 \qquad (21)$$

## 3.2 Problem Encoding

This continuous-variable quadratic program can be transformed into a QUBO problem simply by changing the definition range of all variables to [0, 1]. In addition, we fit a scaler for each variable that converts it from its original definition range to [0, 1] and vice versa (Listing 10).

```python
scalers = []
for v in qp.vARIABLES:
    if(v.vartype == VarTypeCONTINUOUS):
        scaler = MinMaxScaler().fit(np.array([v.lowerbound, v.upperbound]).reshape(-1, 1))
        scalers.append(scaler)
        v.vartype = VarTypeBINARY
```

<caption>Listing 10: Creation of a quadratic program with Docplex.</caption>

However, note that no transformation is applied to the variables at this point; we have merely changed the type of variables. The QUBO problem is then converted to an Ising model, and the cost operator is derived from it (Listing 11).

```python
cost, _ = qp.to_ising()
num_qubits = cost.num_qubits
```

<caption>Listing 11: Conversion to the Ising model.</caption>

## 3.3 QAOA Mixers

The choice of the QAOA mixer depends on whether the continuous variables are defined with binary, one-hot, or domain-wall encoding. In our case, intuition tells us that the binary mixer is the best choice, as we use binary variables that are not encoded; only the type of the variable has changed. However, we would like to confirm
our intuition. Therefore, let us briefly review the three types of mixers in the literature [33, 34].

We use rotational quantum gates to implement each scheme of the mixers we choose. This allows us to determine which angle $(0, \frac{\pi}{2}, \pi, \frac{3\pi}{2})$ maximizes the performance of the optimization process for a given mixer.

### 3.3.1 Binary Encoding

The most direct way to encode discrete variables into qubits is to convert each variable into their binary representation. With this approach, a discrete variable of size $m$ can be encoded in $\log_2(m)$ qubits, which is easily implementable using the following Hamiltonian terms:

$$H_X(\Theta) = \sum_{i}^{N} R_X(\Theta)_i \qquad (22)$$

where $X_i$ is the Pauli $X$ operator applied to the $i$th qubit in the binary encoding.

The corresponding circuit form is as follows (Fig. 10).

$$|q_i\rangle \rightarrow [R_X] \rightarrow$$

<caption>Fig. 10: Gate representation of binary encoding.</caption>

This scheme is the default mixer used by the original QAOA. The implementation in Listing 12 allows the specification of a custom angle when creating the mixer.

```python
1 from qiskit.circuit import QuantumCircuit, QuantumRegister
2
3 def create_X_mixer(angle):
4     def mixer_X(num_qubits):
5         qr = QuantumRegister(num_qubits)
6         mixer = QuantumCircuit(qr)
7     for i in range(num_qubits):
8         mixer.rx(angle, qr[i])
9
10 return mixer_X
11
```

<caption>Listing 12: X mixer.</caption>

### 3.3.2 One-Hot Encoding

One-hot encoding transforms categorical variables into a numerical format that enhances machine learning and deep learning models. Each category value is represented as a binary vector, where only one bit is set to 1, and all others are 0. For example, if we have three categories—blue, yellow, and green—each would be assigned a unique binary vector (e.g., blue: 100, yellow: 010, green: 001).

One-hot encoding enables more concise circuits at the expense of requiring more qubits, whereas binary encoding makes the opposite trade-off [35].
For one-hot encoding, the mixer is based on XY Hamiltonians as follows:

$$H_{XY}(\Theta) = \sum_{i}^{N-1} (R_X(\Theta)_i R_X(\Theta)_{i+1} + R_Y(\Theta)_i R_Y(\Theta)_{i+1}) \quad (23)$$

A prerequisite is to implement an XY interaction Hamiltonian using two parametric two-qubit X ⊗ X and Y ⊗ Y interactions (XX and YY rotations, respectively).

First, we implement the XX operator as

$$R_X(\Theta) R_X(\Theta) = \exp\left(-i\frac{\theta}{2}X \otimes X\right) = R_{XX}(\Theta) \quad (24)$$

That is,

$$R_{XX}(\Theta) = \begin{bmatrix} \cos(\frac{\theta}{2}) & 0 & 0 & -i \sin(\frac{\theta}{2}) \\ 0 & \cos(\frac{\theta}{2}) & -i \sin(\frac{\theta}{2}) & 0 \\ 0 & -i \sin(\frac{\theta}{2}) & \cos(\frac{\theta}{2}) & 0 \\ -i \sin(\frac{\theta}{2}) & 0 & 0 & \cos(\frac{\theta}{2}) \end{bmatrix} \quad (25)$$

Second, we implement the YY rotation as

$$R_Y(\Theta) R_Y(\Theta) = \exp\left(-i\frac{\theta}{2}Y \otimes Y\right) = R_{YY}(\Theta) \quad (26)$$

That is,

$$R_{YY}(\Theta) = \begin{bmatrix} \cos(\frac{\theta}{2}) & 0 & 0 & i \sin(\frac{\theta}{2}) \\ 0 & \cos(\frac{\theta}{2}) & -i \sin(\frac{\theta}{2}) & 0 \\ 0 & -i \sin(\frac{\theta}{2}) & \cos(\frac{\theta}{2}) & 0 \\ i \sin(\frac{\theta}{2}) & 0 & 0 & \cos(\frac{\theta}{2}) \end{bmatrix} \quad (27)$$

Finally, we obtain

$$H_{XY}(\Theta) = \exp\left(-i\frac{\theta}{2}X \otimes X\right) \exp\left(-i\frac{\theta}{2}Y \otimes Y\right) \quad (28)$$

This can be simplified to

$$H_{XY}(\Theta) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos(\theta) & -i \sin(\theta) & 0 \\ 0 & -i \sin(\theta) & \cos(\theta) & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \quad (29)$$

The effect of these two operators is similar to that of the iSWAP gate when $\theta = -\frac{\pi}{2}$, that is, when the gate is maximally entangled. Listing 13 shows how to create an XY mixer with a specific angle. The mixer is further displayed in Fig. 11.

1. from qiskit.circuit import QuantumCircuit, QuantumRegister

2.

3. def create_XY_mixer(angle):

4. def mixer_XY(num_qubits):
```python
qr = QuantumRegister(num_qubits)
mixer = QuantumCircuit(qr)
beta = Parameter(f"beta")
for i in range(num_qubits - 1):
    mixer.rxx beta + angle, qr[i], qr[i+1])
    mixer.rry(0 + angle, qr[i], qr[i+1])
return mixer

return mixer_XY
```

<figure><img src="image_11.png" /><figcaption>Fig. 11: Gate representation of the XY mixer.</figcaption></figure>

### 3.3.3 Domain-Wall Encoding

Unlike the previous two encodings, which are derived from classical computer science, domain-wall encoding originates from physics. It was proposed in [36] as an alternative method of encoding discrete variables into qubits, and it is based on the physics of domain walls in one-dimensional Ising spin chains.

Consider a spin chain represented as $|1100\rangle$, where 1 denotes a spin-up state and 0 a spin-down state. The transition between 1 and 0 marks the domain wall. This concept allows a discrete variable $x$, which can take $n$ possible values, to be encoded by positioning the domain wall within a chain of $n-1$ spins or qubits. For example, consider a variable $x \in \{0, 1, 2\}$. This variable can be encoded with three qubits:

* $x = 0$ is represented by all spins pointing up ($|11\rangle$).

* $x = 1$ corresponds to the domain wall at the first position. ($|10\rangle$)

* $x = 2$ has the domain wall at the second position. ($|00\rangle$)

This new encoding of discrete variables may be more useful in near-term applications, as it requires fewer qubits than the traditional one-hot method [33].

Flipping a qubit adjacent to a single domain wall does not change the overall number of domain walls in the model. Therefore, a domain-wall mixer should only cause a bit to flip if it is adjacent to a domain wall. This property is satisfied by the following Hamiltonian [33]:

$$H_{XZ}(\Theta) = \sum_{i}^{N-1} (R_Z(\Theta)_{i-1} R_X(\Theta)_i - R_X(\Theta)_i R_Z(\Theta)_{i+1}) \quad (30)$$
First, we implement a ZX interaction Hamiltonian using two parametric two-qubit $Z \otimes X$ interactions (rotations around ZX):

$$R_Z(\Theta) R_X(\Theta) = \exp\left(-i\frac{\theta}{2} X \otimes Z\right) = R_{ZX} \qquad (31)$$

That is,

$$R_{ZX} = \begin{bmatrix} \cos(\frac{\theta}{2}) & 0 & -i \sin(\frac{\theta}{2}) & 0 \\ 0 & \cos(\frac{\theta}{2}) & 0 & i \sin(\frac{\theta}{2}) \\ -i \sin(\frac{\theta}{2}) & 0 & \cos(\frac{\theta}{2}) & 0 \\ 0 & i \sin(\frac{\theta}{2}) & 0 & \cos(\frac{\theta}{2}) \end{bmatrix} \qquad (32)$$

Second, we implement the XZ rotation

$$R_X(\Theta) R_Z(\Theta) = \exp\left(-i\frac{\theta}{2} Z \otimes X\right) = R_{XZ} \qquad (33)$$

That is,

$$R_{XZ} = \begin{bmatrix} \cos(\frac{\theta}{2}) & -i \sin(\frac{\theta}{2}) & 0 & 0 \\ -i \sin(\frac{\theta}{2}) & \cos(\frac{\theta}{2}) & 0 & 0 \\ 0 & 0 & \cos(\frac{\theta}{2}) & i \sin(\frac{\theta}{2}) \\ 0 & 0 & i \sin(\frac{\theta}{2}) & \cos(\frac{\theta}{2}) \end{bmatrix} \qquad (34)$$

This mixer flips the ith qubit only when it is directly adjacent to a domain wall, that is, if the values of the qubits at indices i − 1 and i + 1 are different; otherwise, it does not introduce any change to the qubit [33]. Listing 14 shows how to create a domain-wall encoding mixer with a specific angle. The mixer is further displayed in Fig. 12.

```python
1 from qiskit.circuit import QuantumCircuit, QuantumRegister
2
3 def create_XZ_mixer(angle):
4     def mixer_XZ(num_qubits):
5         qr = QuantumRegister(num_qubits)
6         mixer = QuantumCircuit(qr)
7         beta = Parameter(f"beta")
8         for i in range(num_qubits - 1):
9             mixer.rzx beta + angle, qr[i], qr[i+1])
10            mixer.rzx(0 + angle, qr[i], qr[i+1]).inverse(annotated=True)
12     return mixer
14
15 return mixer_XZ
```

<caption>Listing 14: Domain-wall encoding.</caption>

## 3.4 Ansatz Construction

Once we have fixed the mixer and the cost operator, we instantiate the QAOA ansatz circuit with Qiskit. The circuit `ansatz_0` shown in Listing 15 differs from `ansatz` in that it lacks a measurement operation at its end. The absence of measurement is intentional: `ansatz` is designed for circuit optimization, and the inclusion of a measurement
<figure><img src="image_12.png" /><figcaption>Fig. 12: Gate representation of the domain-wall encoding mixer.</figcaption></figure>

operation prevents direct computation of the output state vector. To address this limitation, `ansatz_0` is employed to evaluate the output state vector without interference from measurement operations.

```python
1 from qiskit.circuit.library import QAOAAnsatz
2
3 ansatz_0 = QAOAAnsatz(cost_operator=cost, reps=n_reps, initial_state=None,
4                       mixer_operator=mixer).decompose()
5
6 ansatz = QAOAAnsatz(cost_operator=cost, reps=n_reps, initial_state=None,
7                       mixer_operator=mixer).decompose()
7 ansatz.measure_all()
```

Listing 15: Creating the QAOA ansatz.

We can now instantiate a simulator to run the ansatz. Listing 16 explains how this is done with Qiskit.

```python
1 from qiskit_aer import AerSimulator
2 from qiskit.primitives import Backend Sampler
3
4 backend = AerSimulator(method="statevector", cuStateVec_enable=True)
5 quantum_instance = Backend Sampler(
6     backend, options={"shots": 200, "seed_simulator": 42}
7 )
8 quantum_instance.transpile_options["seed_transpile"] = 42
```

Listing 16: Creating a quantum simulator.

## 3.5 Loss Function

We then optimize the parameters of the circuit, not based on the expectation values, but rather on the quasi-distribution. Consider the following example:

* We have two variables *a* and *b*.

* Each variable is represented by one qubit.

* The optimizer adjusts the parameters, and we measure the qubits, yielding the following distribution: `{|00⟩: 0.2, |01⟩: 0.3, |10⟩: 0.4, |11⟩: 0.1}`. Note that the probability of the first (resp. second) qubit being in state $|0⟩$ is 0.5 (resp. 0.6).

* Thus, we retain 0.5 and 0.6 as the new values for our variables *a* and *b*.

This approach differs from classical QAOA, which optimizes the expectation value $\langle\psi|H_P|\psi\rangle$, where $|\psi\rangle$ is the most probable state (e.g. $|10\rangle$) and $H_P$ is our cost
Hamiltonian. In our case, the expectation value becomes:

$$0.2f(|00\rangle) + 0.3f(|01\rangle) + 0.4f(|10\rangle) + 0.1f(|11\rangle) \quad (35)$$

where f is our cost function. Listing 17 computes the probability of the ith qubit being in state $|0\rangle$.

```python
def prob job, i:
    quasi_dists = job.result().quasi_dists[0]
    p = 0
    for key in quasi_dists:
        if (key & 2**(n_var - 1 - i)):
            p += quasi_dists[key]
    # p is in the range [0, 1]
    # We now need to scale it to the definition range of our continuous variables
    p = scalers[i].inverse Transform([[p]])[0][0]
    return p
```

Listing 17: Obtaining a probability from a quasi-distribution.

This probability is used as the new value for the ith variable associated with the ith qubit. Note also how we use the scalers computed in Listing 10 to map a probability in the range [0, 1] into the definition range of the variable. The loss function can then be defined as in Listing 18.

```python
import numpy as np

def loss (params):
    job = quantum_instance.run (ansatz, params)
    var_hat = [prob (job, i) for i in range (n_var)]
    cost = objective_expr. evaluate (var_hat)
    return cost

initial.guess = np. array ([1, 1] * <number of repetitions>)
result = optimizer. minimize (loss, initial.guess)
```

Listing 18: Obtaining a probability from a quasi-distribution.

As can be seen in Listing 18, the variable optimizer is not defined. We now need to determine which optimizer can best optimize our QAOA-CV ansatz.

## 3.6 Optimizer Selection

The performance of QAOA depends on the choice of the mixer operator and the classical optimizer. In [37], several classical optimizers were benchmarked for use with QAOA, and sequential least-squares programming (SLSQP) was recommended. In practice, simultaneous perturbation stochastic approximation (SPSA) [38, 39] may be a better choice as it is designed to deal with noisy environments, such as a real quantum backend or a quantum simulator integrating a noise model.

SPSA and SLSQP are identified as suitable optimizers for our QAOA-CV implementation. Additionally, the COBYLA optimizer is included in our list. COBYLA is frequently employed as a first-choice optimizer in the development of quantum algorithms due to its ability to handle constrained problems, including equality and inequality constraints.

In summary, we select the following optimizers:
1. SLSQP, which determines a local search direction by solving the second-order local approximation of the cost function that satisfies the constraints.

2. SPSA, which employs a stochastic perturbation vector to compute an approximate gradient of the cost function.

3. COBYLA, which uses linear approximations of the target and constraint functions to optimize a simplex within a trust region of the parameter space.

SPSA and COBYLA are gradient-free optimization methods, whereas SLSQP is based on gradients. The former techniques evaluate the objective function at different points in the parameter space, iteratively searching for the optimal solution through various strategies, and the latter is an iterative method that extensively uses the gradient information of the objective function during iterations.

# 4 Results

The optimizers that use gradient-free optimization methods, that is, SPSA and COBYLA, show better performance than the one based on gradients, namely SLSQP. The minimum values obtained by these three methods are as follows:

* SLSQP: 6.563844 with one repetition (all mixers and angles yield the same results).

* COBYLA: 0.265225 with four repetitions (all mixers and angles yield the same results).

* SPSA: 0.190096 with three repetitions, mixer $X$, and angle $2\pi$.

The number of repetitions affects all optimizers (Fig. 13). However, we find that mixers and angles have no impact on the results obtained by the COBYLA and SLSQP optimizers (Fig. 14).

We can see in Fig. 14 that the minimum found by SLSQP is high. In fact, SLSQP fails to converge, as shown in Fig. 15. As for SPSA, the effect of the number of repetitions, the mixer, and the mixer's angle is visible in Fig. 16.

Table 1 reports the effect size of these factors on the optimization minimum and time. The effect size metric used is eta squared ($\eta^2$), which represents the proportion of total variance in the dependent variable that is explained by the independent variable, ranging from 0 (no effect) to 1 (complete explanation of variance). According to Cohen's rule of thumb, we can make the following conclusions:

* Angles have a small effect on the minimum ($\eta^2 < 0.06$) but no effect on the time ($\eta^2 < 0.01$).

* The mixer has no effect on the optimization time or minimum ($\eta^2 < 0.01$).

* Repetition has a large effect on the minimum and optimization time ($\eta^2 > 0.14$).

# 5 Discussion

In this article, we have studied a new implementation of QAOA with continuous variables for gate-based universal quantum computers. Strictly speaking, the algorithm we propose is not a generalization of QAOA but rather a novel approach inspired by the QAOA framework. In fact, the implemented QAOA-CV shares the same circuit
<figure><img src="image_13.png" /><figcaption>Fig. 13: Minimum value by repetition number and optimizer.</figcaption></figure>

<table><caption>**Table 1:** Eta squared values of SPSA alone on the optimization time and result.</caption><thead><tr><td></td><td>Time</td><td>Minimum</td></tr></thead><tbody><tr><td>Angle</td><td>0.007623740241322329</td><td>0.014636278497318245</td></tr><tr><td>Mixer</td><td>0.00034583382308554946</td><td>0.009974619161926</td></tr><tr><td>Repetition</td><td>0.9274534530371639</td><td>0.7690917349911481</td></tr></tbody></table>

structure, cost, and mixer operators as the original QAOA, but differs by its cost function.

In fact, state-of-the-art implementations for QAOA-CV on universal quantum computers usually require the conversion of continuous variables into binary ones, by rounding the variables to a certain precision. The more significant digits, the more qubits are necessary. Our method does not suffer from this limitation and is scalable with the number of variables, independently of their precision.

Polynomial Unconstrained Binary Optimization (PUBO) [40] is another approach that avoids unnecessary binary encodings, reducing resource overhead while preserving solution quality. QAOA-CV provides a natural alternative to this method, while retaining the conceptual simplicity of the QUBO approach.

We benchmarked this new algorithm, testing different optimizers, numbers of circuit repetitions, mixers, and mixers' angles. Overall, our findings demonstrate that QAOA can be adapted effectively to continuous-variable problems, provided that optimizers and circuit parameters are carefully selected.

The SLSQP optimizer failed to converge for the problem considered, contradicting prior recommendations in the literature [37]. In fact, the QAOA-CV algorithm introduced in this paper and the original QAOA have different cost functions, and
<figure><img src="image_14.png" /><figcaption>**Fig. 14:** Average minimum value as a function of the mixer, angle, and optimizer.</figcaption></figure>

the assumption that the SLSQP optimizer would work with this new version may be unjustified.

The best performance was achieved using SPSA, three repetitions, and the default binary *X* mixer. Interestingly, the mixer type and angles had minimal effect on the optimization minimum. This aligns with the observation that specific mixers, such as *XY* or *XZ*, are primarily advantageous for specialized variable encodings like binary, one-hot, or domain-wall encoding. Since our implementation did not involve encoding transformations but only a change in variable types, there was no significant reason to expect these alternatives to outperform the default binary *X* mixer.
<figure><img src="image_15.png" /><figcaption>Fig. 15: Loss curves of COBYLA (top) and SLSQP (bottom).</figcaption></figure>

The number of circuit repetitions had a major impact on performance across all optimizers. Nevertheless, this comes with a trade-off: more repetitions lead to longer optimization times. This is an important consideration for practical implementations, in which balancing accuracy and efficiency is crucial.
<figure><img src="image_16.png" /><figcaption>Fig. 16: Loss curves of SPSA.</figcaption></figure>

# 6 Limitations

A key limitation identified in this study is the inability of SPSA to achieve the global minimum of 0.1369 for the problem of interest. This indicates a potential for further optimization, particularly in hyperparameter tuning. For instance, the current configuration of SPSA allows updates that do not necessarily reduce the loss (blocking=False), which could hinder its convergence to the true minimum.
Another key limitation of our study is that all experiments were conducted on simulators. As a result, we did not exploit any quantum computational advantages and did not account for quantum decoherence, which refers to the instability of quantum states over time, influenced by factors such as environmental noise, temperature, and interactions with surrounding qubits. Notably, quantum noise increases with the number of qubits, potentially negating any computational benefits by introducing errors. Developing large, error-tolerant quantum circuits remains an ongoing challenge [41], which we chose to overlook at this stage of our implementation. Additionally, practical constraints related to hardware, such as batching jobs to fit the limited qubit capacity of current quantum devices, were not considered in this study.

Finally, our approach focuses only on gate-based quantum computers, where the expectation value of a qubit is either $|0⟩$ or $|1⟩$. This approach is not valid for other types of quantum computers, where this expectation value is continuous.

# 7 Conclusion

In this study, we introduced a QAOA algorithm for continuous-variable optimization on gate-based universal quantum computers using Qiskit. We demonstrated both the feasibility and effectiveness of such an algorithm. Our findings show that QAOA can serve as a robust tool for addressing optimization problems involving continuous variables on *universal* quantum computers. Notably, since no variable encoding is required, the number of qubits scales linearly with the number of continuous variables, ensuring resource efficiency. Our results indicate that SPSA is a good candidate as an optimizer for the QAOA-CV approach, as it performed better than COBYLA and SLSQP on the problem we considered in this work. Key future research directions include finding the optimal parameters for SPSA and validating the use of QAOA-CV and SPSA to solve diverse optimization problems. That is, to validate the conclusions of this work with a larger benchmark.

# Code Availability

This implementation of QAOA-CV was contributed to the *pyRiemann-qiskit* repository [42] under the name *QAOACVOptimizer*. The code is available under the BSD three-clause license.

# References

[1] Huot, C., Kea, K., Kim, T.-K., Han, Y.: Enhancing Knapsack-based Financial Portfolio Optimization Using Quantum Approximate Optimization Algorithm (2024). https://arxiv.org/abs/2402.07123

[2] Khurana, R.: Applications of quantum computing in telecom e-commerce: Analysis of qkd, qaoa, and qml for data encryption, speed optimization, and ai-driven customer experience. Vectoral (2022)
[3] Papanikolaou, M.: Hybrid quantum - classical machine learning for the problem of protein-folding. Master's thesis, National Technical University of Athens School of Electrical and Computer Engineering (2024)

[4] Cerf, N.J., Leuchs, G., Polzik, E.S. (eds.): Quantum Information with Continuous Variables of Atoms and Light. World Scientific, Singapore (2007)

[5] Braunstein, S.L., Van Loock, P.: Quantum information with continuous variables. Reviews of modern physics **77*(2), 513–577 (2005)

[6] Matsuura, T.: Digital Quantum Information Processing with Continuous-Variable Systems. Springer, Cham (2023)

[7] Asavanant, W., Furusawa, A.: Optical quantum computers. Optical quantum computers (2022)

[8] Verdon, G., Arrazola, J.M., Brádler, K., Killoran, N.: A Quantum Approximate Optimization Algorithm for continuous problems (2019). https://arxiv.org/abs/1902.00409

[9] Enomoto, Y., Anai, K., Udagawa, K., Takeda, S.: Continuous-variable quantum approximate optimization on a programmable photonic quantum processor. Physical Review Research 5(4), 043005 (2023)

[10] Javadi-Abhari, A., Treinish, M., Krsulich, K., Wood, C.J., Lishman, J., Gacon, J., Martiel, S., Nation, P.D., Bishop, L.S., Cross, A.W., Johnson, B.R., Gambetta, J.M.: Quantum computing with Qiskit (2024). https://doi.org/10.48550/arXiv.2405.08810

[11] Grover, L.K.: A fast quantum mechanical algorithm for database search. In: Proceedings of the Twenty-eighth Annual ACM Symposium on Theory of Computing, pp. 212–219 (1996)

[12] Shor, P.W.: Polynomial-time algorithms for prime factorization and discrete logarithms on a quantum computer. SIAM review **41*(2), 303–332 (1999)

[13] Fowler, A.G., Mariantoni, M., Martinis, J.M., Cleland, A.N.: Surface codes: Towards practical large-scale quantum computation. Physical Review A—Atomic, Molecular, and Optical Physics **86**(3), 032324 (2012)

[14] Bharti, K., Cervera-Lierta, A., Kyaw, T.H., Haug, T., Alperin-Lea, S., Anand, A., Degroote, M., Heimonen, H., Kottmann, J.S., Menke, T., et al.: Noisy intermediate-scale quantum algorithms. Reviews of Modern Physics **94**(1), 015004 (2022)

[15] Romero Fontalvo, J.: Variational quantum information processing. PhD thesis (2019)
[16] Cerezo, M., Arrasmith, A., Babbush, R., Benjamin, S.C., Endo, S., Fujii, K., McClean, J.R., Mitarai, K., Yuan, X., Cincio, L., et al.: Variational quantum algorithms. Nature Reviews Physics 3(9), 625–644 (2021)

[17] Variational Algorithms — IBM Quantum Learning — learning.quantum.ibm.com. https://learning.quantum.ibm.com/course/variational-algorithm-design/variational-algorithms#simplified-hybrid-workflow. [Accessed 07-03-2025]

[18] Ganguly, S.: Quantum Machine Learning: An Applied Approach: The Theory and Application of Quantum Machine Learning in Science and Industry. Apress, Ashford, UK (2021). https://doi.org/10.1007/978-1-4842-7098-1

[19] Iglesias Munilla, A.: Optimization through Quantum Computing. Master of Science, Universitat Politècnica de Catalunya (UPC) - BarcelonaTech, Spain (2023)

[20] Peruzzo, A., McClean, J., Shadbolt, P., Yung, M.-H., Zhou, X.-Q., Love, P.J., Aspuru-Guzik, A., O'Brien, J.L.: A variational eigenvalue solver on a photonic quantum processor. Nature communications 5(1), 4213 (2014)

[21] Combarro, E.F., González-Castillo, S., Di Meglio, A.: A Practical Guide to Quantum Machine Learning and Quantum Optimization: Hands-on Approach to Modern Quantum Algorithms. Packt Publishing, Limited, Birmingham (2023)

[22] Phab, L., Louise, S., Sirdey, R.: First Attempts at Cryptanalyzing a (Toy) Block Cipher by Means of Quantum Optimization Approaches. Journal of Computational Science 69, 102004 (2023) https://doi.org/10.1016/j.jocs.2023.102004. Accessed 2025-04-01

[23] Farhi, E., Goldstone, J., Gutmann, S.: A quantum approximate optimization algorithm. arXiv preprint arXiv:1411.4028 (2014)

[24] Hadfield, S.: On the representation of boolean and real functions as hamiltonians for quantum computing. ACM Transactions on Quantum Computing 2(4), 1–21 (2021)

[25] Mannapov, I.: The Improvement of Decision Tree Construction Algorithm Based On Quantum Heuristic Algorithms. arXiv. arXiv:2212.14725 [quant-ph] (2022). https://doi.org/10.48550/arXiv.2212.14725. http://arxiv.org/abs/2212.14725 Accessed 2025-04-01

[26] Hadfield, S., Wang, Z., O'Gorman, B., Rieffel, E.G., Venturelli, D., Biswas, R.: From the Quantum Approximate Optimization Algorithm to a Quantum Alternating Operator Ansatz. Algorithms 12(2), 34 (2019) https://doi.org/10.3390/a12020034. Number: 2 Publisher: Multidisciplinary Digital Publishing Institute. Accessed 2025-04-01
[27] Mitarai, K., Negoro, M., Kitagawa, M., Fujii, K.: Quantum circuit learning. Physical Review A **98**(3), 032309 (2018)

[28] Schuld, M., Bergholm, V., Gogolin, C., Izaac, J., Killoran, N.: Evaluating analytic gradients on quantum hardware. Physical Review A **99**(3), 032331 (2019)

[29] Solve utility-scale quantum optimization problems — IBM Quantum Learning — learning.quantum.ibm.com. https://learning.quantum.ibm.com/tutorial/quantum-approximate-optimization-algorithm. [Accessed 10-03-2025]

[30] Sturm, A.: Theory and Implementation of the Quantum Approximate Optimization Algorithm: A Comprehensible Introduction and Case Study Using Qiskit and IBM Quantum Computers. arXiv. arXiv:2301.09535 (2023). https://doi.org/10.48550/arXiv.2301.09535. http://arxiv.org/abs/2301.09535 Accessed 2024-11-06

[31] Lloyd, S.: Quantum approximate optimization is computationally universal (2018). https://arxiv.org/abs/1812.11075

[32] Powell, M.J.D.: In: Gomez, S., Hennart, J.-P. (eds.) A Direct Search Optimization Method That Models the Objective and Constraint Functions by Linear Interpolation, pp. 51–67. Springer, Dordrecht (1994). https://doi.org/10.1007/978-94-015-8330-5_4

[33] Plewa, J., Sienko, J.: Hybrid algorithms for workflow scheduling problem in quantum devices based on gate model. PhD thesis, Master’s Thesis, AGH University of Science and Technology, Kraków, 2021 ... (2021)

[34] Plewa, J., Sieńko, J., Rycerz, K.: Variational Algorithms for Workflow Scheduling Problem in Gate-Based Quantum Devices. COMPUTING AND INFORMATICS **40**(4), 897–929 (2021) https://doi.org/10.31577/cai.2021.4.897. Number: 4. Accessed 2024-02-08

[35] Hadfield, S., Wang, Z., O’gorman, B., Rieffel, E.G., Venturelli, D., Biswas, R.: From the quantum approximate optimization algorithm to a quantum alternating operator ansatz. Algorithms **12**(2), 34 (2019)

[36] Chancellor, N.: Domain wall encoding of discrete variables for quantum annealing and qaoa. Quantum Science and Technology **4**(4), 045004 (2019) https://doi.org/10.1088/2058-9565/ab33c2

[37] Fernández-Pendás, M., Combarro, E.F., Vallecorsa, S., Ranilla, J., Rúa, I.F.: A study of the performance of classical minimizers in the Quantum Approximate Optimization Algorithm. Journal of Computational and Applied Mathematics **404**, 113388 (2022) https://doi.org/10.1016/j.cam.2021.113388. Accessed 2024-10-30
[38] Spall, J.C.: A one-measurement form of simultaneous perturbation stochastic approximation. Automatica 33(1), 109–112 (1997) https://doi.org/10.1016/S0005-1098(96)00149-5. Accessed 2021-09-21

[39] Spall, J.C.: Adaptive stochastic approximation by the simultaneous perturbation method. IEEE Transactions on Automatic Control 45(10), 1839–1853 (2000) https://doi.org/10.1109/TAC.2000.880982. Conference Name: IEEE Transactions on Automatic Control

[40] Stein, J., Chamanian, F., Zorn, M., Nüßlein, J., Zielinski, S., Kölle, M., Linnhoff-Popien, C.: Evidence that pubo outperforms qubo when solving continuous optimization problems with the qaoa. In: Proceedings of the Companion Conference on Genetic and Evolutionary Computation (GECCO '23 Companion), pp. 2254–2262. ACM, ??? (2023). https://doi.org/10.1145/3583133.3596358

[41] Kim, Y., Eddins, A., Anand, S., Wei, K.X., Berg, E., Rosenblatt, S., Nayfeh, H., Wu, Y., Zaletel, M., Temme, K., Kandala, A.: Evidence for the utility of quantum computing before fault tolerance. Nature 618(7965), 500–505 (2023) https://doi.org/10.1038/s41586-023-06096-3. Number: 7965 Publisher: Nature Publishing Group. Accessed 2023-06-17

[42] Andreev, A., Cattan, G., Chevallier, S., Barthélemy, Q.: pyRiemann-qiskit: A Sandbox for Quantum Classification Experiments with Riemannian Geometry. Research Ideas and Outcomes 9 (2023) https://doi.org/10.3897/rio.9.e101006. Publisher: Pensoft Publishers. Accessed 2023-03-20