at.lattice.parameters#

Functions

AttributeArray(value[, shape, dtype])

Create an array of attributes, which may contain parameters.

Classes

Param(value, *[, name, conversion, bounds, ...])

Standalone scalar parameter.

ParamArray(value[, shape, dtype])

Simulate a numpy array where items may be parameterised.

class Param(value, *, name='', conversion=<function _nop>, bounds=None, delta=1.0)[source]#

Bases: ParamBase, VariableBase

Standalone scalar parameter.

See VariableBase for a description of inherited methods

Parameters:
  • value (Number) – Initial value of the parameter

  • name (str) – Name of the parameter. If omitted or blank, a unique name is generated.

  • conversion (Callable[[Any], Any]) – data conversion function

  • bounds (tuple[Number, Number] | None) – Lower and upper bounds of the parameter value

  • delta (Number) – Initial variation step.

fast_value()[source]#

Return the value of the parameter.

set_conversion(conversion)[source]#

Set the data type conversion function.

This method is called when a parameter is assigned to an Element attribute. It can only be set once.

Parameters:

conversion (Callable[[Any], Any]) – Function to convert values to the appropriate type

Raises:

ValueError – If attempting to change an already set conversion function

property value: int | float#

Current value of the parameter.

class ParamArray(value, shape=(-1, ), dtype=<class 'float'>)[source]#

Bases: ndarray

Simulate a numpy array where items may be parameterised.

This class allows creating arrays that can contain Parameter objects. It provides a value property that returns a numeric array with the current values of all parameters. Changes to the numeric array are propagated back to the parameters.

This is primarily used for element attributes that can be parameterised.

class ValueArray(parent, dtype=<class 'float'>)[source]#

Bases: ndarray

Subclass of ndarray which reports changes back to its parent ParamArray.

This array is used as the value property of ParamArray. When items in this array are modified, the changes are propagated back to the ParamArray parent.

This is the array obtained with an element get_attribute. It is also the one used when setting an item of an array attribute.

Parameters:
  • parent (ParamArray) – The parent ParamArray

  • dtype (npt.DTypeLike) – Data type of the array.

Returns:

A new ValueArray instance

fast_value()[source]#

Numeric array with the current values of all the parameters.

This property returns a ValueArray that contains the numeric values of all parameters in the array. Changes to this array are propagated back to the ParamArray parent.

Returns:

A numeric array with the current parameter values

property value: ndarray#
AttributeArray(value, shape=(-1, ), dtype=<class 'float'>)[source]#

Create an array of attributes, which may contain parameters.

This function creates either a ParamArray (if the input contains parameters) or a _SafeArray (if the input contains only regular values).

Parameters:
Returns:

Either a ParamArray or a SafeArray depending on the input