Skip to content

Photonics

strawberryfields

Maintained by xanaduai

Strawberry Fields is one of the flagship photonics projects and a strong entry point for readers who want to understand optical quantum computing software.

PythonApache-2.0FlagshipArchive
strawberryfields illustration

Resource snapshot

Category

Photonics

Stars

850

Last pushed

Jan 16, 2026Updated 7mo ago

Open issues

43

What it is

Many newcomers assume the ecosystem is basically a contest among a few circuit frameworks. Strawberry Fields is a useful corrective because it shows a mature, domain-specific stack built around photonic ideas, representations, and workflows.

That makes it educationally valuable whether or not the reader plans to work in photonics directly. It broadens the mental map of what quantum software can look like.

Who it's for

Readers exploring photonic computing, optical models, or ecosystem breadth beyond the most common gate-model stacks.

What you can build or learn

  • Understand photonic circuit concepts and software abstractions.
  • Compare optical workflows with gate-model frameworks.
  • Use the project as a reference point for a different branch of the ecosystem.

Code samples

Examples from the repository.

Boson Sampling (examples/boson_sampling.py)
#!/usr/bin/env python3
import strawberryfields as sf
from strawberryfields.ops import *
# initialize engine and program objects
eng = sf.Engine(backend="fock", backend_options={"cutoff_dim": 7})
boson_sampling = sf.Program(4)
with boson_sampling.context as q:
    # prepare the input fock states
    Fock(1) | q[0]
    Fock(1) | q[1]
    Vac     | q[2]
    Fock(1) | q[3]
    # rotation gates
    Rgate(0.5719) | q[0]
    Rgate(-1.9782) | q[1]
    Rgate(2.0603) | q[2]
    Rgate(0.0644) | q[3]
    # beamsplitter array
    BSgate(0.7804, 0.8578)  | (q[0], q[1])
    BSgate(0.06406, 0.5165) | (q[2], q[3])
    BSgate(0.473, 0.1176)   | (q[1], q[2])
    BSgate(0.563, 0.1517)   | (q[0], q[1])
    BSgate(0.1323, 0.9946)  | (q[2], q[3])
    BSgate(0.311, 0.3231)   | (q[1], q[2])
    BSgate(0.4348, 0.0798)  | (q[0], q[1])
    BSgate(0.4368, 0.6157)  | (q[2], q[3])
    # end circuit
