Skip to main content
CodeSpeedTest
Languages
Start TypingJump into a test — pick any languageAdaptive TrainingUnlock chars as you master themPractice DrillsFocused sessions targeting weak spotsDaily ChallengesNew coding challenges every dayRace ModeCompete against others in real timeAI OpponentRace against an AI at your WPM levelTournamentsLive coding speed tournamentsArcade GamesZType, Overkill Survival, Glyphica & moreGamificationXP, coins, badges & quests
LeaderboardGlobal rankings for every languageCertificatesEarn verifiable Bronze / Silver / Gold certsActivityDaily streaks & historical analyticsProfileYour stats, badges & achievements
Browse Languages500+ languages with real code examplesBlogTips, guides & deep divesFree ToolsWPM calculator, typing speed report & moreFAQCommon questions answeredGetting StartedNew to CodeSpeedTest?AboutOur story & missionSupportGet help — Pro users get priorityContactGet in touch with the team
Pricing
  1. Home
  2. /
  3. Learn
  4. /
  5. Strawberry-fields

Learn Strawberry-fields - 10 Code Examples & CST Typing Practice Test

Strawberry Fields is a Python library for photonic quantum computing using continuous-variable (CV) quantum systems. It enables the design, simulation, and execution of quantum circuits on photonic platforms.

View all 10 Strawberry-fields code examples →
Strawberry Fields Simple Quantum CircuitStrawberry Fields Coherent State PreparationStrawberry Fields Squeezed StateStrawberry Fields Beam Splitter ExampleStrawberry Fields Displacement GateStrawberry Fields Two-mode EntanglementStrawberry Fields Rotation GateStrawberry Fields Kerr GateStrawberry Fields Controlled-Z GateStrawberry Fields Homodyne Measurement

Learn STRAWBERRY-FIELDS with Real Code Examples

Updated Nov 25, 2025

Explain

Strawberry Fields allows developers to construct and simulate quantum circuits using continuous-variable quantum computation, unlike qubit-based systems.

It supports both Gaussian and non-Gaussian states, making it suitable for photonic quantum algorithms.

The library abstracts complex quantum photonic operations and integrates with simulators and hardware backends for experimentation.

Core Features

High-level circuit construction using Python API

Built-in simulators (Fock, Gaussian, and TF backends)

Gate and measurement operations for CV systems

Support for quantum state tomography and analysis

Integration with TensorFlow and PyTorch for quantum ML

Basic Concepts Overview

Mode: the photonic equivalent of a qubit in CV systems

Gate: operations on modes (e.g., displacement, squeezing)

Circuit: sequence of gates applied to quantum modes

Measurement: extracting classical information from quantum modes

Backend: simulator or real photonic device executing the circuit

Project Structure

notebooks/ - interactive experiments and tutorials

circuits/ - custom CV quantum circuit definitions

simulations/ - backend simulation results

data/ - measurement outcomes and analyses

scripts/ - automation and utility functions

Building Workflow

Import Strawberry Fields and initialize a program

Add photonic modes to the circuit

Apply Gaussian and non-Gaussian gates

Measure modes to obtain classical outcomes

Simulate or execute on supported hardware backends

Difficulty Use Cases

Beginner: simulate simple Gaussian circuits

Intermediate: implement non-Gaussian operations

Advanced: quantum machine learning experiments

Expert: optimize large photonic circuits

Enterprise: integrate hybrid quantum-classical pipelines

Comparisons

Strawberry Fields vs Qiskit: SF targets CV photonic systems; Qiskit targets qubits on IBM hardware

Strawberry Fields vs Cirq: SF is photonic and CV; Cirq targets qubits on Google hardware

Strawberry Fields vs Pennylane: SF can integrate with Pennylane for hybrid ML

Strawberry Fields vs PyQuil: SF focuses on CV photonics; PyQuil targets Rigetti qubits

Strawberry Fields vs Braket: SF is specialized for CV photonics; Braket is multi-hardware qubit platform

