# Quantum operations¶

Module name: strawberryfields.ops

Note

In the strawberryfields.ops API we use the convention $$\hbar=2$$ by default, however this can be changed on engine initialisation.

See Conventions and formulas for more details.

This module defines and implements the Python-embedded quantum programming language for continuous-variable (CV) quantum systems. The syntax is modeled after ProjectQ [40].

Quantum operations (state preparation, unitary gates, measurements, channels) act on register objects using the following syntax:

with eng:
G(params) | q
F(params) | (q[1], q[6], q[2])


Here eng is an instance of strawberryfields.engine.Engine and defines the context in which the commands are executed. Within each command, the part on the left is an Operation instance, quite typically a constructor call for the requested operation class with the relevant parameters. The vertical bar calls the __or__() method of the Operation object, with the part on the right as the parameter. The part on the right is a single strawberryfields.engine.RegRef object or, for multi-mode gates, a sequence of them. It is of course also possible to construct gates separately and reuse them several times:

R = Rgate(s)
with eng:
R   | q
Xgate(t) | q
R.H | q


There are six kinds of Operation objects:

• Preparation operations only manipulate the register state:

eng, q = sf.Engine(3)
with eng:
Vac | q[0]
All(Coherent(0.4, 0.2)) | (q[1], q[2])

• Transformations such as Gate and Channel operations only manipulate the register state:

eng, q = sf.Engine(2)
with eng:
Dgate(0.3)   | q[0]
BSgate(-0.5) | q[0:2]

• Measurement operations manipulate the register state and produce classical information. The information is directly available only after the simulation has been run up to the point of measurement:

eng, q = sf.Engine(2)
with eng:
Measure       | q[0]
eng.run()
Dgate(q[0].val) | q[1]


Alternatively one may use a symbolic reference to the register containing the measurement result by supplying registers as the argument to an Operation, in which case the measurement may be deferred, i.e., we may symbolically use the measurement result before it exists:

eng, (alice, bob) = sf.Engine(2)
with eng:
Measure   | alice
Dgate(alice) | bob
eng.run()


One may also include an arbitrary post-processing function for the measurement result, to be applied before using it as the argument to another Operation. The convert() decorator can be used in Python to convert a user-defined function into a post-processing function recognized by the engine:

@convert
def square(q):
return q ** 2

eng, q = sf.Engine(2)
with eng:
Measure           | q[0]
Dgate(square(q[0])) | q[1]
eng.run()


Finally, the lower-level strawberryfields.engine.RegRefTransform (RR) and an optional lambda function can be used to achieve the same functionality:

eng, q = sf.Engine(3)
with eng:
Measure       | q[0]
Dgate(RR(q[0])) | q[1]
Dgate(RR(q[0], lambda q: q ** 2)) | q[2]
eng.run()

• Meta-operations such as Delete and New_modes Operations delete and create modes during program execution. In practice the user only deals with the pre-constructed instances Del and New:

eng, (alice,) = sf.Engine(1)
with eng:
Sgate(1)    | alice
bob, charlie = New(2)
BSgate(0.5) | (alice, bob)
CXgate(1)   | (alice, charlie)
Del         | alice
S2gate(0.4) | (charlie, bob)

• Finally, Decomposition operations are a special case, and can act as either transformations or state preparation, depending on the decomposition used. Decompositions calculate the required elementary Gate and/or Preparation objects and parameters in order to decompose specific transformations or states. Examples of objects that are supported by decompositions include covariance matrices, interferometers, and symplectic transformations.

## Base classes¶

The abstract base class hierarchy exists to provide the correct semantics for the actual operations that inherit them.

 Operation(par) Abstract base class for quantum operations acting on one or more subsystems. Preparation(par) Abstract base class for operations that demolish the previous state of the subsystem entirely. Transformation(par) Abstract base class for transformations. Gate(par) Abstract base class for unitary quantum gates. Channel(par) Abstract base class for channels. Measurement(par[, select]) Abstract base class for projective subsystem measurements. Decomposition(par) Abstract base class for decompositions. MetaOperation() Abstract base class for metaoperations.

