# Default Gaussian plugin¶

Module name: pennylane.plugins.default_gaussian

Short name: "default.gaussian"

The default.gaussian plugin is meant to be used as a template for writing PennyLane device plugins for new CV backends.

It implements the necessary Device methods as well as all built-in continuous-variable Gaussian operations, and provides a very simple simulation of a Gaussian-based quantum circuit architecture.

The following is the technical documentation of the implementation of the plugin. You will not need to read and understand this to use this plugin.

## Auxillary functions¶

 partitions(s[, include_singles]) Partitions a sequence into all groupings of pairs and singles of elements. fock_prob(mu, cov, event[, hbar]) Returns the probability of detection of a particular PNR detection event.

## Gates and operations¶

 rotation(phi) Rotation in the phase space. displacement(state, wire, alpha[, hbar]) Displacement in the phase space. squeezing(r, phi) Squeezing in the phase space. quadratic_phase(s) Quadratic phase shift. beamsplitter(theta, phi) Beamsplitter. two_mode_squeezing(r, phi) Two-mode squeezing. controlled_addition(s) CX gate. controlled_phase(s) CZ gate. interferometer(U) Interferometer

## State preparation¶

 squeezed_cov(r, phi[, hbar]) Returns the squeezed covariance matrix of a squeezed state. vacuum_state(wires[, hbar]) Returns the vacuum state. coherent_state(a[, phi, hbar]) Returns a coherent state. squeezed_state(r, phi[, hbar]) Returns a squeezed state. displaced_squeezed_state(a, phi_a, r, phi_r) Returns a squeezed coherent state thermal_state(nbar[, hbar]) Returns a thermal state. gaussian_state(mu, cov[, hbar]) Returns a Gaussian state. set_state(state, wire, mu, cov) Inserts a single mode Gaussian into the state representation of the complete system.

## Expectations¶

 photon_number(mu, cov, wires, params[, hbar]) Calculates the mean photon number for a given one-mode state. homodyne([phi]) Function factory that returns the Homodyne expectation of a one mode state. poly_quad_expectations(mu, cov, wires, params) Calculates the expectation and variance for an arbitrary polynomial of quadrature operators. fock_expectation(mu, cov, wires, params[, hbar]) Calculates the expectation and variance of a Fock state probability.

## Classes¶

 DefaultGaussian(wires, *[, shots, hbar]) Default Gaussian device for PennyLane.

### Code details¶

partitions(s, include_singles=True)[source]

Partitions a sequence into all groupings of pairs and singles of elements.

Parameters: s (sequence) – the sequence to partition include_singles (bool) – if False, only partitions into pairs is returned. returns a nested tuple, containing all partitions of the sequence. tuple
fock_prob(mu, cov, event, hbar=2.0)[source]

Returns the probability of detection of a particular PNR detection event.

For more details, see:

Parameters: mu (array) – length-$$2N$$ means vector cov (array) – $$2N\times 2N$$ covariance matrix event (array) – length-$$N$$ array of non-negative integers representing the PNR detection event of the multi-mode system. hbar (float) – (default 2) the value of $$\hbar$$ in the commutation relation $$[\x,\p]=i\hbar$$. probability of detecting the event float
rotation(phi)[source]

Rotation in the phase space.

Parameters: phi (float) – rotation parameter symplectic transformation matrix array
displacement(state, wire, alpha, hbar=2)[source]

Displacement in the phase space.

Parameters: state (tuple) – contains means vector and covariance matrix wire (int) – wire that the displacement acts on alpha (float) – complex displacement contains the vector of means and covariance matrix tuple
squeezing(r, phi)[source]

Squeezing in the phase space.

Parameters: r (float) – squeezing magnitude phi (float) – rotation parameter symplectic transformation matrix array
quadratic_phase(s)[source]

Parameters: s (float) – gate parameter symplectic transformation matrix array
beamsplitter(theta, phi)[source]

Beamsplitter.

