SynQ — Optimizing Gate Synthesis

Automating quantum state preparation and gate synthesis with machine learning methods.

Alex K
20 min readJul 18, 2021

The quantum era of computation is here, and the wealth of possible applications which algorithms running on quantum models may aid with is on the verge of being unlocked. Quoting from Princeton class notes on intractability, the following graphic offers insight into the enormous potential upside for quantum algorithms:

In the pursuit of aiding the design and realization of quantum algorithms dedicated to these applications, many in the industry have put forward the possibility of employing methods from machine learning.

Quantum Machine Learning

At the outset, the match seems natural. Machine learning and quantum computing are among the hottest fields in the realm of computing; while the former branch, already deeply ingrained in our daily lives, seeks to discover patterns in immense quantities of data to offer accurate predictions based on them, the latter emerging technology harnesses the phenomena of quantum mechanics to solve complex problems at accelerated computational speeds.

The intersection of these two areas — known as quantum machine learning (QML) — thus not only presents the opportunity to investigate how results from the quantum world can be exploited to solve problems from machine learning, but also offers the potential to improve the computational speed and data storage done by algorithms in quantum programs.

To provide some intuition on the end-to-end QML pipeline, consider the computational steps involved in the training and inference of a hybrid quantum-classical discriminative model for quantum data in TensorFlow Quantum (TFQ), Google’s open-source library for the rapid prototyping of quantum ML models:

  1. After quantum data is loaded as tensors (multi-dimensional arrays of numbers), we specify each tensor as a quantum circuit written in Cirq, before executing them all to generate a quantum dataset.
  2. A quantum neural network can subsequently be prototyped and evaluated — one that will later be embedded inside of a TF compute graph. This model disentangles information typically hidden in an entangled state, leaving it encoded in classical correlations and therefore accessible to local measurements and classical post-processing.
  3. By measuring quantum states, classical information is now extracted in the form of samples from a random variable, the distribution of values from which is dependent on the measured observable and state itself. Averaging over several runs is alternatively employed when a variational algorithm requires the mean values of measurements.
  4. Since the extracted classical information can still be encoded in the classical correlations between measured expectations, deep neural networks are applied to distill these correlations.
  5. A cost function is then evaluated depending on the nature of the classification task (for instance, whether it’s supervised or unsupervised).
  6. Finally, the free parameters in the pipeline are updated via gradient descent in a direction which minimizes cost.

This 6-step process can be diagrammatically illustrated below:

Quantum Transformations

One critical area of application for QML arises from a requirement that subroutines of many quantum algorithms have: the preparation of resource states and a compact decomposition of specific transformations into gates from a universal set. By applying machine learning methods to automate and optimize the construction of these subroutines, we can find quantum circuits that perform a desired transformation between input and output states; that is, given a quantum information task, we’d be able to find the circuit that best achieves it, enabling quantum algorithms to reach their potential.

In the simplest possible case of a single input and a single output, this task corresponds to state preparation: finding a circuit to create a target quantum state. In its generalized form of several inputs and outputs, this is equivalent to gate synthesis: obtaining a circuit that reproduces the action of a target unitary transformation; indeed, the automation of circuit design for gate synthesis is particularly pivotal since many methods rely on product-rule approximations that lead to decompositions which involve a large overhead in the total number of gates. Expressed pictorially, our approach is shown below:

Quantum Machine Learning + Gate Synthesis → Quantum Application Gold

Introducing SynQ

Introducing SynQ: a QML-based model for state preparation + gate synthesis on photonic quantum computers.

The model we are to develop (SynQ) will find circuits that can prepare several single and two-mode quantum states, employing the results to discover circuits capable of synthesizing single and two-mode gates.

SynQ will operate on the continuous-variable (CV) model of photonic quantum computation; indeed, the CV quantum neural networks considered are those with a limited number of layers, and perform state preparation and gate synthesis using circuits with significantly fewer gates than conventional decomposition techniques. These quantum neural networks are subsequently optimized through stimulation of the corresponding circuits using Strawberry Fields — a programming architecture with a TensorFlow backend capable of automatically computing gradients with respect to circuit parameters (this project uses the Adam optimizer throughout).

Special Thanks

This project is a replication of the following paper, the authors of which I owe a debt of gratitude for providing the code and data used, as well as informing much of the corresponding theory.