## Operation class¶

All Operations have the following methods.

 __str__() String representation for the Operation using Blackbird syntax. __or__(reg) Apply the operation to a part of a quantum register. merge(other) Merge the operation with another (acting on the exact same set of subsystems). decompose(reg) Decompose the operation into elementary operations supported by the backend API. apply(reg, backend, hbar, **kwargs) Ask a backend to execute the operation on the current register state right away. _apply(reg, backend, **kwargs) Internal apply method.

## State preparation¶

 Vacuum() Prepare a mode in the vacuum state. Coherent([a, p]) Prepare a mode in a coherent state. Squeezed([r, p]) Prepare a mode in a squeezed vacuum state. DisplacedSqueezed([alpha, r, p]) Prepare a mode in a displaced squeezed state. Thermal([n]) Prepare a mode in a thermal state. Fock([n]) Prepare a mode in a Fock basis state. Catstate([alpha, p]) Prepare a mode in a cat state. Ket(state) Prepare mode(s) using the given ket vector(s) in the Fock basis. DensityMatrix(state) Prepare mode(s) using the given density matrix in the Fock basis. Gaussian(V[, r, decomp, hbar, tol]) Prepare the specified modes in a Gaussian state.

## Measurements¶

 MeasureFock([select]) Photon counting measurement: measures a set of modes in the Fock basis. MeasureHomodyne(phi[, select]) Performs a homodyne measurement, measures one quadrature of a mode. MeasureHeterodyne([select]) Performs a heterodyne measurement on a mode.

## Channels¶

 LossChannel(T) Perform a loss channel operation on the specified mode. ThermalLossChannel(T, nbar) Perform a thermal loss channel operation on the specified mode.

## Decompositions¶

 Interferometer(U[, tol]) Apply a linear interferometer to the specified qumodes. GraphEmbed(A[, max_mean_photon, …]) Embed a graph into an interferometer setup. GaussianTransform(S[, hbar, vacuum, tol]) Apply a Gaussian symplectic transformation to the specified qumodes. Gaussian(V[, r, decomp, hbar, tol]) Prepare the specified modes in a Gaussian state.

## Single-mode gates¶

 Dgate(a[, phi]) Phase space displacement gate. Xgate(x) Position displacement gate. Zgate(p) Momentum displacement gate. Sgate(r[, phi]) Phase space squeezing gate. Rgate(theta) Rotation gate. Pgate(s) Quadratic phase gate. Vgate(gamma) Cubic phase gate. Fouriergate() Fourier gate.

## Two-mode gates¶

 BSgate([theta, phi]) Beamsplitter gate. S2gate(r[, phi]) Two-mode squeezing gate. CXgate([s]) Controlled addition or sum gate in the position basis. CZgate([s]) Controlled phase gate in the position basis. CKgate(kappa) Cross-Kerr gate.

## Meta-operations¶

 All(op) Metaoperation for applying a single-mode operation to every mode in the register. New_modes() Used for adding new modes to the system. Delete() Deletes one or more existing modes.

## Operations shortcuts¶

Several of the operation classes described below come with variables that point to pre-constructed instances; this is to provide shorthands for operations that accept no arguments, as well as for common variants of operations that do.

 Shorthand variable Operation New New_modes Del Delete Vac Vacuum Fourier Fouriergate Measure MeasureFock MeasureX MeasureHomodyne ($$\phi=0$$), $$x$$ quadrature measurement MeasureP MeasureHomodyne ($$\phi=\pi/2$$), $$p$$ quadrature measurement MeasureHD MeasureHeterodyne RR Alias for RegRefTransform

### Code details¶

strawberryfields.ops.warning_on_one_line(message, category, filename, lineno, file=None, line=None)[source]

User warning formatter

class strawberryfields.ops.Operation(par)[source]

Abstract base class for quantum operations acting on one or more subsystems.