Parameters: theta (float) – transmittivity angle ($$t=\cos\theta$$) phi (float) – phase angle ($$r=e^{i\phi}\sin\theta$$) symplectic transformation matrix array
two_mode_squeezing(r, phi)[source]

Two-mode squeezing.

Parameters: r (float) – squeezing magnitude phi (float) – rotation parameter symplectic transformation matrix array
controlled_addition(s)[source]

CX gate.

Parameters: s (float) – gate parameter symplectic transformation matrix array
controlled_phase(s)[source]

CZ gate.

Parameters: s (float) – gate parameter symplectic transformation matrix array
interferometer(U)[source]

Interferometer

Parameters: U (array) – unitary matrix symplectic transformation matrix array
squeezed_cov(r, phi, hbar=2)[source]

Returns the squeezed covariance matrix of a squeezed state.

Parameters: r (float) – the squeezing magnitude p (float) – the squeezing phase $$\phi$$ hbar (float) – (default 2) the value of $$\hbar$$ in the commutation relation $$[\x,\p]=i\hbar$$ the squeezed state array
vacuum_state(wires, hbar=2.0)[source]

Returns the vacuum state.

Parameters: basis (str) – Returns the vector of means and the covariance matrix hbar (float) – (default 2) the value of $$\hbar$$ in the commutation relation $$[\x,\p]=i\hbar$$ the vacuum state array
coherent_state(a, phi=0, hbar=2.0)[source]

Returns a coherent state.

Parameters: a (complex) – the displacement phi (float) – the phase hbar (float) – (default 2) the value of $$\hbar$$ in the commutation relation $$[\x,\p]=i\hbar$$ the coherent state array
squeezed_state(r, phi, hbar=2.0)[source]

Returns a squeezed state.

Parameters: r (float) – the squeezing magnitude phi (float) – the squeezing phase $$\phi$$ hbar (float) – (default 2) the value of $$\hbar$$ in the commutation relation $$[\x,\p]=i\hbar$$ the squeezed state array
displaced_squeezed_state(a, phi_a, r, phi_r, hbar=2.0)[source]

Returns a squeezed coherent state

Parameters: a (real) – the displacement magnitude phi_a (real) – the displacement phase r (float) – the squeezing magnitude phi_r (float) – the squeezing phase $$\phi_r$$ hbar (float) – (default 2) the value of $$\hbar$$ in the commutation relation $$[\x,\p]=i\hbar$$ the squeezed coherent state array
thermal_state(nbar, hbar=2.0)[source]

Returns a thermal state.

Parameters: nbar (float) – the mean photon number hbar (float) – (default 2) the value of $$\hbar$$ in the commutation relation $$[\x,\p]=i\hbar$$ the thermal state array
gaussian_state(mu, cov, hbar=2.0)[source]

Returns a Gaussian state.

This is simply a bare wrapper function, since the means vector and covariance matrix can be passed via the parameters unchanged.

Note that both the means vector and covariance matrix should be in $$(\x_1,\dots, \x_N, \p_1, \dots, \p_N)$$ ordering.

Parameters: mu (array) – vector means. Must be length-$$2N$$, where N is the number of modes cov (array) – covariance matrix. Must be dimension $$2N\times 2N$$, where N is the number of modes hbar (float) – (default 2) the value of $$\hbar$$ in the commutation relation $$[\x,\p]=i\hbar$$ the thermal state array
set_state(state, wire, mu, cov)[source]

Inserts a single mode Gaussian into the state representation of the complete system.

Parameters: state (tuple) – contains means vector and covariance matrix of existing state wire (int) – wire corresponding to the new Gaussian state mu (array) – vector of means to insert cov (array) – covariance matrix to insert contains the vector of means and covariance matrix. tuple
photon_number(mu, cov, wires, params, hbar=2.0)[source]

Calculates the mean photon number for a given one-mode state.

