We introduce Strawberry Fields, an open-source quantum programming architecture for light-based quantum computers. Built in Python, Strawberry Fields is a full-stack library for design, simulation, optimization, and quantum machine learning of continuous-variable circuits. The platform consists of three main components: (i) an API for quantum programming based on an easy-to-use language named Blackbird; (ii) a suite of three virtual quantum computer backends, built in NumPy and Tensorflow, each targeting specialized uses; and (iii) an engine which can compile Blackbird programs on various backends, including the three built-in simulators, and -in the near future -photonic quantum information processors. The library also contains examples of several paradigmatic algorithms, including teleportation, (Gaussian) boson sampling, instantaneous quantum polynomial, Hamiltonian simulation, and variational quantum circuit optimization. The decades-long worldwide quest to build practical quantum computers is currently undergoing a critical period. During the next few years, a number of different quantum devices will become available to the public. While fault-tolerant quantum computers will one day provide significant computational speedups for problems like factoring [1], search [2] , or linear algebra [3] , near-term quantum devices will be noisy, approximate, and sub-universal [4] . Nevertheless, these emerging quantum processors are expected to be strong enough to show a computational advantage over classical computers for certain problems, an achievement known as quantum supremacy. As we approach this milestone, work is already underway exploring how such quantum processors might best be leveraged. Popular techniques include variational quantum eigensolvers [5, 6] , quantum approximate optimization algorithms [7, 8] , sampling from computationally hard probability distributions [9] [10] [11] [12] [13] [14] [15] [16] [17] , and quantum annealing [18, 19] . Notably, these methodologies can be applied to tackle important practical problems in chemistry [20] [21] [22] [23] , finance [24] , optimization [25, 26] , and machine learning [27] [28] [29] [30] [31] [32] [33] [34] . These known applications are very promising, yet it is perhaps the unknown future applications of quantum computers that are most tantalizing. We may not know the best applications of quantum computers until these devices become available more widely to researchers, students, entrepreneurs, and programmers worldwide. To this end, a nascent quantum software ecosystem has recently begun to develop [35] [36] [37] [38] [39] [40] [41] [42] [43] [44] [45] [46] [47] [48] . However, a prevailing theme for these software efforts is to target qubitbased quantum devices. In reality, there are several competing models of quantum computing which are equivalent in computational terms, but which are conceptually quite distinct. One prominent approach is the continuous variable (CV) model of quantum computing [49] [50] [51] . In the CV model, the basic information-processing unit is an infinite-dimensional bosonic mode, making it particularly well-suited for implementations and applications based on light. The CV model retains the computational power of the qubit model [52] , while offering a number of unique features. For instance, the CV model is a natural fit for simulating bosonic systems (electromagnetic fields, trapped atoms, harmonic oscillators, Bose-Einstein condensates, phonons, or optomechanical resonators) and for settings where continuous quantum operators -such as position & momentum -are present. Even in classical computing, recent advances from deep learning have demonstrated the power and flexibility of a continuous representation of computation [53, 54] . Here we introduce Strawberry Fields 1 , an open-source software architecture for photonic quantum computing. Strawberry Fields is a full-stack quantum software platform, implemented in Python, specifically targeted to the CV model. Its main element is a new quantum programming language named Blackbird. To lay the groundwork for future photonic quantum computing hardware, Strawberry Fields also includes a suite of three CV quantum simulator backends implemented using NumPy 2 ulation using two distinct representations, while the Tensorflow backend provides additional computational, optimization, and machine learning functionalities. Strawberry Fields comes with a built-in engine to convert Blackbird programs to run on any of the simulator backends or, when they are available, on photonic quantum computers. To accompany the library, an online service for interactive exploration and simulation of CV circuits is available at strawberryfields.ai. The remainder of this white paper is structured as follows. Before presenting Strawberry Fields, we first provide a brief overview of the key ingredients for CV quantum computation, specifically the most important states, gates, and measurements. We then introduce the Strawberry Fields architecture in full, presenting the Blackbird user language, outlining how to use the library for numerical simulation, optimization, and quantum machine learning. Finally, we discuss the three built-in simulators and the internal representations that they employ. In the Appendices, we give further mathematical and software details and provide full example code for a number of important CV quantum computing tasks. Many physical systems in nature are intrinsically continuous, with light being the prototypical example. Such systems reside in an infinite-dimensional Hilbert space, offering a paradigm for quantum computation which is distinct from the discrete qubit model. This continuous-variable model takes its name from the fact that the quantum operators underlying the model have continuous spectra. It is possible to embed qubit-based computations into the CV picture [57] , so the CV model is as powerful as its qubit counterparts. A high-level comparison of CV quantum computation with the qubit model is depicted in Table I . In the remainder of this section, we will provide a basic presentation of the key elements of the CV model. A more detailed technical overview can be found in Appendix A. Readers experienced with CV quantum computing can safely skip to the next section. The most elementary CV system is the bosonic harmonic oscillator, defined via the canonical mode operatorsâ and a † . These satisfy the well-known commutation relation It is also common to work with the quadrature operators (also called the position & momentum oper-  where [x,p] = iħ hˆ . We can picture a fixed harmonic oscillator mode (say, within an optical fibre or a waveguide on a photonic chip) as a single 'wire' in a quantum circuit. These qumodes are the fundamental information-carrying units of CV quantum computers. By combining multiple qumodeseach with corresponding operatorsâ i andâ † i -and interacting them via sequences of suitable quantum gates, we can implement a general CV quantum computation. The dichotomy between qubit and CV systems is perhaps most evident in the basis expansions of quantum states: For qubits, we use a discrete set of coefficients; for CV systems, we can have a continuum. The states |x〉 are the eigenstates of thex quadrature,x |x〉 = x |x〉, with x ∈ . These quadrature states are special cases of a more general family 2 It is common to picture ħ h as a (dimensionless) scaling parameter for thex andp operators rather than a physical constant. However, there are several conventions for the scaling value in common use [58] . These self-adjoint operators are proportional to the Hermitian and antiHermitian parts of the operatorâ. Strawberry Fields allows the user to specify this value, with the default ħ h = 2. of CV states, the Gaussian states, which we now introduce. Our starting point is the vacuum state |0〉. Other states can be created by evolving the vacuum state according to where H is a bosonic Hamiltonian (i.e., a function of the operatorsâ i andâ † i ) and t is the evolution time. States where the Hamiltonian H is at most quadratic in the operatorsâ i andâ † i (equivalently, inx i andp i ) are called Gaussian. For a single qumode, Gaussian states are parameterized by two continuous complex variables: a displacement parameter α ∈ and a squeezing parameter z ∈ (often expressed as z = r exp(iφ), with r ≥ 0). Gaussian states are so-named because we can identify each Gaussian state with a corresponding Gaussian distribution. For single qumodes, the identification proceeds through its displacement and squeezing parameters. The displacement gives the centre of the distribution, while the squeezing determines the variance and rotation of the distribution (see Fig.  1 ). Multimode Gaussian states, on the other hand, are parameterized by a vector of displacementsr and a covariance matrix V. Many important pure states in the CV model are special cases of the pure Gaussian states; see Table II the form while (undisplaced) squeezed states only have even number states in their expansion: Mixed Gaussian states are also important in the CV picture, for instance, the thermal state which is parameterized via the mean photon number n := Tr(ρ(n)n). Starting from this state, we can consider a mixed-state-creation process similar to Eq. (5), namely Analogously to pure states, by applying Hamiltonians of second-order (or lower) to thermal states, we generate the family of Gaussian mixed states. Unitary operations can be associated with a generating Hamiltonian H via the recipe (cf. Eqs. (5) & (9)) 4 For convenience, we classify unitaries by the degree of their generator. A CV quantum computer is said to be universal if it can implement, to arbitrary precision and with a finite number of steps, any unitary which is polynomial in the mode operators [49] . We can build a multimode unitary by applying a sequence of gates from a universal gate set, each of which acts only on one or two modes. We focus on a universal set made from the following two subsets: Gaussian gates: Single and two-mode gates which are at most quadratic in the mode operators, e.g., Displacement, Rotation, Squeezing, and Beamsplitter gates. A single-mode gate which is degree 3 or higher, e.g., the Cubic phase gate. A number of fundamental CV gates are presented in Table III. Many of the Gaussian states from the previous section are connected to a corresponding Gaussian gate. Any multimode Gaussian gate can be implemented through a suitable combination of Displacement, Rotation, Squeezing, and Beamsplitter Gates [51], making these gates sufficient for constructing all quadratic unitaries. The cubic phase gate is presented as an exemplary non-Gaussian gate, but any other non-Gaussian gate could also be used to achieve universality. A number of other useful CV gates are listed in Appendix B. Unitary Symbol  As with CV states and gates, we can distinguish between Gaussian and non-Gaussian measurements. The Gaussian class consists of two (continuous) types: homodyne and heterodyne measurements, while the key non-Gaussian measurement is photon counting. These are summarized in Table IV . Ideal homodyne detection is a projective measurement onto the eigenstates of the quadrature operatorx. These states form a continuum, so homodyne measurements are inherently continuous, returning values x ∈ . More generally, we can consider projective measurement onto the Measurement values eigenstates x φ of the Hermitian operator This is equivalent to rotating the state clockwise by φ and performing anx-homodyne measurement. If we have a multimode Gaussian state and we perform homodyne measurement on one of the modes, the conditional state of the unmeasured modes remains Gaussian. Whereas homodyne detection is a measurement ofx, heterodyne detection can be seen as a simultaneous measurement of bothx andp. Because these operators do not commute, they cannot be simultaneously measured without some degree of uncertainty. Equivalently, we can picture heterodyne measurement as projection onto the coherent states, with measurement operators 1 π |α〉〈α|. Because the coherent states are not orthogonal, there is a corresponding lack of sharpness in the measurements. If we perform heterodyne measurement on one mode of a multimode state, the conditional state on the remaining modes stays Gaussian. Photon counting (also known as as photon-number resolving measurement), is a complementary measurement method to the '-dyne' measurements, revealing the particlelike, rather than the wave-like, nature of qumodes. This measurement projects onto the number eigenstates |n〉, returning non-negative integer values n ∈ . Except for the outcome n = 0, a photon-counting measurement on a single mode of a multimode Gaussian state will cause the remaining modes to become non-Gaussian. Thus, photoncounting can be used as an ingredient for implementing non-Gaussian gates. A related process is photodetection, where a detector only resolves the vacuum state from nonvacuum states. This process has only two measurement operators, namely |0〉〈0| and − |0〉〈0|.  The Strawberry Fields library has been designed with several key goals in mind. Foremost, it is a standard-bearer for the CV model, laying the groundwork for future photonic quantum computers. As well, Strawberry Fields is designed to be simple to use, giving entry points for as many users as possible. Finally, since the potential applications of nearterm quantum computers are still being worked out, it is important that Strawberry Fields provides powerful tools to easily explore many different use-cases and applications. Strawberry Fields has been implemented in Python, a modern language with a gentle learning curve which is already familiar to many programmers and scientific practitioners. The accompanying quantum simulator backends are built upon the widely used Python packages NumPy and Tensorflow. All Strawberry Fields code is open source. Strawberry Fields can be accessed programmatically as a Python package, or via a browser-based interface for designing quantum circuits. A pictorial outline of Strawberry Fields' key elements and their interdependencies is presented in Fig. 2 . Conceptually, the software stack is separated into two main pieces: a user-facing frontend layer and a lower-level backends component. The frontend encompasses the Strawberry Fields Python API and the Blackbird quantum programming language. These elements provide access points for users to design quantum circuits. These circuits are then linked to a backend via a quantum compiler engine. For a backend, the engine can currently target one of three included quantum computer simulators. When CV quantum processors become available in the near future, the engine will also build and run circuits on those devices. Applications, such as the Strawberry Fields Interactive website, can be built by leveraging the frontend API. In the remainder of this section, the key elements of Strawberry Fields will be presented in more detail. Proceeding through a series of examples, we show how CV quantum computations can be defined using the Blackbird language, then compiled and run on a quantum computer backend. We also outline how to use Strawberry Fields for optimization and machine learning on quantum circuits. Finally, we discuss the suite of quantum computer simulators included within Strawberry Fields. As classical computers have become progressively more powerful, the languages used to program them have also undergone considerable paradigmatic changes. Machine code gave way to human-readable assembly languages, followed by higher-level procedural and object-oriented languages. With each generation, the trend has been towards higher levels of abstraction, separating the programmer more and more from details of the actual computer hardware. Quantum computers are still at an early stage of development, so while we can imagine what higher-level quantum programming might look like, in the near term we first need to build languages which are conceptually closer to the quantum hardware. Blackbird is a quantum assembly language, with operations that match the basic CV states, gates, and measurements outlined in the previous section. We have built an implementation of Blackbird using Python 3 as the embedding language. The abstract syntax keeps a close connection between code and the quantum operations that they implement; this syntax is modeled after that of Project Q [42], but specialized to the CV setting. We will introduce the elements of Blackbird through a series of basic examples, discussing more technical aspects as they arise. Quantum computations consist of four main ingredients: state preparations, application of gates, performing mea-6 surements, and adding/removing subsystems. In Blackbird, these are all considered as Operations, and share the same basic syntax. In the following code examples, we use the variable q for a set of qumodes (more specifically, a quantum register), the details of which are deferred until the next section. Our Conceptually, the vertical bar symbol '|' separates Operations -like state preparation -from the registers that they act upon. Notice that we can use Operations inline, or construct them separately and reuse them several times. After creating states, we will want to transform these using quantum gates. Blackbird supports all of the gates listed in the previous section as well as a number of composite gates, each of which can be decomposed using the universal gates. The supported composite gates are: controlled X (CXgate), controlled Z (CZgate), quadratic phase (Pgate), and twomode squeezing (S2gate Measurements have several effects. For one, the numerical result of the measurement is placed in a classical register. As well, the state of all remaining qumodes is projected to the (normalized) conditional state for that measurement value. Finally, the state of the measured qumode is reset to the vacuum state. This is the typical behaviour of photonic hardware, where measurements absorb all the energy of the measured qumode. Within Python, Blackbird programs are managed by an eng.run(). We will discuss the Strawberry Fields backends further in a later section. When a Strawberry Fields Engine is constructed, the user must specify the number of qumode subsystems to begin with. This number is required for the initialization of the Engine, but may change within a computation (e.g., when temporary ancilla modes are used). Qumodes can be added/deleted by using the New and Del Operations. An Engine maintains a unique numeric indexing for the quantum registers based on the order they were added. When a subsystem is deleted from the circuit, no further gates can act on that register. In quantum algorithms, it is common to process a measurement result classically and use the post-processed value as a parameter for further operations in a circuit. Strawberry Fields provides the convert decorator to transform a userspecified numerical function into one which acts on registers. 1 @sf.convert 2 def neg(x): 5 # A Blackbird computation using classical 6 # data processing 7 with eng: 10 eng.run("gaussian") Codeblock 7: Symbolically processing a measured value before using it. The measurement Operations in Strawberry Fields are stochastic in nature, with outcomes determined by some underlying quantum probability distribution. Often it is convenient to select specific values for these measurements rather than sampling them. For instance, we might want to explore the conditional state created by a specific value, determine the measurement-dependent corrections we need to make in a teleportation circuit, or even design an algorithm which inherently contains post-selection. This functionality is supported in Strawberry Fields through the op-8 tional keyword argument select, which can be supplied for any measurement Operation. The measurement outcome will then return exactly this value, while the remaining modes will be projected into the conditional state corresponding to this value 3 . 1 with eng: Codeblock 8: Selecting a specific desired measurement outcome. Strawberry Fields can perform quantum circuit simulations using both numerical and symbolic representations. Numerical computation is the default operating mode and is supported by all three supplied backends. Symbolic computation is enabled only for the Tensorflow backend. In this section, we outline the main Tensorflow functionalities accessible through the Strawberry Fields frontend interface. More details about the corresponding Tensorflow backend are discussed in the next section. Tensorflow [56] models calculations abstractly using a computational graph, where individual operations are represented as nodes and their dependencies by directed edges. This viewpoint separates the symbolic representation of a computation from its numerical evaluation, and makes optimization and machine learning more amenable. On top of this, Tensorflow provides a number of advanced functionalities, including automatic gradient computation, GPU utilization, built-in optimization algorithms, and various other machine learning tools. Note that the term 'quantum machine learning' will be used here in a hybrid sense, i.e., applying conventional machine learning methods to quantum systems. To build a Tensorflow computational graph using Strawberry Fields, we instantiate an Engine, declare a circuit in Blackbird code, then execute eng.run on the Tensorflow ("tf") backend. To keep the underlying simulation fully symbolic, the extra argument eval=False must be given. 1 # Create Engine and run symbolic computation 2 import strawberryfields as sf 3 from strawberryfields.ops import * 4 import tensorflow as tf 5 6 eng, q = sf.Engine(num_subsystems=1) 7 with eng: 3 Users should be careful to avoid post-selection on measurement values which have no probability of occuring given the current circuit state. In this case, the expected behaviour of a backend is not defined. Codeblock 12: Processing a measurement result using a neural network. The Tensorflow backend additionally supports the use of batched processing, allowing for many evaluations of a quantum circuit to potentially be computed in parallel. Scalars are automatically broadcast to the specified batch size. Finally, we can easily run circuit simulations on special-purpose hardware like GPUs or TPUs.  The ultimate goal is for Blackbird programs to be carried out on photonic quantum computers. To lay the groundwork for these emerging devices, Strawberry Fields comes with a suite of three CV quantum computer simulators specially designed for the CV model. These simulators target different use-cases and support different functionality. For example, many important algorithms in the CV formalism involve only Gaussian states, operations, and measurements. We can take advantage of this structure to more efficiently simulate such computations. Other circuits have inherently non-Gaussian elements to them; for these, the Fock basis provides the standard description. These representations are available in Strawberry Fields in the Gaussian backend and the Fock backend, respectively. The third builtin backend is the Tensorflow backend. Also using the Fock representation, this backend is geared primarily towards optimization and machine learning applications. Most Blackbird operations are supported across all three backends. A small subset, however, are not supported uniformly due to mathematical incompatibility. For example, the Gaussian backend does not generally support nonGaussian gates or the preparation/measurement of Fock states. Sometimes it is also useful to work with a backend directly. To allow this, Strawberry Fields provides a backend API, giving access to additional methods and properties which are not part of the streamlined frontend API. A standalone backend can be created in Strawberry Fields using strawberryfields.backend.load_backend(name) where name is one of "gaussian", "fock", or "tf" (for comparison, the backend associated to an Engine eng is available via eng.backend). Three important backend methods, common to all simulators, are begin_circuit, reset, and state. The first command instantiates the circuit simulation, the second re-10 sets the simulation back to an initial vacuum state, clearing all previous operations, and the third returns a class which encapsulates the current quantum state of the simulator. In addition to containing the numerical (or symbolic) state data, state classes also contain a number of useful methods and attributes for further exploring the quantum state, such as fidelity, mean_photon, or wigner. As a convenience for the user, all simulations carried out via eng.run will return a state class representing the final circuit state (see Appendix C for examples). This backend, written in NumPy, uses the symplectic formalism to represent CV systems. At a high level, this representation tracks the quantum state of an N -mode quantum system using two Gaussian components: a 2N -dimensional displacement vectorr and a 2N × 2N -dimensional covariance matrix V (a deeper technical overview is located in Appendix A). After we have created a Gaussian state (either via state = eng.run(backend="gaussian") or by directly calling the state method of a Gaussian backend), we can accessr and V via state.means and state.cov, respectively. Other useful Gaussian state methods are displacement and squeezing, which return the Gaussian parameters associated to the underlying state. The scaling of the symplectic representation with the number of modes is O(N 2 ). On one hand, this is quite powerful. It allows us to to efficiently simulate any computations which are fully Gaussian. On the other, the formalism is not expressive enough to simulate more general quantum computations. Only a small number of non-Gaussian methods are available for this backend. These are auxiliary methods where we extract some non-Gaussian information from a Gaussian state, but do not update the state of the circuit. One such method is fock_prob, which is implemented using an optimized -yet still exponentially scalingalgorithm. This method enables simulation of the Gaussian boson sampling algorithm [10] using the Gaussian backend; see Appendix C for a complete code example. This backend, also written in NumPy, uses a fundamentally different description for qumodes than the Gaussian representation. As discussed in the introductory sections, the Fock representation encodes quantum computation in a countably infinite-dimensional Hilbert space. This representation is faithful, allowing a precise description of CV systems, in particular non-Gaussian circuits. Yet simulating infinite-dimensional systems leads to some computational tradeoffs which are not present for qubit simulators. Most importantly, we impose a cutoff dimension D for simulations (chosen by the user), so the Fock backend only covers a restricted set of number states {|0〉 , ..., |D − 1〉} for each mode. The size of simulated quantum systems thus depends on both the number of subsystems N and the cutoff, being O(D N ). We contrast this with qubit systems, where the base is fixed, i.e., O(2 N ). While these scalings are both exponential, in practice simulating qumode systems for D > 2 is more computationally demanding than qubits. This is because the (truncated) qumode subsystems have a higher dimension and thus encode more information than their qubit counterparts. Physically, imposing a cutoff is a reasonable strategy since higher photon-number states must have higher energy and, in practice, quantum-optical systems will have bounded energy (e.g., limited by the power of a laser). On the other hand, there are certainly states which can be easily prepared in the lab, yet would not fit accurately on the simulator. Thus, some care must be taken to trade off between the numerical cutoff value, the number of modes, and the energy scale of the circuit. If the energy scale is sufficiently low that all states fit within the specified cutoff, then simulations with the Fock and Gaussian backends will be in numerical agreement. Like the Gaussian backend, the Fock backend has a state method which encapsulates the numerical state, while also providing a number of methods and attributes specific to the Fock representation (such as ket, trace, and all_fock_probs.  The other built-in backend for Strawberry Fields is coded using Tensorflow. As a simulator, it uses the same internal representation as the Fock backend (Fock basis, finite cutoff, pure vs. mixed state representations, etc.) and has the same methods. It can operate as a numerical simulator similar to the other backends. Its main purpose, however, is to leverage the many powerful tools provided by Tensorflow to enable optimization and machine learning on quantum circuits. Much of this functionality was presented in the previous section, so we will not repeat it here. Like the other simulators, users can query the Tensorflow  We have introduced Strawberry Fields, a multi-faceted software platform for continuous-variable quantum computing. The main components of this library -a custom quantum programming language (Blackbird), a compiler engine, and a suite of quantum simulators targeting distinct applications -have been presented in detail. Further information is available in both the Appendices and the Strawberry Fields online documentation. The stage is now set for the broader community to use Strawberry Fields for exploration, research, and development of new quantum algorithms, specialized circuits, and machine learning models. We anticipate the creation of further software applications and backend modules for the Strawberry Fields platform (developed both internally and externally), providing advanced functionality and applications for quantum computing and quantum machine learning.
Xanadu is a company that makes photonic quantum computers, which can process information stored in quantum states of light REF .
Strawberry Fields: A Software Platform for Photonic Quantum Computing
Quantum 3, 129 (2019)
Physics Mathematics