Skip to content

variable

Modules:

Name Description
descriptor_any_type
descriptor_array
descriptor_base
descriptor_bool
descriptor_number
descriptor_str
parameter
parameter_dependency_resolver

Classes

Modules

descriptor_any_type

Classes:

Name Description
DescriptorAnyType

A Descriptor for any type that does not fit the other

Classes

DescriptorAnyType(name, value, unique_name=None, description=None, url=None, display_name=None, parent=None)

A Descriptor for any type that does not fit the other Descriptors.

Should be avoided when possible. It was created to hold the symmetry operations used in the SpaceGroup class of EasyCrystallography.

param name: Name of the descriptor param value: Value of the descriptor param description: Description of the descriptor param url: URL of the descriptor param display_name: Display name of the descriptor param parent: Parent of the descriptor .. note:: Undo/Redo functionality is implemented for the attributes variance, error, unit and value.

Methods:

Name Description
encode

Use an encoder to covert an EasyScience object into another

decode

Re-create an EasyScience object from the output of an encoder.

from_dict

Re-create an EasyScience object from a full encoded dictionary.

Attributes:

Name Type Description
value numbers.Number

Get the value.

name str

Get the name of the object.

display_name str

Get a pretty display name.

description str

Get the description of the object.

url str

Get the url of the object.

unique_name str

Get the unique name of this object.

Attributes
value property writable

Get the value.

Returns:

Type Description
numbers.Number

Value of self.

name property writable

Get the name of the object.

Returns:

Type Description
str

Name of the object.

display_name property writable

Get a pretty display name.

Returns:

Type Description
str

The pretty display name.

description property writable

Get the description of the object.

Returns:

Type Description
str

Description of the object.

url property writable

Get the url of the object.

Returns:

Type Description
str

Url of the object.

unique_name property writable

Get the unique name of this object.

Returns:

Type Description
str

Unique name of this object.

Functions
encode(skip=None, encoder=None, **kwargs)

Use an encoder to covert an EasyScience object into another format. Default is to a dictionary using SerializerDict.

Parameters:

Name Type Description Default
skip Optional[List[str]]

List of field names as strings to skip when forming the encoded object. By default, None.

None
encoder Optional[SerializerBase]

The encoder to be used for encoding the data. By default, None.

None
**kwargs

Any additional key word arguments to be passed to the encoder.

{}

Returns:

Type Description
Any

Encoded object containing all information to reform an EasyScience object.

decode(obj, decoder=None) classmethod

Re-create an EasyScience object from the output of an encoder. The default decoder is SerializerDict.

Parameters:

Name Type Description Default
obj Any

Encoded EasyScience object.

required
decoder Optional[SerializerBase]

Decoder to be used to reform the EasyScience object. By default, None.

None

Returns:

Type Description
Any

Reformed EasyScience object.

from_dict(obj_dict) classmethod

Re-create an EasyScience object from a full encoded dictionary.

Parameters:

Name Type Description Default
obj_dict Dict[str, Any]

Dictionary containing the serialized contents (from SerializerDict) of an EasyScience object.

required

Returns:

Type Description
Any

Reformed EasyScience object.

Functions

descriptor_array

Classes:

Name Description
DescriptorArray

A Descriptor for Array values with units.

Classes

DescriptorArray(name, value, unit='', variance=None, unique_name=None, description=None, url=None, display_name=None, parent=None, dimensions=None)

A Descriptor for Array values with units.

The internal representation is a scipp array.

param name: Name of the descriptor param value: List containing the values of the descriptor param unit: Unit of the descriptor param variance: Variances of the descriptor param description: Description of the descriptor param url: URL of the descriptor param display_name: Display name of the descriptor param parent: Parent of the descriptor param dimensions: List of dimensions to pass to scipp. Will be autogenerated if not supplied. .. note:: Undo/Redo functionality is implemented for the attributes variance, error, unit and value.

Methods:

Name Description
from_scipp

Create a DescriptorArray from a scipp array.

convert_unit

Convert the value from one unit system to another.

__copy__

Return a copy of the current DescriptorArray.

as_dict

Dict representation of the current DescriptorArray.

__array_ufunc__

DescriptorArray does not generally support Numpy array

__array_function__

DescriptorArray does not generally support Numpy array

__add__

Perform element-wise addition with another DescriptorNumber,

__radd__

Handle reverse addition for DescriptorArrays, DescriptorNumbers,

__sub__

Perform element-wise subtraction with another DescriptorArray,

__rsub__

Perform element-wise subtraction with another DescriptorNumber,

__mul__

Perform element-wise multiplication with another

__rmul__

Handle reverse multiplication for DescriptorNumbers, lists, and

__truediv__

Perform element-wise division with another DescriptorNumber,

__rtruediv__

Handle reverse division for DescriptorNumbers, lists, and

__pow__

Perform element-wise exponentiation with another

__rpow__

Defers reverse pow with a descriptor array, a ** array.

__neg__

Negate all values in the DescriptorArray.

__abs__

Replace all elements in the DescriptorArray with their absolute

__getitem__

Slice using scipp syntax.

__delitem__

Defer slicing to scipp.

