sf.apps.sample¶
Functionality for generating GBS samples using classical simulators.
See also
Generating samples¶
An \(M\) mode GBS device can be programmed by specifying an \((M \times M)\)dimensional symmetric matrix \(A\) [49]. Running this device results in samples that carry relevant information about the encoded matrix \(A\). When sampling, one must also specify the mean number of photons in the device, the form of detection used at the output: threshold detection or photonnumberresolving (PNR) detection, as well as the amount of loss.
The sample()
function provides a simulation of sampling from GBS.
Here, each output sample is an \(M\)dimensional list. If threshold detection is used
(threshold = True
), each element of a sample is either a zero (denoting no photons detected)
or a one (denoting one or more photons detected), conventionally called a “click”.
If photonnumber resolving (PNR) detection is used (threshold = False
) then elements of a
sample are nonnegative integers counting the number of photons detected in each mode. The loss
parameter allows for simulation of photon loss in the device, which is the most common form of
noise in quantum photonics. Here, loss = 0
describes ideal lossfree GBS, while generally
0 <= loss <= 1
describes the proportion of photons lost while passing through the device.
Samples can be postselected based upon their total number of photons or clicks and the numpy
random seed used to generate samples can be fixed.
The vibronic()
function allows users to sample Gaussian states for computing molecular
vibronic spectra.
Generating subgraphs¶
There are two forms to represent a sample from a GBS device:
In the form returned by
sample()
, each sample is a length \(M\) list of counts in each mode, e.g., the sample[2, 1, 2, 0, 1]
denotes two photons in mode 0, 1 photon in mode 1, and so forth.The alternative representation is a list of modes where photons or clicks were observed, e.g., the above sample can be written alternatively as
[0, 0, 1, 2, 2, 4]
.
Converting from the former representation to the latter can be achieved with:
Convert a list of counts to a list of modes where photons or clicks were observed. 
Graphs can be encoded into GBS through their adjacency matrix. Resultant samples
can then be used to pick out nodes from the graph to form a subgraph. If threshold detection is
used, any nodes that click are selected as part of the subgraph. For example, if a sample is
[1, 1, 1, 0, 1]
then the corresponding subgraph has nodes [0, 1, 2, 4]
. This can be found
using:
>>> modes_from_counts([1, 1, 1, 0, 1])
[0, 1, 2, 4]
A collection of GBS samples from a graph, given by sample()
in the first form, can be
converted to subgraphs using:

Converts samples to their subgraph representation. 
A typical workflow would be:
>>> g = nx.erdos_renyi_graph(5, 0.7)
>>> a = nx.to_numpy_array(g)
>>> s = sample(a, 3, 4)
>>> s = to_subgraphs(s, g)
[[0, 2], [0, 1, 2, 4], [1, 2, 3, 4], [1]]
The subgraphs sampled from GBS are likely to be dense [44], motivating their
use within heuristics for problems such as maximum clique (see clique
).
Functions
Convert a list of counts to a list of modes where photons or clicks were observed. 


Postselect samples by imposing a minimum and maximum number of photons or clicks. 

Generate simulated samples from GBS encoded with a symmetric matrix \(A\). 

Seed for random number generators. 

Converts samples to their subgraph representation. 

Generate samples for computing vibronic spectra. 
Contents
Downloads