Parameters

class lightworks.Parameter(value: T, bounds: list[Number] | None = None, label: str | None = None)

Bases: Generic[T]

Enables the definition a modifiable parameter that can be used as part of a Circuit. It allows for the parameter to be modified after utilisation in a Circuit for the adjustment of the functionality with having to redefine the entire object. Once created the value of the parameter should be modified with the get and set functions.

Parameters:
  • value (Any) – The value to be assigned to the parameter.

  • bounds (list | None, optional) – If specified this allows for restrictions to be implemented on the value of each parameter. In optimisations this can also used to set parameter bounds if the optimisation allows. Bounds should be given as a list in the format [min_bound, max_bound]. Note bounds are only supported in the case of Numeric values.

  • label (str | None, optional) – Used to set an optional label which is then shown when using the display circuit method, instead of the parameter value.

get() T

Returns the current value of the parameter.

has_bounds() bool

Checks if the parameter has at least one bound given.

property max_bound: Number | None

The upper bound of the parameter value.

property min_bound: Number | None

The lower bound of the parameter value.

set(value: Any) None

Update the current value of the parameter.

class lightworks.ParameterDict(**kwargs: Parameter[Any])

Bases: UserDict[str, Parameter[Any]]

Stores a number of Parameters, using assigned keys to reference each Parameter object. This has custom get and set item which allows for the parameter object to be retrieved and the parameter value to be changed with the [] operator. For example ParameterDict[“a”] would return a Parameter object and ParameterDict[“a”] = 1 would set the value of the Parameter associated with the ‘a’ key to 1.

get_bounds() dict[str, tuple[Number | float, Number | float]]

Retrieves the bounds for all parameters stored in the ParameterDict and returns as a dictionary, where the keys match those used to store the parameters. If a particular parameter does not have one or both bounds set then the bounds will be set to +- inf.

has_bounds() bool

Checks if any of the parameters stored in the dictionary has a minimum and/or maximum bounds associated with it.

items() list[tuple[str, Any]]

Returns pairs of keys and parameter values in a list.

property params: list[str]

Returns a list of all parameter keys used in the dictionary.

remove(key: Any) None

Removes the parameter associated with the provided key from the ParameterDict.

Raises:

KeyError – Raised in cases where the key to remove does not exit in the ParameterDict.