__setitem__

__setitem via slice is not allowed, since we currently do not

trace

Computes the trace over the descriptor array.

sum

Uses scipp to sum over the requested dims.

encode

Use an encoder to covert an EasyScience object into another

decode

Re-create an EasyScience object from the output of an encoder.

from_dict

Re-create an EasyScience object from a full encoded dictionary.

Attributes:

Name Type Description
full_value Variable

Get the value of self as a scipp array.

value numbers.Number

Get the value without units.

dimensions list

Get the dimensions used for the underlying scipp array.

unit str

Get the unit.

variance np.ndarray

Get the variance as a Numpy ndarray.

error Optional[np.ndarray]

The standard deviations, calculated as the square root of

name str

Get the name of the object.

display_name str

Get a pretty display name.

description str

Get the description of the object.

url str

Get the url of the object.

unique_name str

Get the unique name of this object.

Attributes
full_value property writable

Get the value of self as a scipp array.

This should be usable for most cases.

Returns:

Type Description
Variable

Value of self with unit.

value property writable

Get the value without units.

The Scipp array can be obtained from obj.full_value.

Returns:

Type Description
numbers.Number

Value of self without unit.

dimensions property writable

Get the dimensions used for the underlying scipp array.

Returns:

Type Description
list

Dimensions of self.

unit property writable

Get the unit.

Returns:

Type Description
str

Unit as a string.

variance property writable

Get the variance as a Numpy ndarray.

Returns:

Type Description
np.ndarray

Variance.

error property writable

The standard deviations, calculated as the square root of variances.

Returns:

Type Description
Optional[np.ndarray]

A numpy array of standard deviations, or None if variances are not set.

name property writable

Get the name of the object.

Returns:

Type Description
str

Name of the object.

display_name property writable

Get a pretty display name.

Returns:

Type Description
str

The pretty display name.

description property writable

Get the description of the object.

Returns:

Type Description
str

Description of the object.

url property writable

Get the url of the object.

Returns:

Type Description
str

Url of the object.

unique_name property writable

Get the unique name of this object.

Returns:

Type Description
str

Unique name of this object.

Functions
from_scipp(name, full_value, **kwargs) classmethod

Create a DescriptorArray from a scipp array.

Parameters:

Name Type Description Default
name str

Name of the descriptor.

required
full_value Variable

Value of the descriptor as a scipp variable.

required
**kwargs Any

Additional parameters for the descriptor.

{}

Returns:

Type Description
DescriptorArray

DescriptorArray.

Raises:

Type Description
TypeError

If full_value is not a scipp Variable.

convert_unit(unit_str)

Convert the value from one unit system to another.

Parameters:

Name Type Description Default
unit_str str

New unit in string form.

required

Raises:

Type Description
TypeError

If unit_str is not a string.

UnitError

If the unit conversion fails.

__copy__()

Return a copy of the current DescriptorArray.

as_dict(skip=None)

Dict representation of the current DescriptorArray.

The dict contains the value, unit and variances, in addition to the properties of DescriptorBase.

__array_ufunc__(ufunc, method, *inputs, **kwargs)

DescriptorArray does not generally support Numpy array functions.

For example, np.argwhere(descriptorArray: DescriptorArray) should fail. Modify this function if you want to add such functionality.

__array_function__(func, types, args, kwargs)

DescriptorArray does not generally support Numpy array functions.

For example, np.argwhere(descriptorArray: DescriptorArray) should fail. Modify this function if you want to add such functionality.

__add__(other)

Perform element-wise addition with another DescriptorNumber, DescriptorArray, list, or number.

Parameters:

Name Type Description Default
other Union[DescriptorArray, DescriptorNumber, list, numbers.Number]

The object to add. Must be a DescriptorArray or DescriptorNumber with compatible units, or a list with the same shape if the DescriptorArray is dimensionless, or a number.

required

Returns:

Type Description
DescriptorArray

A new DescriptorArray representing the result of the addition.

__radd__(other)

Handle reverse addition for DescriptorArrays, DescriptorNumbers, lists, and scalars.

Ensures unit compatibility when other is a DescriptorNumber.

__sub__(other)

Perform element-wise subtraction with another DescriptorArray, list, or number.

Parameters:

Name Type Description Default
other Union[DescriptorArray, list, np.ndarray, numbers.Number]

The object to subtract. Must be a DescriptorArray with compatible units, or a list with the same shape if the DescriptorArray is dimensionless.

required

Returns:

Type Description
DescriptorArray

A new DescriptorArray representing the result of the subtraction.

__rsub__(other)

Perform element-wise subtraction with another DescriptorNumber, list, or number.

Parameters:

Name Type Description Default
other Union[DescriptorNumber, list, numbers.Number]

The object to subtract. Must be a DescriptorArray with compatible units, or a list with the same shape if the DescriptorArray is dimensionless.

required

Returns:

Type Description
DescriptorArray

A new DescriptorArray representing the result of the subtraction.

__mul__(other)

Perform element-wise multiplication with another DescriptorNumber, DescriptorArray, list, or number.

Parameters:

Name Type Description Default
other Union[DescriptorArray, DescriptorNumber, list, numbers.Number]