Versioning Timeline

2018 - Initial release of Strawberry Fields by Xanadu

2019 - Fock and Gaussian backends added

2020 - Integration with PennyLane for quantum ML

2021 - TensorFlow backend with automatic differentiation

2023 - Support for multi-mode Gaussian boson sampling and photonic hardware backends

Glossary

Mode: photonic analog of a qubit

Gate: quantum operation on a mode

Circuit: sequence of gate operations

Gaussian state: quantum state with Gaussian statistics

Non-Gaussian state: quantum state with non-Gaussian properties

Installation Setup

Install Python 3.8+

Install Strawberry Fields via `pip install strawberryfields`

Optionally install TensorFlow or PyTorch for quantum ML

Verify installation with `import strawberryfields as sf`

Test built-in simulators using example circuits

Environment Setup

Install Python 3.8+

Install Strawberry Fields via pip

Install optional ML libraries (TensorFlow, PyTorch)

Set up environment variables for hardware backends

Verify by running example circuits

Config Files

config.toml - optional backend configuration

notebooks/ - interactive example programs

circuits/ - user-defined circuit modules

simulations/ - store simulation results

scripts/ - automation and utility functions

Cli Commands

python example.py - run a Strawberry Fields script

sf --list-backends - list available simulators and hardware

sf --run-prog prog.py - execute a circuit

sf --export-circuit prog.py - export circuit diagram

sf --analyze-state prog.py - visualize quantum state

Internationalization

Used globally in research and academia

Documentation primarily in English

Compatible with international quantum algorithm standards

Integrates with widely-used Python ML frameworks

Community contributions worldwide

Accessibility

Python-based and cross-platform

Open-source Apache 2.0 license

Accessible for research, education, and hybrid algorithm development

Community tutorials and example notebooks available

Supports photonic hardware and local simulators

Ui Styling

Jupyter notebooks for interactive experimentation

Matplotlib or Plotly for visualization

CLI outputs for simulation results

Optional GUI tools for circuit construction

Integration with dashboards for analysis

State Management

Track quantum program versions

Log simulation and hardware results

Store measurement outcomes

Maintain reproducibility

Manage hybrid quantum-classical pipelines

Data Management

Serialize measurement data and states

Cache simulation results

Document gate parameters and circuit structure

Organize experiments for benchmarking

Analyze classical-quantum interface outputs

Architecture

Python-based SDK for CV quantum circuits

Backends for Fock, Gaussian, and TensorFlow simulations

Integration with PennyLane for hybrid algorithms

Modular design for gate operations and measurements

Tools for visualization and analysis of quantum states

Rendering Model

Python-based high-level circuit API

Backends for Fock, Gaussian, and TensorFlow simulation

Visualization of quantum states and measurement outcomes

Integration with classical ML workflows

Cloud and hardware backend execution support

Architectural Patterns

Separation of circuit definition and execution

Modular design for gates and measurements

Backend-agnostic simulation and hardware execution

Integration with hybrid quantum-classical pipelines

Extensible for photonic quantum algorithm research

Real World Architectures

Gaussian boson sampling experiments

Variational quantum algorithms for ML

Photonic quantum teleportation protocols

Hybrid quantum-classical optimization pipelines

Quantum state tomography and analysis

Design Principles

Enable photonic continuous-variable quantum programming

Support hybrid quantum-classical workflows

Provide flexible, modular Python API

Facilitate research in quantum algorithms and ML

Abstract hardware complexity while supporting backend execution

Scalability Guide

Use Gaussian backends for large-scale circuits

Limit Fock cutoff dimensions for efficient simulation

Batch execution for hybrid classical-quantum experiments

Optimize gate sequences to reduce resource consumption

Monitor backend performance and execution time

Migration Guide

Update Strawberry Fields via pip

Check API changes for backends and gate definitions

Update example scripts and notebooks as needed

Validate circuits on simulator before hardware execution

