From bf1bf17122b2cd42f459ef86c154c4143a8e1b22 Mon Sep 17 00:00:00 2001 From: Dilan Pathirana Date: Tue, 26 Mar 2024 23:19:40 +0100 Subject: [PATCH] doc --- petab_select/model.py | 23 ++++++++++++++++++++++- petab_select/problem.py | 12 +++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/petab_select/model.py b/petab_select/model.py index dc1e8bf0..073d80d3 100644 --- a/petab_select/model.py +++ b/petab_select/model.py @@ -744,6 +744,17 @@ def models_to_yaml_list( def unhash_model(model_hash: str): + """Convert a model hash into model subspace information. + + Args: + model_hash: + The model hash, in the format produced by :func:`hash_model`. + + Returns: + The model subspace ID, and the indices that correspond to a unique + model in the subspace. The indices can be converted to a model with + the `ModelSubspace.indices_to_model` method. + """ model_subspace_id, hashed_model_subspace_indices = model_hash.split( MODEL_HASH_DELIMITER ) @@ -767,7 +778,17 @@ def unhash_model(model_hash: str): return model_subspace_id, model_subspace_indices -def hash_model(model: Model): +def hash_model(model: Model) -> str: + """Create a unique hash for a model. + + Args: + model: + The model. + + Returns: + The hash. The format is the model subspace followed by a representation + of the indices of the model parameters in its subspace. + """ try: hashed_model_subspace_indices = ''.join( MODEL_SUBSPACE_INDICES_HASH_MAP[index] diff --git a/petab_select/problem.py b/petab_select/problem.py index 39dc086e..433ea561 100644 --- a/petab_select/problem.py +++ b/petab_select/problem.py @@ -239,7 +239,17 @@ def get_best( ) return best_model - def model_hash_to_model(self, model_hash: str): + def model_hash_to_model(self, model_hash: str) -> Model: + """Get the model that matches a model hash. + + Args: + model_hash: + The model hash, in the format produced by + :func:`petab_select.model.hash_model`. + + Returns: + The model. + """ model_subspace_id, model_subspace_indices = unhash_model(model_hash) model = self.model_space.model_subspaces[ model_subspace_id