The object to multiply. Must be a DescriptorArray or DescriptorNumber with compatible units, or a list with the same shape if the DescriptorArray is dimensionless.

required

Returns:

Type Description
DescriptorArray

A new DescriptorArray representing the result of the addition.

__rmul__(other)

Handle reverse multiplication for DescriptorNumbers, lists, and scalars.

Ensures unit compatibility when other is a DescriptorNumber.

__truediv__(other)

Perform element-wise division with another DescriptorNumber, DescriptorArray, list, or number.

Parameters:

Name Type Description Default
other Union[DescriptorArray, DescriptorNumber, list, numbers.Number]

The object to use as a denominator. Must be a DescriptorArray or DescriptorNumber with compatible units, or a list with the same shape if the DescriptorArray is dimensionless.

required

Returns:

Type Description
DescriptorArray

A new DescriptorArray representing the result of the addition.

Raises:

Type Description
ZeroDivisionError

If any denominator element is zero.

__rtruediv__(other)

Handle reverse division for DescriptorNumbers, lists, and scalars.

Ensures unit compatibility when other is a DescriptorNumber.

__pow__(other)

Perform element-wise exponentiation with another DescriptorNumber or number.

Parameters:

Name Type Description Default
other Union[DescriptorNumber, numbers.Number]

The object to use as a denominator. Must be a number or DescriptorNumber with no unit or variance.

required

Returns:

Type Description
DescriptorArray

A new DescriptorArray representing the result of the addition.

Raises:

Type Description
Exception

If exponentiation fails inside scipp.

UnitError

If the exponent has units.

ValueError

If the exponent has variance or if the result is not a number.

__rpow__(other)

Defers reverse pow with a descriptor array, a ** array.

Exponentiation with regards to an array does not make sense, and is not implemented.

__neg__()

Negate all values in the DescriptorArray.

__abs__()

Replace all elements in the DescriptorArray with their absolute values.

Note that this is different from the norm of the DescriptorArray.

__getitem__(a)

Slice using scipp syntax.

Defer slicing to scipp.

__delitem__(a)

Defer slicing to scipp.

This should fail, since scipp does not support delitem.

__setitem__(a, b)

setitem via slice is not allowed, since we currently do not give back a view to the DescriptorArray upon calling __getitem.

trace(dimension1=None, dimension2=None)

Computes the trace over the descriptor array.

The submatrix defined dimension1 and dimension2 must be square. For a rank k tensor, the trace will run over the firs two dimensions, resulting in a rank k-2 tensor.

Parameters:

Name Type Description Default
dimension1 Optional[str]

First dimension to perform trace over. If not provided, the trace uses the first two dimensions.

None
dimension2 Optional[str]

Second dimension to perform trace over. If not provided, the trace uses the first two dimensions.

None

Returns:

Type Description
Union[DescriptorArray, DescriptorNumber]

Descriptor representing the trace result.

Raises:

Type Description
ValueError

If exactly one dimension is provided, if the dimensions are identical, or if a requested dimension does not exist.

sum(dim=None)

Uses scipp to sum over the requested dims.

Parameters:

Name Type Description Default
dim Optional[Union[str, list]]

The dim(s) in the scipp array to sum over. If None, will sum over all dims. By default, None.

None

Returns:

Type Description
Union[DescriptorArray, DescriptorNumber]

Descriptor representing the summed data.

encode(skip=None, encoder=None, **kwargs)

Use an encoder to covert an EasyScience object into another format. Default is to a dictionary using SerializerDict.

Parameters:

Name Type Description Default
skip Optional[List[str]]

List of field names as strings to skip when forming the encoded object. By default, None.

None
encoder Optional[SerializerBase]

The encoder to be used for encoding the data. By default, None.

None
**kwargs

Any additional key word arguments to be passed to the encoder.

{}

Returns:

Type Description
Any

Encoded object containing all information to reform an EasyScience object.

decode(obj, decoder=None) classmethod

Re-create an EasyScience object from the output of an encoder. The default decoder is SerializerDict.

Parameters:

Name Type Description Default
obj Any

Encoded EasyScience object.

required
decoder Optional[SerializerBase]

Decoder to be used to reform the EasyScience object. By default, None.

None

Returns:

Type Description
Any

Reformed EasyScience object.

from_dict(obj_dict) classmethod

Re-create an EasyScience object from a full encoded dictionary.

Parameters:

Name Type Description Default
obj_dict Dict[str, Any]

Dictionary containing the serialized contents (from SerializerDict) of an EasyScience object.

required

Returns:

Type Description
Any

Reformed EasyScience object.

Functions

descriptor_base

Classes:

Name Description
DescriptorBase

This is the base of all variable descriptions for models.

Classes

DescriptorBase(name, unique_name=None, description=None, url=None, display_name=None, parent=None)

This is the base of all variable descriptions for models.

It contains all information to describe a single unique property of an object. This description includes a name and value as well as optionally a unit, description and url (for reference material). Also implemented is a callback so that the value can be read/set from a linked library object.

A Descriptor is typically something which describes part of a model and is non-fittable and generally changes the state of an object.