Ensure reproducible results after upgrade

Performance Notes

Fock simulation scales exponentially with number of modes and cutoff dimension

Gaussian simulation is efficient for large circuits but limited to Gaussian states

TensorFlow backend allows automatic differentiation

Simulation time depends on gate complexity

Parallel execution supported on certain backends

Security Notes

Run code locally or on trusted cloud environments

Ensure sensitive classical data is not exposed during hybrid workflows

Monitor resource usage for large simulations

Validate circuits before using hardware backends

Reproducibility through random seed initialization

Monitoring Analytics

Track simulation and hardware job outcomes

Visualize measurement distributions and quantum states

Analyze circuit performance metrics

Compare Gaussian and Fock simulation results

Audit hybrid algorithm execution results

Code Quality

Follow Python and Strawberry Fields best practices

Document gates, circuits, and modules

Maintain reproducibility in notebooks and scripts

Optimize simulation and execution efficiency

Use modular components for circuit reuse

Practical Examples

Simulate single-mode squeezing

Construct and run a Gaussian boson sampling circuit

Implement a variational quantum circuit for machine learning

Perform CV quantum teleportation simulation

Analyze quantum state statistics and measurement outcomes

Troubleshooting

Verify correct number of modes matches gate definitions

Ensure backend dependencies are installed

Check integration with PennyLane or ML libraries

Debug with simple Gaussian circuits first

Validate measurement results against expected theory

Testing Guide

Simulate circuits with small number of modes first

Validate gate sequences and measurement results

Compare Gaussian vs Fock simulations

Visualize state distributions and probabilities

Check reproducibility with fixed random seeds

Deployment Options

Run experiments locally using Fock or Gaussian simulators

Use TensorFlow backend for differentiable quantum programming

Integrate with PennyLane for hybrid ML pipelines

Deploy variational circuits on photonic hardware backends

Automate experiments using Python scripts

Tools Ecosystem

Strawberry Fields Core - circuit construction and execution

Simulators - Fock, Gaussian, and TensorFlow backends

PennyLane Integration - hybrid quantum-classical ML

Quantum state analysis and visualization tools

Resource estimation modules for large photonic circuits

Integrations

Python scientific libraries (NumPy, SciPy, Matplotlib)

TensorFlow and PyTorch for automatic differentiation

PennyLane for hybrid quantum-classical workflows

Integration with Jupyter notebooks for interactive experimentation

Classical optimization frameworks for variational algorithms

Productivity Tips

Start with Gaussian circuits before non-Gaussian

Use Jupyter notebooks for interactive testing

Cache simulation results for large circuits

Leverage PennyLane for hybrid ML workflows

Visualize quantum states for debugging and analysis

Challenges

Understanding continuous-variable quantum mechanics

Optimizing simulation for large mode numbers

Integrating classical machine learning with quantum circuits

Analyzing non-Gaussian quantum states

Bridging theory and experimental photonic hardware

Learning Path

Learn Python programming

Understand continuous-variable quantum computing concepts

Practice constructing Gaussian circuits in Strawberry Fields

Explore non-Gaussian operations and simulations

Integrate circuits with machine learning pipelines

Skill Improvement Plan

Week 1: Install Strawberry Fields and run basic Gaussian circuits

Week 2: Implement simple Fock state operations

Week 3: Build variational quantum circuits and integrate with TensorFlow

Week 4: Simulate multi-mode Gaussian boson sampling circuits

Week 5: Analyze and optimize circuits; deploy on photonic hardware

Interview Questions

What is Strawberry Fields and its primary use?

Explain continuous-variable quantum computing

How do Gaussian and non-Gaussian operations differ?

Describe integration with PennyLane for quantum ML

Compare Strawberry Fields to qubit-based frameworks like Qiskit

Cheat Sheet

sf.Program(N) - create program with N photonic modes

with prog.context as q: Dgate(alpha) | q[0] - apply displacement gate