Juan Miguel Arrazola, Thomas R. Bromley, Josh Izaac, Casey R. Myers, Kamil Brádler, and Nathan Killoran. Machine learning method for state preparation and gate synthesis on photonic quantum computers. Quantum Science and Technology, 4 024004 (2019).

Automated Circuit Design

In order to maximize the generality and flexibility of our variational circuit, we employ a CV quantum neural network consisting of multiple layers L composed of the following sequence of gates:

Furthermore, the displacement and squeezing gates are defined as:

Additionally, the linear optical interferometers are made up of single-mode rotation gates:

The circuit architecture for a single layer of the quantum neural network is shown below; since the gates in every layer constitute a universal set, this network architecture is capable of simulating any universal CV quantum circuit with at most polynomial overhead:

The displacement, squeezing, rotation, beam splitter, and non-Gaussian gates in a single layer all contain free parameters; these parameters, denoted by vector θ, determine the strength of the transformation carried out by the gate; our project is to find the choice of parameters which optimizes some cost function C(vector θ), which is achieved by employing “vanilla” gradient descent. Commencing with randomly initiated values for parameters vector θ, we then compute the gradient:

We then update the parameters based on the following rule:

This process iterates until the cost function no longer exhibits improvement, at which point the parameter values corresponding to the minimum cost function determine the proposed solution circuit for the task at hand.

Moreover, we fix the non-Gaussian element Φ of each layer to be the Kerr gate, as its diagonality in the Fock basis lends itself to faster and more reliable numerical simulations:

We then truncate each mode to a subspace of a fixed cut-off dimension — one large enough to fully contain the state at all stages of the simulation.

State Preparation

In the case of a single input and output, our goal is simply to find a quantum circuit that performs a unitary transformation U, for a given canonical input state |Ψ₀⟩ and target output state |Ψ⟩, satisfying the following relationship:

Since this equation fixes just a single column of the unitary U in a basis containing the input state |Ψ₀⟩, the remaining components of U are free parameters; to maintain simplicity, we fix the input state to be the vacuum:

In order to prepare a given target state, we fix the quantum neural network’s architecture by selecting the number of layers (its depth). We then achieve optimization by minimizing the cost function:

In the following, several canonical single and two-mode states are selected, and our machine learning methods and optimization techniques are leveraged to find quantum circuits that prepare them.

1. Single Photon States

In the first example, our project is to prepare a single photon. These states are relied upon by the BB84 protocol — one the leading candidates in quantum cryptography — where security is provided by the mere fact that it is not possible to measure the quantum state of a single photon without perturbing it, not to mention the system’s inability to be partially measured (since it is the ultimate quantum of electromagnetic radiation).

In this simulation, we select a single-mode, 8-layer quantum neural network, yielding a total of 40 gates from a universal set and the linear optical interferometer’s reduction to a rotation gate:

The optimization process can be visualized through the visual progression of the Wigner function of the neural network’s output state. Initially, randomly prepared output state is quite close to the vacuum; however, almost immediately afterwards, the network learns to include negativity in the Wigner function, before carving an output state that increasingly resembles an ideal single photon. The GIF below plots the Wigner functions produced by the gradient descent algorithm for the first 85 steps:

After 1000 steps of the optimization algorithm, a circuit is found that prepares a state (right) with 99.998% fidelity to a perfect single photon (left). The contour plots of the Wigner functions are displayed below, along with the corresponding wavefunctions:

Along with the random initialization of gate parameters in the network, the Adam method for stochastic optimization leads to a non-deterministic output (different performances across each run). Although the algorithm converges to low values of the cost function for a sufficiently large number of steps in every instance, the values differ across independent runs for a fixed number of steps; it is therefore desirable to perform many optimization sessions and select the best output among them. The following graph portrays the progress in minimizing the cost function for 15 independent runs of the algorithm, while the inset plot shows values of the cost function from 500 to 1000 steps:

Finally, we consider the role that the network’s depth plays in state preparation performance. Intuitively, it is clear that large circuits (with a correspondingly large number of layers in the network) are required to prepare complex quantum states. However, for every layer added, the number of parameters to optimize increases; by consequence, more resources are needed to simulate the resulting circuits, engendering longer optimization times. Accordingly, it is logical to derive an adequate number of layers such that sufficiently high fidelities can be reached with minimal expenditure of computational resources. The following graph portrays the average value of the cost function (over 10 independent runs) after 1000 steps of optimization for quantum neural networks with a varied number of layers, demonstrating that the single photon state can be approximated well using just a few layers:

