variable
Modules:
| Name | Description |
|---|---|
descriptor_array |
|
descriptor_base |
|
descriptor_bool |
|
descriptor_number |
|
descriptor_str |
|
parameter |
|
parameter_dependency_resolver |
|
Classes:
| Name | Description |
|---|---|
DescriptorArray |
A |
DescriptorBase |
This is the base of all variable descriptions for models. |
DescriptorBool |
A |
DescriptorNumber |
A |
DescriptorStr |
A |
Parameter |
A Parameter is a DescriptorNumber which can be used in fitting. |
Classes
DescriptorArray(value, *, unit='', variance=None, unique_name=None, description=None, url=None, display_name=None, dimensions=None)
A Descriptor for Array values with units.
The internal representation is a scipp array.
All arguments after value are keyword-only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Union[list, np.ndarray]
|
Values of this object. |
required |
unit
|
Optional[Union[str, sc.Unit]]
|
This object can have a physical unit associated with it. By default, ''. |
''
|
variance
|
Optional[Union[list, np.ndarray]]
|
The variances of the values, with the same shape as
|
None
|
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. Falls back to |
None
|
dimensions
|
Optional[list]
|
List of dimensions to pass to scipp. Autogenerated if not supplied. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
UnitError
|
If |
ValueError
|
If |
Methods:
| Name | Description |
|---|---|
from_dict |
Re-create an EasyScience object from a full encoded dictionary. |
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. |
to_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, |
__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. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique 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. |
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 |
Attributes
unique_name
property
writable
Get the unique 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. |
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
error
property
writable
Methods:
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
|
required |
Returns:
| Type | Description |
|---|---|
EasyBase
|
Reformed EasyScience object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input dictionary does not describe the expected class. |
from_scipp(full_value, **kwargs)
classmethod
Create a DescriptorArray from a scipp array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
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 |
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 |
UnitError
|
If the unit conversion fails. |
__copy__()
Return a copy of the current DescriptorArray.
to_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
|
Returns:
| Type | Description |
|---|---|
Union[DescriptorArray, DescriptorNumber]
|
Descriptor representing the summed data. |
DescriptorBase(*, unique_name=None, description=None, url=None, display_name=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 value as well as optionally a unit, 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.
It contains all information to describe a single unique property of an object. This description includes a 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 |
|---|---|---|---|
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. Falls back to |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If any optional string field has an invalid type. |
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object from a full encoded dictionary. |
__copy__ |
Return a copy of the object. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique 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. |
value |
Any
|
Get the value of the object. |
Attributes
unique_name
property
writable
Get the unique 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. |
value
abstractmethod
property
writable
Get the value of the object.
Methods:
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skip
|
Optional[List[str]]
|
List of field names as strings to skip when forming the dictionary. By default, None. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Encoded object containing all information to reform an EasyScience object. |
Notes
A unique_name that was generated automatically is not
written; only an explicitly supplied one is, so that a
deserialized object gets a fresh name instead of clashing with
the original. Likewise display_name is omitted when it is
None. Pass skip to drop further fields.
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
|
required |
Returns:
| Type | Description |
|---|---|
EasyBase
|
Reformed EasyScience object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input dictionary does not describe the expected class. |
__copy__()
Return a copy of the object.
DescriptorBool(value, *, unique_name=None, description=None, url=None, display_name=None)
A Descriptor for boolean values.
All arguments after value are keyword-only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
bool
|
Value 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. Falls back to |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Methods:
| Name | Description |
|---|---|
to_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 |
|---|---|---|
unique_name |
str
|
Get the unique 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. |
value |
bool
|
Get the value of self. |
Attributes
unique_name
property
writable
Get the unique 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. |
value
property
writable
Get the value of self.
Returns:
| Type | Description |
|---|---|
bool
|
Value of self. |
Methods:
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skip
|
Optional[List[str]]
|
List of field names as strings to skip when forming the dictionary. By default, None. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Encoded object containing all information to reform an EasyScience object. |
Notes
A unique_name that was generated automatically is not
written; only an explicitly supplied one is, so that a
deserialized object gets a fresh name instead of clashing with
the original. Likewise display_name is omitted when it is
None. Pass skip to drop further fields.
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
|
required |
Returns:
| Type | Description |
|---|---|
EasyBase
|
Reformed EasyScience object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input dictionary does not describe the expected class. |
DescriptorNumber(value, *, unit='', variance=None, unique_name=None, description=None, url=None, display_name=None, **kwargs)
A Descriptor for Number values with units.
The internal representation is a scipp scalar.
All arguments after value are keyword-only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
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, None. |
None
|
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. Falls back to |
None
|
**kwargs
|
Any
|
Additional keyword arguments used during (de)serialization. |
{}
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
UnitError
|
If |
ValueError
|
If |
Methods:
| Name | Description |
|---|---|
from_dict |
Re-create an EasyScience object from a full encoded dictionary. |
from_scipp |
Create a DescriptorNumber from a scipp constant. |
convert_unit |
Convert the value from one unit system to another. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique 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. |
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. |
Attributes
unique_name
property
writable
Get the unique 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. |
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. |
Methods:
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
|
required |
Returns:
| Type | Description |
|---|---|
EasyBase
|
Reformed EasyScience object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input dictionary does not describe the expected class. |
from_scipp(full_value, **kwargs)
classmethod
Create a DescriptorNumber from a scipp constant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
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 |
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 |
DescriptorStr(value, *, unique_name=None, description=None, url=None, display_name=None)
A Descriptor for string values.
All arguments after value are keyword-only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Value 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. Falls back to |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Methods:
| Name | Description |
|---|---|
to_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 |
|---|---|---|
unique_name |
str
|
Get the unique 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. |
value |
str
|
Get the value of self. |
Attributes
unique_name
property
writable
Get the unique 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. |
value
property
writable
Get the value of self.
Returns:
| Type | Description |
|---|---|
str
|
Value of self with unit. |
Methods:
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skip
|
Optional[List[str]]
|
List of field names as strings to skip when forming the dictionary. By default, None. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Encoded object containing all information to reform an EasyScience object. |
Notes
A unique_name that was generated automatically is not
written; only an explicitly supplied one is, so that a
deserialized object gets a fresh name instead of clashing with
the original. Likewise display_name is omitted when it is
None. Pass skip to drop further fields.
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
|
required |
Returns:
| Type | Description |
|---|---|
EasyBase
|
Reformed EasyScience object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input dictionary does not describe the expected class. |
Parameter(value, *, unit='', variance=0.0, min=-np.inf, max=np.inf, fixed=False, unique_name=None, description=None, url=None, display_name=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.
All arguments after value are keyword-only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
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. Falls back
to |
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 |
Methods:
| Name | Description |
|---|---|
from_scipp |
Create a DescriptorNumber from a scipp constant. |
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. |
to_dict |
Overwrite the to_dict method to handle dependency information. |
from_dict |
Custom deserialization to handle parameter dependencies. |
resolve_pending_dependencies |
Resolve pending dependencies after deserialization. |
Attributes:
| Name | Type | Description |
|---|---|---|
unique_name |
str
|
Get the unique 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. |
unit |
str
|
Get the unit. |
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. |
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? |
Attributes
unique_name
property
writable
Get the unique 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. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
Unit as a string. |
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. |
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. |
Methods:
from_scipp(full_value, **kwargs)
classmethod
Create a DescriptorNumber from a scipp constant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
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 |
from_dependency(dependency_expression, dependency_map=None, desired_unit=None, **kwargs)
classmethod
Create a dependent Parameter directly from a dependency expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
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 |
UnitError
|
If converting to the desired unit fails. |
to_dict(skip=None)
Overwrite the to_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.
Modules
descriptor_array
Classes:
| Name | Description |
|---|---|
DescriptorArray |
A |
Classes
DescriptorArray(value, *, unit='', variance=None, unique_name=None, description=None, url=None, display_name=None, dimensions=None)
A Descriptor for Array values with units.
The internal representation is a scipp array.
All arguments after value are keyword-only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Union[list, np.ndarray]
|
Values of this object. |
required |
unit
|
Optional[Union[str, sc.Unit]]
|
This object can have a physical unit associated with it. By default, ''. |
''
|
variance
|
Optional[Union[list, np.ndarray]]
|
The variances of the values, with the same shape as
|
None
|
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. Falls back to |
None
|
dimensions
|
Optional[list]
|
List of dimensions to pass to scipp. Autogenerated if not supplied. By default, None. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
UnitError
|
If |
ValueError
|
If |
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. |
to_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, |
__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. |
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 |
unique_name |
str
|
Get the unique 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. |
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
error
property
writable
unique_name
property
writable
Get the unique 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. |
Methods:
from_scipp(full_value, **kwargs)
classmethod
Create a DescriptorArray from a scipp array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
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 |
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 |
UnitError
|
If the unit conversion fails. |
__copy__()
Return a copy of the current DescriptorArray.
to_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
|
Returns:
| Type | Description |
|---|---|
Union[DescriptorArray, DescriptorNumber]
|
Descriptor representing the summed data. |
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
|
required |
Returns:
| Type | Description |
|---|---|
EasyBase
|
Reformed EasyScience object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input dictionary does not describe the expected class. |
descriptor_base
Classes:
| Name | Description |
|---|---|
DescriptorBase |
This is the base of all variable descriptions for models. |
Classes
DescriptorBase(*, unique_name=None, description=None, url=None, display_name=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 value as well as optionally a unit, 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.
It contains all information to describe a single unique property of an object. This description includes a 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 |
|---|---|---|---|
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. Falls back to |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If any optional string field has an invalid type. |
Methods:
| Name | Description |
|---|---|
to_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object from a full encoded dictionary. |
__copy__ |
Return a copy of the object. |
Attributes:
| Name | Type | Description |
|---|---|---|
description |
str
|
Get the description of the object. |
url |
str
|
Get the url of the object. |
value |
Any
|
Get the value of the object. |
unique_name |
str
|
Get the unique name of the object. |
display_name |
str
|
Get a pretty display name. |
Attributes
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. |
value
abstractmethod
property
writable
Get the value of the object.
unique_name
property
writable
Get the unique name of the object.
display_name
property
writable
Get a pretty display name.
Returns:
| Type | Description |
|---|---|
str
|
The pretty display name. |
Methods:
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skip
|
Optional[List[str]]
|
List of field names as strings to skip when forming the dictionary. By default, None. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Encoded object containing all information to reform an EasyScience object. |
Notes
A unique_name that was generated automatically is not
written; only an explicitly supplied one is, so that a
deserialized object gets a fresh name instead of clashing with
the original. Likewise display_name is omitted when it is
None. Pass skip to drop further fields.
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
|
required |
Returns:
| Type | Description |
|---|---|
EasyBase
|
Reformed EasyScience object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input dictionary does not describe the expected class. |
__copy__()
Return a copy of the object.
Modules
descriptor_bool
Classes:
| Name | Description |
|---|---|
DescriptorBool |
A |
Classes
DescriptorBool(value, *, unique_name=None, description=None, url=None, display_name=None)
A Descriptor for boolean values.
All arguments after value are keyword-only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
bool
|
Value 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. Falls back to |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Methods:
| Name | Description |
|---|---|
to_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. |
unique_name |
str
|
Get the unique 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. |
Attributes
value
property
writable
Get the value of self.
Returns:
| Type | Description |
|---|---|
bool
|
Value of self. |
unique_name
property
writable
Get the unique 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. |
Methods:
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skip
|
Optional[List[str]]
|
List of field names as strings to skip when forming the dictionary. By default, None. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Encoded object containing all information to reform an EasyScience object. |
Notes
A unique_name that was generated automatically is not
written; only an explicitly supplied one is, so that a
deserialized object gets a fresh name instead of clashing with
the original. Likewise display_name is omitted when it is
None. Pass skip to drop further fields.
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
|
required |
Returns:
| Type | Description |
|---|---|
EasyBase
|
Reformed EasyScience object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input dictionary does not describe the expected class. |
descriptor_number
Classes:
| Name | Description |
|---|---|
DescriptorNumber |
A |
Functions:
| Name | Description |
|---|---|
notify_observers |
Decorator to notify observers of a change in the descriptor. |
Classes
DescriptorNumber(value, *, unit='', variance=None, unique_name=None, description=None, url=None, display_name=None, **kwargs)
A Descriptor for Number values with units.
The internal representation is a scipp scalar.
All arguments after value are keyword-only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
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, None. |
None
|
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. Falls back to |
None
|
**kwargs
|
Any
|
Additional keyword arguments used during (de)serialization. |
{}
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
UnitError
|
If |
ValueError
|
If |
Methods:
| Name | Description |
|---|---|
from_scipp |
Create a DescriptorNumber from a scipp constant. |
convert_unit |
Convert the value from one unit system to another. |
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. |
unique_name |
str
|
Get the unique 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. |
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. |
unique_name
property
writable
Get the unique 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. |
Methods:
from_scipp(full_value, **kwargs)
classmethod
Create a DescriptorNumber from a scipp constant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
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 |
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 |
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
|
required |
Returns:
| Type | Description |
|---|---|
EasyBase
|
Reformed EasyScience object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input dictionary does not describe the expected class. |
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 |
Classes
DescriptorStr(value, *, unique_name=None, description=None, url=None, display_name=None)
A Descriptor for string values.
All arguments after value are keyword-only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Value 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. Falls back to |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Methods:
| Name | Description |
|---|---|
to_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. |
unique_name |
str
|
Get the unique 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. |
Attributes
value
property
writable
Get the value of self.
Returns:
| Type | Description |
|---|---|
str
|
Value of self with unit. |
unique_name
property
writable
Get the unique 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. |
Methods:
to_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerBases generic convert_to_dict method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skip
|
Optional[List[str]]
|
List of field names as strings to skip when forming the dictionary. By default, None. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Encoded object containing all information to reform an EasyScience object. |
Notes
A unique_name that was generated automatically is not
written; only an explicitly supplied one is, so that a
deserialized object gets a fresh name instead of clashing with
the original. Likewise display_name is omitted when it is
None. Pass skip to drop further fields.
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
|
required |
Returns:
| Type | Description |
|---|---|
EasyBase
|
Reformed EasyScience object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input dictionary does not describe the expected class. |
parameter
Classes:
| Name | Description |
|---|---|
Parameter |
A Parameter is a DescriptorNumber which can be used in fitting. |
Classes
Parameter(value, *, unit='', variance=0.0, min=-np.inf, max=np.inf, fixed=False, unique_name=None, description=None, url=None, display_name=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.
All arguments after value are keyword-only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
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. Falls back
to |
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 |
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. |
to_dict |
Overwrite the to_dict method to handle dependency information. |
from_dict |
Custom deserialization to handle parameter dependencies. |
resolve_pending_dependencies |
Resolve pending dependencies after deserialization. |
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. |
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? |
unique_name |
str
|
Get the unique 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. |
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. |
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. |
unique_name
property
writable
Get the unique 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. |
unit
property
writable
Get the unit.
Returns:
| Type | Description |
|---|---|
str
|
Unit as a string. |
Methods:
from_dependency(dependency_expression, dependency_map=None, desired_unit=None, **kwargs)
classmethod
Create a dependent Parameter directly from a dependency expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
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 |
UnitError
|
If converting to the desired unit fails. |
to_dict(skip=None)
Overwrite the to_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.
from_scipp(full_value, **kwargs)
classmethod
Create a DescriptorNumber from a scipp constant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
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 |
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. |