Skip to content

Commit

Permalink
Merge branch 'develop' into rdata_status_int
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl authored Jan 16, 2023
2 parents 75db04f + 6e44a70 commit de87340
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
9 changes: 7 additions & 2 deletions python/sdist/amici/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,19 @@ def _imported_from_setup() -> bool:
from .sbml_import import SbmlImporter, assignmentRules2observables
from .ode_export import ODEModel, ODEExporter

from typing import Protocol
from typing import Protocol, runtime_checkable


@runtime_checkable
class ModelModule(Protocol):
"""Enable Python static type checking for AMICI-generated model
modules"""

def getModel(self) -> amici.Model:
pass
...

def get_model(self) -> amici.Model:
...


class add_path:
Expand Down
3 changes: 2 additions & 1 deletion python/sdist/amici/__init__.template.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'version currently installed.'
)

from TPL_MODELNAME._TPL_MODELNAME import *
from .TPL_MODELNAME import *
from .TPL_MODELNAME import getModel as get_model

__version__ = 'TPL_PACKAGE_VERSION'
5 changes: 4 additions & 1 deletion python/sdist/amici/petab_objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
RES = 'res'
SRES = 'sres'
RDATAS = 'rdatas'
EDATAS = 'edatas'


@log_execution_time('Simulating PEtab model', logger)
Expand Down Expand Up @@ -92,6 +93,7 @@ def simulate_petab(
* cost function value (``LLH``),
* list of :class:`amici.amici.ReturnData` (``RDATAS``),
* list of :class:`amici.amici.ExpData` (``EDATAS``),
corresponding to the different simulation conditions.
For ordering of simulation conditions, see
Expand Down Expand Up @@ -163,7 +165,8 @@ def simulate_petab(

return {
LLH: llh,
RDATAS: rdatas
RDATAS: rdatas,
EDATAS: edatas,
}


Expand Down
5 changes: 5 additions & 0 deletions python/tests/test_sbml_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ def test_logging_works(observable_dependent_error_model, caplog):
assert rdata.status != amici.AMICI_SUCCESS
assert "mxstep steps taken" in caplog.text

@skip_on_valgrind
def test_model_module_is_set(observable_dependent_error_model):
model_module = observable_dependent_error_model
assert isinstance(model_module.getModel().module, amici.ModelModule)


@pytest.fixture(scope='session')
def model_steadystate_module():
Expand Down
7 changes: 7 additions & 0 deletions swig/modelname.template.i
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@ using namespace amici;
%}


// Make model module accessible from the model
%feature("pythonappend") amici::generic_model::getModel %{
import sys
val.module = sys.modules['.'.join(__name__.split('.')[:-1])]
%}


// Process symbols in header
%include "wrapfunctions.h"

0 comments on commit de87340

Please sign in to comment.