2. ON States

In the measurement-based model of CV optical quantum computing, quantum gates are applied via gate teleportation, in which the measurement of a resource state in a neighboring mode enables the application of a corresponding gate on a target mode. It has been shown that superpositions of vacuum and Fock states of the following form can be employed via gate teleportation:

These “ON states” are employed to apply this gate to the first order in τ:

These ON states can be used to implement the cubic and higher-order quadrature phase gates to first order in gate strength, delivering greater control over the final gate and a reduction in the number of superpositions.

After selecting N = 9 ON state as the state preparation target alongside setting a = 1 to ensure the state is an equal superposition of a 9-photon Fock state and the vacuum, we fix a network of depth 20 (consisting of 100 gates) and optimize it over 5000 steps, using a cut-off dimension of 14. The resulting circuit can prepare a state (right) with 99.93% fidelity to the ideal ON state (left). Again, the contour plots of the Wigner functions are displayed below, along with the corresponding wavefunctions:

3. GKP States

Gottesman-Kitaev-Preskill (GKP) states are considered a central resource for fault-tolerant error correction in optical CV quantum computing; in particular, GKP states are among the leading candidates for correcting errors when encoding qubits into oscillators. Ideal Hex GKP states are given by:

Selecting a Hex GKP state with µ = 1, ∆ = 0.3 as the target for state preparation, a network with 25 layers (reflecting the greater complexity of these states), and a cut-off dimension of 51, we optimize for 10,000 steps. The circuit obtained prepares a state (right) with 99.60% fidelity to the target Hex GKP state (left), with the counter plots of the Wigner functions along with the corresponding wavefunctions once again depicted below:

4. Random States

Having solely examined symmetrical states thus far, it remains to be demonstrated that our methods have the versatility to prepare unstructured states; to showcase that they do, we consider a random state of the form:

Fixing a value of d = 15 and selecting a 25-layer network with a cut-off dimension of 20, we carry out the optimization for 5000 steps. The resulting circuit can prepare a state (right) with 99.82% with respect to the target random state (left), with the counter plots of the Wigner functions and their wavefunctions displayed below as usual:

5. NOON States

Finally, our state preparation method can be extended to two-mode states; since the Hilbert space dimension in the simulation is quadratically larger than in the single-mode case, this optimization far more computationally intensive. We select a NOON state as the target state, defined as follows:

Recognized for their ability to make precision phase measurements when used in an optical interferometer, NOON states play a critical role in quantum metrology and quantum sensing; for instance, consider the observable:

The expectation value of A for a system in a NOON state would switch between +1 and −1 when θ changes from 0 to π/N, while the error in the phase measurement becomes the following:

This is the Heisenberg limit, and gives a quadratic improvement over the standard quantum limit. In our simulation, we set the NOON state with N = 5 as the target state, fixing a network of depth 20 with a cut-off dimension of 10. This network prepares a state with 99.89% fidelity (right) to the ideal target state (left), as depicted in the corresponding two-dimensional wavefunctions Ψₙₒₒₙ(x, y):

The state preparation process can now be generalized by considering the gate synthesis problem, in which we consider the action of the circuit not just on a fixed input, but also on a complete orthonormal basis of a given Hilbert space.

Gate Synthesis

Gates refer to quantum transformations operating either on the full infinite-dimensional Hilbert space or on a restricted subspace of a set of modes. Rather than synthesizing the target unitary gate Vₜ by decomposing it into a fixed set of elementary gates (an approach vulnerable to errors arising due to Trotterization and commutator approximations), we can approximate Vₜ using a CV quantum neural network, optimizing its parameters to replicate the action of the target gate. Furthermore, this method ensures the realization of a deterministic Vₜ of fixed depth, giving the user control over the number of elementary gates used.

