Photonic Quantum Computing

Photonic Quantum Computing

Strawberry Fields: A Software Platform for Photonic Quantum Computing Nathan Killoran, Josh Izaac, Nicolás Quesada, Ville Bergholm, Matthew Amy, and Christian Weedbrook Xanadu, 372 Richmond St W, Toronto, M5V 1X6, Canada We introduce Strawberry Fields, an open-source quantum programming architecture for light-based quantum computers, and detail its key features. 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. Introduction 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 computational 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–17], and quantum annealing [18, 19]. Notably, these methodologies can be applied to tackle important practical problems in chemistry [20–23], finance [24], optimization [25, 26], and machine learning [27–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–47]. 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 [48–50]. 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 (cf. Chap. 4 of Ref. [51]), 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 [52, 53] in comparison to the discrete computational model which has historically dominated. Here we introduce Strawberry Fields1 , 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, Straw1 This document refers to Strawberry Fields version 0.9. Full documentation is available online at strawberryfields.readthedocs.io. arXiv:1804.03159v2 [quant-ph] 4 Mar 2019 2 berry Fields also includes a suite of three CV quantum simulator backends implemented using NumPy [54] and TensorFlow [55]. 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. Aside from being the first quantum software framework to support photonic quantum computation with continuous-variables, Strawberry Fields provides additional computational features not presently available in the quantum software ecosystem: 1. We provide two numeric simulators; a Gaussian backend, and a Fock-basis backend. These two formulations are unique to the CV model of quantum computation due to the use of an infinite Hilbert space, and came with their own technical challenges. (a) The Gaussian backend provides state-of-the-art methods and functions for calculating the fidelity and Fock state probabilities, involving calculations of the classically intractable hafnian [56]. (b) The Fock backend allows operations such as squeezing and beamsplitters to be performed in the Fock-basis, a computationally intensive calculation that has been highly vectorized and benchmarked for performance. 2. We provide a suite of important circuit decompositions appearing in quantum photonics – such as the Williamson, Bloch-Messiah, and Clements decompositions. 3. The Fock-basis backend written using the TensorFlow machine learning library allows for symbolic calculations, automatic differentiation, and backpropagation through CV quantum simulations. As far as we are aware, this is the first quantum simulation library written using a high-level machine learning library, with support for dataflow programming and automatic differentiation. 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 quantum assembly 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. Quantum Computation with Continuous Variables 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. From Qubits to Qumodes 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. CV Qubit Basic element Qumodes Qubits Relevant operators Quadratures x?, ?p Mode operators a?, a? ? Pauli operators σ? x ,σ? y ,σ?z Common states Coherent states |α? Squeezed states |z? Number states |n? Pauli eigenstates |0/1?,|±?,|±i? Common gates Rotation, Displacement, Squeezing, Beamsplitter, Cubic Phase Phase shift, Hadamard, CNOT, T-Gate Common measurements Homodyne |xφ??xφ|, Heterodyne 1 π |α??α|, Photon-counting |n??n| Pauli eigenstates |0/1??0/1|,|±??±|, | ± i??±i| Table I: Basic comparison of the CV and qubit settings. The most elementary CV system is the bosonic harmonic oscillator, defined via the canonical mode operators a? and a? ? . These satisfy the well-known commutation relation [a?, a? ? ] = I. It is also common to work with the quadrature operators (also called the position & momentum oper- 3 ators)2 , x? := vt?h 2 (a? + a? ? ), (1) ?p := ?i vt?h 2 (a? ? a? ? ), (2) where [x?, ?p] = i?h?I. 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 qumodes – each with corresponding operators a?i and a? ? i – and interacting them via sequences of suitable quantum gates, we can implement a general CV quantum computation. CV States The dichotomy between qubit and CV systems is perhaps most evident in the basis expansions of quantum states: Qubit |φ? = φ0 |0? + φ1 |1?, (3) Qumode |ψ? = Z d x ψ(x)|x?. (4) For qubits, we use a discrete set of coefficients; for CV systems, we can have a continuum. The states |x? are the eigenstates of the x? quadrature, x? |x? = x |x?, with x ∈ R. These quadrature states are special cases of a more general family of CV states, the Gaussian states, which we now introduce. Gaussian states Our starting point is the vacuum state |0?. Other states can be created by evolving the vacuum state according to |ψ? = exp(?i tH)|0?, (5) where H is a bosonic Hamiltonian (i.e., a function of the operators a?i and a? ? i ) and t is the evolution time. States where the Hamiltonian H is at most quadratic in the operators a?i and a? ? i (equivalently, in x?i and ?pi ) are called Gaussian. For a single qumode, Gaussian states are parameterized by two continuous complex variables: a displacement parameter α ∈ C and a squeezing parameter z ∈ C (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 2 It is common to picture ?h as a (dimensionless) scaling parameter for the x? and ?p 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 a?. Strawberry Fields allows the user to specify this value, with the default ?h = 2. FIG. 1: Schematic representation of a Gaussian state for a single mode. The shape and orientation are parameterized by the displacement α and squeezing z = r exp(iφ). 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 displacements ˉr and a covariance matrix V. Many important pure states in the CV model are special cases of the pure Gaussian states; see Table II for a summary. State family Displacement Squeezing Vacuum state |0? α = 0 z = 0 Coherent states |α? α ∈ C z = 0 Squeezed states |z? α = 0 z ∈ C Displaced squeezed states |α, z? α ∈ C z ∈ C x? eigenstates |x? α ∈ C, x = 2 q?h 2 Re(α) φ = 0, r → ∞ ?p eigenstates |p? α ∈ C, p = 2 q?h 2 Im(α) φ = π, r → ∞ Fock states |n? N.A. N.A. Table II: Common single-mode pure states and their relation to the displacement and squeezing parameters. All listed families are Gaussian, except for the Fock states. The n = 0 Fock state is also the vacuum state. Fock states Complementary to the continuous Gaussian states are the discrete Fock states (or number states) |n?, where n are nonnegative integers. These are the eigenstates of the number operator n? = a? ? a?. The Fock states form a discrete (countable) basis for qumode systems. Thus, each of the Gaussian states considered in the previous section can be expanded in the Fock-state basis. For example, coherent states have 4 the form |α? = exp ? ? |α| 2 2 ?X∞ n=0 α n p n! |n?, (6) while (undisplaced) squeezed states only have even number states in their expansion: |z? = 1 p cosh r X∞ n=0 p (2n)! 2nn! [?e iφ tanh(r)]n |2n?. (7) Mixed states Mixed Gaussian states are also important in the CV picture, for instance, the thermal state ρ(n) := X∞ n=0 n n (1 + n) n+1 |n??n|, (8) 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 ρ = exp(?i tH)ρ(n) exp(i tH). (9) Analogously to pure states, by applying Hamiltonians of second-order (or lower) to thermal states, we generate the family of Gaussian mixed states. CV Gates Unitary operations can be associated with a generating Hamiltonian H via the recipe (cf. Eqs. (5) & (9)) U := exp (?i tH). (10) 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 [48]. 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. Non-Gaussian gate: 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 [50], 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. Gate Unitary Symbol Displacement Di (α) = exp (αa? ? i ? α ? a?i ) D Rotation Ri (φ) = exp (iφn?i ) R Squeezing Si (z) = exp ( 1 2 (z ? a? 2 i ? za? ?2 i )) S Beamsplitter BSi j(θ,φ) = exp (θ(e iφ a?ia? ? j ? e ?iφ a? ? i a?j )) BS Cubic phase Vi (γ) = exp i γ 3?h x? 3 i  V Table III: Some important CV model gates. All listed gates except the cubic phase gate are Gaussian. CV Measurements 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. Homodyne measurements Ideal homodyne detection is a projective measurement onto the eigenstates of the quadrature operator x?. These states form a continuum, so homodyne measurements are inherently continuous, returning values x ∈ R. More generally, we can consider projective measurement onto the eigenstates xφ of the Hermitian operator x?φ := cosφ x? + sinφ ?p. (11) This is equivalent to rotating the state clockwise by φ and performing an x?-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. Heterodyne measurements Whereas homodyne detection is a measurement of x?, heterodyne detection can be seen as a simultaneous measurement of both x? and ?p. 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 5 Measurement Measurement Operators Measurement values Homodyne |xφ??xφ| x ∈ R Heterodyne 1 π |α??α| α ∈ C Photon counting |n??n| n ∈ N Table IV: Key measurement types for the CV model. The ‘-dyne’ measurements are Gaussian, while photon-counting is non-Gaussian. Photon Counting 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 ∈ 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 I ? |0??0|. The Strawberry Fields Software Platform 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 assembly 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. Further, high-level quantum computing applications can be built by leverging the Strawberry Fields frontend API. Existing examples include the Strawberry Fields Interactive website, the Quantum Machine Learning Toolbox (for streamlining the training of variational quantum circuits), and SFOpenBoson (an interface between the electronic structure library OpenFermion [45] and Strawberry Fields). 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. Blackbird: A Quantum Programming Language 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 standalone domain specific language (DSL) for continuous-variable quantum computation. With a welldefined grammar in extended Backus-Naur form, and both Python and C++ parsers available, Blackbird provides operations that match the basic CV states, gates, and measurements, and maps directly to low-level hardware instructions. The abstract syntax keeps a close connection between code and the quantum operations that they implement; this syntax is modeled after that of ProjectQ [41], but specialized to the CV setting. Blackbird can be used as part of the Strawberry Fields stack, but also directly with photonic quantum computing hardware systems. Within the Strawberry Fields framework, we have built an implementation of Blackbird using Python 3 as the embedding language — an ‘embedded’ DSL. This ‘Pythonenhanced’ Blackbird language provides the same core operations and follows the same grammar and syntactical rules as the standalone DSL, but, by nature, may also contain valid Python constructs. Furthermore, Strawberry Fields’ ‘Python-enhanced’ Blackbird provides users with additional 6 COMPILER ENGINE FRONT-ENDS BACK-ENDS Strawberry Fields Interactive Server Applications Strawberry Fields API Blackbird Quantum Programming Language Quantum Processor Simulators Fock Representation Gaussian Representation NumPy Tensorflow NumPy FIG. 2: Outline of the Strawberry Fields software stack. The Strawberry Fields Interactive server is available online at strawberryfields.ai. quantum operations that are decomposed into lower-level Blackbird assembly commands. We will introduce the elements of Blackbird through a series of basic examples, discussing more technical aspects as they arise. Operations Quantum computations consist of four main ingredients: state preparations, application of gates, performing measurements, 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 first considered Operation is state preparation. By default, qumodes are initialized in the vacuum state. Various other important CV states can be created with simple Blackbird commands. 1 # Create the vacuum state in qumode 0 2 Vac | q[0] 3 4 # Create a coherent state in qumode 1 5 alpha = 2.0 + 1j 6 Coherent(alpha) | q[1] 7 8 # Create squeezed states in qumodes 0 & 1 9 S = Squeezed(2.0) 10 S | q[0] 11 S | q[1] 12 13 # Create a Fock state in qumode 1 14 Fock(4) | q[1] Codeblock 1: Blackbird code for creating various CV quantum states. Blackbird state preparations such as those used in Codeblock 1 implicitly reset the existing state of the qumodes. 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. 1 # Apply the Displacement gate to qumode 0 2 alpha = 2.0 + 1j 3 Dgate(alpha) | q[0] 4 5 # Apply the Rotation gate 6 phi = 1.157 7 Rgate(phi) | q[0] 8 9 # Apply the Squeezing gate 10 Sgate(2.0, 0.17) | q[0] 11 12 # Apply the Beamsplitter gate to qumodes 0 & 1 13 BSgate(0.314, 0.223) | (q[0], q[1]) 14 15 # Apply Cubic phase gate (VGate) to qumode 0 16 gamma = 0.1 17 Vgate(gamma) | q[0] 18 19 # Apply Hermitian conjugate of a gate 20 V = Vgate(gamma) 21 V.H | q[0] Codeblock 2: Blackbird code for applying various CV 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). A full list of gates currently supported in Blackbird can be found in Appendix B. Finally, we can specify measurement Operations using Blackbird. 7 1 # Homodyne measurement at angle phi 2 phi = 0.785 3 MeasureHomodyne(phi) | q[0] 4 5 # Special homodyne measurements 6 MeasureX | q[0] 7 MeasureP | q[1] 8 9 # Heterodyne measurement 10 MeasureHeterodyne() | q[0] 11 MeasureHD | q[1] # shorthand 12 13 # Number state measurements of various qumodes 14 MeasureFock() | q[0] 15 MeasureFock() | (q[1], q[2]) # multiple modes 16 Measure | q[3] # shorthand Codeblock 3: Blackbird code for carrying out CV measurements. 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. Running Blackbird Programs in Python Within Python, Blackbird programs are managed by an Engine. The function Engine in the Strawberry Fields API will instantiate an Engine, returning both the Engine and its corresponding quantum register. The Engine is used as a Python context manager, providing a convenient way to encapsulate Blackbird programs. 1 # Create Engine and quantum register 2 import strawberryfields as sf 3 eng, q = sf.Engine(num_subsystems=2) 4 5 # The register is also available via ,→ eng.register 6 assert q == eng.register 7 8 # Put Blackbird Operations in namespace 9 from strawberryfields.ops import * 10 11 # Declare a Blackbird program 12 from math import pi 13 z = 4. 14 S = Sgate(z) 15 B = BSgate(pi / 4, 0) 16 with eng: 17 S | q[0] 18 S.H | q[1] 19 B | q 20 MeasureP | q[0] 21 MeasureP | q[1] 22 23 # Execute Blackbird program and extract values 24 eng.run(backend="gaussian") 25 vals = [reg.val for reg in q] Codeblock 4: Code for declaring and running Blackbird programs using the Strawberry Fields library. The above code example is runnable and carries out a complete quantum computation, namely the preparation and measurement of an EPR entangled state. Note that Operations can be declared outside of the Engine, but their action on the quantum registers must come within the Engine context. Also notice that our register has a length of 2, so any single-mode Operations must act on specific elements, i.e., q[i], while two-mode Operations can act on q directly. Finally, the user must specify a backend – as well as any backend-dependent settings – when calling eng.run(). We will discuss the Strawberry Fields backends further in a later section. Quantum and Classical Registers 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. 1 # A Blackbird circuit where gates 2 # are added and deleted 3 alice = q[0] 4 with eng: 5 Sgate(1) | alice 6 bob, charlie = New(2) 7 BSgate(0.5) | (alice, bob) 8 CXgate(1) | (alice, charlie) 9 Del | alice 10 S2gate(0.4) | (charlie, bob) 11 12 # Attempting to act on registers which have 13 # been removed will raise an IndexError 14 try: 15 with eng: 16 Dgate(0.1) | alice 17 except Exception as e: 18 assert isinstance(e, IndexError) Codeblock 5: Adding and deleting qumode subsystems. 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. As stated earlier, measurement Operations produce classical information (the measurement result) and manipulate the corresponding register. Compared to previously released quantum programming frameworks, such as ProjectQ, PyQuil, and Qiskit, Strawberry Fields has been designed so that the notation q[i], while principally denoting the quantum register, may also encapsulate classical information or a classical register. This behaviour is contextual, 8 and unique to Strawberry Fields. For example, prior to measurement, q[i] simply references a quantum register. Once a measurement operation is performed, q[i] continues to represent a quantum register — now reset to the vacuum state — as well as storing the numerical value of the measurement, accessible via the attribute q[i].val. Note that this numerical value is only available if a computation has been run up to the point of measurement. We may also use a classical measurement result symbolically as a parameter in later gates without first running the computation. To do this, we simply pass the measured register (e.g., q[i]) explicitly as an argument to the required gate. As before, the Strawberry Fields quantum register object is contextual — when passed as a gate argument, Strawberry Fields implicitly accesses the encapsulated classical register. 1 # Numerical evaluation of a measurement 2 # result using eng.run() 3 with eng: 4 MeasureX | q[0] 5 eng.run("gaussian") 6 val = q[0].val 7 8 # Use a measured register symbolically 9 # in another gate 10 with eng: 11 MeasureX | q[0] 12 Dgate(q[0]) | q[1] 13 eng.run("gaussian") Codeblock 6: Evaluating measurement results numerically and using them symbolically. 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): 3 return -x 4 5 # A Blackbird computation using classical 6 # data processing 7 with eng: 8 MeasureX | q[0] 9 Dgate(neg(q[0])) | q[1] 10 eng.run("gaussian") Codeblock 7: Symbolically processing a measured value before using it. Post-selection 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 optional 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 value3 . 1 with eng: 2 Fock(3) | q[0] 3 Fock(2) | q[1] 4 BSgate() | (q[0], q[1]) 5 MeasureFock(select=4) | q[0] 6 MeasureFock() | q[1] 7 eng.run("fock", cutoff_dim=6) 8 assert q[0].val == 4 Codeblock 8: Selecting a specific desired measurement outcome. Decompositions In addition to the core CV operations discussed above, Strawberry Fields also provides support for some important decompositions frequently used in quantum optics. These include the (a) Williamson decomposition [59], for decomposing arbitrary Gaussian states to a symplectic transformation acting on a thermals state, (b) the BlochMessiah decomposition [60–62], for decomposing the action of symplectic transformations to interferometers and single-mode squeezing, and (c) the Clements decomposition [63], for decomposing multi-mode linear interferometers into arrays of beamsplitters and rotations of fixed depth. In all cases, the resulting decomposition into the universal CV gate set may be viewed via the engine method eng.print_applied(). Strawberry Fields thus provides a natural environment for embedding graphs and matrices in quantum optical circuits, and viewing the resulting physical components. 1 U = np.array([[1-1j, np.sqrt(2)], 2 [-np.sqrt(2), 1+1j]])/2 3 4 eng, q = sf.Engine(2) 5 6 with eng: 7 Squeezed(0.43) | q[0] 8 Interferometer(U) | (q[0], q[1]) 9 10 eng.run("gaussian") 11 eng.print_applied() 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. 9 12 # >> Squeezed(0.43, 0) | (q[0]) 13 # >> Rgate(2.356) | (q[0]) 14 # >> BSgate(0.7854, 0) | (q[0], q[1]) 15 # >> Rgate(-3.142) | (q[0]) 16 # >> Rgate(0.7854) | (q[1]) Codeblock 9: Using the in-built Clements decomposition to decompose a 2 × 2 Interferometer into beamsplitters and phase rotations

要查看或添加评论,请登录

Sam Greenblatt的更多文章

社区洞察

其他会员也浏览了