Parameters: mu (array) – length-2 vector of means cov (array) – $$2\times 2$$ covariance matrix wires (Sequence[int]) – wires to calculate the expectation for params (None) – no parameters are used for this expectation value hbar (float) – (default 2) the value of $$\hbar$$ in the commutation relation $$[\x,\p]=i\hbar$$ contains the photon number expectation and variance tuple
homodyne(phi=None)[source]

Function factory that returns the Homodyne expectation of a one mode state.

Parameters: phi (float) – the default phase space axis to perform the Homodyne measurement A function that accepts a single mode means vector, covariance matrix, and phase space angle phi, and returns the quadrature expectation value and variance. function
poly_quad_expectations(mu, cov, wires, params, hbar=2.0)[source]

Calculates the expectation and variance for an arbitrary polynomial of quadrature operators.

Parameters: mu (array) – length-2 vector of means cov (array) – $$2\times 2$$ covariance matrix wires (Sequence[int]) – wires to calculate the expectation for params (array) – a $$(2N+1)\times (2N+1)$$ array containing the linear and quadratic coefficients of the quadrature operators $$(\I, \x_0, \p_0, \x_1, \p_1,\dots)$$ hbar (float) – (default 2) the value of $$\hbar$$ in the commutation relation $$[\x,\p]=i\hbar$$ the mean and variance of the quadrature-polynomial observable tuple
fock_expectation(mu, cov, wires, params, hbar=2.0)[source]

Calculates the expectation and variance of a Fock state probability.

Parameters: mu (array) – length-$$2N$$ vector of means cov (array) – $$2N\times 2N$$ covariance matrix wires (Sequence[int]) – wires to calculate the expectation for params (Sequence[int]) – the Fock state to return the expectation value for hbar (float) – (default 2) the value of $$\hbar$$ in the commutation relation $$[\x,\p]=i\hbar$$ the Fock state expectation and variance tuple
identity(*_, **__)[source]

Returns 1.

Returns: the Fock state expectation and variance tuple
class DefaultGaussian(wires, *, shots=0, hbar=2)[source]

Default Gaussian device for PennyLane.

Parameters: wires (int) – the number of modes to initialize the device in shots (int) – How many times should the circuit be evaluated (or sampled) to estimate the expectation values. 0 yields the exact result. hbar (float) – (default 2) the value of $$\hbar$$ in the commutation relation $$[\x,\p]=i\hbar$$
pre_apply()[source]

Called during execute() before the individual operations are executed.

apply(operation, wires, par)[source]

Apply a quantum operation.

For plugin developers: this function should apply the operation on the device.

Parameters: operation (str) – name of the operation wires (Sequence[int]) – subsystems the operation is applied on par (tuple) – parameters for the operation
expand(S, wires)[source]

Expands a Symplectic matrix S to act on the entire subsystem.

Parameters: S (array) – a $$2M\times 2M$$ Symplectic matrix wires (Sequence[int]) – the wires of the modes that S acts on the resulting $$2N\times 2N$$ Symplectic matrix array
expval(observable, wires, par)[source]

Return the expectation value of an observable.

For plugin developers: this function should return the expectation value of the given observable on the device.

Parameters: observable (str) – name of the observable wires (Sequence[int]) – subsystems the observable is to be measured on par (tuple) – parameters for the observable expectation value float
var(observable, wires, par)[source]

Return the variance value of an observable.

For plugin developers: this function should return the variance value of the given observable on the device.

Parameters: observable (str) – name of the observable wires (Sequence[int]) – subsystems the observable is to be measured on par (tuple) – parameters for the observable expectation value float
reset()[source]

Reset the device

reduced_state(wires)[source]

Returns the vector of means and the covariance matrix of the specified wires.

Parameters: wires (int of Sequence[int]) – indices of the requested wires means is an array containing the vector of means, and cov is a square array containing the covariance matrix tuple (means, cov)
operations

Get the supported set of operations.

Returns: the set of PennyLane operation names the device supports set[str]
observables

Get the supported set of observables.

Returns: the set of PennyLane observable names the device supports set[str]