# sf.compilers.GaussianUnitary¶

class GaussianUnitary[source]

Bases: strawberryfields.compilers.compiler.Compiler

Compiler to arrange a Gaussian quantum circuit into the canonical Symplectic form.

This compiler checks whether the circuit can be implemented as a sequence of Gaussian operations. If so, it arranges them in the canonical order with displacement at the end. After compilation, the circuit will consist of at most two operations, a GaussianTransform and a Dgate.

This compiler can be accessed by calling Program.compile() with ‘gaussian_unitary’ specified.

Example:

Consider the following Strawberry Fields program, compiled using the ‘gaussian_unitary’ compiler:

from strawberryfields.ops import Xgate, Zgate, Sgate, Dgate, Rgate
import strawberryfields as sf

circuit = sf.Program(1)
with circuit.context as q:
Xgate(0.4) | q[0]
Zgate(0.5) | q[0]
Sgate(0.6) | q[0]
Dgate(1.0+2.0j) | q[0]
Rgate(0.3) | q[0]
Sgate(0.6, 1.0) | q[0]

compiled_circuit = circuit.compile(compiler="gaussian_unitary")


We can now print the compiled circuit, consisting of one GaussianTransform and one Dgate:

>>> compiled_circuit.print()
GaussianTransform([[ 0.3543 -1.3857]
[-0.0328  2.9508]]) | (q[0])
Dgate(-1.151+3.91j, 0) | (q[0])

 circuit A rigid circuit template that defines this circuit specification. decompositions graph The allowed circuit topologies or connectivity of the class, modelled as a directed acyclic graph. interactive primitives short_name
circuit

A rigid circuit template that defines this circuit specification.

This property is optional. If arbitrary topologies are allowed in the circuit class, do not define this property. In such a case, it will simply return None.

If a backend device expects a specific template for the recieved Blackbird script, this method will return the serialized Blackbird circuit in string form.

Returns

Blackbird program or template representing the circuit

Return type

Union[str, None]

decompositions = {'BipartiteGraphEmbed': {}, 'CXgate': {}, 'CZgate': {}, 'Fouriergate': {}, 'Gaussian': {}, 'GraphEmbed': {}, 'Pgate': {}, 'Xgate': {}, 'Zgate': {}}
graph

The allowed circuit topologies or connectivity of the class, modelled as a directed acyclic graph.

This property is optional; if arbitrary topologies are allowed in the circuit class, this will simply return None.

Returns

a directed acyclic graph

Return type

networkx.DiGraph

interactive = True
primitives = {'All', 'BSgate', 'Dgate', 'GaussianTransform', 'Interferometer', 'MZgate', 'Rgate', 'S2gate', 'Sgate', '_Delete', '_New_modes', 'sMZgate'}
short_name = 'gaussian_unitary'
 compile(seq, registers) Try to arrange a quantum circuit into the canonical Symplectic form. decompose(seq) Recursively decompose all gates in a given sequence, as allowed by the circuit specification.
compile(seq, registers)[source]

Try to arrange a quantum circuit into the canonical Symplectic form.

This method checks whether the circuit can be implemented as a sequence of Gaussian operations. If the answer is yes it arranges them in the canonical order with displacement at the end.

Parameters
• seq (Sequence[Command]) – quantum circuit to modify

• registers (Sequence[RegRefs]) – quantum registers

Returns

modified circuit

Return type

List[Command]

Raises

CircuitError – the circuit does not correspond to a Gaussian unitary

decompose(seq)

Recursively decompose all gates in a given sequence, as allowed by the circuit specification.

This method follows the directives defined in the primitives and decompositions class attributes to determine whether a command should be decomposed.

The order of precedence to determine whether decomposition should be applied is as follows.

1. First, we check if the operation is in decompositions. If not, decomposition is skipped, and the operation is applied as a primitive (if supported by the Compiler).

2. Next, we check if (a) the operation supports decomposition, and (b) if the user has explicitly requested no decomposition.

• If both (a) and (b) are true, the operation is applied as a primitive (if supported by the Compiler).

• Otherwise, we attempt to decompose the operation by calling decompose() recursively.

Parameters

list[strawberryfields.program_utils.Command] – list of commands to be decomposed

Returns

list of compiled commands for the circuit specification

Return type