Sgate(r) | q[0] - apply squeezing gate

MeasureFock() | q[0] - measure mode in Fock basis

engine.run(prog) - execute circuit on chosen backend

Books

Continuous-Variable Quantum Computing with Strawberry Fields

Photonic Quantum Information Processing

Quantum Machine Learning with Continuous Variables

Practical Photonic Quantum Computing

Introduction to Strawberry Fields and Xanadu's platform

Tutorials

Strawberry Fields documentation tutorials

Gaussian boson sampling examples

Quantum machine learning with PennyLane

CV quantum teleportation simulation

Fock state circuit simulations

Official Docs

https://strawberryfields.ai

https://github.com/XanaduAI/strawberryfields

Community Links

Strawberry Fields GitHub repository

Xanadu community forums

Quantum StackExchange

PennyLane community for hybrid ML

Academic research groups in photonic quantum computing

Community Support

Strawberry Fields GitHub repository

Xanadu documentation and tutorials

PennyLane community forums

Quantum StackExchange discussions

Academic research groups focused on CV quantum computing

Monetization

Research grants and collaborations

Quantum algorithm consulting

Education and training in photonic quantum computing

Hybrid quantum-classical optimization solutions

Scientific publications and workshops

Future Roadmap

Enhanced multi-mode photonic hardware support

Improved non-Gaussian gate libraries

Better integration with TensorFlow and PyTorch

Advanced quantum machine learning modules

Expanded tutorials and educational resources

When Not To Use

If only qubit-based quantum computation is required

For users unfamiliar with photonic or continuous-variable systems

When hardware access to non-photonic devices is needed

For small, classical quantum simulations where qubits suffice

If Python integration with ML frameworks is not desired

Final Summary

Strawberry Fields is a Python library for photonic continuous-variable quantum computing.

Supports circuit construction, simulation, and execution on photonic hardware.

Integrates with ML frameworks for hybrid quantum-classical algorithms.

Offers Gaussian and Fock simulators, along with resource and state analysis tools.

Widely used for research, quantum algorithm prototyping, and photonic quantum machine learning.

Faq

Is Strawberry Fields free?

Yes - open-source under Apache 2.0 license.

Which quantum devices does SF support?

Simulators locally; Xanadu photonic hardware backends.

Can SF simulate large photonic circuits?

Yes - Fock and Gaussian simulators for various circuit sizes.

Does SF support quantum machine learning?

Yes - integrates with PennyLane, TensorFlow, and PyTorch.

Is SF suitable for beginners?

Yes, with Python experience and some understanding of photonic quantum computing.

Code Sample Descriptions

1

Strawberry Fields Simple Quantum Circuit

import strawberryfields as sf
from strawberryfields.ops import Sgate,CNOT,MeasureFock

prog = sf.Program(2)
with prog.context as q:
    Sgate(0.543)|q[0]
    CNOT|(q[0],q[1])
    MeasureFock()|q[0]
    MeasureFock()|q[1]

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

A minimal example creating a 2-mode photonic quantum circuit, applying gates, and measuring the output.

Let’s Try →
2

Strawberry Fields Coherent State Preparation

import strawberryfields as sf
from strawberryfields.ops import Coherent,MeasureFock

prog = sf.Program(1)
with prog.context as q:
    Coherent(1.0)|q[0]
    MeasureFock()|q[0]

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

Prepares a coherent state in a single mode and measures it.

Let’s Try →
3

Strawberry Fields Squeezed State

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

prog = sf.Program(1)
with prog.context as q:
    Sgate(0.8)|q[0]
    MeasureFock()|q[0]

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

Prepares a squeezed state in a single mode and measures it.

Let’s Try →
4

Strawberry Fields Beam Splitter Example

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

prog = sf.Program(2)
with prog.context as q:
    BSgate(0.5,0)|q[0],q[1]
    MeasureFock()|q[0]
    MeasureFock()|q[1]

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

