# sf.compilers.Xunitary¶

class Xunitary[source]

Bases: strawberryfields.compilers.compiler.Compiler

General interferometer or unitary compiler for the X class of circuits.

This compilation routine is performed at the interferometer/unitary matrix level.

This compiler accepts the following gates, decompositions, and measurements:

All S2gate operations, if present, must be placed at the start of the program, and match the X-series topology. That is, for a device with $$2N$$ modes, the S2gate operations can only be applied to modes $$(m, m+N)$$.

Subsequent operations represent the interferometer, and may consist of any combination of BSgate, MZgate, Interferometer, BipartiteGraphEmbed, as long as the unitary on modes $$(0, 1,\dots, N-1)$$ is repeated on modes $$(N, N+1, \dots, 2N-1)$$. The unitary will automatically be compiled to match the topology of the X-series.

Finally, the circuit must complete with Fock measurements.

Example

The compiler may be used on its own:

>>> prog.compile(compiler="Xunitary")


Alternatively, it can be combined with an X series device specification to include additional information, such as allowed parameter ranges.

>>> eng = sf.RemoteEngine("X8")
>>> spec = eng.device_spec
>>> prog.compile(device=spec, compiler="Xunitary")

 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': {'drop_identity': False, 'mesh': 'rectangular_symmetric'}}
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 = False
primitives = {'BSgate', 'Interferometer', 'MZgate', 'MeasureFock', 'Rgate', 'S2gate'}
short_name = 'Xunitary'
 compile(seq, registers) Class-specific circuit compilation method. decompose(seq) Recursively decompose all gates in a given sequence, as allowed by the circuit specification.
compile(seq, registers)[source]

Class-specific circuit compilation method.

If additional compilation logic is required, child classes can redefine this method.

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

• registers (Sequence[RegRefs]) – quantum registers

Returns

modified circuit

Return type

List[Command]

Raises

CircuitError – the given circuit cannot be validated to belong to this circuit class

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