Releases: XanaduAI/strawberryfields
Release 0.15.1
Improvements
- Adds the ability to bypass recompilation of programs if they have been compiled already to the target device. (#447)
Breaking Changes
- Changes the default compiler for devices that don't specify a default from
"Xcov"
to"Xunitary"
. This compiler is slightly more strict and only compiles the unitary, not the initial squeezers, however avoids any unintentional permutations. (#445)
Bug fixes
- Fixes a bug where a program that amounts to the identity operation would cause an error when compiled using the
xcov
compiler. (#444)
Documentation
- Updates the
README.rst
file and hardware access links. (#448)
Contributors
This release contains contributions from (in alphabetical order):
Theodor Isacsson, Josh Izaac, Nathan Killoran, Nicolás Quesada, Antal Száva
Release 0.15.0
New features since last release
-
Adds the ability to train variational GBS circuits in the applications layer. (#387) (#388) (#391) (#393) (#414) (#415)
Trainable parameters can be embedded into a VGBS class:
from strawberryfields.apps import data, train d = data.Mutag0() embedding = train.Exp(d.modes) n_mean = 5 vgbs = train.VGBS(d.adj, 5, embedding, threshold=False, samples=np.array(d[:1000]))
Properties of the variational GBS distribution for different choices of trainable parameters can then be inspected:
>>> params = 0.1 * np.ones(d.modes) >>> vgbs.n_mean(params) 3.6776094165797364
A cost function can then be created and its value and gradient accessed:
>>> h = lambda x: np.sum(x) >>> cost = train.Stochastic(h, vgbs) >>> cost(params, n_samples=1000) 3.940396998165503 >>> cost.grad(params, n_samples=1000) array([-0.54988876, -0.49270263, -0.6628071 , -1.13057762, -1.13568456, -0.70180571, -0.6266806 , -0.68803539, -1.11032533, -1.12853718, -0.59172261, -0.47830748, -0.96901676, -0.66938217, -0.85162006, -0.27188134, -0.26955011])
For more details, see the VGBS training demo.
-
Feature vectors of graphs can now be calculated exactly in the
apps.similarity
module of the applications layer. Datasets of pre-calculated feature vectors are available inapps.data
. (#390) (#401)>>> from strawberryfields.apps import data >>> from strawberryfields.apps.similarity import feature_vector_sampling >>> samples = data.Mutag0() >>> feature_vector_sampling(samples, [2, 4, 6]) [0.19035, 0.2047, 0.1539]
For more details, see the graph similarity demo.
-
A new
strawberryfields.apps.qchem
module has been introduced, centralizing all quantum chemistry applications. This includes various new features and improvements:-
Adds the
apps.qchem.duschinsky()
function for generation of the Duschinsky rotation matrix and displacement vector which are needed to simulate a vibronic process with Strawberry Fields. (#434) -
Adds the
apps.qchem.dynamics
module for simulating vibrational quantum dynamics in molecules. (#402) (#411) (#419) (#421) (#423) (#430)This includes:
-
dynamics.evolution()
constructs a custom operation that encodes the input chemical information. This custom operation can then be used within a Strawberry FieldsProgram
. -
dynamics.sample_coherent()
,dynamics.sample_fock()
anddynamics.sample_tmsv()
functions allow for generation of samples from a variety of input states. -
The probability of an excited state can then be estimated with the
dynamics.prob()
function, which calculates the relative frequency of the excited state among the generated samples. -
Finally, the
dynamics.marginals()
function generates marginal distributions.
-
-
The
sf.apps.vibronic
module has been relocated to within theqchem
module. As a result, theapps.sample.vibronic()
function is now accessible underapps.qchem.vibronic.sample()
, providing a single location for quantum chemistry functionality. (#416)
For more details, please see the qchem documentation.
-
-
The
GaussianState
returned from simulations using the Gaussian backend now has feature parity with theFockState
object returned from the Fock backends. (#407)In particular, it now supports the following methods:
GaussianState.dm()
GaussianState.ket()
GaussianState.all_fock_probs()
In addition, the existing
GaussianState.reduced_dm()
method now supports multi-mode reduced density matrices. -
Adds the
sf.utils.samples_expectation
,sf.utils.samples_variance
andsf.utils.all_fock_probs_pnr
functions for obtaining counting statistics from samples. (#399) -
Compilation of Strawberry Fields programs has been overhauled.
-
Strawberry Fields can now access the Xanadu Cloud device specifications API. The
Connection
class has a new methodConnection.get_device
, which returns aDeviceSpec
class. (#429) (#432) -
New
Xstrict
,Xcov
, andXunitary
compilers for compiling programs into the X architecture have been added. (#358) (#438) -
Finally, the
strawberryfields.circuitspecs
module has been renamed tostrawberryfields.compilers
.
-
-
Adds
diagonal_expectation
method for theBaseFockState
class, which returns the expectation value of any operator that is diagonal in the number basis. (#389) -
Adds
parity_expectation
method as an instance ofdiagonal_expectation
for theBaseFockState
class, and its own function forBaseGaussianState
. This returns the expectation value of the parity operator, defined as (-1)^N. (#389)
Improvements
-
Modifies the rectangular interferometer decomposition to make it more efficient for hardware devices. Rather than decomposing the interferometer using Clements :math:
T
matrices, the decomposition now directly produces Mach-Zehnder interferometers corresponding to on-chip phases. (#363) -
Changes the
number_expectation
method for theBaseFockState
class to be an instance ofdiagonal_expectation
. (#389) -
Increases the speed at which the following gates are generated:
Dgate
,Sgate
,BSgate
andS2gate
by relying on a recursive implementation recently introduced inthewalrus
. This has substantial effects on the speed of theFockbackend
and theTFbackend
, especially for high cutoff values. (#378) (#381) -
All measurement samples can now be accessed via the
results.all_samples
attribute, which returns a dictionary mapping the mod index to a list of measurement values. This is useful for cases where a single mode may be measured multiple times. (#433)
Breaking Changes
-
Removes support for Python 3.5. (#385)
-
Complex parameters now are expected in polar form as two separate real parameters. (#378)
Contributors
This release contains contributions from (in alphabetical order):
Juan Miguel Arrazola, Tom Bromley, Jack Ceroni, Aroosa Ijaz, Theodor Isacsson, Josh Izaac, Nathan Killoran, Soran Jahangiri, Shreya P. Kumar, Filippo Miatto, Nicolás Quesada, Antal Száva
0.14.0.post2
Post release to address changes to the documentation.
Release 0.14.0
New features since last release
-
The
"tf"
backend now supports TensorFlow 2.0 and above. (#283) (#320) (#323) (#361) (#372) (#373) (#374) (#375) (#377)For more details and demonstrations of the new TensorFlow 2.0-compatible backend, see our optimization and machine learning tutorials.
For example, using TensorFlow 2.0 to train a variational photonic circuit:
eng = sf.Engine(backend="tf", backend_options={"cutoff_dim": 7}) prog = sf.Program(1) with prog.context as q: # Apply a single mode displacement with free parameters Dgate(prog.params("a"), prog.params("p")) | q[0] opt = tf.keras.optimizers.Adam(learning_rate=0.1) alpha = tf.Variable(0.1) phi = tf.Variable(0.1) for step in range(50): # reset the engine if it has already been executed if eng.run_progs: eng.reset() with tf.GradientTape() as tape: # execute the engine results = eng.run(prog, args={'a': alpha, 'p': phi}) # get the probability of fock state |1> prob = results.state.fock_prob([1]) # negative sign to maximize prob loss = -prob gradients = tape.gradient(loss, [alpha, phi]) opt.apply_gradients(zip(gradients, [alpha, phi])) print("Value at step {}: {}".format(step, prob))
-
Adds the method
number_expectation
that calculates the expectation value of the product of the number operators of a given set of modes. (#348)prog = sf.Program(3) with prog.context as q: ops.Sgate(0.5) | q[0] ops.Sgate(0.5) | q[1] ops.Sgate(0.5) | q[2] ops.BSgate(np.pi/3, 0.1) | (q[0], q[1]) ops.BSgate(np.pi/3, 0.1) | (q[1], q[2])
Executing this on the Fock backend,
>>> eng = sf.Engine("fock", backend_options={"cutoff_dim": 10}) >>> state = eng.run(prog).state
we can compute the expectation value
<n_0 n_2>
:>>> state.number_expectation([0, 2])
Improvements
-
Add details to the error message for failed remote jobs. (#370)
-
The required version of The Walrus was increased to version 0.12, for
tensor number expectation support. (#380)
Contributors
This release contains contributions from (in alphabetical order):
Tom Bromley, Theodor Isacsson, Josh Izaac, Nathan Killoran, Filippo Miatto, Nicolás Quesada, Antal Száva, Paul Tan.
Release 0.13.0
New features since last release
-
Adds initial support for the Xanadu's photonic quantum hardware. (#101) (#148) (#294) (#327) (#328) (#329) (#330) (#334) (#336) (#337) (#339)
Jobs can now be submitted to the Xanadu Quantum Cloud platform to be run on supported hardware using the new
RemoteEngine
:import strawberryfields as sf from strawberryfields import ops from strawberryfields.utils import random_interferometer # replace AUTH_TOKEN with your Xanadu Quantum Cloud access token con = sf.api.Connection(token="AUTH_TOKEN") eng = sf.RemoteEngine("X8", connection=con) prog = sf.Program(8) U = random_interferometer(4) with prog.context as q: ops.S2gate(1.0) | (q[0], q[4]) ops.S2gate(1.0) | (q[1], q[5]) ops.S2gate(1.0) | (q[2], q[6]) ops.S2gate(1.0) | (q[3], q[7]) ops.Interferometer(U) | q[:4] ops.Interferometer(U) | q[4:] ops.MeasureFock() | q result = eng.run(prog, shots=1000)
For more details, see the photonic hardware quickstart and tutorial.
-
Significantly speeds up the Fock backend of Strawberry Fields, through a variety of changes:
-
The Fock backend now uses The Walrus high performance implementations of the displacement, squeezing, two-mode squeezing, and beamsplitter operations. (#287) (#289)
-
Custom tensor contractions which make use of symmetry relations for the beamsplitter and the two-mode squeeze gate have been added, as well as more efficient contractions for diagonal operations in the Fock basis. (#292)
-
-
New
sf
command line program for configuring Strawberry Fields for access to the Xanadu cloud platform, as well as submitting and executing jobs from the command line. (#146) (#312)The new Strawberry Fields command line program
sf
provides several utilities including:-
sf configure [--token] [--local]
: configure the connection to the cloud platform -
sf run input [--output FILE]
: submit and execute quantum programs from the command line -
sf --ping
: verify your connection to the Xanadu cloud platform
For more details, see the documentation.
-
-
New configuration functions to load configuration from keyword arguments, environment variables, and configuration files. (#298) (#306)
This includes the ability to automatically store Xanadu cloud platform credentials in a configuration file using the new function
sf.store_account("AUTHENTICATION_TOKEN")
as well as from the command line,
$ sf configure --token AUTHENTICATION_TOKEN
Configuration files can be saved globally, or locally on a per-project basis. For more details, see the configuration documentation
-
Adds configuration functions for resetting, deleting configurations, as well as displaying available configuration files. (#359)
-
Adds the
x_quad_values
andp_quad_values
methods to thestate
class. This allows calculation of x and p quadrature probability distributions by integrating across the Wigner function. (#270) -
Adds support in the applications layer for node-weighted graphs.
Sample from graphs with node weights using a special-purpose encoding (#295):
from strawberryfields.apps import sample # generate a random graph g = nx.erdos_renyi_graph(20, 0.6) a = nx.to_numpy_array(g) # define node weights # and encode into the adjacency matrix w = [i for i in range(20)] a = sample.waw_matrix(a, w) s = sample.sample(a, n_mean=10, n_samples=10) s = sample.postselect(s, min_count=4, max_count=20) s = sample.to_subgraphs(s, g)
Node weights can be input to search algorithms in the
clique
andsubgraph
modules (#296) (#297):from strawberryfields.apps import clique c = [clique.shrink(s_, g, node_select=w) for s_ in s] [clique.search(c_, g, iterations=10, node_select=w) for c_ in c]
from strawberryfields.apps import subgraph subgraph.search(s, g, min_size=5, max_size=8, node_select=w)
Improvements
-
Moved Fock backend apply-gate functions to
Circuit
class, and removedapply_gate_einsum
andCircuits._apply_gate
, since they were no longer used. (#293) -
Results returned from all backends now have a unified type and shape. In addition, attempting to use batching, post-selection and feed-foward together with multiple shots now raises an error. (#300)
-
Modified the rectangular decomposition to ensure that identity-like unitaries are implemented with no swaps. (#311)
Bug fixes
-
Symbolic Operation parameters are now compatible with TensorFlow 2.0 objects. (#282)
-
Added
sympy>=1.5
to the list of dependencies. Removed thesympy.functions.atan2
workaround now that SymPy has been fixed. (#280) -
Removed two unnecessary else statements that pylint complained about. (#290)
-
Fixed a bug in the
MZgate
, where the internal and external phases were in the wrong order in both the docstring and the argument list. The new signature isMZgate(phase_in, phase_ex)
, matching the existingrectangular_symmetric
decomposition. (#301) -
Updated the relevant methods in
RemoteEngine
andConnection
to deriveshots
from the Blackbird script orProgram
if not explicitly specified. (#327) -
Fixed a bug in homodyne measurements in the Fock backend, where computed probability values could occasionally include small negative values due to floating point precision error. (#364)
-
Fixed a bug that caused an exception when printing results with no state. (#367)
-
Improves the Takagi decomposition, by making explicit use of the eigendecomposition of real symmetric matrices. (#352)
Contributors
This release contains contributions from (in alphabetical order):
Ville Bergholm, Tom Bromley, Jack Ceroni, Theodor Isacsson, Josh Izaac, Nathan Killoran, Shreya P Kumar,
Leonhard Neuhaus, Nicolás Quesada, Jeremy Swinarton, Antal Száva, Paul Tan, Zeid Zabaneh.
Release 0.13.0.rc0
New features since last release
-
Adds initial support for the Xanadu's photonic quantum hardware. (#101) (#148) (#294) (#327) (#328) (#329) (#330) (#334) (#336) (#337) (#339)
Jobs can now be submitted to the Xanadu cloud platform to be run on supported hardware using the new
RemoteEngine
:import strawberryfields as sf from strawberryfields import ops from strawberryfields.utils import random_interferometer # replace AUTHENTICATION_TOKEN with your Xanadu cloud access token con = sf.api.Connection(token="AUTH_TOKEN") eng = sf.RemoteEngine("X8", connection=con) prog = sf.Program(8) U = random_interferometer(4) with prog.context as q: ops.S2gate(1.0) | (q[0], q[4]) ops.S2gate(1.0) | (q[1], q[5]) ops.S2gate(1.0) | (q[2], q[6]) ops.S2gate(1.0) | (q[3], q[7]) ops.Interferometer(U) | q[:4] ops.Interferometer(U) | q[4:] ops.MeasureFock() | q result = eng.run(prog, shots=1000)
For more details, see the photonic hardware quickstart and tutorial.
-
Significantly speeds up the Fock backend of Strawberry Fields, through a variety of changes:
-
The Fock backend now uses The Walrus high performance implementations of the displacement, squeezing, two-mode squeezing, and beamsplitter operations. (#287) (#289)
-
Custom tensor contractions which make use of symmetry relations for the beamsplitter and the two-mode squeeze gate have been added, as well as more efficient contractions for diagonal operations in the Fock basis. (#292)
-
-
New
sf
command line program for configuring Strawberry Fields for access to the Xanadu cloud platform, as well as submitting and executing jobs from the command line. (#146) (#312)The new Strawberry Fields command line program
sf
provides several utilities including:-
sf configure [--token] [--local]
: configure the connection to the cloud platform -
sf run input [--output FILE]
: submit and execute quantum programs from the command line -
sf --ping
: verify your connection to the Xanadu cloud platform
For more details, see the documentation.
-
-
New configuration functions to load configuration from keyword arguments, environment variables, and configuration files. (#298) (#306)
This includes the ability to automatically store Xanadu cloud platform credentials in a configuration file using the new function
sf.store_account("AUTHENTICATION_TOKEN")
as well as from the command line,
$ sf configure --token AUTHENTICATION_TOKEN
Configuration files can be saved globally, or locally on a per-project basis. For more details, see the configuration documentation
-
Adds the
x_quad_values
andp_quad_values
methods to thestate
class. This allows calculation of x and p quadrature probability distributions by integrating across the Wigner function. (#270) -
Adds support in the applications layer for node-weighted graphs.
Sample from graphs with node weights using a special-purpose encoding (#295):
from strawberryfields.apps import sample # generate a random graph g = nx.erdos_renyi_graph(20, 0.6) a = nx.to_numpy_array(g) # define node weights # and encode into the adjacency matrix w = [i for i in range(20)] a = sample.waw_matrix(a, w) s = sample.sample(a, n_mean=10, n_samples=10) s = sample.postselect(s, min_count=4, max_count=20) s = sample.to_subgraphs(s, g)
Node weights can be input to search algorithms in the
clique
andsubgraph
modules (#296) (#297):from strawberryfields.apps import clique c = [clique.shrink(s_, g, node_select=w) for s_ in s] [clique.search(c_, g, iterations=10, node_select=w) for c_ in c]
from strawberryfields.apps import subgraph subgraph.search(s, g, min_size=5, max_size=8, node_select=w)
Improvements
-
Moved Fock backend apply-gate functions to
Circuit
class, and removedapply_gate_einsum
andCircuits._apply_gate
, since they were no longer used. (#293) -
Results returned from all backends now have a unified type and shape. In addition, attempting to use batching, post-selection and feed-foward together with multiple shots now raises an error. (#300)
-
Modified the rectangular decomposition to ensure that identity-like unitaries are implemented with no swaps. (#311)
Bug fixes
-
Symbolic Operation parameters are now compatible with TensorFlow 2.0 objects. (#282)
-
Added
sympy>=1.5
to the list of dependencies. Removed thesympy.functions.atan2
workaround now that SymPy has been fixed. (#280) -
Removed two unnecessary else statements that pylint complained about. (#290)
-
Fixed a bug in the
MZgate
, where the internal and external phases were in the wrong order in both the docstring and the argument list. The new signature isMZgate(phase_in, phase_ex)
, matching the existingrectangular_symmetric
decomposition. (#301) -
Updated the relevant methods in
RemoteEngine
andConnection
to deriveshots
from the Blackbird script orProgram
if not explicitly specified. (#327)
Contributors
This release contains contributions from (in alphabetical order):
Ville Bergholm, Tom Bromley, Jack Ceroni, Theodor Isacsson, Josh Izaac, Nathan Killoran, Shreya P Kumar,
Leonhard Neuhaus, Nicolás Quesada, Jeremy Swinarton, Antal Száva, Paul Tan, Zeid Zabaneh.
Release 0.12.1
This is a very minor bugfix release, to address some installation issues with the previous v0.12.0.
-
Add new Strawberry Fields applications paper to documentation #274
-
Update figure for GBS device in documentation #275
-
Fix installation issue with incorrect minimum version number for
thewalrus
, fix an incorrect URL in theREADME
, and add the applications data to theMANIFEST.in
file. #272 #277 #273 #278
Contributors
This release contains contributions from (in alphabetical order):
Ville Bergholm, Tom Bromley, Nicolás Quesada, Paul Tan
Release 0.12
New features
-
A new applications layer, allowing users to interface samples generated from near-term photonic devices with problems of practical interest. The
apps
package consists of the following modules:-
The
apps.sample
module, for encoding graphs and molecules into Gaussian boson sampling (GBS) and generating corresponding samples. -
The
apps.subgraph
module, providing a heuristic algorithm for finding dense subgraphs from GBS samples. -
The
apps.clique
module, providing tools to convert subgraphs sampled from GBS into cliques and a heuristic to search for larger cliques. -
The
apps.similarity
module, allowing users to embed graphs into high-dimensional feature spaces using GBS. Resulting feature vectors provide measures of graph similarity for machine learning tasks. -
The
apps.points
module, allowing users to sample subsets of points according to new point process that can be generated from a GBS device. -
The
apps.vibronic
module, providing functionality to construct the vibronic absorption spectrum of a molecule from GBS samples.
-
Improvements
-
The documentation was improved and refactored. Changes include:
Contributors
This release contains contributions from (in alphabetical order):
Juan Miguel Arrazola, Tom Bromley, Josh Izaac, Soran Jahangiri, Nicolás Quesada
Version 0.11.2
New features
-
Adds the MZgate to ops.py, representing a Mach-Zehnder interferometer. This is not a primitive of the existing simulator backends; rather,
_decompose()
is defined, decomposing it into an external phase shift, two 50-50 beamsplitters, and an internal phase shift. #127 -
The
Chip0Spec
circuit class now defines acompile
method, allowing arbitrary unitaries comprised of{Interferometer, BSgate, Rgate, MZgate}
operations to be validated and compiled to match the topology of chip0. #127 -
strawberryfields.ops.BipartiteGraphEmbed
quantum decomposition now added, allowing a bipartite graph to be embedded on a device that allows for initial two-mode squeezed states, and block diagonal unitaries. -
Added threshold measurements, via the new operation
MeasureThreshold
, and provided implementation of this operation in the Gaussian backend. #152 -
Programs can now have free parameters/arguments which are only bound to numerical values when the Program is executed, by supplying the actual argument values to the
Engine.run
method. #163
API Changes
-
The
strawberryfields.ops.Measure
shorthand has been deprecated in favour ofstrawberryfields.ops.MeasureFock()
. #145 -
Several changes to the
strawberryfields.decompositions
module: #127-
The name
clements
has been replaced withrectangular
to correspond with the shape of the resulting decomposition. -
All interferometer decompositions (
rectangular
,rectangular_phase_end
,rectangular_symmetric
, andtriangular
) now have standardized outputs(tlist, diag, tilist)
, so they can easily be swapped.
-
-
Several changes to
ops.Interferometer
: #127-
The calculation of the ops.Interferometer decomposition has been moved from
__init__
to_decompose()
, allowing the interferometer decomposition type to be set by aCircuitSpec
during compilation. -
**kwargs
is now passed through fromOperation.decompose
->Gate.decompose
->SpecificOp._decompose
, allowing decomposition options to be passed during compilation. -
ops.Interferometer
now accepts the keyword argumentmesh
to be set during initialization, allowing the user to specify the decomposition they want.
-
-
Moves the
Program.compile_seq
method toCircuitSpecs.decompose
. This allows it to be accessed from theCircuitSpec.compile
method. Furthermore, it now must also be passed the program registers, as compilation may sometimes require this. #127 -
Parameter class is replaced by
MeasuredParameter
andFreeParameter
, both inheriting fromsympy.Symbol
. Fixed numeric parameters are handled by the built-in Python numeric classes and numpy arrays. #163 -
Parameter
,RegRefTransform
andconvert
are removed. #163
Improvements
-
Photon-counting measurements can now be done in the Gaussian backend for states with nonzero displacement. #154
-
Added a new test for the cubic phase gate #160
-
Added new integration tests for the Gaussian gates that are not primitive, i.e., P, CX, CZ, and S2. #173
Bug fixes
-
Fixed bug in
strawberryfields.decompositions.rectangular_symmetric
so its returned phases are all in the interval [0, 2*pi), and corrects the function docstring. #196 -
When using the
'gbs'
compilation target, the measured registers are now sorted in ascending order in the resulting compiled program. #144 -
Fixed typo in the Gaussian Boson Sampling example notebook. #133
-
Fixed a bug in the function
smeanxp
of the Gaussian Backend simulator. #154 -
Clarified description of matrices that are accepted by graph embed operation. #147
-
Fixed typos in the documentation of the CX gate and BSgate #166 #167 #169
Release 0.11.1
Improvements
-
Added the
circuit_spec
attribute toBaseBackend
to denote which CircuitSpecs class should be used to validate programs for each backend #125. -
Removed the
return_state
keyword argument fromLocalEngine.run()
. Now no state object is returned ifmodes==[]
. #126
Bug fixes
-
Fixed a typo in the boson sampling tutorial. #133
-
Allows imported Blackbird programs to store
target
options as default run options. During eng.run, if no run options are provided as a keyword argument, the engine will fall back on the run options stored within the program.This fixes a bug where shots specified in Blackbird scripts were not being passed to
eng.run
. #130 -
Removes
ModuleNotFoundError
from the codebase, replacing all occurrences withImportError
. SinceModuleNotFoundError
was only introduced in Python 3.6+, this fixes a bug where Strawberry Fields was not importable on Python 3.5 #124. -
Updates the Chip0 template to use MeasureFock() | [0, 1, 2, 3], which will allow correct fock measurement behaviour when simulated on the Gaussian backend. #124
-
Fixed a bug in the
GraphEmbed
op, which was not correctly determining when a unitary was the identity #128.