The extra_deps instance variable is a set containing the RegRef the Operation depends on. In the quantum diagram notation it corresponds to the vertical double lines of classical information entering the Operation that originate in a measurement of a subsystem.

This abstract base class may be initialised with parameters; see the Parameter class for more details.

Parameters: par (Sequence[..]) – parameters. len(par) >= 1. Alternatively, set to [] or None to allow initialisation with no parameters.
p = None

list[Parameter]

extra_deps

Extra dependencies due to parameters that depend on deferred measurements.

Returns: dependencies set[RegRef]
merge(other)[source]

Merge the operation with another (acting on the exact same set of subsystems).

Note

For subclass overrides: merge may return a newly created object, or self, or other, but it must never modify self or other because the same Operation objects may be also used elsewhere.

Parameters: other (Operation) – operation to merge this one with other * self. The return value None represents the identity gate (doing nothing). Operation, None MergeFailure – if the two operations cannot be merged
decompose(reg)[source]

Decompose the operation into elementary operations supported by the backend API.

Parameters: reg (Sequence[RegRef]) – subsystems the operation is acting on decomposition as a list of operations acting on specific subsystems list[Command]
apply(reg, backend, hbar, **kwargs)[source]

Ask a backend to execute the operation on the current register state right away.

Takes care of parameter evaluations and any pending formal transformations (like dagger) and then calls _apply.

Parameters: Keyword Arguments: reg (Sequence[RegRef]) – subsystem(s) the operation is acting on backend (BaseBackend) – backend to execute the operation eval_params (bool) – set this to False to explicitly turn off the evaluation of parameters in the Operation.apply method. This is useful if the parameters are pre-evaluated prior to calling this method. The result of self._apply
class strawberryfields.ops.Preparation(par)[source]

Abstract base class for operations that demolish the previous state of the subsystem entirely.

merge(other)[source]

Merge the operation with another (acting on the exact same set of subsystems).

Note

For subclass overrides: merge may return a newly created object, or self, or other, but it must never modify self or other because the same Operation objects may be also used elsewhere.

Parameters: other (Operation) – operation to merge this one with other * self. The return value None represents the identity gate (doing nothing). Operation, None MergeFailure – if the two operations cannot be merged
class strawberryfields.ops.Measurement(par, select=None)[source]

Abstract base class for projective subsystem measurements.

The measurement is deferred: its result is available only after the backend has executed it. The value of the measurement can be accessed in the program through the symbolic subsystem reference to the measured subsystem.

When the measurement happens, the state of the circuit is updated to the conditional state corresponding to the measurement result. Measurements also support postselection, see below.

Parameters: select (None, Sequence[Number]) – Desired values of the measurement results, one for each subsystem the measurement acts on. Allows the post-selection of specific measurement results instead of randomly sampling. None means no postselection.
select = None

postselection values, one for each measured subsystem

Type: None, Sequence[Number]
merge(other)[source]

Merge the operation with another (acting on the exact same set of subsystems).

Note

For subclass overrides: merge may return a newly created object, or self, or other, but it must never modify self or other because the same Operation objects may be also used elsewhere.

Parameters: other (Operation) – operation to merge this one with other * self. The return value None represents the identity gate (doing nothing). Operation, None MergeFailure – if the two operations cannot be merged
apply(reg, backend, hbar, **kwargs)[source]

Ask a backend to execute the operation on the current register state right away.

Like Operation.apply(), but also stores the measurement result in the RegRefs.

class strawberryfields.ops.Decomposition(par)[source]

Abstract base class for decompositions.

This class provides the base behaviour for decomposing various objects into a sequence of gates and state preparations.

merge(other)[source]

Merge the operation with another (acting on the exact same set of subsystems).

Note

For subclass overrides: merge may return a newly created object, or self, or other, but it must never modify self or other because the same Operation objects may be also used elsewhere.

Parameters: other (Operation) – operation to merge this one with other * self. The return value None represents the identity gate (doing nothing). Operation, None MergeFailure – if the two operations cannot be merged
class strawberryfields.ops.Transformation(par)[source]

Abstract base class for transformations.