It contains all information to describe a single unique property of an object. This description includes a name, description and url (for reference material).

A Descriptor is typically something which describes part of a model and is non-fittable and generally changes the state of an object.

Parameters:

Name Type Description Default
name str

Name of this object.

required
unique_name Optional[str]

Unique identifier for this object. By default, None.

None
description Optional[str]

A brief summary of what this object is. By default, None.

None
url Optional[str]

Lookup url for documentation/information. By default, None.

None
display_name Optional[str]

A pretty name for the object. By default, None.

None
parent Optional[Any]

The object which this descriptor is attached to. By default, None.

None

Raises:

Type Description
TypeError

If name is not a string or if any optional string field has an invalid type.

Methods:

Name Description
__copy__

Return a copy of the object.

encode

Use an encoder to covert an EasyScience object into another

decode

Re-create an EasyScience object from the output of an encoder.

as_dict

Convert an EasyScience object into a full dictionary using

from_dict

Re-create an EasyScience object from a full encoded dictionary.

Attributes:

Name Type Description
name str

Get the name of the object.

display_name str

Get a pretty display name.

description str

Get the description of the object.

url str

Get the url of the object.

unique_name str

Get the unique name of this object.

value Any

Get the value of the object.

Attributes
name property writable

Get the name of the object.

Returns:

Type Description
str

Name of the object.

display_name property writable

Get a pretty display name.

Returns:

Type Description
str

The pretty display name.

description property writable

Get the description of the object.

Returns:

Type Description
str

Description of the object.

url property writable

Get the url of the object.

Returns:

Type Description
str

Url of the object.

unique_name property writable

Get the unique name of this object.

Returns:

Type Description
str

Unique name of this object.

value abstractmethod property writable

Get the value of the object.

Functions
__copy__()

Return a copy of the object.

encode(skip=None, encoder=None, **kwargs)

Use an encoder to covert an EasyScience object into another format. Default is to a dictionary using SerializerDict.

Parameters:

Name Type Description Default
skip Optional[List[str]]

List of field names as strings to skip when forming the encoded object. By default, None.

None
encoder Optional[SerializerBase]

The encoder to be used for encoding the data. By default, None.

None
**kwargs

Any additional key word arguments to be passed to the encoder.

{}

Returns:

Type Description
Any

Encoded object containing all information to reform an EasyScience object.

decode(obj, decoder=None) classmethod

Re-create an EasyScience object from the output of an encoder. The default decoder is SerializerDict.

Parameters:

Name Type Description Default
obj Any

Encoded EasyScience object.

required
decoder Optional[SerializerBase]

Decoder to be used to reform the EasyScience object. By default, None.

None

Returns:

Type Description
Any

Reformed EasyScience object.

as_dict(skip=None)

Convert an EasyScience object into a full dictionary using SerializerDict. This is a shortcut for obj.encode(encoder=SerializerDict)

Parameters

skip : Optional[List[str]], default=None List of field names as strings to skip when forming the dictionary. By default, None.

Returns

Dict[str, Any] Encoded object containing all information to reform an EasyScience object.

from_dict(obj_dict) classmethod

Re-create an EasyScience object from a full encoded dictionary.

Parameters:

Name Type Description Default
obj_dict Dict[str, Any]

Dictionary containing the serialized contents (from SerializerDict) of an EasyScience object.

required

Returns:

Type Description
Any

Reformed EasyScience object.

Functions

Modules

descriptor_bool

Classes:

Name Description
DescriptorBool

A Descriptor for boolean values.

Classes

DescriptorBool(name, value, unique_name=None, description=None, url=None, display_name=None, parent=None)

A Descriptor for boolean values.

Methods:

Name Description
encode

Use an encoder to covert an EasyScience object into another

decode

Re-create an EasyScience object from the output of an encoder.

as_dict

Convert an EasyScience object into a full dictionary using

from_dict

Re-create an EasyScience object from a full encoded dictionary.

Attributes:

Name Type Description
value bool

Get the value of self.

name str

Get the name of the object.

display_name str

Get a pretty display name.

description str

Get the description of the object.

url str

Get the url of the object.

unique_name str

Get the unique name of this object.

Attributes
value property writable

Get the value of self.

Returns:

Type Description
bool

Value of self.

name property writable

Get the name of the object.

Returns:

Type Description
str

Name of the object.

display_name property writable

Get a pretty display name.

Returns:

Type Description
str

The pretty display name.

description property writable

Get the description of the object.

Returns:

Type Description
str

Description of the object.

url property writable

Get the url of the object.

Returns:

Type Description
str

Url of the object.

unique_name property writable

Get the unique name of this object.

Returns:

Type Description
str

Unique name of this object.

Functions
encode(skip=None, encoder=None, **kwargs)

Use an encoder to covert an EasyScience object into another format. Default is to a dictionary using SerializerDict.

Parameters:

Name Type Description Default
skip Optional[List[str]]

List of field names as strings to skip when forming the encoded object. By default, None.

None
encoder Optional[SerializerBase]

The encoder to be used for encoding the data. By default, None.

None
**kwargs

Any additional key word arguments to be passed to the encoder.

{}

Returns:

