Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions pypesto/select/postprocessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def waterfall_plot_postprocessor(
plt.savefig(str(plot_output_path))


def save_postprocessor(
def save_minimize_result_postprocessor(
problem: ModelProblem,
output_path: TYPE_PATH = ".",
use_model_hash: bool = False,
Expand All @@ -68,7 +68,7 @@ def save_postprocessor(

from functools import partial
output_path = 'results'
pp = partial(save_postprocessor, output_path=output_path)
pp = partial(save_minimize_result_postprocessor, output_path=output_path)
selector = pypesto.select.ModelSelector(
problem=problem,
model_postprocessor=pp,
Expand All @@ -93,6 +93,54 @@ def save_postprocessor(
)


def save_postprocessor(*args, **kwargs):
"""Use `save_minimize_result_postprocessor`. Deprecated."""
warnings.warn(
"`save_postprocessor` is deprecated. Use "
"`save_minimize_result_postprocessor`.",
DeprecationWarning,
stacklevel=2,
)
save_minimize_result_postprocessor(*args, **kwargs)


def save_model_postprocessor(
problem: ModelProblem,
output_path: TYPE_PATH = ".",
use_model_hash: bool = False,
):
"""Save the model.

When used, first set the output folder for results, e.g. with
:func:`functools.partial`. This is because postprocessors should take only a
single parameter: an optimized model.

.. code-block:: python

from functools import partial
output_path = 'results'
pp = partial(save_yaml_postprocessor, output_path=output_path)
selector = pypesto.select.ModelSelector(
problem=problem,
model_postprocessor=pp,
)

Parameters
----------
problem:
A model selection :class:`ModelProblem` that has been optimized.
output_path:
The location where output will be stored.
use_model_hash:
Whether the filename should use the model hash. Defaults to ``False``,
in which case the model ID is used instead.
"""
stem = problem.model.model_id
if use_model_hash:
stem = str(problem.model.hash)
problem.model.to_yaml(Path(output_path) / (stem + ".yaml"))


def model_id_binary_postprocessor(problem: ModelProblem):
"""Change a PEtab Select model ID to a binary string.

Expand Down