Paper commentary
Quantum agents in the Gym: a variational quantum algorithm for deep Q-learning
- Problem Value-based reinforcement learning with a parametrized quantum circuit is hard because a circuit's readout fixes the range of its outputs, while optimal Q-values can be large and shift as the agent improves.
- Method The DQN loop is rebuilt around a hardware-efficient PQC. States are encoded as X rotations, optionally with trainable input scaling and data re-uploading, and trainable output weights widen the readout range. The variants are tested on Cart Pole and compared with neural networks of matched parameter counts.
- Results Data re-uploading combined with trainable input weights solved Cart Pole in 3000 episodes on average with the best hyperparameter set and in 600 episodes with a sub-optimal set. The best PQC with 25 layers and 302 parameters took 500 episodes, and the best NN with 562 parameters took 250.

Figure 1 : PQC architecture used in this work. Each layer consists of a parametrized rotation along theY and Z axes on each qubit, and a daisy chain of CZ gates. The green boxes correspond to data encoding gates that en- code data as parameters of X rotations. When data re- uploading is used, the whole circuit pictured is repeated in each layer, without data re-uploading only the varia- tional part without the initial X rotations is repeated.
Original paper · CC BY 4.0 · Andrea Skolik, Sofiene Jerbi, Vedran Dunjko · Quantum agents in the Gym: a variational quantum algorithm for deep Q-learning · Original paper figure · Extracted the figure area from page 7 of the original PDF.Why the readout range limits quantum Q-learning
The readout observable of a quantum model fixes the range of values it can return, so a PQC's outputs stay within a bounded interval. A neural network has no such restriction and can even move its output range during training. Q-values, in contrast, depend on the reward function and the discount factor, and they need not sit in a fixed interval.
As an agent improves at balancing the pole, the Q-values it should approximate grow, so the needed output range changes during training. Earlier PQC Q-learning models for Cart Pole did not reach a solving score, which left open whether a value-based PQC agent can solve this kind of task at all.
Quantum Q-learning agent
The Q-function is a parametrized circuit U_θ(s) whose parameters are updated, and a target circuit with copied parameters is refreshed at fixed intervals. The rest of the DQN procedure is kept: experience replay supplies training batches, an ε-greedy rule picks actions, and a target network supplies the update targets.
The label for a visited state-action pair starts from a copy of the circuit's output vector, and only the entry of the chosen action is replaced by the reward plus γ times the largest target Q-value of the next state. The loss is the mean squared error between the output vector and this label, averaged over a batch B, so only the chosen entry contributes a difference.
This ansatz is highly expressive and is susceptible to barren plateaus for many qubits and layers, which the authors judge not to matter at the small state and action spaces considered.
Encoding states as rotation angles
Discrete states are written as bitstrings, and the bits set to one are flipped on an all-zero state. Each component of a continuous state is mapped through the arctan function, so values fall in the interval from minus π/2 to π/2, and each value sets the angle of an X rotation.
Encoding by X rotations alone lets the circuit model only simple sine functions of its input. The encoding can be repeated either in parallel across more qubits or in sequence between the variational layers, and the sequential form is called data re-uploading. Within the Fourier-series view of PQCs, the accessible frequencies follow the eigenvalues of the encoding gates, the highest degree grows with how often the encoding gate is repeated, and the input scale must match the frequencies of the target function.
The input scaling is made trainable, so the encoded angle for input component x_i is arctan of x_i times a trainable weight w_{d_i}.
Trainable output range
For Cart Pole the measured observables are Pauli-ZZ operators, with O_L equal to Z1 Z2 for the left action and O_R equal to Z3 Z4 for the right action, acting on four qubits. A trainable weight for each action is added to the measured value, so the Q-value is the expectation value plus a trained offset term. A Pauli-ZZ expectation value lies between minus one and one, so the trainable weight is the part that lets the output reach the scale of Q-values that reach about 86 in Cart Pole.
Encoding ablation on Cart Pole
The ablation compares agents without data re-uploading, without trainable input scaling, and with both, under a best and a sub-optimal hyperparameter set. Each configuration averages 10 randomly initialized agents with 5 layers of the circuit, and the environment counts as solved when the average score over the last 100 episodes is at least 195.
Neither data re-uploading nor trainable input weights alone produce agents that solve Cart Pole within 5000 episodes under either hyperparameter set. Combining both enhancements solves Cart Pole in 3000 episodes at most on average with the best hyperparameters and in 600 episodes at most with the sub-optimal set. The authors attribute this to the need to match the PQC's expressivity to the learning task.
Readout range ablation on Cart Pole
The comparison holds the agents fixed and varies only the readout: trainable output weights against fixed output ranges of [0, 1], [0, 90] and [0, 180]. Agents with the fixed range [0, 1] stay at an extremely low score across all 5000 episodes under both hyperparameter sets. The trainable-output agents solve Cart Pole under both hyperparameter sets.
Final Q-values of trainable-output agents that converge late reach approximately 176, which is above the bound of 90 used for the fixed range. Agents with the fixed range [0, 180] can fail completely depending on the remaining hyperparameters.
PQCs and neural networks by parameter count
PQCs range from 5 to 30 layers, with parameter counts from 62 to 362, and NNs have two hidden layers with widths from (10, 10) to (64, 64), with parameter counts from 182 to 4610. A hyperparameter optimization was run for each configuration separately, and results average ten agents per configuration.
The best PQC has 25 layers and 302 parameters and takes 500 episodes on average to solve Cart Pole. The best NN has 20 units in each hidden layer and 562 parameters, and it solves Cart Pole in 250 episodes on average. Increasing the parameter count does not improve performance monotonically for either model family.
For the best individual agents, the PQC with 5 layers and 62 parameters takes 206 episodes, and the NN with two hidden layers of 30 units and 1142 parameters takes 186 episodes. The authors note that PQCs seem to suffer more from training instability as the number of parameters grows than NNs do.
Scale of optimal Q-values in Cart Pole
The Q-value of an episode with horizon H = 200 under an optimal policy is the sum of discount factors from k = 0 to H minus 1. Formally, Q*(s,a) equals the sum over k from 0 to H minus 1 of γ^k, and this is the upper bound used for the trainable range. With γ = 0.99 the maximum optimal Q-value is about 86, which is far above the range that computational basis measurements can produce.
The largest Q-values of one of the best quantum models are close to this optimum of about 86. Actual Q-values also depend on episode length, so the lower bound comes from the shortest failing episode and the upper bound applies only to a single optimal episode.
Optimal Q-values from optimal policies
Solving an environment with a deterministic argmax policy requires only the correct ordering of Q-values rather than their exact values. Monte Carlo sampling of Q-values is hard in general, because an agent cannot reach arbitrary states in polynomial time.
For SL-DLP with γ = 0 and two actions, the Q-value of the optimal action is the reward of a correct classification, and the wrong action's Q-value follows from the fact that only two distinct values exist.
This method does not resemble tabular or DQN-type Q-learning, and whether a rigorous quantum advantage holds for either policy-based RL or Q-learning remains open.
Limitations
The ansatz is susceptible to barren plateaus for large numbers of qubits and layers, and the small state and action spaces studied here do not reach that regime. Quantitative comparisons are reported for Cart Pole, where the ablations use 10 agents and 5 layers and the training horizon is 5000 episodes. Optimal Q-values are not computed for Cart Pole because its state space is continuous, so magnitude comparisons with a reference optimum are not provided.
Paper info
- Authors
- Andrea Skolik, Sofiene Jerbi, Vedran Dunjko
- Venue
- arXiv · Preprint
- First published
- 2021-3-28
- Added
- 2026-11-6
- Updated
- 2022-5-16
- Version
- v3
- arXiv
- 2103.15084
- DOI
- 10.22331/q-2022-05-24-720
- Category
- quant-ph
- Original paper terms
- CC BY 4.0
- What we show
- Paper info, commentary and permitted figures from the original paper
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Abstract
Quantum machine learning (QML) has been identified as one of the key fields that could reap advantages from near-term quantum devices, next to optimization and quantum chemistry. Research in this area has focused primarily on variational quantum algorithms (VQAs), and several proposals to enhance supervised, unsupervised and reinforcement learning (RL) algorithms with VQAs have been put forward. Out of the three, RL is the least studied and it is still an open question whether VQAs can be competitive with state-of-the-art classical algorithms based on neural networks (NNs) even on simple benchmark tasks. In this work, we introduce a training method for parametrized quantum circuits (PQCs) that can be used to solve RL tasks for discrete and continuous state spaces based on the deep Q-learning algorithm. We investigate which architectural choices for quantum Q-learning agents are most important for successfully solving certain types of environments by performing ablation studies for a number of different data encoding and readout strategies. We provide insight into why the performance of a VQA-based Q-learning algorithm crucially depends on the observables of the quantum model and show how to choose suitable observables based on the learning task at hand. To compare our model against the classical DQN algorithm, we perform an extensive hyperparameter search of PQCs and NNs with varying numbers of parameters. We confirm that similar to results in classical literature, the architectural choices and hyperparameters contribute more to the agents' success in a RL setting than the number of parameters used in the model. Finally, we show when recent separation results between classical and quantum agents for policy gradient RL can be extended to inferring optimal Q-values in restricted families of environments.
Quote from the paper
Andrea Skolik, Sofiene Jerbi, Vedran Dunjko (2021). Quantum agents in the Gym: a variational quantum algorithm for deep Q-learning. arXiv:2103.15084v3. https://doi.org/10.22331/q-2022-05-24-720
BibTeX
@article{skolik2021quantum,
title = {{Quantum agents in the Gym: a variational quantum algorithm for deep Q-learning}},
author = {Andrea Skolik and Sofiene Jerbi and Vedran Dunjko},
year = {2021},
eprint = {2103.15084},
archivePrefix = {arXiv},
doi = {10.22331/q-2022-05-24-720},
url = {https://arxiv.org/abs/2103.15084v3}
}