sf.compilers.Xcov¶
-
class
Xcov
[source]¶ Bases:
strawberryfields.compilers.compiler.Compiler
General state compiler for the X class of circuits.
An important property of this compilation routine is that it is done at the covariance matrix level. This implies that one should not use it to compare the interferometers of a given circuit since they may differ by permutations in the unitary and the squeezing parameters.
This compiler accepts the following gates, decompositions, and measurements:
The operations above may be provided in any combination and order, provided that the unitary is identical between the modes \((0, 1,\dots, N-1)\), and does not mix between these two sets of modes.
Finally, the circuit must complete with Fock measurements.
Example
The compiler may be used on its own:
>>> prog.compile(compiler="Xcov")
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="Xcov")
Attributes
A rigid circuit template that defines this circuit specification.
The allowed circuit topologies or connectivity of the class, modelled as a directed acyclic graph.
-
circuit
¶ A rigid circuit template that defines this circuit specification.
If arbitrary topologies are allowed in the circuit class, this function will simply return
None
.If a backend device expects a specific template for the received Blackbird script, this method will return the serialized Blackbird circuit in string form.
- Returns
Blackbird circuit 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', 'Sgate'}¶
-
short_name
= 'Xcov'¶
Methods
add_loss
(program, device)Adds realistic loss to circuit.
compile
(seq, registers)Class-specific circuit compilation method.
decompose
(seq)Recursively decompose all gates in a given sequence, as allowed by the circuit specification.
init_circuit
(layout)Sets the circuit in the compiler class.
Resets the
circuit
andgraph
class attributes.update_params
(program, device)Updates and checks parameters in the program circuit.
-
add_loss
(program, device)¶ Adds realistic loss to circuit.
Child classes which are hardware compilers should override this method with device specific loss added to the circuit.
-
compile
(seq, registers)[source]¶ Class-specific circuit compilation method.
If additional compilation logic is required, child classes can redefine this method.
- Parameters
- Returns
modified circuit
- Return type
Sequence[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
anddecompositions
class attributes to determine whether a command should be decomposed.The order of precedence to determine whether decomposition should be applied is as follows.
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 theCompiler
).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
-
classmethod
init_circuit
(layout)¶ Sets the circuit in the compiler class.
- Parameters
layout (str) – the circuit layout for the target device
- Return type
None
-
classmethod
reset_circuit
()¶ Resets the
circuit
andgraph
class attributes.- Return type
None
-
update_params
(program, device)¶ Updates and checks parameters in the program circuit.
Child classes can override this method with compiler specific logic. If no parameters need to be updated, and are separately checked, this method should not be overridden and be left empty.
- Parameters
program (Program) – Program containing the circuit and gate parameters
device (DeviceSpec) – device specification containing the valid parameter values
- Return type
None
-