Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Petab Importer reforge #1442

Merged
merged 42 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
cab5b27
Moved creation of the amici objective function to a separate class, l…
PaulJonasJost Jul 31, 2024
cf348c1
Remove check gradients, as this can be done in an objective function
PaulJonasJost Jul 31, 2024
3775c3c
Added functions with a not implementedError and moved most of them to…
PaulJonasJost Jul 31, 2024
68f365b
Moved import to a factory, allowing a single PEtabImporter to functio…
PaulJonasJost Aug 3, 2024
d214852
Resolve potential annotation problems.
PaulJonasJost Aug 3, 2024
7482672
Solved the problem of x_names not saving the fixd parameters. similar…
PaulJonasJost Aug 5, 2024
cf2edcd
rewrote petab testsuite to fit new design.
PaulJonasJost Aug 5, 2024
385030b
Adjusted text and example code for new changes
PaulJonasJost Aug 5, 2024
10c6765
import error with petab simulator
PaulJonasJost Aug 5, 2024
722d637
updated code
PaulJonasJost Aug 5, 2024
f0f672f
import petab as optional
PaulJonasJost Aug 5, 2024
a321a39
Adjusted roadrunner example and also solved issue in PetabImporterRR
PaulJonasJost Aug 5, 2024
865c3cc
Another import
PaulJonasJost Aug 5, 2024
cd96ac0
Another import and spline error
PaulJonasJost Aug 5, 2024
94ed171
Merge branch 'develop' into petab_simulator_support
PaulJonasJost Aug 5, 2024
c9f9f7b
Changed the documentation that is included
PaulJonasJost Aug 5, 2024
32f930d
Merge remote-tracking branch 'origin/petab_simulator_support' into pe…
PaulJonasJost Aug 5, 2024
33e1a33
added test for petabSimulator with the example of basico
PaulJonasJost Aug 5, 2024
1ccdbf2
Fix text for check gradients and fix roadrunner notebook.
PaulJonasJost Aug 5, 2024
b80b4c8
added test for petabSimulator with the example of basico
PaulJonasJost Aug 8, 2024
ce91536
cleared output
PaulJonasJost Aug 9, 2024
9bbdb13
Hopeflly renamed everything
PaulJonasJost Aug 9, 2024
fef1387
Temporary fix for roadrunner fd objective
PaulJonasJost Aug 9, 2024
662de64
correct installation of basico as petab simulator in test
PaulJonasJost Aug 23, 2024
a34a54b
Removed try-except in simulator as it is to unspecific. Now requiring…
PaulJonasJost Aug 23, 2024
40269ec
Merge branch 'develop' into petab_simulator_support
PaulJonasJost Aug 23, 2024
e21533d
not basico but copasi-basico
PaulJonasJost Aug 23, 2024
5293eef
Merge remote-tracking branch 'origin/petab_simulator_support' into pe…
PaulJonasJost Aug 23, 2024
77bb2bb
not copasi-basico but copasi-basico[petab]
PaulJonasJost Aug 23, 2024
8962a52
Merge branch 'develop' into petab_simulator_support
PaulJonasJost Sep 4, 2024
f5f5d39
Adjusted some description text
PaulJonasJost Sep 9, 2024
479ba3e
Merge branch 'develop' into petab_simulator_support
PaulJonasJost Sep 9, 2024
53c8e61
More accurate documentation
PaulJonasJost Sep 9, 2024
4c4e978
Replaced Usage of roadrunner, amici, petab strings with constants
PaulJonasJost Sep 9, 2024
5e5be6d
Update doc/example/petab_import.ipynb
PaulJonasJost Sep 9, 2024
2831e47
Merge branch 'develop' into petab_simulator_support
PaulJonasJost Sep 11, 2024
20057d5
Update doc/example/petab_import.ipynb
PaulJonasJost Sep 16, 2024
460213b
Renamed factory mentions as it was not a fitting name.
PaulJonasJost Sep 16, 2024
fde7b07
added option to pass simulator type and simulator to create_objective…
PaulJonasJost Sep 16, 2024
a09e8bf
Merge branch 'develop' into petab_simulator_support
PaulJonasJost Sep 16, 2024
983da42
Merge branch 'develop' into petab_simulator_support
PaulJonasJost Sep 17, 2024
809a8e0
Merge branch 'develop' into petab_simulator_support
PaulJonasJost Sep 23, 2024
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
6 changes: 3 additions & 3 deletions doc/example/petab_import.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The model must be imported to pyPESTO and AMICI. Therefore, we create a `pypesto.PetabImporter` from the problem. The importer itself creates a `pypesto.petab.Factory`, which is used to create the AMICI objective and model."
"In order to import the model into pyPESTO, we additionally need a simulator. We can clarify the simulator through the `, simulator_type` argument. Supported simulators are e.g.`amici` and `roadrunner`. We will use AMICI as our example simulator. Therefore, we create a `pypesto.PetabImporter` from the problem. The importer itself creates a `pypesto.petab.Factory`, which is used to create the AMICI objective and model."
PaulJonasJost marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
Expand All @@ -116,7 +116,7 @@
},
"outputs": [],
"source": [
"importer = pypesto.petab.PetabImporter(petab_problem)\n",
"importer = pypesto.petab.PetabImporter(petab_problem, simulator_type=\"amici\")\n",
"factory = importer.create_objective_creator()\n",
"\n",
"model = factory.create_model(verbose=False)\n",
Expand Down Expand Up @@ -155,7 +155,7 @@
"metadata": {},
"outputs": [],
"source": [
"importer = pypesto.petab.PetabImporter.from_yaml(yaml_config)\n",
"importer = pypesto.petab.PetabImporter.from_yaml(yaml_config, simulator_type=\"amici\")\n",
"problem = importer.create_problem() # creating the problem from the importer. The objective can be found at problem.objective"
]
},
Expand Down
4 changes: 4 additions & 0 deletions pypesto/C.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ class EnsembleType(Enum):
X0 = "x0"
ID = "id"

