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

Make model module accessible from model instance #1932

Merged
merged 3 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion python/sdist/amici/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,13 @@ def _imported_from_setup() -> bool:
class ModelModule(Protocol):
"""Enable Python static type checking for AMICI-generated model
modules"""
module: "ModelModule"

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'
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"