python v0.23.x

Strawberryfields

Xanadu's Python library for photonic quantum computing

Quick install

pip install strawberryfields

Background and History

Strawberry Fields was created by Xanadu, a Canadian quantum computing company founded in 2016 by Christian Weedbrook, and first released as open-source software in 2018. The framework was developed to provide a programming environment for continuous-variable (CV) photonic quantum computing, a paradigm fundamentally different from the discrete qubit-based gate model used by superconducting and trapped-ion systems. In the CV model, quantum information is encoded in the quadrature amplitudes of light, and operations include squeezing, displacement, and beamsplitting rather than Pauli gates and CNOTs.

Xanadu’s founding vision centered on building photonic quantum computers that operate at room temperature using squeezed light as the quantum resource. Strawberry Fields was the software layer that made this hardware paradigm accessible to researchers and developers. The framework’s name is a nod to the Beatles song, continuing a tradition of whimsical naming in the quantum computing community. Its API is organized around Program objects that operate on optical modes (qumodes), with gates applied using a context manager syntax.

A significant milestone for Strawberry Fields came in June 2022, when Xanadu published a Nature paper claiming quantum computational advantage using its Borealis photonic processor for Gaussian boson sampling (GBS). The GBS experiments were programmed and analyzed using Strawberry Fields. The framework supports multiple simulation backends: a Fock-basis backend for exact photon-number calculations (limited by Hilbert space truncation), a Gaussian backend for efficient simulation of Gaussian states, and a TensorFlow backend for differentiable photonic circuit optimization.

As of 2025, Strawberry Fields remains available and functional, though Xanadu’s primary development focus has shifted toward PennyLane, which serves as the company’s main framework for both photonic and cross-platform quantum computing. Strawberry Fields continues to be the specialized tool for CV photonic programming, particularly for GBS applications, quantum optics research, and experiments on Xanadu’s photonic hardware. The project has over 700 GitHub stars and is referenced in numerous photonic quantum computing publications.

Installation

pip install strawberryfields

For Xanadu Cloud access (X8/Borealis hardware):

sf configure --token YOUR_API_TOKEN

Key Imports

import strawberryfields as sf
from strawberryfields import ops
from strawberryfields.ops import Sgate, BSgate, MeasureFock, MeasureHomodyne

Core Concepts

Strawberry Fields works with modes (optical modes / qumodes) rather than qubits. Light is the carrier of information. The continuous-variable (CV) paradigm uses:

  • Fock basis: discrete photon-number states |0⟩, |1⟩, |2⟩, …
  • Gaussian states: described by means and covariance matrices (squeezed states, coherent states)
  • Non-Gaussian gates: Kerr, cubic phase - needed for universal QC but expensive

Program Structure

import strawberryfields as sf
from strawberryfields import ops

prog = sf.Program(2)   # 2 optical modes

with prog.context as q:
    ops.Sgate(0.5) | q[0]         # squeeze mode 0
    ops.BSgate(0.78, 0.0) | (q[0], q[1])  # beamsplitter
    ops.MeasureFock() | q[0]      # photon-number measurement

eng = sf.Engine('fock', backend_options={'cutoff_dim': 10})
result = eng.run(prog)
print(result.samples)

Gates

Single-mode gates

GateSyntaxDescription
DisplacementDgate(r, phi)Coherent displacement by amplitude r, phase φ
SqueezingSgate(r, phi)Squeeze by factor r in phase φ direction
RotationRgate(phi)Phase space rotation by φ
KerrKgate(kappa)Non-Gaussian Kerr interaction
Cubic phaseVgate(gamma)Non-Gaussian cubic phase
VacuumVacuum()Prepare vacuum state
CoherentCoherent(r, phi)Prepare coherent state
FockFock(n)Prepare n-photon Fock state
ops.Dgate(0.5, 0.0) | q[0]    # displacement
ops.Sgate(1.0, 0.0) | q[0]    # squeezing
ops.Rgate(3.14159) | q[0]     # rotation by π
ops.Kgate(0.1) | q[0]         # Kerr

Two-mode gates

GateSyntaxDescription
BeamsplitterBSgate(theta, phi)50/50 at theta=π/4
Two-mode squeezingS2gate(r, phi)Entangles two modes
CZ gateCZgate(s)Continuous-variable CZ
CX gateCXgate(s)Continuous-variable CNOT
ops.BSgate(0.7854, 0.0) | (q[0], q[1])   # 50/50 beamsplitter
ops.S2gate(1.0, 0.0) | (q[0], q[1])       # two-mode squeezing

Measurements

ops.MeasureFock() | q[0]           # photon-number measurement
ops.MeasureHomodyne(0.0) | q[0]    # homodyne: X quadrature
ops.MeasureHomodyne(1.5708) | q[0] # homodyne: P quadrature
ops.MeasureHeterodyne() | q[0]     # heterodyne (both quadratures)
ops.MeasureThreshold() | q[0]      # click/no-click detector

Backends

BackendDescription
'fock'Exact Fock-basis simulation (limited to low photon numbers)
'gaussian'Efficient Gaussian state simulation (no Kerr/cubic)
'bosonic'Wigner function simulation
'tf'TensorFlow backend (differentiable)
eng = sf.Engine('fock', backend_options={'cutoff_dim': 8})
eng = sf.Engine('gaussian')
eng = sf.Engine('tf', backend_options={'cutoff_dim': 6})

Running Programs

result = eng.run(prog)

result.samples        # measurement outcomes (list)
result.state          # quantum state object (if no measurement or partial)
result.state.wigner() # Wigner function
result.state.fock_prob([1, 0])  # P(1 photon in mode 0, 0 in mode 1)

Xanadu Cloud Hardware

eng = sf.RemoteEngine('X8')    # Xanadu X8 photonic chip
eng = sf.RemoteEngine('borealis')  # Borealis GBS processor

result = eng.run(prog, shots=100)

Common Patterns

Two-mode entanglement (EPR pair)

prog = sf.Program(2)
with prog.context as q:
    ops.S2gate(1.0) | (q[0], q[1])    # two-mode squeezed vacuum
    ops.MeasureHomodyne(0) | q[0]
    ops.MeasureHomodyne(0) | q[1]

Gaussian Boson Sampling

prog = sf.Program(4)
with prog.context as q:
    # Squeezed inputs
    for i in range(4):
        ops.Sgate(1.0) | q[i]
    # Interferometer (beamsplitters)
    ops.BSgate() | (q[0], q[1])
    ops.BSgate() | (q[2], q[3])
    ops.BSgate() | (q[1], q[2])
    # Photon-number detection
    ops.MeasureFock() | q

eng = sf.Engine('fock', backend_options={'cutoff_dim': 5})
result = eng.run(prog, shots=10)
print(result.samples)

Differentiable circuit (TensorFlow)

import tensorflow as tf

eng = sf.Engine('tf', backend_options={'cutoff_dim': 7})
prog = sf.Program(1)

with prog.context as q:
    r = sf.ops.SqueezingEmbedding([0.5], wires=q)
    ops.Kgate(0.1) | q[0]
    ops.MeasureFock() | q[0]

with tf.GradientTape() as tape:
    result = eng.run(prog)
    loss = tf.abs(result.state.fock_prob([0]) - 0.5)

gradient = tape.gradient(loss, prog.params)