Skip to content

base_classes

Modules:

Name Description
based_base
collection_base

.. deprecated::

easy_list
model_base
new_base
obj_base

.. deprecated::

Classes

Modules

based_base

Classes:

Name Description
BasedBase

Classes

BasedBase(name, interface=None, unique_name=None)

Methods:

Name Description
__reduce__

Make the class picklable.

generate_bindings

Generate or re-generate bindings to an interface (if exists).

switch_interface

Switch or create a new interface.

get_parameters

Get all parameter objects as a list.

get_fit_parameters

Get all objects which can be fitted (and are not fixed) as a

__copy__

Return a copy of the object.

as_dict

Convert an object into a full dictionary using

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
unique_name str

Get the unique name of the object.

name str

Get the common name of the object.

interface InterfaceFactoryTemplate

Get the current interface of the object.

Attributes
unique_name property writable

Get the unique name of the object.

name property writable

Get the common name of the object.

Returns:

Type Description
str

Common name of the object.

interface property writable

Get the current interface of the object.

Functions
__reduce__()

Make the class picklable.

Due to the nature of the dynamic class definitions special measures need to be taken.

Returns:

Type Description
tuple

Tuple consisting of how to make the object.

generate_bindings()

Generate or re-generate bindings to an interface (if exists).

Raises:

Type Description
AttributeError

If interface has not been set.

switch_interface(new_interface_name)

Switch or create a new interface.

get_parameters()

Get all parameter objects as a list.

Returns:

Type Description
List[Parameter]

List of Parameter objects.

get_fit_parameters()

Get all objects which can be fitted (and are not fixed) as a list.

Returns:

Type Description
List[Parameter]

List of Parameter objects which can be used in fitting.

__copy__()

Return a copy of the object.

as_dict(skip=None)

Convert an 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.

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.

Modules

collection_base

.. deprecated:: This module has been moved to easyscience.legacy.collection_base. Please update your imports.

Classes

Modules

easy_list

Classes:

Name Description
EasyList

Classes

EasyList(*args, protected_types=None, unique_name=None, display_name=None, **kwargs)

Parameters:

Name Type Description Default
*args ProtectedType_ | list[ProtectedType_]

Initial items to add to the list.

()
protected_types list[Type[NewBase]] | Type[NewBase] | None

Types that are allowed in the list. Can be a single NewBase subclass or a list of them. If None,. By default, None.

None
unique_name Optional[str]

Optional unique name for the list. By default, None.

None
display_name Optional[str]

Optional display name for the list. By default, None.

None
**kwargs Any

Additional keyword arguments used during deserialization.

{}

Raises:

Type Description
TypeError

If protected_types is not a supported NewBase type or iterable of supported types.

Methods:

Name Description
__getitem__

Get an item by index, slice, or unique_name.

__setitem__

Set an item at an index.

__delitem__

Delete an item by index, slice, or name.

__len__

Return the number of items in the collection.

insert

Insert an item at an index.

get_all_variables

Get all Descriptor and Parameter objects from all

sort

Sort the collection according to the given key function.

pop

Remove and return an item at the given index or unique_name.

to_dict

Convert the EasyList to a dictionary for serialization.

from_dict

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

__copy__

Return a copy of the object.

get_all_parameters

Get all Parameter objects as a list.

get_fittable_parameters

Get all parameters which can be fitted as a list.

get_free_parameters

Get all parameters which are currently free to be fitted as a

get_fit_parameters

This is an alias for get_free_parameters.

Attributes:

Name Type Description
unique_name str

Get the unique name of the object.

display_name str

Get a pretty display name.

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.

Functions
__getitem__(idx)
__getitem__(idx: int) -> ProtectedType_
__getitem__(idx: slice) -> 'EasyList[ProtectedType_]'
__getitem__(idx: str) -> ProtectedType_

Get an item by index, slice, or unique_name.

Parameters:

Name Type Description Default
idx int | slice | str

Index, slice, or unique_name of the item.

required

Returns:

Type Description
ProtectedType_ | 'EasyList[ProtectedType_]'

The item or a new EasyList for slices.

Raises:

Type Description
KeyError

If idx is a string that does not match any item.

TypeError

If idx is not an int, slice, or string.

__setitem__(idx, value)
__setitem__(idx: int, value: ProtectedType_) -> None
__setitem__(
    idx: slice, value: Iterable[ProtectedType_]
) -> None

Set an item at an index.

Parameters:

Name Type Description Default
idx int | slice

Index to set.

required
value ProtectedType_ | Iterable[ProtectedType_]

New value.

required

Raises:

Type Description
TypeError

If idx or value has an invalid type.

ValueError

If slice assignment changes the slice length.

__delitem__(idx)

Delete an item by index, slice, or name.

Parameters:

Name Type Description Default
idx int | slice | str

Index, slice, or name of item to delete.

required

Raises:

Type Description
KeyError

If idx is a string that does not match any item.

TypeError

If idx is not an int, slice, or string.