We begin by describing any unitary by a set of input-output relations between basis states: given a set of orthogonal input states {|Ψ₀⁽ᴼ⁾⟩, . . . , |Ψ₀⁽⁾⟩}, the enactment of Vₜ can be described by specifying a set of target states |Ψ⁾⟩ = V|Ψ₀⁽⁾⟩ for all i = 0, . . . , d−1. We then fix the input states to be the first d states in the Fock basis of each mode: |Ψ₀⁽⁾⟩ = |i⟩, where |i⟩ refers to the Fock state of i photons; for unitaries acting on the infinite-dimensional multimode space, |Ψ₀⁽⁾⟩ represents a restriction on the countably infinite number of relations — a description capturing its action solely on a subspace of a restricted number of photons. In fact, energy constraints in any physical implementation of CV photonic quantum computing results in the introduction of an effective photon number restriction, providing the user with the opportunity to fix d such that this limitation is matched.

In order to optimize the unitary transformation U(vector θ) performed by the quantum network, we select the following cost function:

In the following, the performance of gate synthesis in applications to several single and two-mode gates is measured by calculating the average fidelity between Vₜ and the circuit unitary U(vector θ) when applied over all states with support in the input d-dimensional Fock subspace.

1. Cubic Phase Gates

A cubic phase gate is a single mode non-Gaussian unitary that forms a universal set for CV photonic quantum computing (in combination with Gaussian gates, that is), considered suitable for achieving universal fault-tolerant quantum computation with GKP states. This gate is defined as:

Our project is to synthesize a gate that replicates the action of the cubic phase gate on a subspace of the infinite-dimensional Hilbert space. In this particular simulation, we fix a gate parameter of γ = 0.01, set this subspace to be the 10-dimensional subspace of states with at most 9 photons, select a network of depth 25, and optimize for 4000 steps.

Since the cubic phase gate increases the photon number, it maps states in the subspace of at most d−1 photons to states that may have more than d−1 photons; this transformation is represented in terms of a d-column matrix, where columns have dimension d′ > d, and column i represents the result of applying the gate to the i-th Fock state.

The following presents visualizations of the transformation matrices for the ideal cubic phase gate (left) and the synthesized transformation U(vector θ) (right); the red and green panels in each case correspond to the real and imaginary part of the matrices respectively, and the squares within them representing elements of the matrices in the Fock basis, with dark squares indicating large positive values, light squares signaling large negative values, and squares of neutral brightness designating zero entries:

The synthesized gate has an average fidelity of 99.86% with respect to the ideal cubic phase gate — that is, the average gate fidelity between both transformations is 99.86%. We visualize these transformations by applying both the ideal and synthesized gate to the equal superposition state in the d-dimensional subspace given by:

The Wigner functions of the states resulting from applying the ideal cubic phase gate (left) and the synthesized gate (right) to the equal superposition state |Ψ₁₀⟩ of the equation above are shown below:

However, due to the random initialization of gate parameters and the use of stochastic gradient descent, these results are non-deterministic (just as seen in the state preparation setting). The following figure plots the progress in minimizing the cost function for 10 independent runs of the optimization algorithm for the cubic phase gate with parameter γ = 0.01 acting on a 6-dimensional subspace (left) and a 10-dimensional subspace (right):

Interestingly, the outcome of these optimization runs varies enormously, with many becoming stuck in local minima that are far from optimal. This is because increasing the number of relations defining the transformation serves to make the optimization landscape more complicated, adding to the computational overhead; as such, this behavior is exhibited less frequently in the 6-dimensional subspace than in the 10-dimensional subspace.

2. Quantum Fourier Transforms

In this second example, we consider a unitary transformation acting on a finite-dimensional system embedded into the first d Fock states of a single mode — one with the effect of mapping input Fock states into equal superpositions of all Fock states, thereby performing a transformation between two mutually-unbiased bases. We define this gate as the Quantum Fourier Transform (QFT) in relation to the equivalent transformation employed in discrete systems:

Since this is a highly complex gate, we fix d = 8 and carry out gate synthesis with 40 layers for 8000 steps. The following presents visualizations of transformation matrices for the ideal QFT unitary acting on the Fock basis (left) and the synthesized transformation U(vector θ) (right):

The average gate fidelity between both transformations is 98.89%. The Wigner functions of the states resulting from applying the ideal random gate (left) and the synthesized gate (right) to the equal superposition state |Ψ₈⟩:

3. Random Unitary

Finding ourselves in the same position as in the state preparation case, the suitability of our gate synthesis methods for unstructured transformations remains to be demonstrated; to showcase this, we generate a random unitary V according to the Haar measure that acts only on the 5-dimensional space of at most 4 photons.

