quri_parts.circuit.parameter_shift module#


Represents a set of parameter shifts appearing in the parameter shift rule. The shift for each parameter is stored as an integer. The actual shift is calculated by multiplying the integer with math.pi / 2.

class ParameterShiftsAndCoef(shifts, coef)#

Bases: NamedTuple

A pair of parameter shifts and a coefficient appearing in the parameter shift rule.

  • shifts (circuit.parameter_shift.ParameterShifts) –

  • coef (float) –

shifts: ParameterShifts#

Shifts for parmeters.

coef: float#

A differential coefficient associated with the parameter shifts.

class ShiftedParameters(param_mapping, shifts_with_coef=((frozenset({}), 1.0),))#

Bases: object

A set of parameter shifts and associated coefficients obtained as a result of applying parameter shift rule.


The current implementation support only linear mappings between input and output parameters (i.e. LinearParameterMapping).

When created without shifts_with_coef, it corresponds to the original parametric circuit (i.e. only one component with no parameter shift and coefficient = 1.0). Instances returned by get_derivatives() method contains pairs of parameter shifts and associated coefficients. To evaluate derivative of an expectation value of an observable, estimate an expectation value of the observable with parameters obtained by get_shifted_parameters_and_coef(), multiply it with the coefficient, and then sum up all terms.

param_mapping: LinearParameterMapping#
shifts_with_coef: Collection[ParameterShiftsAndCoef] = ((frozenset({}), 1.0),)#

Returns a sequence of ShiftedParameterss corresponding to derivatives of the original ShiftedParameters with respect to each input parameter.

When the original instance corresponds to the original parametric circuit with a linear mapping on \(\theta^\text{(in)}_i\), given an arbitrary observable \(\hat{O}\), the returned sequence corresponds to derivatives

\[\left( \frac{\partial\langle\hat{O}\rangle}{\partial\theta^\text{(in)}_0}, \ldots, \frac{\partial\langle\hat{O}\rangle}{\partial\theta^\text{(in)}_{m-1}}, \right).\]
Return type:



Returns shifted parameter values and associated coefficients, which can be used for evaluation of derivatives, given parameter values where the derivatives are evaluated.


param_vals (Sequence[float]) –

Return type:

Collection[tuple[Sequence[float], float]]