This class provides the base behaviour for operations which act on existing states.

class strawberryfields.ops.Channel(par)[source]

Abstract base class for channels.

This class provides the base behaviour for non-unitary maps and transformations.

merge(other)[source]

Merge the operation with another (acting on the exact same set of subsystems).

Note

For subclass overrides: merge may return a newly created object, or self, or other, but it must never modify self or other because the same Operation objects may be also used elsewhere.

Parameters: other (Operation) – operation to merge this one with other * self. The return value None represents the identity gate (doing nothing). Operation, None MergeFailure – if the two operations cannot be merged
class strawberryfields.ops.Gate(par)[source]

Abstract base class for unitary quantum gates.

The first parameter p[0] of the Gate class is special:

• The value p[0] = 0 corresponds to the identity gate.
• The inverse gate is obtained by negating p[0].
• Two gates of this class can be merged by adding the first parameters together, assuming all the other parameters match.
dagger = None

formal inversion of the gate

Type: bool
H

Returns a copy of the gate with the self.dagger flag flipped.

H stands for hermitian conjugate.

Returns: formal inverse of this gate Gate
apply(reg, backend, hbar, **kwargs)[source]

Ask a backend to execute the operation on the current register state right away.

Like Operation.apply(), but takes into account the special nature of p[0] and applies self.dagger.

Returns: Gates do not return anything, return value is None None
merge(other)[source]

Merge the operation with another (acting on the exact same set of subsystems).

Note

For subclass overrides: merge may return a newly created object, or self, or other, but it must never modify self or other because the same Operation objects may be also used elsewhere.

Parameters: other (Operation) – operation to merge this one with other * self. The return value None represents the identity gate (doing nothing). Operation, None MergeFailure – if the two operations cannot be merged
class strawberryfields.ops.Vacuum[source]

Prepare a mode in the vacuum state.

Can be accessed via the shortcut variable Vac.

class strawberryfields.ops.Coherent(a=0.0, p=0.0)[source]

Prepare a mode in a coherent state.

The gate is parameterized so that a user can specify a single complex number $$a=\alpha$$ or use the polar form $$a = r, p=\phi$$ and still get the same result.

Parameters: a (complex) – displacement parameter $$\alpha$$ p (float) – phase angle $$\phi$$
class strawberryfields.ops.Squeezed(r=0.0, p=0.0)[source]

Prepare a mode in a squeezed vacuum state.

Parameters: r (float) – squeezing magnitude p (float) – squeezing angle $$\phi$$
class strawberryfields.ops.DisplacedSqueezed(alpha=0.0, r=0.0, p=0.0)[source]

Prepare a mode in a displaced squeezed state.

A displaced squeezed state is prepared by squeezing a vacuum state, and then applying a displacement operator.

$\ket{\alpha,z} = D(\alpha)\ket{0,z} = D(\alpha)S(z)\ket{0},$

where the squeezing parameter $$z=re^{i\phi}$$.

Parameters: alpha (complex) – displacement parameter r (float) – squeezing magnitude p (float) – squeezing angle $$\phi$$
class strawberryfields.ops.Fock(n=0)[source]

Prepare a mode in a Fock basis state.

The prepared mode is traced out and replaced with the Fock state $$\ket{n}$$. As a result the state of the other subsystems may have to be described using a density matrix.

Parameters: n (int) – Fock state to prepare
class strawberryfields.ops.Catstate(alpha=0, p=0)[source]

Prepare a mode in a cat state.

A cat state is the coherent superposition of two coherent states,

$\ket{\text{cat}(\alpha)} = \frac{1}{N} (\ket{\alpha} +e^{i\phi} \ket{-\alpha}),$

where $$N = \sqrt{2 (1+\cos(\phi)e^{-2|\alpha|^2})}$$ is the normalization factor.

This is a Strawberry Fields quantum gate operator, and thus is used within an engine context as follows:

with eng:
Catstate(1, 0.2) | q[0]

