mxlpy 0.19.0__py3-none-any.whl → 0.21.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,9 +6,6 @@ It includes support for both Assimulo and Scipy integrators, with Assimulo being
6
6
 
7
7
  from __future__ import annotations
8
8
 
9
- __all__ = ["DefaultIntegrator"]
10
-
11
-
12
9
  from .int_scipy import Scipy
13
10
 
14
11
  try:
@@ -17,3 +14,7 @@ try:
17
14
  DefaultIntegrator = Assimulo
18
15
  except ImportError:
19
16
  DefaultIntegrator = Scipy
17
+
18
+ __all__ = [
19
+ "DefaultIntegrator",
20
+ ]
@@ -2,14 +2,9 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from dataclasses import dataclass
6
-
7
- __all__ = [
8
- "Assimulo",
9
- ]
10
-
11
5
  import contextlib
12
6
  import os
7
+ from dataclasses import dataclass
13
8
  from typing import TYPE_CHECKING, Literal
14
9
 
15
10
  import numpy as np
@@ -25,6 +20,11 @@ if TYPE_CHECKING:
25
20
  from mxlpy.types import Array, ArrayLike
26
21
 
27
22
 
23
+ __all__ = [
24
+ "Assimulo",
25
+ ]
26
+
27
+
28
28
  @dataclass
29
29
  class Assimulo:
30
30
  """Assimulo integrator for solving ODEs.
@@ -2,13 +2,8 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from dataclasses import dataclass, field
6
-
7
- __all__ = [
8
- "Scipy",
9
- ]
10
-
11
5
  import copy
6
+ from dataclasses import dataclass, field
12
7
  from typing import TYPE_CHECKING, cast
13
8
 
14
9
  import numpy as np
@@ -20,6 +15,11 @@ if TYPE_CHECKING:
20
15
  from collections.abc import Callable
21
16
 
22
17
 
18
+ __all__ = [
19
+ "Scipy",
20
+ ]
21
+
22
+
23
23
  @dataclass
24
24
  class Scipy:
25
25
  """Scipy integrator for solving ODEs.
mxlpy/label_map.py CHANGED
@@ -24,13 +24,15 @@ import numpy as np
24
24
 
25
25
  from mxlpy.model import Model
26
26
 
27
- __all__ = ["LabelMapper"]
28
-
29
27
  if TYPE_CHECKING:
30
28
  from collections.abc import Callable, Mapping
31
29
 
32
30
  from mxlpy.types import Derived
33
31
 
32
+ __all__ = [
33
+ "LabelMapper",
34
+ ]
35
+
34
36
 
35
37
  def _total_concentration(*args: float) -> float:
36
38
  """Calculate sum of isotopomer concentrations.
mxlpy/linear_label_map.py CHANGED
@@ -16,13 +16,15 @@ from typing import TYPE_CHECKING
16
16
 
17
17
  from mxlpy.model import Derived, Model
18
18
 
19
- __all__ = ["LinearLabelMapper"]
20
-
21
19
  if TYPE_CHECKING:
22
20
  from collections.abc import Mapping
23
21
 
24
22
  import pandas as pd
25
23
 
24
+ __all__ = [
25
+ "LinearLabelMapper",
26
+ ]
27
+
26
28
 
27
29
  def _generate_isotope_labels(base_name: str, num_labels: int) -> list[str]:
28
30
  """Generate list of isotopomer names for a compound.
mxlpy/mc.py CHANGED
@@ -22,7 +22,6 @@ from typing import TYPE_CHECKING, Protocol, cast
22
22
  import pandas as pd
23
23
 
24
24
  from mxlpy import mca, scan
25
- from mxlpy.integrators import DefaultIntegrator
26
25
  from mxlpy.parallel import Cache, parallelise
