|
10 | 10 | from math import nan |
11 | 11 | from numbers import Number |
12 | 12 | from pathlib import Path |
13 | | -from typing import TYPE_CHECKING |
| 13 | +from typing import TYPE_CHECKING, Any |
14 | 14 |
|
15 | 15 | import pandas as pd |
16 | 16 | import sympy as sp |
@@ -1096,6 +1096,52 @@ def __iadd__(self, other): |
1096 | 1096 | ) |
1097 | 1097 | return self |
1098 | 1098 |
|
| 1099 | + def model_dump(self, **kwargs) -> dict[str, Any]: |
| 1100 | + """Convert this Problem to a dictionary. |
| 1101 | +
|
| 1102 | + This function is intended for debugging purposes and should not be |
| 1103 | + used for serialization. The output of this function may change |
| 1104 | + without notice. |
| 1105 | +
|
| 1106 | + The output includes all PEtab tables, but not the model itself. |
| 1107 | +
|
| 1108 | + See `pydantic.BaseModel.model_dump <https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_dump>`__ |
| 1109 | + for details. |
| 1110 | +
|
| 1111 | + :example: |
| 1112 | +
|
| 1113 | + >>> from pprint import pprint |
| 1114 | + >>> p = Problem() |
| 1115 | + >>> p += core.Parameter(id="par", lb=0, ub=1) |
| 1116 | + >>> pprint(p.model_dump()) |
| 1117 | + {'conditions': [], |
| 1118 | + 'config': {'extensions': [], |
| 1119 | + 'format_version': '2.0.0', |
| 1120 | + 'parameter_file': None, |
| 1121 | + 'problems': []}, |
| 1122 | + 'experiments': [], |
| 1123 | + 'mappings': [], |
| 1124 | + 'measurements': [], |
| 1125 | + 'observables': [], |
| 1126 | + 'parameters': [{'estimate': 'true', |
| 1127 | + 'id': 'par', |
| 1128 | + 'lb': 0.0, |
| 1129 | + 'nominal_value': None, |
| 1130 | + 'scale': <ParameterScale.LIN: 'lin'>, |
| 1131 | + 'ub': 1.0}]} |
| 1132 | + """ |
| 1133 | + res = { |
| 1134 | + "config": (self.config or ProblemConfig()).model_dump(**kwargs), |
| 1135 | + } |
| 1136 | + res |= self.mapping_table.model_dump(**kwargs) |
| 1137 | + res |= self.condition_table.model_dump(**kwargs) |
| 1138 | + res |= self.experiment_table.model_dump(**kwargs) |
| 1139 | + res |= self.observable_table.model_dump(**kwargs) |
| 1140 | + res |= self.measurement_table.model_dump(**kwargs) |
| 1141 | + res |= self.parameter_table.model_dump(**kwargs) |
| 1142 | + |
| 1143 | + return res |
| 1144 | + |
1099 | 1145 |
|
1100 | 1146 | class ModelFile(BaseModel): |
1101 | 1147 | """A file in the PEtab problem configuration.""" |
|
0 commit comments