autofit.ModelInstance#

class autofit.ModelInstance(child_items: Optional[Union[List, Dict]] = None, id_=None)[source]#

Bases: AbstractModel

An instance of a Collection or Model. This is created by optimisers and correspond to a point in the parameter space.

@DynamicAttrs

An instance of a Collection or Model. This is created by optimisers and correspond to a point in the parameter space.

Parameters:

child_items

The child items of the instance. This can be a list or dict.

If a list, the items are assigned to the instance in order. If a dict, the items are assigned to the instance by key and accessed by attribute.

Methods

as_model

Convert this instance to a model

attribute_tuples_with_type

Tuples describing the name and instance for attributes in the model with a given type, recursively.

copy

Create a copy of the model.

direct_tuples_with_type

freeze

Freeze this object.

from_dict

Recursively parse a dictionary returning the model, collection or instance that is represents.

has

Does this instance have an attribute which is of type cls?

items

model_tuples_with_type

All models of the class in this model which have at least one free parameter, recursively.

models_with_type

Return all models of a given type in the model tree.

next_id

object_for_path

Get the object at a given path.

path_instance_tuples_for_class

Tuples containing the path tuple and instance for every instance of the class in the model tree.

replacing_for_path

Create a new model replacing the value for a given path with a new value

tree_flatten

Flatten the instance into a PyTree

tree_unflatten

Create an instance from a flattened PyTree

unfreeze

Unfreeze this object.

values

Attributes

child_items

component_number

dict

A dictionary representation of this object

identifier

label

property dict#

A dictionary representation of this object

tree_flatten() Tuple[List, Tuple][source]#

Flatten the instance into a PyTree

classmethod tree_unflatten(aux_data: Tuple, children: List)[source]#

Create an instance from a flattened PyTree

Parameters:
  • aux_data – Auxiliary information that remains unchanged including the keys of the dict

  • children – Child objects subject to change

Return type:

An instance of this class

as_model(model_classes: Union[type, Iterable[type]] = (), excluded_classes: Union[type, Iterable[type]] = ())[source]#

Convert this instance to a model

Parameters:
  • model_classes – The classes to convert to models

  • excluded_classes – The classes to exclude from conversion

Return type:

A model