quri_parts.circuit.parameter_mapping module

ParameterValueAssignment

ParameterValueAssignment represents a Mapping which assigns concrete values to a set of parameters.

Mapper

Mapper represents a function that maps a set of parameter values (input) to another set of parameter values (output).

alias of Callable[[Mapping[Parameter, float]], Mapping[Parameter, float]]

SeqMapper

SeqMapper represents a function that maps a sequence of parameter values (input) to another sequence of parameter values (output).

alias of Callable[[Sequence[float]], Sequence[float]]

class ParameterMapping(*args, **kwargs)

Bases: Protocol

ParameterMapping represents a mapping of a set of parameters to another set of parameters.

It can be considered as a function mapping \(m\) input parameters to \(n\) output parameters:

\[(\theta^\text{(out)}_0, \ldots, \theta^\text{(out)}_{n-1}) = f(\theta^\text{(in)}_0, \ldots, \theta^\text{(in)}_{m-1})\]
abstract property in_params: Sequence[Parameter]

Returns a sequence of input Parameters.

abstract property out_params: Sequence[Parameter]

Returns a sequence of output Parameters.

abstract property mapper: circuit.parameter_mapping.Mapper

Returns a function that maps an input ParameterValueAssignment to an output ParameterValueAssignment (i.e. \(f\)).

It is expected that the function captures the state of ParameterMapping at the time that this property is accessed and does not reflect subsequent changes in the state of the ParameterMapping instance.

abstract property seq_mapper: circuit.parameter_mapping.SeqMapper

Returns a function that maps a sequence of input parameter values to a sequence of output parameter values (i.e. \(f\)).

It is expected that the function captures the state of ParameterMapping at the time that this property is accessed and does not reflect subsequent changes in the state of the ParameterMapping instance.

abstract property mapping: Mapping[Parameter, circuit.parameter_mapping.ParameterOrLinearFunction]

Returns a mapping from output parameters to input parameters or linear functions of input parameters.

get_derivatives()

Returns a sequence of ParameterMappings of derivatives of the original ParameterMapping with respect to each input parameter.

The returned sequence corresponds to

\[\left( \frac{\partial f}{\partial \theta^\text{(in)}_0}, \ldots, \frac{\partial f}{\partial \theta^\text{(in)}_{m-1}} \right),\]

where \(f\) is defined as described in ParameterMapping docstring.

Return type:

Sequence[ParameterMapping]

class ParameterMappingBase

Bases: ABC

An abstract class used as a base for implementing ParameterMapping.

Currently this class only has a general implementation of seq_mapper() method.

abstract property in_params: Sequence[Parameter]
abstract property out_params: Sequence[Parameter]
abstract property mapper: circuit.parameter_mapping.Mapper
abstract property is_trivial_mapping: bool

Returns if the mapping is trivial one-to-one mapping (Identity function).

property seq_mapper: circuit.parameter_mapping.SeqMapper
LinearParameterFunction

A type representing a linear (affine) function of parameters. It is an alias for mapping from Parameter to float coefficients. A constant term can be represented as a coefficient for CONST.

ParameterOrLinearFunction

A union type of Parameter and LinearParameterFunction.

alias of Parameter | Mapping[Parameter, float]

class LinearParameterMapping(in_params=(), out_params=(), mapping={})

Bases: ParameterMappingBase

A ParameterMapping representing a linear (affine) transformation of parameters.

The mapping is represented as a Mapping from Parameters to ParameterOrLinearFunctions. For example, if the mapping is defined as:

\[\begin{split}\begin{align} \theta^\text{(out)}_0 &= 0.1\theta^\text{(in)}_1 + 0.2, \\ \theta^\text{(out)}_1 &= 0.3\theta^\text{(in)}_0 + 0.4\theta^\text{(in)}_1, \end{align}\end{split}\]

the mapping argument should be as the following:

{
    out_param_0: { in_param_1: 0.1, CONST: 0.2 },
    out_param_1: { in_param_0: 0.3, in_param_1: 0.4 },
}

where in_param_0(1) and out_param_0(1) are input and output Parameter instances respectively.

Parameters:
with_data_updated(*, in_params_addition=(), out_params_addition=(), mapping_update={})
Parameters:
  • in_params_addition (Sequence[Parameter])

  • out_params_addition (Sequence[Parameter])

  • mapping_update (Mapping[Parameter, circuit.parameter_mapping.ParameterOrLinearFunction])

Return type:

LinearParameterMapping

property in_params: Sequence[Parameter]
property out_params: Sequence[Parameter]
property mapping: Mapping[Parameter, circuit.parameter_mapping.ParameterOrLinearFunction]
property mapper: circuit.parameter_mapping.Mapper
property is_trivial_mapping: bool

Returns if the mapping is trivial one-to-one mapping (Identity function).

get_derivatives()

Returns a sequence of LinearParameterMappings of derivatives of the original LinearParameterMapping with respect to each input parameter.

Since the original mapping is linear, the returned mappings only contains constant terms. For example, for the linear mapping defined in the docstring of LinearParameterMapping, the returned derivatives are as follows:

\[\begin{split}\begin{align} \frac{\partial f}{\partial \theta^\text{(in)}_0} &= (0, 0.3)\\ \frac{\partial f}{\partial \theta^\text{(in)}_1} &= (0.1, 0.4) \end{align}\end{split}\]
Return type:

Sequence[LinearParameterMapping]

combine(other)
Parameters:

other (LinearParameterMapping)

Return type:

LinearParameterMapping