Models#

class panorama.systems.models.Models(models=None)#

Bases: object

Represents a collection of models and provides interfaces for interaction.

This class is designed to manage a collection of Model objects. It provides functionality for iterating over the models, accessing model details, generating mappings between function units and their models, and handling families associated with models. Additionally, it allows reading model configurations from JSON files and adding new models to the collection.

__init__(models=None)#

Initializes an instance of the class.

Parameters:

models (Set[Model]) – A set of models to be used. Defaults to None.

__iter__()#

Yields Model instances from the internal model getter.

This method provides an iterator over the Model objects retrieved from the self._model_getter. Each model instance is yielded one at a time.

Yields:

Model – The next model instance in the sequence.

add_model(model)#

Adds a new model to the collection if it does not already exist.

This method allows adding a model to the collection, provided that no model with the same name exists in the current collection. If a model with the same name is already present, a KeyError will be raised. Before adding the model, it ensures the validity of the model by invoking its check_model method.

Parameters:

model (Model) – The model instance to be added to the collection.

Raises:
  • KeyError – If a model with the same name is already present in the collection.

  • Any exception raised by model.check_model() if the model is invalid.

property families: Generator[Family, None, None]#

Provides a generator that yields unique Family instances from models.

This property iterates over all models, collects all unique Family instances associated with the models, and yields them one by one.

Yields:

Generator[Family, None, None] – A generator of Family instances.

families_to_model()#

Generates a mapping of Family objects to their corresponding Model objects.

Constructs a dictionary mapping each Family object in the families attribute to its associated Model object, derived from the model attribute of each Family.

Returns:
  • Dict[Family, Model] – A dictionary where keys are Family objects

  • and values are their corresponding Model objects.

Return type:

Dict[Family, Model]

property func_units: Generator[FuncUnit, None, None]#

Gets a generator of distinct functional units (FuncUnit) across all models.

Yields:

Generator[FuncUnit, None, None] – A generator that iterates over unique functional units found within all models.

func_units_to_model()#

Creates a mapping between func units and their corresponding models.

This method iterates through the collection of function units and creates a dictionary where each function unit is associated with its corresponding model. It provides a convenient structure to access models by their related function units.

Returns:
  • Dict[FuncUnit, Model] – A dictionary mapping function units to their

  • respective models.

Return type:

Dict[FuncUnit, Model]

get_model(name)#

Retrieves a model from the internal collection based on its name.

This method attempts to fetch a model from an internal mapping using the provided name. If the name does not exist in the mapping, a KeyError is raised. On success, it returns the corresponding model.

Parameters:

name (str) – The name of the model to retrieve.

Returns:

Model – The model corresponding to the provided name.

Raises:

KeyError – If the provided name does not exist in the internal mapping.

Return type:

Model

read(model_path)#

Reads a model configuration from a JSON file, processes it, and adds the parsed model.

This function attempts to read the provided file path as a JSON file, extract model configuration data from it, and handle any parsing errors that may occur. Successful processing results in the extracted model being added to the system.

Parameters:

model_path (Path) – Path to the configuration JSON file to be read.

Raises:
  • KeyError – If one or more required keys are missing in the JSON file.

  • TypeError – If one or more attributes in the JSON file are not correctly structured.

  • ValueError – If one or more attributes have unacceptable values in the JSON file.

  • Exception – For any unexpected issues encountered while reading the JSON file.

property size: int#

Gets the size of the value attribute.

This property computes the size of the value attribute by returning its length.

Returns:

int – The length of the value attribute.

property value: List[Model]#

Gets the list of Model instances that are currently available.

This property provides access to all the Model instances contained within the object.

Returns:

List[Model] – A list of Model instances.