Type Description
Any

Encoded object containing all information to reform an EasyScience object.

decode(obj, decoder=None) classmethod

Re-create an EasyScience object from the output of an encoder. The default decoder is SerializerDict.

Parameters:

Name Type Description Default
obj Any

Encoded EasyScience object.

required
decoder Optional[SerializerBase]

Decoder to be used to reform the EasyScience object. By default, None.

None

Returns:

Type Description
Any

Reformed EasyScience object.

as_dict(skip=None)

Convert an EasyScience object into a full dictionary using SerializerDict. This is a shortcut for obj.encode(encoder=SerializerDict)

Parameters

skip : Optional[List[str]], default=None List of field names as strings to skip when forming the dictionary. By default, None.

Returns

Dict[str, Any] Encoded object containing all information to reform an EasyScience object.

from_dict(obj_dict) classmethod

Re-create an EasyScience object from a full encoded dictionary.

Parameters:

Name Type Description Default
obj_dict Dict[str, Any]

Dictionary containing the serialized contents (from SerializerDict) of an EasyScience object.

required

Returns:

Type Description
Any

Reformed EasyScience object.

Functions

descriptor_number

Classes:

Name Description
DescriptorNumber

A Descriptor for Number values with units.

Functions:

Name Description
notify_observers

Decorator to notify observers of a change in the descriptor.

Classes

DescriptorNumber(name, value, unit='', variance=None, unique_name=None, description=None, url=None, display_name=None, parent=None, **kwargs)

A Descriptor for Number values with units.

The internal representation is a scipp scalar.

param name: Name of the descriptor param value: Value of the descriptor param unit: Unit of the descriptor param variance: Variance of the descriptor param description: Description of the descriptor param url: URL of the descriptor param display_name: Display name of the descriptor param parent: Parent of the descriptor .. note:: Undo/Redo functionality is implemented for the attributes variance, error, unit and value.

Methods:

Name Description
from_scipp

Create a DescriptorNumber from a scipp constant.

convert_unit

Convert the value from one unit system to another.

encode

Use an encoder to covert an EasyScience object into another

decode

Re-create an EasyScience object from the output of an encoder.

from_dict

Re-create an EasyScience object from a full encoded dictionary.

Attributes:

Name Type Description
full_value Variable

Get the value of self as a scipp scalar.

value numbers.Number

Get the value.

unit str

Get the unit.

variance float

Get the variance.

error float

The standard deviation for the parameter.

name str

Get the name of the object.

display_name str

Get a pretty display name.

description str

Get the description of the object.

url str

Get the url of the object.

unique_name str

Get the unique name of this object.

Attributes
full_value property writable

Get the value of self as a scipp scalar.

This is should be usable for most cases.

Returns:

Type Description
Variable

Value of self with unit.

value property writable

Get the value.

This should be usable for most cases. The full value can be obtained from obj.full_value.

Returns:

Type Description
numbers.Number

Value of self with unit.

unit property writable

Get the unit.

Returns:

Type Description
str

Unit as a string.

variance property writable

Get the variance.

Returns:

Type Description
float

Variance.

error property writable

The standard deviation for the parameter.

Returns:

Type Description
float

Error associated with parameter.

name property writable

Get the name of the object.

Returns:

Type Description
str

Name of the object.

display_name property writable

Get a pretty display name.

Returns:

Type Description
str

The pretty display name.

description property writable

Get the description of the object.

Returns:

Type Description
str

Description of the object.

url property writable

Get the url of the object.

Returns:

Type Description
str

Url of the object.

unique_name property writable

Get the unique name of this object.

Returns:

Type Description
str

Unique name of this object.

Functions
from_scipp(name, full_value, **kwargs) classmethod

Create a DescriptorNumber from a scipp constant.

Parameters:

Name Type Description Default
name str

Name of the descriptor.

required
full_value Variable

Value of the descriptor as a scipp scalar.

required
**kwargs Any

Additional parameters for the descriptor.

{}

Returns:

Type Description
DescriptorNumber

DescriptorNumber.

Raises:

Type Description
TypeError

If full_value is not a scalar scipp Variable.

convert_unit(unit_str)

Convert the value from one unit system to another.

Parameters:

Name Type Description Default
unit_str str

New unit in string form.

required
encode(skip=None, encoder=None, **kwargs)

Use an encoder to covert an EasyScience object into another format. Default is to a dictionary using SerializerDict.

Parameters:

Name Type Description Default
skip Optional[List[str]]

List of field names as strings to skip when forming the encoded object. By default, None.

None
encoder Optional[SerializerBase]

The encoder to be used for encoding the data. By default, None.

None
**kwargs

Any additional key word arguments to be passed to the encoder.

{}

Returns:

Type Description
Any

Encoded object containing all information to reform an EasyScience object.

decode(obj, decoder=None) classmethod

Re-create an EasyScience object from the output of an encoder. The default decoder is SerializerDict.

Parameters:

Name Type Description Default
obj Any

Encoded EasyScience object.

required
decoder Optional[SerializerBase]

Decoder to be used to reform the EasyScience object. By default, None.

None

Returns:

Type Description
Any

Reformed EasyScience object.