Parameters: alpha (complex) – displacement parameter p (float) – parity, where $$\phi=p\pi$$. p=0 corresponds to an even cat state, and p=1 an odd cat state.
class strawberryfields.ops.Ket(state)[source]

Prepare mode(s) using the given ket vector(s) in the Fock basis.

The prepared modes are traced out and replaced with the given ket state (in the Fock basis). As a result the state of the other subsystems may have to be described using a density matrix.

The provided kets must be each be of length cutoff_dim, matching the cutoff dimension used in calls to eng.run.

Parameters: state (array or BaseFockState) – state vector in the Fock basis. This can be provided as either: a single ket vector, for single mode state preparation a multimode ket, with one array dimension per mode a BaseFockState state object.
class strawberryfields.ops.DensityMatrix(state)[source]

Prepare mode(s) using the given density matrix in the Fock basis.

The prepared modes are traced out and replaced with the given state (in the Fock basis). As a result, the overall state of system will also have to be described using a density matrix.

The provided density matrices must be of size [cutoff_dim, cutoff_dim], matching the cutoff dimension used in calls to eng.run.

Parameters: state (array or BaseFockState) – density matrix in the Fock basis. This can be provided as either: a single mode two-dimensional matrix $$\rho_{ij}$$, a multimode tensor $$\rho_{ij,kl,\dots,mn}$$, with two indices per mode, a BaseFockState state object.
class strawberryfields.ops.Thermal(n=0)[source]

Prepare a mode in a thermal state.

The requested mode is traced out and replaced with the thermal state $$\rho(\bar{n})$$. As a result the state will be described using a density matrix.

Parameters: n (float) – mean thermal population of the mode
class strawberryfields.ops.MeasureFock(select=None)[source]

Photon counting measurement: measures a set of modes in the Fock basis.

Also accessible via the shortcut variable Measure.

The modes are projected to the Fock state corresponding to the result of the measurement.

class strawberryfields.ops.MeasureHomodyne(phi, select=None)[source]

Performs a homodyne measurement, measures one quadrature of a mode.

• Position basis measurement: $$\phi = 0$$ (also accessible via the shortcut variable MeasureX).
• Momentum basis measurement: $$\phi = \pi/2$$. (also accessible via the shortcut variable MeasureP)

The measured mode is reset to the vacuum state.

Parameters: phi (float) – measurement angle $$\phi$$ select (None, float) – (Optional) desired values of measurement result. Allows the post-selection of specific measurement results instead of randomly sampling.
class strawberryfields.ops.MeasureHeterodyne(select=None)[source]

Performs a heterodyne measurement on a mode.

Also accessible via the shortcut variable MeasureHD.

Samples the joint Husimi distribution $$Q(\vec{\alpha}) = \frac{1}{\pi}\bra{\vec{\alpha}}\rho\ket{\vec{\alpha}}$$. The measured mode is reset to the vacuum state.

Parameters: select (None, complex) – (Optional) desired values of measurement result. Allows the post-selection of specific measurement results instead of randomly sampling.
class strawberryfields.ops.LossChannel(T)[source]

Perform a loss channel operation on the specified mode.

This channel couples mode $$\a$$ to another bosonic mode $$\hat{b}$$ prepared in the vacuum state using the following transformation:

$\a \mapsto \sqrt{T} a+\sqrt{1-T} \hat{b}$
Parameters: T (float) – the loss parameter $$0\leq T\leq 1$$.
class strawberryfields.ops.ThermalLossChannel(T, nbar)[source]

Perform a thermal loss channel operation on the specified mode.

This channel couples mode $$\a$$ to another bosonic mode $$\hat{b}$$ prepared in a thermal state with mean photon number $$\bar{n}$$, using the following transformation:

$\a \mapsto \sqrt{T} a+\sqrt{1-T} \hat{b}$
Parameters: T (float) – the loss parameter $$0\leq T\leq 1$$. nbar (float) – mean photon number of the environment thermal state
class strawberryfields.ops.Dgate(a, phi=0.0)[source]

Phase space displacement gate.

