{'fraction_non_alphanumeric': 0.030264522821576764, 'fraction_numerical': 0.00762448132780083, 'mean_word_length': 4.879097423387711, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 2, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
A quantum-classical cloud platform optimized for variational hybrid algorithms

In order to support near-term applications of quantum computing, a new compute paradigm has emerged--the quantum-classical cloud--in which quantum computers (QPUs) work in tandem with classical computers (CPUs) via a shared cloud infrastructure. In this work, we enumerate the architectural requirements of a quantum-classical cloud platform, and present a framework for benchmarking its runtime performance. In addition, we walk through two platform-level enhancements, parametric compilation and active qubit reset, that specifically optimize a quantum-classical architecture to support variational hybrid algorithms (VHAs), the most promising applications of near-term quantum hardware. Finally, we show that integrating these two features into the Rigetti Quantum Cloud Services (QCS) platform results in considerable improvements to the latencies that govern algorithm runtime.


Introduction
The first experimental realizations of quantum algorithms date back to over a decade ago [17,35,27,23], but in the last three years quantum computing has rapidly transitioned from a field of scientific research to a full-fledged technology industry. The recent demonstration of quantum supremacy over classical computing [11] is a considerable milestone, but there is still much progress to be made on the road to solving realworld problems with quantum computers and achieving quantum advantage. Improving the error rates of quantum devices [12,30] and ultimately reaching the regime of fault tolerance [48] is necessary for unlocking the most powerful known applications of quantum computers. At the same time, the industry has increased its focus on finding ways to solve valuable problems using the noisy intermediate-scale quantum (NISQ) processors that are currently available [49].
The desire to provide the research community with access to scarce quantum hardware in order to shorten the path to quantum advantage resulted in the development of a new compute architecture-the quantum cloud. As part of this architecture, the concept of an Internet-accessible data center has been extended to include quantum devices. Infrastructure for the quantum cloud requires a slew of new specialized hardware, for example, dilution refrigerators to house superconducting qubits and racks of microwave instruments to control them. To build the quantum cloud, some developers of quantum computers have pivoted to being full-stack, using in-house infrastructure to offer cloud-based access to their quantum devices [2,7]. In addition, some traditional cloud providers have begun to add quantum backends through strategic hardwaresoftware partnerships [1,3].
The first iteration of quantum cloud offerings employed a hybrid cloud model [40], in which users of the service submitted quantum programs using a web API to a queue hosted by the public cloud (e.g. Amazon Web Services). Then, a server colocated with a quantum processor would periodically pull jobs off of the queue, execute them, and return results back to the user. This approach was effective in offering worldwide, public access to quantum resources, but suffers in terms of runtime efficiency due to the overhead of using a shared queue. In addition, the traditional web API model fails to capitalize on or adapt to any properties specific to using a quantum device for computation.
In particular, the most promising approach to effectively using near-term quantum devices is through variational hybrid algorithms (VHAs) [39] which employ a quantumclassical architecture, essentially leveraging the quantum computer as a co-processor alongside a powerful classical computer. These algorithms have been applied to areas such as combinatorial optimization [25,45], quantum chemistry [46,44], and machine learning [56], and numerous proposals for applications of the variational method continue to arise with increasing frequency [16,54]. However, VHAs require a tight coupling between quantum and classical resources, and using a public-cloud-hosted queue is slow with respect to the scale of quantum operations (and especially so on a superconducting device) [34]. In addition, a quantum cloud architecture must be specifically optimized in order to efficiently support the variational model of execution. In this work, we investigate architectural bottlenecks of this new quantum-classical cloud, and provide a benchmarking framework to analyze its runtime performance. We then use the benchmark to quantify the dramatic reduction in latency achieved by the Rigetti Quantum Cloud Services (QCS) platform via the implementation of specialized techniques for quantum program compilation and qubit register reset.

Runtime bottlenecks in the quantum-classical cloud
The job of a quantum cloud platform is to ingest programs written in a backendindependent high-level quantum programming language [53,22], compile them into a platform-specific representation, run them on an available quantum device, and return the results to the user. Specifically, a quantum cloud platform has four essential components: (i) An apparatus that houses the physical objects that act as qubits (e.g. an optical table and trapping system for ions or neutral atoms).
(ii) A control system containing instruments for manipulating that apparatus in order to drive the desired evolution and read out qubit measurement results.
(iii) An executor that orchestrates the control system to run quantum programs and return measurement results to the user.
(iv) A compiler that takes in quantum programs and produces instrument binaries for the executor.
To be categorized as quantum-classical cloud, a platform must also include access to classical compute resources. Depending on the particular qubit implementation used by the platform, the CPU-QPU interaction could become the largest bottleneck in the variational model of execution. For example, when using superconducting qubits (with gate times in the tens of nanoseconds) the CPU and QPU should be physically colocated in order to enable a low-latency link between the user and the quantum device. Although colocating user and compute is not a new concept in cloud computing in general, it has yet to take hold broadly in quantum computing, and drastically reduces overhead in VHAs. For Rigetti QCS, which uses superconducting qubits as the backend, users interact with the QPU via a preconfigured development environment called the quantum machine image (QMI) (Fig. 1a). The QMI is a virtual machine running on a classical compute cluster located inside the Rigetti quantum data center in Berkeley, CA, and contains the Forest SDK [6] for building applications using the quantum instruction language Quil [53]. Once written, quantum programs are sent to the Aspen Compiler for compilation into pulse-level instructions (Fig. 1b). The information that encodes this gate-to-pulse mapping is contained within a calibration database, and is updated whenever the system drifts out of spec. The binaries that are returned by the compiler are then sent to the Aspen Executor (Fig. 1c), which loads them onto a collection of The classical compute (CPU) is connected over the network to a collection of quantum processors (QPUs), which are composed of a classical host computer, control system rack, dilution refrigerator, and quantum integrated circuit (QuIC). (a) Users write quantum programs using Quil on the QMI, which is located inside the data center. Rigetti-custom microwave arbitrary waveform generators (AWGs) and receivers, and triggers the instruments to begin execution (Fig. 1d). The Rigetti AWGs then send microwave pulses into a dilution refrigerator to manipulate and read out the state of the Aspen-4 16-qubit quantum processor (Fig. 1e). Finally, the bitstrings resulting from readout are returned to the user compute environment ( Fig. 1f-g) for processing and analysis.
In the variational model of execution, one seeks to minimize an objective function [4] that is expensive to compute on classical hardware, by embedding it as a subroutine on a quantum computer. To begin, a classical computer takes an initial guess and instructs a quantum computer to perform a predetermined computation. Then, from the output statistics of sampling the quantum program many times, a classical optimizer running on the CPU updates the QPU instructions for the next round of iteration. Depending on the difficulty of the problem, and the quality of the QPU, this will repeat many times before finding a potential solution [38]. Thus, the structure of a variational hybrid algorithm is broken into two nested loops: an outer variational iteration loop, and an inner quantum execution loop. We denote each roundtrip completion of the variational iteration loop as an iteration step, and each roundtrip completion of the quantum execution loop as a shot. Each iteration step includes communicating with the QPU, waiting for it to return results, and using an optimizer to decide what to run on the QPU next. Each shot is defined by running a single program of quantum instructions and getting back a single bitstring of measurement outcomes. This structure gives us a way to think about the different components that contribute to hybrid algorithm runtime-they either occur once per step in the variational iteration loop, or once per shot in the quantum execution loop. In order to improve the performance of QCS and optimize it for the variational model of execution, we began by constructing a latency budget for each of the nested loops ( Table 1).
The components of the per-step latency budget are instrument initialization, network communication, and compilation, which is the largest contributor by at least one order of magnitude. The contribution from instrument initialization has already been substantially reduced by using custom control hardware. In addition, the runtime of a single shot is split between gates (for manipulating and entangling qubit states), readout (for measuring and extracting bitstring outcomes), and qubit reset. Qubit reset can be performed passively, by waiting for all qubits to relax to their ground states. However, this relaxation process is the same decoherence process that determines T 1 , one of the metrics for qubit lifetime. Therefore, this passive qubit reset time will only increase as qubit performance gets better [42,29], and it already dominates the per-shot latency budget. Thus, from examining the two latency budgets, compilation and qubit reset are the areas to which improvements would have the largest impact on algorithm runtime.  Table 1. Per-step and per-shot latency budgets for the Aspen-4 QPU via QCS, rounded to one significant figure. The per-step budget was collected by running Max-Cut QAOA [25] on two qubits, and measuring the completion time for each of the components. The per-shot budget contains the average gate and readout times for Aspen-4 from the calibration database. The reset time is five times the longest T 1 time measured on Aspen-4 (see Fig. 3 for details). The compilation task is further broken down into two components: the first which converts arbitrary quantum programs into ones that use the gateset and topology of the target quantum device (about 150 ms) [5]; and the second which converts this nativized program into pulse-level instrument binaries (about 50 ms).

Optimizing for the variational execution model
Having identified compilation and qubit reset as potential bottlenecks for a quantumclassical cloud architecture, we walk through specific enhancements made to mitigate their contributions to the latency budgets of Rigetti's quantum cloud platform.

Parametric compilation
The underlying quantum program for a variational algorithm is parametric, meaning that from iteration step to iteration step, the sequence of instructions is static and only the instruction arguments change. Thus, a specialized compiler that preserves this parametric ansatz structure can leverage it to improve runtime. To build such a compiler, we need to understand the physical implementation of a highlevel quantum program in order to determine which instructions are easy to modify parametrically at runtime. For superconducting quantum processors (and many other QPU implementations), qubits are controlled by shaped radio frequency (RF) or microwave pulses typically generated by an AWG. The pulse amplitude, duration, and phase control the rotation angle and axis effected on the qubits. Typically the phase of the pulse is determined by an abstract rotating reference frame set to a frequency determined by the physics of the qubits. Z-rotations of a qubit then correspond to instantaneous reference frame update events that change the phase of subsequent microwave pulses. Without loss of generality, we can directly relate each parameter of a variational algorithm to Z-rotations or phase updates for one or more qubit reference frames. Previously, the arguments to these SHIFT-PHASE operations were provided at compile-time, and hardcoded in the instrument binary. Thus, for every step in a VHA, new instrument binaries would need to be compiled, such that these arguments could be updated.
To circumvent this need for re-compiling, we implemented a feature called parametric compilation. Like a standard executable file, each instrument binary includes a header and a collection of sections [18]. The instruction memory section contains executable code, and the waveform memory section contains pulse shapes that are referenced by the instruction memory. Rather than having SHIFT-PHASE instructions use a static data field as an argument, each instrument binary now additionally has a data memory section which instructions can access via reference. Like classical shared memory, the data memory section can also be updated at runtime by an external process in order to change the effect of the binary [8]. The data memory section layout of a particular binary is prescribed by Quil's DECLARE syntax (Fig. 2), which can be used to initialize named memory registers of various data types (BIT, OCTET, INTEGER, and REAL). Once initialized, the memory registers can be provided as arguments to parameterized gates such as RZ. When these gates are compiled (Fig. 1b) they become SHIFT-PHASE operations that reference entries in an empty data memory section. Upon execution, the user provides these parametric instrument binaries along with a map of memory register assignments, for example, variational parameters for the current iteration step of a VHA (Fig. 1c). Then, the executor fills in the data memory section using the memory map to produce patched binaries (Fig. 1d). For each step in a VHA, these binaries can be re-patched with a new set of variational parameters, and thus the variational iteration loop can repeat until termination without the need for compilation. (b) Figure 2. Quantum programs, written in Quil, for Max-Cut QAOA on two qubits, and their corresponding circuit diagrams. (a, top) The program, using a specific set of values for variational parameters (β, γ). These show up as arguments to RZ gates, with β = π/4 and γ = π/2. Thus, every iteration step, the program itself has to be updated with new variational parameters and re-compiled before execution. (b, bottom) The program, taking advantage of parametric compilation. Now, rather than providing values for β and γ when writing the program, we instead initialize realvalued classical memory registers beta and gamma using Quil's DECLARE syntax, and use them as arguments for the RZ gates. This allows for their assignment to be deferred from compile-time to run-time, and eliminates the need for re-compilation between variational iteration steps.

Active qubit reset
Rather than waiting for qubits to passively reset, we can implement a protocol called active qubit reset that sets all qubits to their ground states at the beginning of a computation. This has been previously demonstrated by controllably transferring qubit excited state population to a system with a much faster decay rate (such as the readout resonators) [24,36,11], or by performing a measurement and then quickly feeding back to apply a conditional X gate [50,52]. But, for this protocol to be useful, the conditional control flow needs to happen on a timescale comparable to the quantum gates, and it cannot introduce significant error into proceeding computations. We chose to implement this classical feedback loop on our platform because it additionally unlocks more complex feedback/feedforward circuits that take advantage of mid-circuit measurements. To support this, the compilation toolchain can propagate control flow structures down to the hardware pulse sequencers. Coupled with the ability to rapidly broadcast qubit measurement results across the control system, active reset is not a special-case operation but instead a simple if-then-else control flow branching off of qubit measurement results. By providing the RESET instruction at the top of a Quil program, users can signal to the compilation toolchain that they would like to enable active qubit reset. When ingested by the compiler, the RESET directive is translated to control-flow graphs (CFGs) [10] for each qubit that encapsulate the branching and looping structure of the active reset protocol. The program starts at header block h c , which is initialized with c, the number of active reset rounds to perform. It then jumps to measurement block M and increments the feedback counter κ. If the measurement result is a 0, the program then jumps to idle block I; otherwise, it jumps to feedback block X. After I or X the program jumps back to M unless κ equals c. In that case it jumps to U , the main body block. (b-e) Optimal quadrature histograms of IQ signal data from three successive rounds of active reset (c-e) on a single Aspen-4 qubit starting from an equal superposition input state (b). On Aspen-4, T 1 times range from 10 to 20 µs. Thus, in order to achieve a reset fidelity F > 99 % in the passive reset case, we must wait for 5T 1 = 100 µs between shots (as 1 − e −5 > 0.99). If we instead use active qubit reset, we can perform three rounds of measurement and feedback on the order of 10 µs. By the third round (e), we achieve a reset fidelity of F = 99.6 %.
Control-flow graphs are composed of nodes called basic blocks, each of which includes a sequence of instructions without branching and up to two directed edges, or jump targets, to follow once the instructions are complete. If a block has two jump targets, it also contains a conditional expression for choosing between them. Each singlequbit RESET CFG contains four basic blocks-a header block, a measurement block, an idle block, and a feedback block (Fig. 3a). The program starts at the header block, which initializes a counter to track the number of active reset rounds performed, and then jumps to the measurement block and increments the counter. The measurement block contains readout and capture instructions for the qubit, and conditionally jumps to either the idle or feedback blocks dependent on the bit result produced by the measurement. If the result is 1, the qubit is in the excited state, and therefore the feedback block containing the X gate program is executed. Otherwise, if the result is 0, the program jumps to the idle block. After either the idle or feedback block is completed, the program then jumps to the measurement block again if the counter is less than the number of reset rounds requested. After each single-qubit program traverses its active reset CFG, the program jumps to the first basic block of the main body quantum circuit and proceeds until completion.
The time required to perform the active reset protocol is dependent on the underlying architecture of a QPU. For Aspen-4, we require three rounds of feedback to achieve a reset performance comparable to that of passive qubit reset (Fig. 3b-e). All active reset sequences must be completed before the main body program begins, and the readout operations on Aspen-4 are in the 2 to 3 µs range. Combined with a broadcast and feedback latency of around 1 µs, this results in an active reset time of 9 to 12 µs, approximately a tenfold improvement over passive reset times.

A volumetric framework for benchmarking runtime
A useful metric for determining the runtime performance of a quantum-classical cloud platform is QPU latency, which tells us how long the CPU has to wait between requesting execution on a quantum device and receiving back the results. Generically, this latency depends on the number of qubits involved in the computation, the number of shots requested, and the program being run. We can define a function T (m, n, P) which returns QPU latency and takes a number of qubits m, a number of shots n, and a function P that produces a family of quantum programs for a given number of qubits. Some examples of P are GHZ LINE, which produces the straight-line program to create a GHZ state on m qubits [26], and MAXCUTQAOA COMPLETE, which produces a QAOA program to solve Max-Cut on a fully-connected graph with m nodes [25]. In addition, by sweeping n and measuring T with fixed m and P, we can determine two asymptotic latencies of a platform for a particular family of quantum programs and number of qubits: the single-shot limit (n = 1) tells us the variational step latency (T V ) and the scaling of the latency in the limit of large n tells us the quantum shot latency (T Q ). More formally, we assume that the total latency T is straightforwardly related to the two components in the following manner T (m, n, P) = T V (m, P) + nT Q (m, P). (1) However, T V and T Q are still functions that depend on the number of qubits and the requested quantum program, and therefore need further specification to be an effective cross-platform benchmark. Naively choosing m = 1 and P to be circuits containing only MEASURE instructions makes it trivial to experimentally benchmark the system. By sweeping the number of shots, measuring latency, and fitting the data to a linear model, the resulting latency-axis intercept gives T V (1, MEASURE) and the resulting slope gives T Q (1, MEASURE). These numbers well-encapsulate some parts of the performance of a particular architecture, but fail to capture how the architecture fares as the number of qubits increases or as the program complexity changes. For example, potential pitfalls such as long gate times or a poorly scaling control system initialization routine are entirely omitted by the benchmark. But, simply setting m to be the maximum device size available on a particular platform is equally misleading, as current NISQ devices often have error rates such that they cannot produce useful entanglement across the entire QPU.
Although there is no unanimously supported benchmark for QPU performance within the community (and there may never be), log quantum volume [ ... . . .

Figure 4.
Random phase gadget (RPG) family of volumetric circuits, used for benchmarking runtime on a quantum-classical cloud platform. (left) The qubits and layers are indexed starting at zero, and the angle values α i,j for qubit j and layer i are chosen at random. Although the circuit family could be defined for an arbitrary number of layers d and qubits m, we choose m = d = log 2 V Q in order to determine computationally relevant latencies. It is important to note, however, that this choice is arbitrary and only meant to simplify the benchmark. As in quantum volume, if the number of qubits is odd, the bottom qubit line has no gates. To benchmark a number of qubits m, we choose a set of permutations {π}, run the resulting circuit r times, and compute the average runtime. For each run, we randomize all the α values and collect n shots. This effectively emulates a VHA [20], as the permutations are fixed ahead of time, and only the phase gadgets themselves change. Then, repeating this entire process for multiple permutation sets ensures that we get a good estimate of the average runtime for a particular number of qubits. (right) Example Quil circuit from RPG(2), meaning m = d = 2, and using parametric compilation to defer the assignment of α values.
has been proposed as a reasonable near-term metric for the number of qubits that can be meaningfully used in a computation. We are interested in something that is similar to quantum volume (so that the choice of number of qubits remains relevant), but more appropriate for the near-term VHAs. Variational algorithms contain structures known as phase gadgets [19], which are RZ gates sandwiched between CNOTs. These structures are often the cornerstone of parametric-ansatz-style programs, and therefore we propose using a volumetric family of circuits [15] that we call random phase gadgets (RPG) to benchmark algorithm runtime. The RPG circuit family incorporates the permutation aspect of quantum volume for exercising connectivity, parallelism, and gateset [47], but replaces the random 2Q unitaries with phase gadgets that have RZ gates with randomly chosen arguments (Fig. 4). In addition, each permutation is followed by a layer of Hadamard gates on all qubits, to make it more difficult to compile away the phase gadgets. Setting m = log 2 V Q and P = RPG gives us the computationally relevant step (T V ) and shot (T Q ) latency of a QPU Fitting the resulting runtime data to the linear model T (n) = T V + nT Q then allows us to easily estimate variational algorithm runtimes using the computationally relevant QPU latency for a particular device available on a quantum cloud platform.

QPU latency results on Quantum Cloud Services
Using the aforementioned volumetric framework for benchmarking runtime, we calculate T V and T Q for four different versions of the Rigetti quantum cloud platform. To demonstrate the initial performance improvements resulting from simply colocating CPU and QPU, we first plot median user runtime data from over 851,000 quantum programs run on the Acorn and Agave QPUs via the Forest Web API, the initial version of Rigetti's platform (Fig. 5a). The Forest Web API used the first-generation model of quantum cloud access, routing each job through a queue on Amazon Web Services (AWS), which resulted in considerable latencies (T Q = 270 µs, T V = 1.0 s). If we instead use QCS's colocated architecture, T V drops to 410 ms and T Q to 110 µs for the Aspen-4 QPU (Fig. 5b). Across all the programs run on the Forest Web API, the average number of involved qubits was 3. In addition, the log quantum volume for Aspen-4 is log 2 V Q = 3, and thus it is reasonable to compare the data from the two platforms. Using parametric compilation (Fig. 5c), we can remove the compile step from our runtime calculations, resulting in an improvement for small numbers of shots (T V drops to 36 ms). For higher numbers of shots, passive reset times still dwarf the constant improvement from parametric compilation. Finally, by enabling active qubit reset (Fig. 5d), we get an additional reduction in latency within the quantum execution loop. Thus, in this optimal configuration of the platform, T V = 36 ms and T Q = 21 µs, resulting in greater than 27x and 12x improvements, respectively, over the latencies of the first-generation access model.

Conclusions
Quantum Cloud Services may be the first instance of a quantum-classical cloud platform, but this architectural paradigm will become increasingly common as the industry continues to progress toward useful applications of quantum computers. Error rates and qubit count are well-known to be important system benchmarks within the field, but as more and more hardware providers begin to offer access to quantum resources over the cloud, the latencies that govern this access and the resulting application runtimes will also be critical considerations for platform performance. Addressing these latencies requires approaching system bottlenecks with an interdisciplinary quantum software engineering mindset, bridging the knowledge bases of classical and quantum computing. We have shown that colocation, parametric compilation, and active qubit reset provide considerable improvements over the first-generation of quantum cloud offerings, but they are just a few of the many potential platform optimizations for accelerating industry progress and enabling the achievement of quantum advantage.
Acknowledgements PJK, ECP, RSS, and NAT implemented the parametric compilation toolchain. NAT built the software for expressing active qubit reset as a control-flow graph. CAR coordinated the integration of active qubit reset into the QCS platform. PJK, ECP, and CAR formulated the benchmark, and PJK collected and analyzed all runtime data. PJK and MPS designed the framework for running variational algorithms using parametric compilation. PJK, CAR, and MPS wrote the manuscript and prepared the figures. ‡ This work was funded by Rigetti & Co Inc., dba Rigetti Computing. We thank the Rigetti quantum software team for providing tooling support, the Rigetti fabrication team for manufacturing the device, the Rigetti technical operations team for fridge maintenance, the Rigetti cryogenic hardware team for providing the chip packaging, the Rigetti control systems and embedded software teams for creating the Rigetti AWG control system, and the Rigetti quantum engineering team for building the infrastructure for automated QPU bringup and recalibration.
In addition, the authors would like to specifically thank Lauren C. Capelluto, Steven Heidel, Glenn E. Jones, Anthony M. Polloreno, and Rodney F. Sinclair for their critical ‡ All of the plotting and analysis from the paper can be recreated using the supplementary Jupyter notebooks and datasets [32], which are also available on the notebook hosting service Binder.
contributions to the QPU compiler toolchain, Alexander D. Hill, Joseph A. Valery, Alexa N. Staley, and Blake R. Johnson for their management of QPU performance and deployment, Zachary P. Beane, Adam D. Lynch, Nicolas J. Ochem, and Christopher B. Osborn for their orchestration of the QMI compute infrastructure, E. Schuyler Fried, Diego Scarabelli, and Prasahnt Sivarajah for their crucial work on experimental bringup of active qubit reset, Joshua Combes, Kyle V. Gulshen, and Nicholas C. Rubin for building the readout error mitigation tools that enable the implementation of VHAs, Matthew P. Harrigan and William J. Zeng for their leadership in designing a quantum programming interface to QCS, and Matthew J. Reagor for insightful discussions on modeling and benchmarking QPU latency.

Appendix A. Implementing hybrid algorithms with parametric compilation
The structure of quantum programs for variational hybrid algorithms can be segmented into two parts [37]: parameterized ansatz preparation, and measurement in a variety of multi-qubit Pauli bases. Parametric compilation handles not only the parameterized ansatz component of a VHA, but can also be used to encapsulate measurement in arbitrary bases and symmetrization of readout error-all in a single quantum program. This allows for any VHA to be expressed via a single parametric binary with RZ arguments that are provided and patched at runtime. To show how this is possible, we walk through three examples using pyQuil [33], the Python library for writing and executing Quil programs.

A.1. Readout error symmetrization and mitigation
We can describe measurement imperfections in terms of a confusion matrix M, which describes probabilities of reported measurement outcomes conditioned on the values of the true state of the qubits. For the case of a single qubit, the confusion matrix can be written as While generally M will not be symmetric with respect to the exchange of 0s and 1s, one can enforce such symmetry by flipping bits before measurement and subsequently flipping the measurement outcomes. This symmetrization procedure corresponds to a simple form of twirling [14,13], and in principle can be performed by randomly choosing which bits to flip independently each time a measurement occurs §. When averaging over all the shots, this results in a new effective confusion matrix M , with 0 and 1 replaced by , which is the arithmetic mean of the two. This can be implemented in Quil (for a single qubit, with index 0) by replacing the measurement section of a program with: § More sophisticated approaches to symmetrization can be taken by making use of orthogonal arrays, as implemented in forest-benchmarking [28], but a detailed description of those techniques is beyond the scope of this article.  During the execution of the program, the symmetrization memory region assignments 0 and π must be provided, and the results from the π assignment must be flipped (i.e. XORing the results with the bit value of 1). It is straightforward to check that the effect of symmetric measurement errors is to scale the expectation value of a Pauli observable by factor that depends on the error rates. This immediately suggests how to mitigate the effect of these errors: first characterize the error rates of the symmetrized readout, then rescale the observed expectation values accordingly. The first step is what we call readout calibration, while the second step is what we call readout error mitigation. Since errors due to the singlequbit rotations associated with mapping one Pauli observable to another are orders of magnitude smaller than measurement errors, readout calibration can focus on the expectation of tensor products of Z observables only. Ideally the expectation of any of these tensor products would be +1 for the ground state (the |00 · · · 0 state), but for symmetrized readout error the expectation value will be λ. Simply dividing the expectation value of this same observable for other states by λ corrects for the bias introduced by the measurement errors. Note that, in general, even with symmetrization, a different λ for each different tensor product will be necessary, due to qubit-dependent readout signal-to-noise ratio (SNR) and potential correlations in the readout errors. Moreover, while the bias in the estimation of the expectation value is removed, the uncertainty is increased (as |λ| < 1), so this procedure is not scalable [51]. That being said, it is remarkably effective for small numbers of qubits.
Rather than handling symmetrization manually, we can use pyQuil's Experiment framework. When defining an Experiment in pyQuil, two arguments are required-a program which defines the main body quantum circuit, and a list of settings which specify the different state preparations and measurements that we want to wrap around the main program. In addition, the Experiment object also specifies the number of shots to take, whether or not to perform active qubit reset, and how to symmetrize and calibrate readout. To show how these features are used, we implement readout symmetrization and correction for a 2Q Max-Cut QAOA program (Fig. 6).
Although our QPUs can only perform measurements in the z basis (M z ), performing single-qubit rotations prior to measurement allows us to effectively measure in a different basis Thus, by pre-pending a qubit measurement with an Euler-decomposed single-qubit gate containing R z arguments that can be changed at runtime, we can perform a collection of different measurements with a single parametric binary. In Quil, this is accomplished for a single qubit by adding the following snippet before the measurement block:  Running Bell state tomography on qubits 1 and 2 of the Aspen-4 QPU using parametric compilation and pyQuil's Experiment framework. (a) Bell state tomography, expressed as an Experiment object. The program section contains the gates required to generate the Bell state |Φ + = 1 √ 2 (|00 + |11 ). The settings section contains the 15 different non-identity Pauli measurements required to tomograph a 2Q state, generated by the software library forest-benchmarking [28]. (b) Hinton plot [31,55] of the ideal density matrix ρ as defined by the state |Φ + . (c) Hinton plot of the estimated density matrix ρ est , extracted from readout-corrected experimental data using the linear inversion method [57]. We calculate a Bell state fidelity of F Φ + = 99.35 % by comparing ρ and ρ est using the fidelity function from forest-benchmarking.
Additionally, this can be combined with readout symmetrization, allowing for any desired observable to be symmetrized, calibrated, and corrected. To show how measurement bases can be changed parametrically, we run Bell state tomography using a single binary (Fig. 7).
Running the variational quantum eigensolver to compute the ground state energy of the hydrogen molecule using parametric compilation and pyQuil's Experiment framework. (a) The VQE H 2 algorithm, expressed as an Experiment object. The program section contains the parameterized UCC ansatz U (θ) (Eq. (7)), and the settings section contains the three measurement bases (expressed as Pauli strings) required to estimate the expectation value of the Hamiltonian. The Hamiltonian (Eq. (8)) also contains single-qubit Z terms, but they can be determined from measurement outcomes of the ZZ setting. (b) Results from running the VQE H 2 Experiment on the Quantum Virtual Machine (QVM) [9] as well as qubits 1 and 2 on the Aspen-4 QPU. To demonstrate the framework, we simply scanned 250 values of θ in the range [−π/2, π/2], but the latency numbers would not differ if we instead used an optimizer to update θ each step. We use the table of Hamiltonian coefficients from the appendix of O'Malley et al. to convert our readout-corrected Pauli expectations into expectation values for the H 2 Hamiltonian at different bond lengths. At the minimum-energy bond length R min = 0.750Ȧ we measure an energy difference ∆E min = 8 ± 9 mHa. cluster (UCC) ansatz U (θ) and the Hartree-Fock (HF) reference state |Φ [44], giving Then, the procedure continues by computing the expectation value of the H 2 Hamiltonian, which can be formulated as a sum of multi-qubit Pauli-basis expectation values with coefficients H = g 0 1 + g 1 Z 0 + g 2 Z 1 + g 3 Z 0 Z 1 + g 4 Y 0 Y 1 + g 5 X 0 X 1 .
Finally, the expectation value H is fed to the minimizer to choose the variational parameter θ for the next round of iteration, and this repeats until convergence. Following the protocol in O'Malley et al., we use parametric compilation and pyQuil's Experiment framework to simulate the ground state energy of the H 2 molecule with VQE (Fig. 8).