Applies a beam splitter gate between two modes.

Let’s Try →
5

Strawberry Fields Displacement Gate

import strawberryfields as sf
from strawberryfields.ops import Dgate,MeasureFock

prog = sf.Program(1)
with prog.context as q:
    Dgate(1.0)|q[0]
    MeasureFock()|q[0]

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

Applies a displacement gate on a single mode.

Let’s Try →
6

Strawberry Fields Two-mode Entanglement

import strawberryfields as sf
from strawberryfields.ops import Sgate,CNOT,MeasureFock

prog = sf.Program(2)
with prog.context as q:
    Sgate(0.6)|q[0]
    CNOT|(q[0],q[1])
    MeasureFock()|q[0]
    MeasureFock()|q[1]

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

Creates entanglement between two modes using squeezing and CNOT.

Let’s Try →
7

Strawberry Fields Rotation Gate

import strawberryfields as sf
from strawberryfields.ops import Rgate,MeasureFock

prog = sf.Program(1)
with prog.context as q:
    Rgate(0.7)|q[0]
    MeasureFock()|q[0]

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

Applies a rotation gate on a single mode and measures it.

Let’s Try →
8

Strawberry Fields Kerr Gate

import strawberryfields as sf
from strawberryfields.ops import Kgate,MeasureFock

prog = sf.Program(1)
with prog.context as q:
    Kgate(0.5)|q[0]
    MeasureFock()|q[0]

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

Applies a Kerr gate on a single mode.

Let’s Try →
9

Strawberry Fields Controlled-Z Gate

import strawberryfields as sf
from strawberryfields.ops import CZgate,MeasureFock

prog = sf.Program(2)
with prog.context as q:
    CZgate(0.5)|q[0],q[1]
    MeasureFock()|q[0]
    MeasureFock()|q[1]

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

Applies a controlled-Z gate between two modes.

Let’s Try →
10

Strawberry Fields Homodyne Measurement

import strawberryfields as sf
from strawberryfields.ops import Sgate,MeasureX

prog = sf.Program(1)
with prog.context as q:
    Sgate(0.5)|q[0]
    MeasureX()|q[0]

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

Measures a mode using homodyne measurement.

Let’s Try →

Frequently Asked Questions about Strawberry-fields

What is Strawberry-fields?

Strawberry Fields is a Python library for photonic quantum computing using continuous-variable (CV) quantum systems. It enables the design, simulation, and execution of quantum circuits on photonic platforms.

What are the primary use cases for Strawberry-fields?

Design and simulation of photonic quantum circuits. Quantum machine learning with CV systems. Hybrid classical-quantum algorithm development. Experimentation on photonic hardware backends. Research in Gaussian and non-Gaussian quantum states

What are the strengths of Strawberry-fields?

Specialized for photonic and CV quantum computing. Supports hybrid quantum-classical workflows. Python-based and easy to integrate with ML libraries. Rich simulation options for Gaussian and Fock circuits. Well-documented with tutorials and examples

What are the limitations of Strawberry-fields?

No direct access to general qubit-based quantum hardware. Steep learning curve for those unfamiliar with CV systems. Simulation complexity grows quickly with number of modes. Primarily research-oriented with fewer industrial applications. Requires understanding of quantum optics concepts

How can I practice Strawberry-fields typing speed?

CodeSpeedTest offers 10+ real Strawberry-fields code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.

Learn Other Programming Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypherGremlinPartiqlHaskellElixirFsharpView all languages →
CodeSpeedTest

Improve your coding speed, code accuracy, and programming syntax WPM with practice sessions across 500+ programming languages.

Quick Links

HomeAboutFeaturesGetting StartedLanguages

Legal & Support

Pro ⚡ PricingContactPrivacy PolicyTerms of Service

Connect

CodeSpeedTest on GitHubCodeSpeedTest on TwitterEmail CodeSpeedTest

© 2026 CodeSpeedTest. All rights reserved.