$D(\alpha) = \exp(\alpha a^\dagger -\alpha^* a) = \exp\left(-i\sqrt{2}(\re(\alpha) \hat{p} -\im(\alpha) \hat{x})/\sqrt{\hbar}\right)$

where $$\alpha = r e^{i\phi}$$ has magnitude $$r\geq 0$$ and phase $$\phi$$.

The gate is parameterized so that a user can specify a single complex number $$a=\alpha$$ or use the polar form $$a = r, \phi$$ and still get the same result.

Parameters: a (complex) – displacement parameter $$\alpha$$ phi (float) – extra (optional) phase angle $$\phi$$
class strawberryfields.ops.Xgate(x)[source]

Position displacement gate.

$X(x) = e^{-i x \hat{p}/\hbar}$
Parameters: x (float) – position displacement
class strawberryfields.ops.Zgate(p)[source]

Momentum displacement gate.

$Z(p) = e^{i p \hat{x}/\hbar}$
Parameters: p (float) – momentum displacement
class strawberryfields.ops.Sgate(r, phi=0.0)[source]

Phase space squeezing gate.

$S(z) = \exp\left(\frac{1}{2}(z^* a^2 -z {a^\dagger}^2)\right)$

where $$z = r e^{i\phi}$$.

Parameters: r (float) – squeezing amount phi (float) – squeezing phase angle $$\phi$$
class strawberryfields.ops.Pgate(s)[source]

$P(s) = e^{i \frac{s}{2} \hat{x}^2/\hbar}$
Parameters: s (float) – parameter
decompose(reg)[source]

Decompose the operation into elementary operations supported by the backend API.

Parameters: reg (Sequence[RegRef]) – subsystems the operation is acting on decomposition as a list of operations acting on specific subsystems list[Command]
class strawberryfields.ops.Vgate(gamma)[source]

Cubic phase gate.

$V(\gamma) = e^{i \frac{\gamma}{3} \hat{x}^3/\hbar}$

Warning

The cubic phase gate has lower accuracy than the Kerr gate at the same cutoff dimension.

Parameters: gamma (float) – parameter
class strawberryfields.ops.Kgate(kappa)[source]

Kerr gate.

$K(\kappa) = e^{i \kappa \hat{n}^2}$
Parameters: kappa (float) – parameter
class strawberryfields.ops.Rgate(theta)[source]

Rotation gate.

$R(\theta) = e^{i \theta a^\dagger a}$
Parameters: theta (float) – rotation angle $$\theta$$.
class strawberryfields.ops.BSgate(theta=pi/4, phi=0.)[source]

Beamsplitter gate.

$B(\theta,\phi) = \exp\left(\theta (e^{i \phi} a^\dagger b -e^{-i \phi}a b^\dagger) \right)$
Parameters: theta (float) – Transmittivity angle $$\theta$$. The transmission amplitude of the beamsplitter is $$t = \cos(\theta)$$. The value $$\theta=\pi/4$$ gives the 50-50 beamsplitter (default). phi (float) – Phase angle $$\phi$$. The reflection amplitude of the beamsplitter is $$r = e^{i\phi}\sin(\theta)$$. The value $$\phi = \pi/2$$ gives the symmetric beamsplitter.
class strawberryfields.ops.S2gate(r, phi=0.0)[source]

Two-mode squeezing gate.