We then perform gate synthesis with 25 layers for 1000 steps. The following presents visualizations of the transformation matrices for the ideal random gate (left) and the synthesized transformation U(vector θ) (right):

The average gate fidelity between both transformations is 99.50%. The Wigner functions of the states resulting from applying the ideal random gate (left) and the synthesized gate (right) to the equal superposition state |Ψ₅⟩:

4. Cross-Kerr Interaction

Finally, our gate synthesis method can be extended to two-mode unitaries, focusing on the cross-Kerr interaction, which mediates coupling between photons in different modes by applying a phase that depends on the number of photons in each mode. This non-linear bosonic interaction enables implementations of the non-linear sign gate on photonic quantum bits with maximum efficiency, and a near-deterministic CNOT gate with minimized resource expenditure, not to mention representing the nearest-neighbor or dipole interaction in the Bose-Hubbard model. It can be written as:

We synthesize this cross-Kerr interaction with 25 layers, 10,000 optimization steps, κ = 0.1, and restricting to the first d = 5 Fock states in each mode. The following presents visualizations of the transformation matrices for the ideal two mode cross-Kerr gate (left) and the synthesized transformation U(vector θ) (right):

In order to represent a two-mode unitary as a matrix, we use the following lexicographical ordering to label the rows and columns:

Our architecture approximates the cross-Kerr interaction with an average fidelity to the ideal unitary of 99.994%. We then test the action of both the ideal and learned unitaries by applying them to the equal superposition of two-mode state, which we describe as follows:

To visualize the resultant states, we plot the 2-dimensional wavefunctions (rather than Wigner functions, as in the case of two-mode state preparation) of the states resulting from applying the ideal two mode cross-Kerr gate (left) and the synthesized gate (right) to the equal superposition state |Ψ₅⁽²⁾⟩:

Naturally, extending our gate synthesis methods to the two-mode setting drastically increases the computational overhead, not to mention the fact that the number of relations defining the transformations increases for two modes — just as seen in the case of state preparation, the truncated Hilbert space of the composite system is quadratically larger. High fidelity approximations of a cross-Kerr gate with κ = 0.1 are nonetheless achieved.

Our approach therefore uncovers a short-depth decomposition requiring only 25 Kerr gates and 125 elementary operations, while recent results considering the decompositions of the cross-Kerr into cubic phase and controlled-phase gates necessitate approximately 1000 elementary operations for a decomposition precision of roughly 0.1.

Closing Thoughts

Machine learning and optimization methods hold significant potential to find quantum circuits capable of reproducing desired transformations between input and output states. The approach and results delineated in this article automate the discovery of circuits that perform specific subroutines of quantum algorithms, unlocking the wealth of possible applications for them. In particular, SynQ’s ability to synthesize high-fidelity states and gates using short-depth circuits positions it well for near-term quantum devices; indeed, our methods procure high fidelities above 99% using short-depth circuits across a range of states and gates with important quantum functions, demonstrating their versatility and reliability.

Of course, in order to realize these applications in full, it is essential that these techniques are extended to more general quantum algorithms involving complex transformations between several modes; since these methods necessitate the ability to classically simulate circuits — a task which becomes increasingly burdensome as the number of modes grows — specialized quantum techniques must be leveraged to optimize the circuits directly.

It should also be recognized that Strawberry Fields is currently the only quantum software library which natively supports automatic differentiation, which we apply to optimize the layers of optical gates with variable parameters comprising the quantum network — to achieve the full potential of this model, this feature ought to be accessible to other simulation libraries.

With the breakout of quantum computing nigh, models like SynQ are well-positioned to discover circuits capable of preparing and synthesizing several single and two-mode states and gates, thereby ensuring that quantum algorithms are well-equipped to find the optimal mesh partitioning for finite elements, obtain an equilibrium of urban traffic super-networks, and fulfil their purpose in a plethora of other applications.

Special thanks once again to Juan Miguel Arrazola, Thomas R. Bromley, Josh Izaac, Casey R. Myers, Kamil Brádler, and Nathan Killoran (the authors of Machine learning method for state preparation and gate synthesis on photonic quantum computers) for their paper and Xanadu’s Strawberry Fields for their open-source quantum programming architecture!

--

--

Alex K

17 y/o researcher in Machine Learning & Computational Biology.