qml.variable.Variable

class Variable(idx, name=None, is_kwarg=False)[source]

Bases: object

A reference to dynamically track and update circuit parameters.

Represents a free quantum circuit parameter (with a non-fixed value), or a placeholder for data/other hard-coded data.

Each time the circuit is executed, it is given a vector of flattened positional argument values, and a dictionary mapping keyword-only argument names to vectors of their flattened values. Each element of these vectors corresponds to a Variable instance. Positional arguments are represented by nameless Variables, whereas for keyword-only arguments Variable.name contains the argument name. In both cases Variable.idx is an index into the argument value vector.

The Variable has an optional scalar multiplier for the argument it represents.

Note

Variables currently do not implement any arithmetic operations other than scalar multiplication.

Parameters
  • idx (int) – index into the value vector, >= 0

  • name (None, str) – name of the argument

kwarg_values

current auxiliary parameter values, set in BaseQNode._set_variables()

positional_arg_values

current positional parameter values, set in BaseQNode._set_variables()

val

Current numerical value of the Variable.

kwarg_values = None

current auxiliary parameter values, set in BaseQNode._set_variables()

Type

dict[str->array[float]]

positional_arg_values = None

current positional parameter values, set in BaseQNode._set_variables()

Type

array[float]

val

Current numerical value of the Variable.

Returns

current value of the Variable

Return type

float

render([show_name_only])

Returns a string representation of the Variable.

render(show_name_only=False)[source]

Returns a string representation of the Variable.

Parameters

show_name_only (bool, optional) – Render the name instead of the value.

Returns

A string representation of the Variable

Return type

str