from_dict(obj_dict) classmethod

Re-create an EasyScience object from a full encoded dictionary.

Parameters:

Name Type Description Default
obj_dict Dict[str, Any]

Dictionary containing the serialized contents (from SerializerDict) of an EasyScience object.

required

Returns:

Type Description
Any

Reformed EasyScience object.

Functions

notify_observers(func)

Decorator to notify observers of a change in the descriptor.

Parameters:

Name Type Description Default
func Callable[..., Any]

Function to be decorated.

required

Returns:

Type Description
Callable[..., Any]

Decorated function.

descriptor_str

Classes:

Name Description
DescriptorStr

A Descriptor for string values.

Classes

DescriptorStr(name, value, unique_name=None, description=None, url=None, display_name=None, parent=None)

A Descriptor for string values.

Methods:

Name Description
encode

Use an encoder to covert an EasyScience object into another

decode

Re-create an EasyScience object from the output of an encoder.

as_dict

Convert an EasyScience object into a full dictionary using

from_dict

Re-create an EasyScience object from a full encoded dictionary.

Attributes:

Name Type Description
value str

Get the value of self.

name str

Get the name of the object.

display_name str

Get a pretty display name.

description str

Get the description of the object.

url str

Get the url of the object.

unique_name str

Get the unique name of this object.

Attributes
value property writable

Get the value of self.

Returns:

Type Description
str

Value of self with unit.

name property writable

Get the name of the object.

Returns:

Type Description
str

Name of the object.

display_name property writable

Get a pretty display name.

Returns:

Type Description
str

The pretty display name.

description property writable

Get the description of the object.

Returns:

Type Description
str

Description of the object.

url property writable

Get the url of the object.

Returns:

Type Description
str

Url of the object.

unique_name property writable

Get the unique name of this object.

Returns:

Type Description
str

Unique name of this object.

Functions
encode(skip=None, encoder=None, **kwargs)

Use an encoder to covert an EasyScience object into another format. Default is to a dictionary using SerializerDict.

Parameters:

Name Type Description Default
skip Optional[List[str]]

List of field names as strings to skip when forming the encoded object. By default, None.

None
encoder Optional[SerializerBase]

The encoder to be used for encoding the data. By default, None.

None
**kwargs

Any additional key word arguments to be passed to the encoder.

{}

Returns:

Type Description
Any

Encoded object containing all information to reform an EasyScience object.

decode(obj, decoder=None) classmethod

Re-create an EasyScience object from the output of an encoder. The default decoder is SerializerDict.

Parameters:

Name Type Description Default
obj Any

Encoded EasyScience object.

required
decoder Optional[SerializerBase]

Decoder to be used to reform the EasyScience object. By default, None.

None

Returns:

Type Description
Any

Reformed EasyScience object.

as_dict(skip=None)

Convert an EasyScience object into a full dictionary using SerializerDict. This is a shortcut for obj.encode(encoder=SerializerDict)

Parameters

skip : Optional[List[str]], default=None List of field names as strings to skip when forming the dictionary. By default, None.

Returns

Dict[str, Any] Encoded object containing all information to reform an EasyScience object.

from_dict(obj_dict) classmethod

Re-create an EasyScience object from a full encoded dictionary.

Parameters:

Name Type Description Default
obj_dict Dict[str, Any]

Dictionary containing the serialized contents (from SerializerDict) of an EasyScience object.

required

Returns:

Type Description
Any

Reformed EasyScience object.

Functions

parameter

Classes:

Name Description
Parameter

A Parameter is a DescriptorNumber which can be used in fitting.

Classes

Parameter(name, value, unit='', variance=0.0, min=-np.inf, max=np.inf, fixed=False, unique_name=None, description=None, url=None, display_name=None, callback=property(), parent=None, **kwargs)

A Parameter is a DescriptorNumber which can be used in fitting.

It has additional fields to facilitate this.

Where the descriptor was for static objects, a Parameter is for dynamic objects. A parameter has the ability to be used in fitting and has additional fields to facilitate this.

Parameters:

Name Type Description Default
name str

Name of this object.

required
value numbers.Number

Value of this object.

required
unit Optional[Union[str, sc.Unit]]

This object can have a physical unit associated with it. By default, ''.

''
variance Optional[numbers.Number]

The variance of the value. By default, 0.0.

0.0
min Optional[numbers.Number]

The minimum value for fitting. By default, -np.inf.

-np.inf
max Optional[numbers.Number]

The maximum value for fitting. By default, np.inf.

np.inf
fixed Optional[bool]

If the parameter is free to vary during fitting. By default, False.

False
unique_name Optional[str]

Unique identifier for this object. By default, None.

None
description Optional[str]

A brief summary of what this object is. By default, None.

None
url Optional[str]

Lookup url for documentation/information. By default, None.

None
display_name Optional[str]

The name of the object as it should be displayed. By default, None.

None
callback property

Callback used to synchronize the parameter with an external model.

property()
parent Optional[Any]

The object which is the parent to this one. By default, None.

None
**kwargs Any

Additional keyword arguments used during serialization.

{}

Raises:

Type Description
TypeError

