Matrix

>>> import perceval as pcvl
>>> M = pcvl.Matrix("1 2 3\n4 5 6\n7 8 9")
>>> print(M.pdisplay())
⎡1  2  3⎤
⎢4  5  6⎥
⎣7  8  9⎦
>>> M.is_unitary()
False

Parameter

class perceval.utils.parameter.Parameter(name, value=None, min_v=None, max_v=None, periodic=True)

A Parameter is a used as a variable in a circuit definition

Parameters are a simple way to introduce named variables in a circuit. They take floating number values. When non defined they are associated to sympy symbols and will be used to perform symbolic calculations.

Parameters:
  • name (str) – name of the parameter

  • value (Optional[float]) – optional value, when the value is provided at initialization, the parameter is considered as fixed

  • min_v (Optional[float]) – minimal value that the parameter can take, is used in circuit optimization

  • max_v (Optional[float]) – maximal value that the parameter can take, is used in circuit optimization

  • periodic (bool) – True if the parameter is periodic, False otherwise (default True)

property bounds: tuple[float, float]

Minimal and maximal values for the parameter

property defined: bool

Return True if the parameter has a value (fixed or non fixed)

evalf(subs=None)

Convert the parameter to float, will fail if the parameter has no defined value

Return type:

float

fix_value(v)

Fix the value of a non-fixed Parameter. The Parameter is not variable afterwards.

Parameters:

v (float) – the numerical value

property fixed: bool

Return True if the parameter is fixed

property is_periodic: bool

Return True if the parameter is defined as a period parameter

property is_variable: bool

Returns True for a non-fixed parameter

property max: float

The maximal value of the parameter

property min

The minimal value of the parameter

property pid

Unique identifier for the parameter

reset()

Reset the value of a non-fixed parameter

set_periodic(periodic)

set periodic flag

set_value(v, force=False)

Define the numerical value of a Parameter

Parameters:
  • v (float) – the numerical value

  • force (bool) – enable to change the value of a fixed parameter

Raise:

RuntimeError if the parameter is fixed

property spv: Expr

The current value of the parameter defined as a sympy expression

Expression

class perceval.utils.parameter.Expression(name, parameters)

Symbolic math expression This class allows arithmetic manipulation of the Parameter class.

Example:
>>> p_a = Parameter("A")
>>> p_b = Parameter("B")
>>> sum_ab = Expression("A**2 + B", {p_a, p_b})
>>> p_a.set_value(2)
>>> p_b.set_value(3)
>>> print(float(sum_ab))  # Prints 7.0
Parameters:
  • name (str) – string specifying equation, acts as name of Expression parameter.

  • parameters (set[Parameter]) – set of sub parameter instances used in the expression

property defined: bool

Return True if the parameter has a value (fixed or non fixed)

property is_periodic: bool

Expressions are not considered periodic

property parameters: list[perceval.utils.parameter.Parameter]

Returns list of sub parameters in alphabetical order