Model Serializer#

class besser.utilities.utils.ModelSerializer[source]#

Bases: object

ModelSerializer is a simple class for serializing and deserializing BESSER models and Python objects.

None#

Note

This class uses the pickle module for serialization and deserialization. Ensure that the models/objects you are serializing are safe and trusted since pickle can execute arbitrary code.

dump(model: any, output_dir: str = None, output_file_name: str = None)[source]#

Serialize and save a model to a file.

Parameters:
  • model (any) – the B-UML model to be serialized and saved.

  • output_dir (str, optional) – the directory where the file should be saved. If not provided, the file will be saved in the current working directory.

  • output_file_name (str, optional) – The name of the output file. If not provided, a default name will be used based on the type of the model: For objects of type DomainModel: “{model_name}.buml” For other types: “model.pkl”

Returns:

None, but store the model as a file.

load(model_path=<class 'str'>)[source]#

Deserialize and load a model from a serialized file using pickle.

Parameters:

model_path (str) – the path to the serialized model file.

Returns:

the deserialized model object.

Return type:

model_loaded

besser.utilities.utils.sort_by_timestamp(obj_set: set) list[source]#

Sorts a set of objects by their timestamp attribute.

This function takes a set of objects (which are instances of the NamedElement class in BESSER) and returns a list of those objects, sorted in ascending order based on their timestamp attribute.

Parameters: obj_set (set[NamedElement]): A set of objects to be sorted. Each object must have a timestamp attribute.

Returns: list: A list of the objects sorted by their timestamp in ascending order.