AMICI = "amici"
ROADRUNNER = "roadrunner"
PETAB = "petab"


###############################################################################
# HIERARCHICAL SCALING + OFFSET
Expand Down
4 changes: 2 additions & 2 deletions pypesto/petab/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@


class ObjectiveCreator(ABC):
"""Abstract factory for creating an objective function."""
"""Abstract Creator for creating an objective function."""

@abstractmethod
def create_objective(self, **kwargs) -> ObjectiveBase:
Expand All @@ -84,7 +84,7 @@ def __init__(
validate_petab: bool = True,
):
"""
Initialize the factory.
Initialize the creator.

Parameters
----------
Expand Down
17 changes: 10 additions & 7 deletions pypesto/petab/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
roadrunner = None

from ..C import (
AMICI,
CENSORED,
ORDINAL,
ORDINAL_OPTIONS,
PETAB,
ROADRUNNER,
SEMIQUANTITATIVE,
SPLINE_APPROXIMATION_OPTIONS,
)
Expand Down Expand Up @@ -74,7 +77,7 @@ def __init__(
validate_petab_hierarchical: bool = True,
hierarchical: bool = False,
inner_options: dict | None = None,
simulator_type: str = "amici",
simulator_type: str = AMICI,
simulator: petab.Simulator | None = None,
rr: roadrunner.RoadRunner | None = None,
):
Expand Down Expand Up @@ -168,7 +171,7 @@ def __init__(

self.simulator_type = simulator_type
self.simulator = simulator
if simulator_type == "petab" and simulator is None:
if simulator_type == PETAB and simulator is None:
raise ValueError(
"A petab simulator object must be provided if the simulator "
"type is 'petab'."
Expand All @@ -180,7 +183,7 @@ def from_yaml(
yaml_config: dict | str,
output_folder: str = None,
model_name: str = None,
simulator_type: str = "amici",
simulator_type: str = AMICI,
) -> PetabImporter:
"""Simplified constructor using a petab yaml file."""
petab_problem = petab.Problem.from_yaml(yaml_config)
Expand Down Expand Up @@ -288,7 +291,7 @@ def create_startpoint_method(self, **kwargs) -> StartpointMethod:

def create_objective_creator(self) -> ObjectiveCreator:
"""Choose factory depending on the simulator type."""
if self.simulator_type == "amici":
if self.simulator_type == AMICI:
return AmiciObjectiveCreator(
petab_problem=self.petab_problem,
output_folder=self.output_folder,
Expand All @@ -298,11 +301,11 @@ def create_objective_creator(self) -> ObjectiveCreator:
non_quantitative_data_types=self._non_quantitative_data_types,
validate_petab=self.validate_petab,
)
elif self.simulator_type == "petab":
elif self.simulator_type == PETAB:
return PetabSimulatorObjectiveCreator(
petab_problem=self.petab_problem, simulator=self.simulator
)
elif self.simulator_type == "roadrunner":
elif self.simulator_type == ROADRUNNER:
return RoadRunnerObjectiveCreator(
petab_problem=self.petab_problem, rr=self.roadrunner_instance
)
Expand Down Expand Up @@ -447,7 +450,7 @@ def create_predictor(
condition_ids: Sequence[str] = None,
) -> AmiciPredictor:
"""See :meth:`AmiciObjectiveCreator.create_predictor`."""
if self.simulator_type != "amici":
if self.simulator_type != AMICI:
raise ValueError(
"Predictor can only be created for amici models and is "
"supposed to be created from the AmiciObjectiveCreator."
Expand Down
Loading