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

Add abstraction for (SBML) models #133

Merged
merged 32 commits into from
Jun 22, 2022
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6b26c69
Add abstraction for models
dweindl Apr 26, 2022
796d042
Use new Model in petab.Problem
dweindl Apr 27, 2022
796219b
__init__.py
dweindl Apr 27, 2022
d200396
fix merge
dweindl Apr 28, 2022
52f0ec0
TYPE_CHECKING
dweindl Apr 28, 2022
0736225
Replace most sbml_model occurrences by new Model
dweindl Apr 29, 2022
d798652
doc
dweindl May 4, 2022
9a34c74
..
dweindl May 4, 2022
e0b6e74
Deprecate petab.Problem.from_files
dweindl May 5, 2022
2924c2c
Update petab.Problem to use Model
dweindl May 5, 2022
507c196
Update to test_petab
dweindl May 5, 2022
7d9dae8
Add model type constants; add type code to class; add list of known t…
dweindl May 5, 2022
3d4cda5
Model.to_file
dweindl May 5, 2022
d8d1774
fixup, doc
dweindl May 19, 2022
ee977a7
cleanup assert_model_parameters_in_condition_or_parameter_table
dweindl May 19, 2022
c04a75d
Use petab.Model in parameter mapping
dweindl May 19, 2022
69f826e
sbml_model->model
dweindl May 20, 2022
9bc1e6f
cleanup
dweindl May 20, 2022
4996699
Merge branch 'develop' into abstract_model
dweindl May 24, 2022
d540c47
fixup merge
dweindl May 24, 2022
78251a0
Merge branch 'develop' into abstract_model
dweindl May 25, 2022
bb61a12
fix merge
dweindl May 25, 2022
66e1bc4
Merge branch 'develop' into abstract_model
dweindl May 25, 2022
ed7c23c
is/are
dweindl Jun 20, 2022
4dbcfe0
Update petab/models/model.py
dweindl Jun 20, 2022
804188b
Update petab/models/model.py
dweindl Jun 20, 2022
3b337b0
the
dweindl Jun 20, 2022
d66e18a
import
dweindl Jun 20, 2022
5464928
fixup rename
dweindl Jun 20, 2022
4dcf1f6
PARAMETER_SEPARATOR
dweindl Jun 20, 2022
a9bf397
Merge branch 'develop' into abstract_model
dweindl Jun 20, 2022
49e518c
..
dweindl Jun 21, 2022
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
Prev Previous commit
Next Next commit
Add model type constants; add type code to class; add list of known t…
…ypes
dweindl committed May 19, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 7d9dae8b4a8e885b4b7a0bce48c52b323c9f9383
4 changes: 4 additions & 0 deletions petab/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
MODEL_TYPE_SBML = 'sbml'

known_model_types = {MODEL_TYPE_SBML}
Comment on lines +1 to +3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be here or the constants file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer keeping it more modular, but could consider importing it in petab.C


from .model import Model # noqa F401
16 changes: 13 additions & 3 deletions petab/models/model.py
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@

import abc
from typing import Any, Iterable, Tuple
from . import MODEL_TYPE_SBML, known_model_types


class Model:
@@ -24,6 +25,12 @@ def from_file(filepath_or_buffer: Any) -> Model:
"""
...

@classmethod
@property
@abc.abstractmethod
def type_id(cls):
...

@abc.abstractmethod
def get_parameter_ids(self) -> Iterable[str]:
"""Get all parameter IDs from this model
@@ -114,9 +121,12 @@ def model_factory(filepath_or_buffer: Any, model_language: str) -> Model:
:param model_language: PEtab model language ID for the given model
:returns: A :py:class:`Model` instance representing the given model
"""

if model_language == "sbml":
if model_language == MODEL_TYPE_SBML:
from .sbml_model import SbmlModel
return SbmlModel.from_file(filepath_or_buffer)

raise ValueError(f"Unsupported model format: {model_language}")
if model_language in known_model_types:
raise NotImplementedError(
f"Unsupported model format: {model_language}")

raise ValueError(f"Unknown model format: {model_language}")
4 changes: 4 additions & 0 deletions petab/models/sbml_model.py
Original file line number Diff line number Diff line change
@@ -5,13 +5,17 @@

import libsbml

from . import MODEL_TYPE_SBML
from .model import Model
from ..sbml import (get_sbml_model, is_sbml_consistent, load_sbml_from_string,
log_sbml_errors)


class SbmlModel(Model):
"""PEtab wrapper for SBML models"""

type_id = MODEL_TYPE_SBML

def __init__(
self,
sbml_model: libsbml.Model = None,
7 changes: 5 additions & 2 deletions petab/problem.py
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
from . import (conditions, core, format_version, measurements, observables,
parameter_mapping, parameters, sampling, sbml, yaml)
from .C import * # noqa: F403
from .models import MODEL_TYPE_SBML
from .models.model import Model, model_factory
from .models.sbml_model import SbmlModel

@@ -127,7 +128,8 @@ def from_files(
"future version. Use `petab.Problem.from_yaml instead.",
DeprecationWarning, stacklevel=2)

model = model_factory(sbml_file, 'sbml') if sbml_file else None
model = model_factory(sbml_file, MODEL_TYPE_SBML) \
if sbml_file else None

condition_df = conditions.get_condition_df(condition_file) \
if condition_file else None
@@ -219,7 +221,8 @@ def from_yaml(yaml_config: Union[Dict, Path, str]) -> 'Problem':
get_path(yaml_config[PARAMETER_FILE])) \
if yaml_config[PARAMETER_FILE] else None

model = model_factory(get_path(problem0[SBML_FILES][0]), 'sbml') \
model = model_factory(get_path(problem0[SBML_FILES][0]),
MODEL_TYPE_SBML) \
if problem0[SBML_FILES] else None

if problem0[MEASUREMENT_FILES]: