Skip to content

Commit

Permalink
Allow overriding model name during PySB import (#1801)
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl authored May 20, 2022
1 parent 8546384 commit 13b7422
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
12 changes: 5 additions & 7 deletions python/amici/petab_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def import_petab_problem(
:param model_name:
Name of the generated model. If model file name was provided,
this defaults to the file name without extension, otherwise
the SBML model ID will be used.
the model ID will be used.
:param force_compile:
Whether to compile the model even if the target folder is not empty,
Expand All @@ -303,12 +303,9 @@ def import_petab_problem(
else:
model_output_dir = os.path.abspath(model_output_dir)

if PysbPetabProblem and isinstance(petab_problem, PysbPetabProblem):
if model_name is None:
model_name = petab_problem.pysb_model.name
else:
raise ValueError(
"Argument model_name currently not allowed for pysb models")
if PysbPetabProblem and isinstance(petab_problem, PysbPetabProblem) \
and model_name is None:
model_name = petab_problem.pysb_model.name
elif model_name is None:
model_name = _create_model_name(model_output_dir)

Expand All @@ -333,6 +330,7 @@ def import_petab_problem(
if PysbPetabProblem and isinstance(petab_problem, PysbPetabProblem):
import_model_pysb(
petab_problem,
model_name=model_name,
model_output_dir=model_output_dir,
**kwargs)
else:
Expand Down
10 changes: 8 additions & 2 deletions python/amici/petab_import_pysb.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ def import_model_pysb(
petab_problem: PysbPetabProblem,
model_output_dir: Optional[Union[str, Path]] = None,
verbose: Optional[Union[bool, int]] = True,
model_name: Optional[str] = None,
**kwargs
) -> None:
"""
Expand All @@ -329,11 +330,13 @@ def import_model_pysb(
:param verbose:
Print/log extra information.
:param model_name:
Name of the generated model module
:param kwargs:
Additional keyword arguments to be passed to
:meth:`amici.pysb_import.pysb2amici`.
"""

set_log_level(logger, verbose)

logger.info("Importing model ...")
Expand Down Expand Up @@ -374,7 +377,10 @@ def import_model_pysb(
observable_table)

from amici.pysb_import import pysb2amici
pysb2amici(pysb_model, model_output_dir, verbose=True,
pysb2amici(model=pysb_model,
output_dir=model_output_dir,
model_name=model_name,
verbose=True,
observables=observables,
sigmas=sigmas,
constant_parameters=constant_parameters,
Expand Down
9 changes: 8 additions & 1 deletion python/amici/pysb_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def pysb2amici(
# See https://github.com/AMICI-dev/AMICI/pull/1672
cache_simplify: bool = False,
generate_sensitivity_code: bool = True,
model_name: Optional[str] = None,
):
r"""
Generate AMICI C++ files for the provided model.
Expand Down Expand Up @@ -124,6 +125,10 @@ def pysb2amici(
:param generate_sensitivity_code:
if set to ``False``, code for sensitivity computation will not be
generated
:param model_name:
Name for the generated model module. If None, :attr:`pysb.Model.name`
will be used.
"""
if observables is None:
observables = []
Expand All @@ -133,6 +138,8 @@ def pysb2amici(
if sigmas is None:
sigmas = {}

model_name = model_name or model.name

set_log_level(logger, verbose)
ode_model = ode_model_from_pysb_importer(
model, constant_parameters=constant_parameters,
Expand All @@ -146,7 +153,7 @@ def pysb2amici(
exporter = ODEExporter(
ode_model,
outdir=output_dir,
model_name=model.name,
model_name=model_name,
verbose=verbose,
assume_pow_positivity=assume_pow_positivity,
compiler=compiler,
Expand Down

0 comments on commit 13b7422

Please sign in to comment.