Strawberry Fields v0.12.0 Released

Hi everyone, we’re excited to announce Strawberry Fields version 0.12.0 :strawberry:

This release includes a major new feature: the apps package, providing an applications layer for using near-term photonic devices to help solve problems of practical interest.

Users can now simulate a near-term photonic algorithm, Gaussian boson sampling, and plug-in samples to help solve the following problems:

Graph and network optimization :woman_teacher:

  • Use heuristics to search for dense regions of a graph with the apps.subgraph module.
Code example
from strawberryfields.apps import data, sample, subgraph
import networkx as nx

s = data.Planted()  # load samples from data module
g = nx.Graph(data.Planted().adj)  # load graph
s = sample.postselect(s, 16, 30)  # postselect sample sizes
s = sample.to_subgraphs(s, g)  # convert samples to subgraphs

k_min = 8  # smallest subgraph size
k_max = 16  # largest subgraph size
r =, g, k_min, k_max)  # implement search algorithm

print(r[10][0])  # densest subgraph of size 10
  • Find large subgraphs that are fully connected, helping solve the maximum clique problem with the apps.clique module.
Code example
from strawberryfields.apps import clique, data, sample
import networkx as nx

p_hat = data.PHat()  # load samples 
g = nx.Graph(p_hat.adj)  # create graph from adjacency matrix
s = sample.postselect(p_hat, 16, 20)  # postselect samples
s = sample.to_subgraphs(s, g)  # convert samples to subgraphs

# shrink subgraphs to a list of cliques
cliques = [clique.shrink(i, g) for i in s]
# run local search for all cliques
cliques = [, g, 10) for c in cliques]

# sort cliques in decreasing size
cliques = sorted(cliques, key=len, reverse=True)
print(cliques[:3]) # the three largest cliques

Machine learning :rocket:

  • Measure similarity between graphs with the apps.similarity module, which can be useful for training machine learning models to classify graphs.
Code example
from strawberryfields.apps import data, similarity

events = [8, 10]  # event photon numbers
max_count = 2  # maximum number of photons per mode

datasets = data.Mutag0(), data.Mutag1(), data.Mutag2(), data.Mutag3()

f1, f2, f3, f4 = (similarity.feature_vector_sampling(data, events, max_count) for data in datasets)  # create feature vectors
print(f1, f2, f3, f4)
  • Sample subsets of points according to a permanental point process, favouring the selection of similar points.
Code example
from strawberryfields.apps import plot, points
import numpy as np

cluster1 = np.random.normal(2, 0.3, (100, 2))  # generate two clusters of points
cluster2 = np.random.normal(4, 0.3, (100, 2))
background = np.random.rand(200, 2) * 6.0  # generate random background points
R = np.concatenate((cluster1, cluster2, background))

sigma = 1.0  # kernel parameter
K = points.rbf_kernel(R, sigma)  # creates kernel matrix

n_mean = 50  # mean number of photons
n_samples = 10  # number of samples
samples = points.sample(K, n_mean, n_samples)  # generates samples

plot.points(R, samples[0], point_size=10)  # plot a sample from the point process

Chemistry :man_scientist:

  • Reconstruct the vibronic absorption spectrum of a molecule using the apps.vibronic module.
Code example
from strawberryfields.apps import data, plot, sample, vibronic

formic = data.Formic()  # load data
molecule_data = formic.w, formic.wp, formic.Ud,  # load properties of molecule
T = 0  # temperature

gbs_params = vibronic.gbs_params(*molecule_data, T)  # encode into GBS parameters

nr_samples = 2
s = sample.vibronic(*gbs_params, nr_samples)  # generate samples

e = vibronic.energies(formic, formic.w, formic.wp)  # convert samples to energies

plot.spectrum(e, xmin=-500, xmax=9000)

Each new addition includes an in-depth tutorial to walk you through solving the problem with a photonic quantum computer. You can also check out our paper at [1912.07634] Applications of Near-Term Photonic Quantum Computers: Software and Algorithms for further details!

We have also carried out an extensive update to our documentation. This includes a new theme and a restructure of the content to make it more accessible. Check out our new look docs at

The full release notes are available at Release Release 0.12 · XanaduAI/strawberryfields · GitHub.

As always, this release would not have been possible without all the help from our contributors:

@jmarrazola , @Tom_Bromley @Josh, Soran Jahangiri, @Nicolas_Quesada