# run the engine
results = eng.run(boson_sampling)
# extract the joint Fock probabilities
probs = results.state.all_fock_probs()
# print the joint Fock state probabilities
print(probs[1, 1, 0, 1])
print(probs[2, 0, 0, 1])
Bosonic Tutorial Sampling (examples/bosonic_tutorial_sampling.py)
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#     http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""A comparison of the asymptotic homodyne distributions and sampled values,
for GKP and cat states."""
import strawberryfields as sf
import numpy as np
import matplotlib.pyplot as plt
# Create cat state
prog_cat = sf.Program(1)
with prog_cat.context as q:
    sf.ops.Catstate(alpha=2) | q
eng = sf.Engine("bosonic")
cat = eng.run(prog_cat).state
# Calculate the asymptotic quadrature distributions
scale = np.sqrt(sf.hbar)
quad = np.linspace(-6, 6, 1000) * scale
cat_prob_x = cat.marginal(0, quad)
cat_prob_p = cat.marginal(0, quad, phi=np.pi / 2)
# Run the program again, collecting x samples this time
prog_cat_x = sf.Program(1)
with prog_cat_x.context as q:
    sf.ops.Catstate(alpha=2) | q
    sf.ops.MeasureX | q
eng = sf.Engine("bosonic")
cat_samples_x = eng.run(prog_cat_x, shots=2000).samples[:, 0]
# Run the program again, collecting p samples this time
prog_cat_p = sf.Program(1)
with prog_cat_p.context as q:
    sf.ops.Catstate(alpha=2) | q
    sf.ops.MeasureP | q
eng = sf.Engine("bosonic")
cat_samples_p = eng.run(prog_cat_p, shots=2000).samples[:, 0]
# Plot the results
Custom Operation (examples/custom_operation.py)
#!/usr/bin/env python3
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#     http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import strawberryfields as sf
from strawberryfields.ops import *
from strawberryfields.utils import operation
@operation(4)
def prepare_squeezing(q):
    """This operation prepares modes 0 and 1
    as squeezed states with r = -1.
    Args:
        q (register): the qumode register.
    """
    S = Sgate(-1)
    S | q[0]
    S | q[1]
@operation(3)
def circuit_op(v1, v2, q):
    """Some gates that are groups into a custom operation.
    Args:
        v1 (float): parameter for CZgate
        v2 (float): parameter for the cubic phase gate
        q (register): the qumode register
    """
    CZgate(v1) | (q[0], q[1])
    Vgate(v2) | q[1]
# initialize engine and program objects
eng = sf.Engine(backend="fock", backend_options={"cutoff_dim": 5})
circuit = sf.Program(4)
with circuit.context as q:
    # The following operation takes no arguments
    prepare_squeezing() | q
    # another operation with 2 parameters that operates on three registers: 0, 1

License

Apache-2.0

SPDX identifier detected from the repository metadata or license files.

Repository README

Preview from the project README.

Rendered as Markdown inside a scrollable preview. Long READMEs stay contained; expand or open on GitHub for the full document.

~383 words · about 2 min readOpen on GitHub

Features

  • Execute photonic quantum algorithms directly on Xanadu's next-generation quantum hardware.

  • High-level functions for solving practical problems including graph and network optimization, machine learning, and chemistry.

  • Includes a suite of world-class simulators—based on cutting-edge algorithms—to compile and simulate photonic algorithms.

  • Train and optimize your quantum programs with our end-to-end differentiable TensorFlow backend.

Installation

Strawberry Fields requires Python version 3.8, 3.9, or 3.10. Installation of Strawberry Fields, as well as all dependencies, can be done using pip:

pip install strawberryfields

Getting started

To get started with writing your own Strawberry Fields code, begin with our photonic circuit quickstart guides.

Contributing to Strawberry Fields

We are not accepting Pull Requests for new features at this time. We welcome contributions for bug fixes, security patches, and documentation improvements only. Thank you for your understanding.

See our contributions page and changelog for more details.

Authors

Strawberry Fields is the work of many contributors

If you are doing research using Strawberry Fields, please cite our papers:

Nathan Killoran, Josh Izaac, Nicolás Quesada, Ville Bergholm, Matthew Amy, and Christian Weedbrook. "Strawberry Fields: A Software Platform for Photonic Quantum Computing", Quantum, 3, 129 (2019).

Thomas R. Bromley, Juan Miguel Arrazola, Soran Jahangiri, Josh Izaac, Nicolás Quesada, Alain Delgado Gran, Maria Schuld, Jeremy Swinarton, Zeid Zabaneh, and Nathan Killoran. "Applications of Near-Term Photonic Quantum Computers: Software and Algorithms", Quantum Sci. Technol. 5 034010 (2020).

Support

If you are having issues, please let us know by posting the issue on our Github issue tracker.

We also have a Slack channel and a discussion forum — come join the discussion and chat with our Strawberry Fields team.

License

Strawberry Fields is free and open source, released under the Apache License, Version 2.0.

Read on GitHub

Activity

Latest release

—

Watchers

34

Python support

—

Learn digest

Get monthly updates when library entries change.

Monthly digest: new library entries, updated flagships, and one editorial pick.

Related resources

Keep exploring nearby tools.

quantumlib

Cirq

Python framework for creating, editing, and running Noisy Intermediate-Scale Quantum (NISQ) circuits.

PythonApache-2.0Flagship

4,971 stars · Updated 3mo ago

open-quantum-safe

liboqs

C library for prototyping and experimenting with quantum-resistant cryptography

CMITFlagship

2,946 stars · Updated 3mo ago

XanaduAI

pennylane

PennyLane is an open-source quantum software platform for quantum computing, quantum machine learning, and quantum chemistry.

PythonApache-2.0FlagshipQtangl relevant

3,229 stars · Updated 3mo ago

Quandela

Perceval

An open source framework for programming photonic quantum computers

PythonMIT

202 stars · Updated 3mo ago

QISKit

qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.

PythonApache-2.0FlagshipQtangl relevant

7,412 stars · Updated 3mo ago

Microsoft

QuantumKatas

Tutorials and programming exercises for learning Q# and quantum computing

Jupyter NotebookMITFlagshipArchive

4,862 stars · Updated 2y ago