Skip to content

Commit 77ce308

Browse files
authored
Merge branch 'develop' into v2_combine_conditions
2 parents d1f692f + 258abc9 commit 77ce308

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

petab/v2/problem.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from math import nan
1111
from numbers import Number
1212
from pathlib import Path
13-
from typing import TYPE_CHECKING
13+
from typing import TYPE_CHECKING, Any
1414

1515
import pandas as pd
1616
import sympy as sp
@@ -1101,6 +1101,52 @@ def __iadd__(self, other):
11011101
)
11021102
return self
11031103

1104+
def model_dump(self, **kwargs) -> dict[str, Any]:
1105+
"""Convert this Problem to a dictionary.
1106+
1107+
This function is intended for debugging purposes and should not be
1108+
used for serialization. The output of this function may change
1109+
without notice.
1110+
1111+
The output includes all PEtab tables, but not the model itself.
1112+
1113+
See `pydantic.BaseModel.model_dump <https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_dump>`__
1114+
for details.
1115+
1116+
:example:
1117+
1118+
>>> from pprint import pprint
1119+
>>> p = Problem()
1120+
>>> p += core.Parameter(id="par", lb=0, ub=1)
1121+
>>> pprint(p.model_dump())
1122+
{'conditions': [],
1123+
'config': {'extensions': [],
1124+
'format_version': '2.0.0',
1125+
'parameter_file': None,
1126+
'problems': []},
1127+
'experiments': [],
1128+
'mappings': [],
1129+
'measurements': [],
1130+
'observables': [],
1131+
'parameters': [{'estimate': 'true',
1132+
'id': 'par',
1133+
'lb': 0.0,
1134+
'nominal_value': None,
1135+
'scale': <ParameterScale.LIN: 'lin'>,
1136+
'ub': 1.0}]}
1137+
"""
1138+
res = {
1139+
"config": (self.config or ProblemConfig()).model_dump(**kwargs),
1140+
}
1141+
res |= self.mapping_table.model_dump(**kwargs)
1142+
res |= self.condition_table.model_dump(**kwargs)
1143+
res |= self.experiment_table.model_dump(**kwargs)
1144+
res |= self.observable_table.model_dump(**kwargs)
1145+
res |= self.measurement_table.model_dump(**kwargs)
1146+
res |= self.parameter_table.model_dump(**kwargs)
1147+
1148+
return res
1149+
11041150

11051151
class ModelFile(BaseModel):
11061152
"""A file in the PEtab problem configuration."""

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build-system]
22
requires = [
3-
"setuptools>=62",
3+
"setuptools>=77",
44
"wheel",
55
]
66
build-backend = "setuptools.build_meta"
@@ -24,7 +24,7 @@ dependencies = [
2424
"antlr4-python3-runtime==4.13.1",
2525
"pydantic>=2.10",
2626
]
27-
license = {text = "MIT License"}
27+
license = "MIT"
2828
authors = [
2929
{name = "The PEtab developers"},
3030
]

0 commit comments

Comments
 (0)