If any numeric or boolean input has the wrong type.

ValueError

If value falls outside the provided bounds or if the bounds are invalid.

Notes

Undo/Redo functionality is implemented for the attributes value, variance, error, min, max, bounds, fixed, unit

Methods:

Name Description
from_dependency

Create a dependent Parameter directly from a dependency

make_dependent_on

Make this parameter dependent on another parameter.

make_independent

Make this parameter independent.

variance

Set the variance.

error

Set the standard deviation for the parameter.

convert_unit

Perform unit conversion.

set_desired_unit

Set the desired unit for a dependent Parameter.

as_dict

Overwrite the as_dict method to handle dependency information.

from_dict

Custom deserialization to handle parameter dependencies.

resolve_pending_dependencies

Resolve pending dependencies after deserialization.

encode

Use an encoder to covert an EasyScience object into another

decode

Re-create an EasyScience object from the output of an encoder.

from_scipp

Create a DescriptorNumber from a scipp constant.

Attributes:

Name Type Description
independent bool

Is the parameter independent?

dependency_expression str

Get the dependency expression of this parameter.

dependency_map Dict[str, DescriptorNumber]

Get the dependency map of this parameter.

value_no_call_back numbers.Number

Get the currently hold value of self suppressing call back.

full_value Variable

Get the value of self as a scipp scalar.

value numbers.Number

Get the value of self as a Number.

min numbers.Number

Get the minimum value for fitting.

max numbers.Number

Get the maximum value for fitting.

fixed bool

Can the parameter vary while fitting?

name str

Get the name of the object.

display_name str

Get a pretty display name.

description str

Get the description of the object.

url str

Get the url of the object.

unique_name str

Get the unique name of this object.

unit str

Get the unit.

Attributes
independent property writable

Is the parameter independent?

Returns:

Type Description
bool

True = independent, False = dependent.

dependency_expression property writable

Get the dependency expression of this parameter.

Returns:

Type Description
str

The dependency expression of this parameter.

Raises:

Type Description
AttributeError

If the parameter is independent.

dependency_map property writable

Get the dependency map of this parameter.

Returns:

Type Description
Dict[str, DescriptorNumber]

The dependency map of this parameter.

Raises:

Type Description
AttributeError

If the parameter is independent.

value_no_call_back property

Get the currently hold value of self suppressing call back.

Returns:

Type Description
numbers.Number

Value of self without unit.

full_value property writable

Get the value of self as a scipp scalar.

This is should be usable for most cases. If a scipp scalar is not acceptable then the raw value can be obtained through obj.value.

Returns:

Type Description
Variable

Value of self with unit and variance.

value property writable

Get the value of self as a Number.

Returns:

Type Description
numbers.Number

Value of self without unit.

min property writable

Get the minimum value for fitting.

Returns:

Type Description
numbers.Number

Minimum value.

max property writable

Get the maximum value for fitting.

Returns:

Type Description
numbers.Number

Maximum value.

fixed property writable

Can the parameter vary while fitting?

Returns:

Type Description
bool

True = fixed, False = can vary.

name property writable

Get the name of the object.

Returns:

Type Description
str

Name of the object.

display_name property writable

Get a pretty display name.

Returns:

Type Description
str

The pretty display name.

description property writable

Get the description of the object.

Returns:

Type Description
str

Description of the object.

url property writable

Get the url of the object.

Returns:

Type Description
str

Url of the object.

unique_name property writable

Get the unique name of this object.

Returns:

Type Description
str

Unique name of this object.

unit property writable

Get the unit.

Returns:

Type Description
str

Unit as a string.

Functions
from_dependency(name, dependency_expression, dependency_map=None, desired_unit=None, **kwargs) classmethod

Create a dependent Parameter directly from a dependency expression.

Parameters:

Name Type Description Default
name str

The name of the parameter.

required
dependency_expression str

The dependency expression to evaluate. This should be a string which can be evaluated by the ASTEval interpreter.

required
dependency_map Optional[dict]

A dictionary of dependency expression symbol name and dependency object pairs. This is inserted into the asteval interpreter to resolve dependencies. By default, None.

None
desired_unit str | sc.Unit | None

The desired unit of the dependent parameter. By default, None.

None
**kwargs Any

Additional keyword arguments to pass to the Parameter constructor.

{}

Returns:

Type Description
Parameter

A new dependent Parameter object.

make_dependent_on(dependency_expression, dependency_map=None, desired_unit=None)

Make this parameter dependent on another parameter.

This will overwrite the current value, unit, variance, min and max.

How to use the dependency map: If a parameter c has a dependency expression of 'a + b', where a and b are parameters belonging to the model class, then the dependency map needs to have the form {'a': model.a, 'b': model.b}, where model is the model class. I.e. the values are the actual objects, whereas the keys are how they are represented in the dependency expression.

The dependency map is not needed if the dependency expression uses the unique names of the parameters. Unique names in dependency expressions are defined by quotes, e.g. 'Parameter_0' or "Parameter_0" depending on the quotes used for the expression.

Parameters:

Name Type Description Default
dependency_expression str

The dependency expression to evaluate. This should be a string which can be evaluated by a python interpreter.