__len__()

Return the number of items in the collection.

insert(index, value)

Insert an item at an index.

Parameters:

Name Type Description Default
index int

Index to insert at.

required
value ProtectedType_

Item to insert.

required

Raises:

Type Description
TypeError

If index is not an integer or value is of a protected type mismatch.

get_all_variables()

Get all Descriptor and Parameter objects from all elements that are derived from ModelBase.

For each element that is a ModelBase instance, the element's own get_all_variables() method is called and the results are collected into a single flat list.

Returns:

Type Description
List[DescriptorBase]

Flat list of all DescriptorBase objects from all ModelBase elements.

sort(key=None, reverse=False)

Sort the collection according to the given key function.

Parameters:

Name Type Description Default
key Callable[[ProtectedType_], Any]

Mapping function to sort by. By default, None.

None
reverse bool

Whether to reverse the sort. By default, False.

False
pop(index=-1)

Remove and return an item at the given index or unique_name.

Parameters:

Name Type Description Default
index int | str

Index or unique_name of the item to remove. By default, -1.

-1

Returns:

Type Description
ProtectedType_

The removed item.

Raises:

Type Description
KeyError

If index is a string that does not match any item.

TypeError

If index is not an int or string.

to_dict()

Convert the EasyList to a dictionary for serialization.

Returns:

Type Description
dict

Dictionary representation of the EasyList.

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
NewBase

Reformed EasyScience object.

Raises:

Type Description
ImportError

If a protected type cannot be imported.

ValueError

If the input dictionary does not describe an EasyList.

__copy__()

Return a copy of the object.

get_all_parameters()

Get all Parameter objects as a list.

Returns:

Type Description
List[Parameter]

List of Parameter objects.

get_fittable_parameters()

Get all parameters which can be fitted as a list.

Returns:

Type Description
List[Parameter]

List of Parameter objects.

get_free_parameters()

Get all parameters which are currently free to be fitted as a list.

Returns:

Type Description
List[Parameter]

List of Parameter objects.

get_fit_parameters()

This is an alias for get_free_parameters.

To be removed when fully moved to new base classes and minimizer can be changed.

Modules

model_base

Classes:

Name Description
ModelBase

This is the base class for all model classes in EasyScience. It

Classes

ModelBase(unique_name=None, display_name=None)

This is the base class for all model classes in EasyScience. It provides methods to get parameters for fitting and analysis as well as proper serialization/deserialization for DescriptorNumber/Parameter attributes.

It assumes that Parameters/DescriptorNumbers are assigned as properties with the getters returning the parameter but the setter only setting the value of the parameter. e.g.

@property
def my_param(self) -> Parameter:
    '''My param.'''
    return self._my_param


@my_param.setter
def my_param(self, new_value: float) -> None:
    '''My param.'''
    self._my_param.value = new_value

Methods:

Name Description
get_all_variables

Get all Descriptor and Parameter objects as a list.

get_all_parameters

Get all Parameter objects as a list.

get_fittable_parameters

Get all parameters which can be fitted as a list.

get_free_parameters

Get all parameters which are currently free to be fitted as a

get_fit_parameters

This is an alias for get_free_parameters.

from_dict

Re-create an EasyScience object with DescriptorNumber attributes

to_dict

Convert an EasyScience object into a full dictionary using

__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.

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.

Functions
get_all_variables()

Get all Descriptor and Parameter objects as a list.

Returns:

Type Description
List[DescriptorBase]

List of Descriptor and Parameter objects.

get_all_parameters()

Get all Parameter objects as a list.

Returns:

Type Description
List[Parameter]

List of Parameter objects.

get_fittable_parameters()

Get all parameters which can be fitted as a list.

Returns:

Type Description
List[Parameter]

List of Parameter objects.

get_free_parameters()

Get all parameters which are currently free to be fitted as a list.

Returns:

Type Description
List[Parameter]

List of Parameter objects.

get_fit_parameters()

This is an alias for get_free_parameters.

To be removed when fully moved to new base classes and minimizer can be changed.

from_dict(obj_dict) classmethod

Re-create an EasyScience object with DescriptorNumber attributes 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
ModelBase

Reformed EasyScience object.

Raises:

Type Description
SyntaxError

If a deserialized parameter cannot be attached back to the class definition.

ValueError

If the input dictionary does not describe the expected class.

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.

__copy__()

Return a copy of the object.

new_base

Classes:

Name Description
NewBase

This is the new base class for easyscience objects.

Classes

NewBase(unique_name=None, display_name=None)

This is the new base class for easyscience objects.

It provides serialization capabilities as well as unique naming and display naming.

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.

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.

Functions
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.

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
NewBase

Reformed EasyScience object.

Raises:

Type Description
ValueError

If the input dictionary does not describe the expected class.

__copy__()

Return a copy of the object.

Functions

Modules

obj_base

.. deprecated:: This module has been moved to easyscience.legacy.obj_base. Please update your imports.

Classes

Modules