$S_2(z) = \exp\left(z^* ab -z a^\dagger b^\dagger \right) = \exp\left(r (e^{-i\phi} ab -e^{i\phi} a^\dagger b^\dagger \right)$

where $$z = r e^{i\phi}$$.

Parameters: r (float) – squeezing amount phi (float) – squeezing phase angle $$\phi$$
decompose(reg)[source]

Decompose the operation into elementary operations supported by the backend API.

Parameters: reg (Sequence[RegRef]) – subsystems the operation is acting on decomposition as a list of operations acting on specific subsystems list[Command]
class strawberryfields.ops.CXgate(s=1)[source]

Controlled addition or sum gate in the position basis.

$\text{CX}(s) = \int dx \ket{x}\bra{x} \otimes D\left({\frac{1}{\sqrt{2\hbar}}}s x\right) = e^{-i s \: \hat{x} \otimes \hat{p}/\hbar}$

In the position basis it maps $$\ket{x_1, x_2} \mapsto \ket{x_1, s x_1 +x_2}$$.

Parameters: s (float) – addition multiplier
decompose(reg)[source]

Decompose the operation into elementary operations supported by the backend API.

Parameters: reg (Sequence[RegRef]) – subsystems the operation is acting on decomposition as a list of operations acting on specific subsystems list[Command]
class strawberryfields.ops.CZgate(s=1)[source]

Controlled phase gate in the position basis.

$\text{CZ}(s) = \iint dx dy \: e^{i sxy/\hbar} \ket{x,y}\bra{x,y} = e^{i s \: \hat{x} \otimes \hat{x}/\hbar}$

In the position basis it maps $$\ket{x_1, x_2} \mapsto e^{i s x_1 x_2/\hbar} \ket{x_1, x_2}$$.

Parameters: s (float) – phase shift multiplier
decompose(reg)[source]

Decompose the operation into elementary operations supported by the backend API.

Parameters: reg (Sequence[RegRef]) – subsystems the operation is acting on decomposition as a list of operations acting on specific subsystems list[Command]
class strawberryfields.ops.CKgate(kappa)[source]

Cross-Kerr gate.

$CK(\kappa) = e^{i \kappa \hat{n}_1\hat{n}_2}$
Parameters: kappa (float) – parameter
class strawberryfields.ops.Fouriergate[source]

Fourier gate.

Also accessible via the shortcut variable Fourier.

A special case of the phase space rotation gate, where $$\theta=\pi/2$$.

$F = R(\pi/2) = e^{i (\pi/2) a^\dagger a}$
class strawberryfields.ops.MetaOperation[source]

Abstract base class for metaoperations.

This includes subsystem creation and deletion.

class strawberryfields.ops.Delete[source]

Deletes one or more existing modes. Also accessible via the shortcut variable Del.

The deleted modes are traced out. After the deletion the state of the remaining subsystems may have to be described using a density operator.

class strawberryfields.ops.New_modes[source]

Used for adding new modes to the system. Also accessible via the shortcut variable New.

The new modes are prepapred in the vacuum state.

This class cannot be used with the __or__() syntax since it would be misleading, instead we use __call__() on a single instance to dispatch the command to the engine.

class strawberryfields.ops.All(op)[source]

Metaoperation for applying a single-mode operation to every mode in the register.

Parameters: op (Operation) – single-mode operation to apply
op = None

one-subsystem operation to apply

Type: Operation
class strawberryfields.ops.Interferometer(U, tol=1e-11)[source]

Apply a linear interferometer to the specified qumodes.

This operation uses the Clements decomposition to decompose a linear interferometer into a sequence of beamsplitters and rotation gates.

Parameters: U (array) – an $$N\times N$$ complex unitary matrix. tol (float) – the tolerance used when checking if the matrix is unitary: $$|UU^\dagger-I| \leq tol$$
decompose(reg)[source]

Decompose the operation into elementary operations supported by the backend API.

Parameters: reg (Sequence[RegRef]) – subsystems the operation is acting on decomposition as a list of operations acting on specific subsystems list[Command]
class strawberryfields.ops.GraphEmbed(A, max_mean_photon=1.0, make_traceless=True, tol=1e-06)[source]

Embed a graph into an interferometer setup.

This operation uses the Takagi decomposition to decompose an adjacency matrix into a sequence of squeezers and beamsplitters and rotation gates.

Parameters: A (array) – an $$N\times N$$ complex or real symmetric matrix max_mean_photon (float) – threshold value. It guarantees that the mode with the largest squeezing has max_mean_photon as the mean photon number i.e., $$sinh(r_{max})^2 == max_mean_photon$$ make_traceless (boolean) – removes the trace of the input matrix tol (float) – the tolerance used when checking if the input matrix is symmetric: $$|A-A^T| < tol$$
decompose(reg)[source]

Decompose the operation into elementary operations supported by the backend API.

Parameters: reg (Sequence[RegRef]) – subsystems the operation is acting on decomposition as a list of operations acting on specific subsystems list[Command]
class strawberryfields.ops.GaussianTransform(S, hbar=None, vacuum=False, tol=1e-10)[source]

Apply a Gaussian symplectic transformation to the specified qumodes.

This operation uses the Bloch-Messiah decomposition to decompose a symplectic matrix $$S$$:

$S = O_1 R O_2$

where $$O_1$$ and $$O_2$$ are two orthogonal symplectic matrices (and thus passive Gaussian transformations), and $$R$$ is a squeezing transformation in the phase space ($$R=\text{diag}(e^{-z},e^z)$$).

The symplectic matrix describing the Gaussian transformation on $$N$$ modes must satisfy

$\begin{split}S\Omega S^T = \Omega, ~~\Omega = \begin{bmatrix}0&I\\-I&0\end{bmatrix}\end{split}$

where $$I$$ is the $$N\times N$$ identity matrix, and $$0$$ is the zero matrix.

The two orthogonal symplectic unitaries describing the interferometers are then further decomposed via the Interferometer operator and the Clements decomposition:

$U_i = X_i + iY_i$

where

$\begin{split}O_i = \begin{bmatrix}X&-Y\\Y&X\end{bmatrix}\end{split}$
Parameters: S (array) – a $$2N\times 2N$$ symplectic matrix describing the Gaussian transformation. hbar (float) – the value of $$\hbar$$ used in the definition of the $$\x$$ and $$\p$$ quadrature operators. Note that if used inside of an engine context, the hbar value of the engine will override this keyword argument. vacuum (bool) – set to True if acting on a vacuum state. In this case, $$O_2 V O_2^T = I$$, and the unitary associated with orthogonal symplectic $$O_2$$ will be ignored. tol (float) – the tolerance used when checking if the matrix is symplectic: $$|S^T\Omega S-\Omega| \leq tol$$
decompose(reg)[source]

Decompose the operation into elementary operations supported by the backend API.

Parameters: reg (Sequence[RegRef]) – subsystems the operation is acting on decomposition as a list of operations acting on specific subsystems list[Command]
class strawberryfields.ops.Gaussian(V, r=None, decomp=True, hbar=None, tol=1e-06)[source]

Prepare the specified modes in a Gaussian state.

This operation uses the Williamson decomposition to prepare quantum modes into a given Gaussian state, specified by a vector of means and a covariance matrix.

The Williamson decomposition decomposes the Gaussian state into a Gaussian transformation (represented by a symplectic matrix) acting on Thermal states. The Gaussian transformation is then further decomposed into an array of beamsplitters and local squeezing and rotation gates, by way of the GaussianTransform and Interferometer decompositions.

Alternatively, the decomposition can be explicitly turned off, and the backend can be explicitly prepared in the Gaussian state provided. This is only supported by backends using the Gaussian representation.

Parameters: V (array) – the $$2N\times 2N$$ (real and positive definite) covariance matrix. r (array) – a length $$2N$$ vector of means, of the form $$(\x_0,\dots,\x_{N-1},\p_0,\dots,\p_{N-1})$$. If None, it is assumed that $$r=0$$. decomp (bool) – if False, no decomposition is applied, and the specified modes are explicity prepared in the provided Gaussian state. hbar (float) – the value of $$\hbar$$ used in the definition of the $$\x$$ and $$\p$$ quadrature operators. Note that if used inside of an engine context, the hbar value of the engine will override this keyword argument. tol (float) – the tolerance used when checking if the matrix is symmetric: $$|V-V^T| \leq tol$$
decompose(reg)[source]

Decompose the operation into elementary operations supported by the backend API.

Parameters: reg (Sequence[RegRef]) – subsystems the operation is acting on decomposition as a list of operations acting on specific subsystems list[Command]