required
dependency_map Optional[dict]

A dictionary of dependency expression symbol name and dependency object pairs. This is inserted into the asteval interpreter to resolve dependencies. By default, None.

None
desired_unit str | sc.Unit | None

The desired unit of the dependent parameter. If None, the default unit of the dependency expression result is used. By default, None.

None

Raises:

Type Description
NameError

If the dependency expression references unresolved names.

RuntimeError

If the dependency introduces a cyclic dependency.

SyntaxError

If the dependency expression is invalid.

TypeError

If the dependency inputs have invalid types.

UnitError

If converting the dependency result to the desired unit fails.

ValueError

If the dependency expression or dependency map is invalid.

make_independent()

Make this parameter independent.

This will remove the dependency expression, the dependency map and the dependency interpreter.

Returns:

Type Description
None

None.

Raises:

Type Description
AttributeError

If the parameter is already independent.

variance(variance_float)

Set the variance.

Parameters:

Name Type Description Default
variance_float float

Variance as a float.

required

Raises:

Type Description
AttributeError

If the parameter is dependent.

error(value)

Set the standard deviation for the parameter.

Parameters:

Name Type Description Default
value float

New error value.

required

Raises:

Type Description
AttributeError

If the parameter is dependent.

convert_unit(unit_str)

Perform unit conversion.

The value, max and min can change on unit change.

Parameters:

Name Type Description Default
unit_str str

New unit.

required
set_desired_unit(unit_str)

Set the desired unit for a dependent Parameter.

This will convert the parameter to the desired unit.

Parameters:

Name Type Description Default
unit_str str | sc.Unit | None

The desired unit as a string.

required

Raises:

Type Description
AttributeError

If the parameter is independent.

TypeError

If unit_str has an invalid type.

UnitError

If converting to the desired unit fails.

as_dict(skip=None)

Overwrite the as_dict method to handle dependency information.

from_dict(obj_dict) classmethod

Custom deserialization to handle parameter dependencies.

Override the parent method to handle dependency information.

resolve_pending_dependencies()

Resolve pending dependencies after deserialization.

This method should be called after all parameters have been deserialized to establish dependency relationships using serializer_ids.

encode(skip=None, encoder=None, **kwargs)

Use an encoder to covert an EasyScience object into another format. Default is to a dictionary using SerializerDict.

Parameters:

Name Type Description Default
skip Optional[List[str]]

List of field names as strings to skip when forming the encoded object. By default, None.

None
encoder Optional[SerializerBase]

The encoder to be used for encoding the data. By default, None.

None
**kwargs

Any additional key word arguments to be passed to the encoder.

{}

Returns:

Type Description
Any

Encoded object containing all information to reform an EasyScience object.

decode(obj, decoder=None) classmethod

Re-create an EasyScience object from the output of an encoder. The default decoder is SerializerDict.

Parameters:

Name Type Description Default
obj Any

Encoded EasyScience object.

required
decoder Optional[SerializerBase]

Decoder to be used to reform the EasyScience object. By default, None.

None

Returns:

Type Description
Any

Reformed EasyScience object.

from_scipp(name, full_value, **kwargs) classmethod

Create a DescriptorNumber from a scipp constant.

Parameters:

Name Type Description Default
name str

Name of the descriptor.

required
full_value Variable

Value of the descriptor as a scipp scalar.

required
**kwargs Any

Additional parameters for the descriptor.

{}

Returns:

Type Description
DescriptorNumber

DescriptorNumber.

Raises:

Type Description
TypeError

If full_value is not a scalar scipp Variable.

Functions

Modules

parameter_dependency_resolver

Functions:

Name Description
resolve_all_parameter_dependencies

Recursively find all Parameter objects in an object hierarchy and

get_parameters_with_pending_dependencies

Find all Parameter objects in an object hierarchy that have pending

deserialize_and_resolve_parameters

Deserialize parameters from a dictionary and resolve their

Classes

Functions

resolve_all_parameter_dependencies(obj)

Recursively find all Parameter objects in an object hierarchy and resolve their pending dependencies.

This function should be called after deserializing a complex object that contains Parameters with dependencies to ensure all dependency relationships are properly established.

Parameters:

Name Type Description Default
obj Any

The object to search for Parameters (can be a single Parameter, list, dict, or complex object).

required

Raises:

Type Description
ValueError

If one or more pending dependencies cannot be resolved.

get_parameters_with_pending_dependencies(obj)

Find all Parameter objects in an object hierarchy that have pending dependencies.

Parameters:

Name Type Description Default
obj Any

The object to search for Parameters.

required

Returns:

Type Description
List[Parameter]

List of Parameters with pending dependencies.

deserialize_and_resolve_parameters(params_data)

Deserialize parameters from a dictionary and resolve their dependencies.

This is a convenience function that combines Parameter.from_dict() deserialization with dependency resolution in a single call.

Parameters:

Name Type Description Default
params_data Dict[str, Dict[str, Any]]

Dictionary mapping parameter names to their serialized data.

required

Returns:

Type Description
Dict[str, Parameter]

Dictionary mapping parameter names to deserialized Parameters with resolved dependencies.

Modules