27
26
  from mxlpy.scan import (
28
27
  ProtocolWorker,
@@ -42,6 +41,11 @@ from mxlpy.types import (
42
41
  TimeCourseByPars,
43
42
  )
44
43
 
44
+ if TYPE_CHECKING:
45
+ from mxlpy.model import Model
46
+ from mxlpy.types import Array
47
+
48
+
45
49
  __all__ = [
46
50
  "ParameterScanWorker",
47
51
  "parameter_elasticities",
@@ -53,20 +57,6 @@ __all__ = [
53
57
  "variable_elasticities",
54
58
  ]
55
59
 
56
- if TYPE_CHECKING:
57
- from mxlpy.model import Model
58
- from mxlpy.types import Array
59
-
60
- __ALL__ = [
61
- "steady_state",
62
- "time_course",
63
- "time_course_over_protocol",
64
- "parameter_scan_ss",
65
- "compound_elasticities",
66
- "parameter_elasticities",
67
- "response_coefficients",
68
- ]
69
-
70
60
 
71
61
  class ParameterScanWorker(Protocol):
72
62
  """Protocol for the parameter scan worker function."""
@@ -131,7 +121,7 @@ def steady_state(
131
121
  cache: Cache | None = None,
132
122
  rel_norm: bool = False,
133
123
  worker: SteadyStateWorker = _steady_state_worker,
134
- integrator: IntegratorType = DefaultIntegrator,
124
+ integrator: IntegratorType | None = None,
135
125
  ) -> SteadyStates:
136
126
  """Monte-carlo scan of steady states.
137
127
 
@@ -162,6 +152,7 @@ def steady_state(
162
152
  worker,
163
153
  rel_norm=rel_norm,
164
154
  integrator=integrator,
155
+ y0=None,
165
156
  ),
166
157
  model=model,
167
158
  ),
@@ -170,8 +161,8 @@ def steady_state(
170
161
  cache=cache,
171
162
  )
172
163
  return SteadyStates(
173
- variables=pd.concat({k: v.variables for k, v in res.items()}, axis=1).T,
174
- fluxes=pd.concat({k: v.fluxes for k, v in res.items()}, axis=1).T,
164
+ variables=pd.concat({k: v.variables for k, v in res}, axis=1).T,
165
+ fluxes=pd.concat({k: v.fluxes for k, v in res}, axis=1).T,
175
166
  parameters=mc_to_scan,
176
167
  )
177
168
 
@@ -185,7 +176,7 @@ def time_course(
185
176
  max_workers: int | None = None,
186
177
  cache: Cache | None = None,
187
178
  worker: TimeCourseWorker = _time_course_worker,
188
- integrator: IntegratorType = DefaultIntegrator,
179
+ integrator: IntegratorType | None = None,
189
180
  ) -> TimeCourseByPars:
190
181
  """MC time course.
191
182
 
@@ -216,6 +207,7 @@ def time_course(
216
207
  worker,
217
208
  time_points=time_points,
218
209
  integrator=integrator,
210
+ y0=None,
219
211
  ),
220
212
  model=model,
221
213
  ),
@@ -226,8 +218,8 @@ def time_course(
226
218
 
227
219
  return TimeCourseByPars(
228
220
  parameters=mc_to_scan,
229
- variables=pd.concat({k: v.variables.T for k, v in res.items()}, axis=1).T,
230
- fluxes=pd.concat({k: v.fluxes.T for k, v in res.items()}, axis=1).T,
221
+ variables=pd.concat({k: v.variables.T for k, v in res}, axis=1).T,
222
+ fluxes=pd.concat({k: v.fluxes.T for k, v in res}, axis=1).T,
231
223
  )
232
224
 
233
225
 
@@ -241,7 +233,7 @@ def time_course_over_protocol(
241
233
  max_workers: int | None = None,
242
234
  cache: Cache | None = None,
243
235
  worker: ProtocolWorker = _protocol_worker,
244
- integrator: IntegratorType = DefaultIntegrator,
236
+ integrator: IntegratorType | None = None,
245
237
  ) -> ProtocolByPars:
246
238
  """MC time course.
247
239
 
@@ -273,6 +265,7 @@ def time_course_over_protocol(
273
265
  worker,
274
266
  protocol=protocol,
275
267
  integrator=integrator,
268
+ y0=None,
276
269
  time_points_per_step=time_points_per_step,
277
270
  ),
278
271
  model=model,
@@ -281,8 +274,8 @@ def time_course_over_protocol(
281
274
  max_workers=max_workers,
282
275
  cache=cache,
283
276
  )
284
- concs = {k: v.variables.T for k, v in res.items()}
285
- fluxes = {k: v.fluxes.T for k, v in res.items()}
277
+ concs = {k: v.variables.T for k, v in res}
278
+ fluxes = {k: v.fluxes.T for k, v in res}
286
279
  return ProtocolByPars(
287
280
  variables=pd.concat(concs, axis=1).T,
288
281
  fluxes=pd.concat(fluxes, axis=1).T,
@@ -301,7 +294,7 @@ def scan_steady_state(
301
294
  cache: Cache | None = None,
302
295
  rel_norm: bool = False,
303
296
  worker: ParameterScanWorker = _parameter_scan_worker,
304
- integrator: IntegratorType = DefaultIntegrator,
297
+ integrator: IntegratorType | None = None,
305
298
  ) -> McSteadyStates:
306
299
  """Parameter scan of mc distributed steady states.
307
300
 
@@ -348,6 +341,7 @@ def scan_steady_state(
348
341
  parameters=to_scan,
349
342
  rel_norm=rel_norm,
350
343
  integrator=integrator,
344
+ y0=None,
351
345
  ),
352
346
  model=model,
353
347
  ),
@@ -355,8 +349,8 @@ def scan_steady_state(
355
349
  cache=cache,
356
350
  max_workers=max_workers,
357
351
  )
358
- concs = {k: v.variables.T for k, v in res.items()}
359
- fluxes = {k: v.fluxes.T for k, v in res.items()}
352
+ concs = {k: v.variables.T for k, v in res}
353
+ fluxes = {k: v.fluxes.T for k, v in res}
360
354
  return McSteadyStates(
361
355
  variables=pd.concat(concs, axis=1).T,
362
356
  fluxes=pd.concat(fluxes, axis=1).T,
@@ -431,7 +425,7 @@ def variable_elasticities(
431
425
  cache=cache,
432
426
  max_workers=max_workers,
433
427
  )
434
- return cast(pd.DataFrame, pd.concat(res))
428
+ return cast(pd.DataFrame, pd.concat(dict(res)))
435
429
 
436
430
 
437
431
  def parameter_elasticities(
@@ -495,7 +489,7 @@ def parameter_elasticities(
495
489
  cache=cache,
496
490
  max_workers=max_workers,
497
491
  )
498
- return cast(pd.DataFrame, pd.concat(res))
492
+ return cast(pd.DataFrame, pd.concat(dict(res)))
499
493
 
500
494
 
501
495
  def response_coefficients(
@@ -510,7 +504,7 @@ def response_coefficients(
510
504
  disable_tqdm: bool = False,
511
505
  max_workers: int | None = None,
512
506
  rel_norm: bool = False,
513
- integrator: IntegratorType = DefaultIntegrator,
507
+ integrator: IntegratorType | None = None,
514
508
  ) -> ResponseCoefficientsByPars:
515
509
  """Calculate response coefficients using Monte Carlo analysis.
516
510
 
@@ -567,9 +561,7 @@ def response_coefficients(
567
561
  )
568
562
 
569
563
  return ResponseCoefficientsByPars(
570
- variables=cast(
571
- pd.DataFrame, pd.concat({k: v.variables for k, v in res.items()})
572
- ),
573
- fluxes=cast(pd.DataFrame, pd.concat({k: v.fluxes for k, v in res.items()})),
564
+ variables=cast(pd.DataFrame, pd.concat({k: v.variables for k, v in res})),
565
+ fluxes=cast(pd.DataFrame, pd.concat({k: v.fluxes for k, v in res})),
574
566
  parameters=mc_to_scan,
575
567
  )
mxlpy/mca.py CHANGED
@@ -22,21 +22,20 @@ from typing import TYPE_CHECKING
22
22
 
23
23
  import pandas as pd
24
24
 
25
- from mxlpy.integrators import DefaultIntegrator
26
25
  from mxlpy.parallel import parallelise
27
26
  from mxlpy.scan import _steady_state_worker
28
27
  from mxlpy.types import ResponseCoefficients
29
28
 
29
+ if TYPE_CHECKING:
30
+ from mxlpy.model import Model
31
+ from mxlpy.types import IntegratorType
32
+
30
33
  __all__ = [
31
34
  "parameter_elasticities",
32
35
  "response_coefficients",
33
36
  "variable_elasticities",
34
37
  ]
35
38
 
36
- if TYPE_CHECKING:
37
- from mxlpy.model import Model
38
- from mxlpy.types import IntegratorType
39
-
40
39
 
41
40
  def _response_coefficient_worker(
42
41
  parameter: str,
@@ -46,7 +45,7 @@ def _response_coefficient_worker(
46
45
  normalized: bool,
47
46
  rel_norm: bool,
48
47
  displacement: float = 1e-4,
49
- integrator: IntegratorType,
48
+ integrator: IntegratorType | None,
50
49
  ) -> tuple[pd.Series, pd.Series]:
51
50
  """Calculate response coefficients for a single parameter.
52
51
 
@@ -81,6 +80,7 @@ def _response_coefficient_worker(
81
80
  model,
82
81
  rel_norm=rel_norm,
83
82
  integrator=integrator,
83
+ y0=None,
84
84
  )
85
85
 
86
86
  model.update_parameters({parameter: old * (1 - displacement)})
@@ -88,6 +88,7 @@ def _response_coefficient_worker(
88
88
  model,
89
89
  rel_norm=rel_norm,
90
90
  integrator=integrator,
91
+ y0=None,
91
92
  )
92
93
 
93
94
  conc_resp = (upper.variables - lower.variables) / (2 * displacement * old)
@@ -99,6 +100,7 @@ def _response_coefficient_worker(
99
100
  model,
100
101
  rel_norm=rel_norm,
101
102
  integrator=integrator,
103
+ y0=None,
102
104
  )
103
105
  conc_resp *= old / norm.variables
104
106
  flux_resp *= old / norm.fluxes
@@ -237,7 +239,7 @@ def response_coefficients(
237
239
  parallel: bool = True,
238
240
  max_workers: int | None = None,
239
241
  rel_norm: bool = False,
240
- integrator: IntegratorType = DefaultIntegrator,
242
+ integrator: IntegratorType | None = None,
241
243
  ) -> ResponseCoefficients:
242
244
  """Calculate response coefficients.
243
245
 
@@ -284,6 +286,6 @@ def response_coefficients(
284
286
  max_workers=max_workers,
285
287
  )
286
288
  return ResponseCoefficients(
287
- variables=pd.DataFrame({k: v[0] for k, v in res.items()}),
288
- fluxes=pd.DataFrame({k: v[1] for k, v in res.items()}),
289
+ variables=pd.DataFrame({k: v[0] for k, v in res}),
290
+ fluxes=pd.DataFrame({k: v[1] for k, v in res}),
289
291
  )
mxlpy/meta/__init__.py CHANGED
@@ -1,11 +1,13 @@
1
1
  """Metaprogramming facilities."""
2
2
 
3
+ from __future__ import annotations
4
+
5
+ from .codegen_latex import generate_latex_code
6
+ from .codegen_modebase import generate_mxlpy_code
7
+ from .codegen_py import generate_model_code_py
8
+
3
9
  __all__ = [
4
10
  "generate_latex_code",
5
11
  "generate_model_code_py",
6
12
  "generate_mxlpy_code",
7
13
  ]
8
-
9
- from .codegen_latex import generate_latex_code
10
- from .codegen_modebase import generate_mxlpy_code
11
- from .codegen_py import generate_model_code_py