Feed-forward Configurators

Configurators are the way to perform a feed-forward computation. As they are non-unitary components, they can only be added to Processor instances.

Their purpose is to link measurements on given modes to circuits to configure.

They are based on the following common features:

  • A default circuit is mandatory for when the measurement does not fall into one of the configured cases. This circuit determines the size of the configured circuit.

  • All referenced circuits have the same size.

  • The measured modes must be classical (placed after a detector).

  • The circuit position is determined by an offset between the configurator and the configured circuit.

This offset represents the number of modes between the measured modes and the circuit. For positive offsets, the circuit is placed below, the offset being the number of empty modes between the configurator and the circuit (0 means the circuit is right below the configurator). For negative values, the circuit is placed above the measured modes (-1 means that the circuit is right above the configurator).

Two configurators exist.

FFCircuitProvider

This class directly links measurements to circuits or processors. Any circuit or processor matching the default circuit size can be used given all parameters have numerical values.

>>> import perceval as pcvl
>>> p = pcvl.Processor("SLOS", 4)
>>> c = pcvl.FFCircuitProvider(1, offset=1, default_circuit=pcvl.Circuit(2), name="FFCircuitProvider Example")
>>> c.add_configuration([1], pcvl.BS())
>>> p.add(0, pcvl.Detector.threshold())
>>> p.add(0, c)
class perceval.components.feed_forward_configurator.FFCircuitProvider(m, offset, default_circuit, name=None)
DEFAULT_NAME = 'FFC'

For any measurement, FFCircuitProvider will return a circuit or a processor, picked from known mapping of configurations. Each configuration links a measurement to a circuit or processor. If a measurement is received and was not set in the mapping, a mandatory default circuit or processor is returned.

Parameters:
  • m – The number of classical modes that are detected (after a detector)

  • offset – The distance between the configurator and the first mode of the implemented circuits. For positive values, it is the number of empty modes between the configurator and the configured circuit below. For negative values, it is the same but the circuit is located above the configurator (the number of empty modes is abs(offset) - 1, so an offset of -1 means that there is no empty modes between the configurator and the circuit). All circuits are considered to have the size of the biggest possible circuit in this configurator.

  • default_circuit – The circuit to be used if the measured state does not befall into one of the declared cases

assign(assign=None)

Assign values to parameters referenced in assign

Parameters:

assign (Optional[dict[str, float | int]]) – A dictionary mapping parameter_name -> value. Set the value to the parameter whose name is parameter_name for each key of the dictionary.

Raises:

KeyError – If parameter_name is not an existing variable parameter name of the circuit.

block_circuit_size()

Call this to prevent adding circuits bigger than the current maximum size

circuit_template()

Return a fitting representation of the controlled circuit or processor.

Return type:

ACircuit

config_modes(self_modes)

Gives the list of modes on which to place the circuit

Parameters:

self_modes (tuple[int, ...]) – The tuple containing the modes on which the configurator is located, in crescent order

Return type:

tuple[int, ...]

configure(measured_state)

Gives the circuit or processor that must be configured given the measured state

Parameters:

measured_state (BasicState) – The state of size self.m that corresponds to the measurements of the modes on which the configurator is located.

Return type:

ACircuit

Returns:

The processor or circuit that must be set

property defined: bool

check if all parameters of the circuit are fully defined

get_parameters(all_params=False, expressions=False)

Return the parameters of the component

Parameters:
  • all_params (bool) – if False, only returns the variable parameters

  • expressions – if True, returns Expressions and parameters embedded in circuit components. If False, returns the raw parameters that make up the expressions only. Default False.

Return type:

list[Parameter]

Returns:

the list of parameters

is_composite()
Return type:

bool

Returns:

True if the component is itself composed of subcomponents

property name: str

Returns component name

param(param_name)

Extract a Parameter object from its name :type param_name: str :param param_name: The name of the parameter :rtype: Parameter :return: A Parameter object

property params: Iterable[str]
Returns:

a list of all variable parameter names in the component

property vars: dict[str, perceval.utils.parameter.Parameter]
Returns:

A dictionary mapping parameter names to parameters for all variable parameters of the circuit

FFConfigurator

This class links measurements to a mapping of parameter values that can be set in the given circuit.

>>> import perceval as pcvl
>>> p = pcvl.Processor("SLOS", 4)
>>> phi = pcvl.P("phi")
>>> c = pcvl.FFConfigurator(2, offset=1, controlled_circuit=pcvl.PS(phi), default_config={"phi": 0}, name="FFConfigurator Example")
>>> c.add_configuration([1, 0], {"phi": 1.23})
>>> p.add(0, pcvl.Detector.threshold())
>>> p.add(1, pcvl.Detector.threshold())
>>> p.add(0, c)
class perceval.components.feed_forward_configurator.FFConfigurator(m, offset, controlled_circuit, default_config, name=None)
DEFAULT_NAME = 'FFC'

This class relies on a mapping between detections and a mapping of variable names and numerical values, controlling a circuit template.

Parameters:
  • m – The number of classical modes that are detected (after a detector)

  • offset – The distance between the configurator and the first mode of the implemented circuits. For positive values, it is the number of empty modes between the configurator and the configured circuit below. For negative values, it is the same but the circuit is located above the configurator (the number of empty modes is abs(offset) - 1, so an offset of -1 means that there is no empty modes between the configurator and the circuit). All circuits are considered to have the size of the biggest possible circuit in this configurator.

  • controlled_circuit – A circuit containing symbolic parameters whose value will be changed depending on the measured state.

  • default_config – A dictionary mapping the parameters of the circuit and their value to use in case a measured state does not befall into one of the declared cases.

assign(assign=None)

Assign values to parameters referenced in assign

Parameters:

assign (Optional[dict[str, float | int]]) – A dictionary mapping parameter_name -> value. Set the value to the parameter whose name is parameter_name for each key of the dictionary.

Raises:

KeyError – If parameter_name is not an existing variable parameter name of the circuit.

block_circuit_size()

Call this to prevent adding circuits bigger than the current maximum size

circuit_template()

Return a fitting representation of the controlled circuit or processor.

Return type:

ACircuit

config_modes(self_modes)

Gives the list of modes on which to place the circuit

Parameters:

self_modes (tuple[int, ...]) – The tuple containing the modes on which the configurator is located, in crescent order

Return type:

tuple[int, ...]

configure(measured_state)

Gives the circuit or processor that must be configured given the measured state

Parameters:

measured_state (BasicState) – The state of size self.m that corresponds to the measurements of the modes on which the configurator is located.

Return type:

ACircuit

Returns:

The processor or circuit that must be set

property defined: bool

check if all parameters of the circuit are fully defined

get_parameters(all_params=False, expressions=False)

Return the parameters of the component

Parameters:
  • all_params (bool) – if False, only returns the variable parameters

  • expressions – if True, returns Expressions and parameters embedded in circuit components. If False, returns the raw parameters that make up the expressions only. Default False.

Return type:

list[Parameter]

Returns:

the list of parameters

is_composite()
Return type:

bool

Returns:

True if the component is itself composed of subcomponents

property name: str

Returns component name

param(param_name)

Extract a Parameter object from its name :type param_name: str :param param_name: The name of the parameter :rtype: Parameter :return: A Parameter object

property params: Iterable[str]
Returns:

a list of all variable parameter names in the component

property vars: dict[str, perceval.utils.parameter.Parameter]
Returns:

A dictionary mapping parameter names to parameters for all variable parameters of the circuit