Skip to content

Commit

Permalink
doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Dilan Pathirana committed Mar 26, 2024
1 parent bfd6cb5 commit bf1bf17
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
23 changes: 22 additions & 1 deletion petab_select/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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]
Expand Down
12 changes: 11 additions & 1 deletion petab_select/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bf1bf17

Please sign in to comment.