mxlpy 0.15.0__py3-none-any.whl → 0.17.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.
- mxlpy/__init__.py +4 -1
- mxlpy/fns.py +513 -21
- mxlpy/integrators/int_assimulo.py +2 -1
- mxlpy/mc.py +84 -70
- mxlpy/mca.py +97 -98
- mxlpy/meta/codegen_latex.py +279 -14
- mxlpy/meta/source_tools.py +122 -4
- mxlpy/model.py +50 -24
- mxlpy/npe/__init__.py +38 -0
- mxlpy/npe/_torch.py +436 -0
- mxlpy/report.py +33 -6
- mxlpy/sbml/_import.py +5 -2
- mxlpy/scan.py +40 -38
- mxlpy/surrogates/__init__.py +7 -6
- mxlpy/surrogates/_poly.py +12 -9
- mxlpy/surrogates/_torch.py +137 -43
- mxlpy/symbolic/strikepy.py +1 -3
- mxlpy/types.py +18 -5
- {mxlpy-0.15.0.dist-info → mxlpy-0.17.0.dist-info}/METADATA +5 -4
- {mxlpy-0.15.0.dist-info → mxlpy-0.17.0.dist-info}/RECORD +22 -21
- mxlpy/npe.py +0 -277
- {mxlpy-0.15.0.dist-info → mxlpy-0.17.0.dist-info}/WHEEL +0 -0
- {mxlpy-0.15.0.dist-info → mxlpy-0.17.0.dist-info}/licenses/LICENSE +0 -0
mxlpy/mc.py
CHANGED
@@ -31,7 +31,7 @@ from mxlpy.scan import (
|
|
31
31
|
_protocol_worker,
|
32
32
|
_steady_state_worker,
|
33
33
|
_time_course_worker,
|
34
|
-
|
34
|
+
_update_parameters_and_initial_conditions,
|
35
35
|
)
|
36
36
|
from mxlpy.types import (
|
37
37
|
IntegratorType,
|
@@ -74,7 +74,6 @@ class ParameterScanWorker(Protocol):
|
|
74
74
|
def __call__(
|
75
75
|
self,
|
76
76
|
model: Model,
|
77
|
-
y0: dict[str, float] | None,
|
78
77
|
*,
|
79
78
|
parameters: pd.DataFrame,
|
80
79
|
rel_norm: bool,
|
@@ -86,7 +85,6 @@ class ParameterScanWorker(Protocol):
|
|
86
85
|
|
87
86
|
def _parameter_scan_worker(
|
88
87
|
model: Model,
|
89
|
-
y0: dict[str, float] | None,
|
90
88
|
*,
|
91
89
|
parameters: pd.DataFrame,
|
92
90
|
rel_norm: bool,
|
@@ -117,8 +115,7 @@ def _parameter_scan_worker(
|
|
117
115
|
"""
|
118
116
|
return scan.steady_state(
|
119
117
|
model,
|
120
|
-
|
121
|
-
y0=y0,
|
118
|
+
to_scan=parameters,
|
122
119
|
parallel=False,
|
123
120
|
rel_norm=rel_norm,
|
124
121
|
integrator=integrator,
|
@@ -127,8 +124,8 @@ def _parameter_scan_worker(
|
|
127
124
|
|
128
125
|
def steady_state(
|
129
126
|
model: Model,
|
130
|
-
mc_parameters: pd.DataFrame,
|
131
127
|
*,
|
128
|
+
mc_to_scan: pd.DataFrame,
|
132
129
|
y0: dict[str, float] | None = None,
|
133
130
|
max_workers: int | None = None,
|
134
131
|
cache: Cache | None = None,
|
@@ -139,7 +136,7 @@ def steady_state(
|
|
139
136
|
"""Monte-carlo scan of steady states.
|
140
137
|
|
141
138
|
Examples:
|
142
|
-
>>> steady_state(model,
|
139
|
+
>>> steady_state(model, mc_to_scan)
|
143
140
|
p t x y
|
144
141
|
0 0.0 0.1 0.00
|
145
142
|
1.0 0.2 0.01
|
@@ -155,32 +152,35 @@ def steady_state(
|
|
155
152
|
SteadyStates: Object containing the steady state solutions for the given parameter
|
156
153
|
|
157
154
|
"""
|
155
|
+
if y0 is not None:
|
156
|
+
model.update_variables(y0)
|
157
|
+
|
158
158
|
res = parallelise(
|
159
159
|
partial(
|
160
|
-
|
160
|
+
_update_parameters_and_initial_conditions,
|
161
161
|
fn=partial(
|
162
162
|
worker,
|
163
|
-
y0=y0,
|
164
163
|
rel_norm=rel_norm,
|
165
164
|
integrator=integrator,
|
166
165
|
),
|
167
166
|
model=model,
|
168
167
|
),
|
169
|
-
inputs=list(
|
168
|
+
inputs=list(mc_to_scan.iterrows()),
|
170
169
|
max_workers=max_workers,
|
171
170
|
cache=cache,
|
172
171
|
)
|
173
172
|
return SteadyStates(
|
174
173
|
variables=pd.concat({k: v.variables for k, v in res.items()}, axis=1).T,
|
175
174
|
fluxes=pd.concat({k: v.fluxes for k, v in res.items()}, axis=1).T,
|
176
|
-
parameters=
|
175
|
+
parameters=mc_to_scan,
|
177
176
|
)
|
178
177
|
|
179
178
|
|
180
179
|
def time_course(
|
181
180
|
model: Model,
|
181
|
+
*,
|
182
182
|
time_points: Array,
|
183
|
-
|
183
|
+
mc_to_scan: pd.DataFrame,
|
184
184
|
y0: dict[str, float] | None = None,
|
185
185
|
max_workers: int | None = None,
|
186
186
|
cache: Cache | None = None,
|
@@ -190,7 +190,7 @@ def time_course(
|
|
190
190
|
"""MC time course.
|
191
191
|
|
192
192
|
Examples:
|
193
|
-
>>> time_course(model, time_points,
|
193
|
+
>>> time_course(model, time_points, mc_to_scan)
|
194
194
|
p t x y
|
195
195
|
0 0.0 0.1 0.00
|
196
196
|
1.0 0.2 0.01
|
@@ -203,27 +203,29 @@ def time_course(
|
|
203
203
|
3.0 0.4 0.03
|
204
204
|
Returns:
|
205
205
|
tuple[concentrations, fluxes] using pandas multiindex
|
206
|
-
Both dataframes are of shape (#time_points * #
|
206
|
+
Both dataframes are of shape (#time_points * #mc_to_scan, #variables)
|
207
207
|
|
208
208
|
"""
|
209
|
+
if y0 is not None:
|
210
|
+
model.update_variables(y0)
|
211
|
+
|
209
212
|
res = parallelise(
|
210
213
|
partial(
|
211
|
-
|
214
|
+
_update_parameters_and_initial_conditions,
|
212
215
|
fn=partial(
|
213
216
|
worker,
|
214
217
|
time_points=time_points,
|
215
|
-
y0=y0,
|
216
218
|
integrator=integrator,
|
217
219
|
),
|
218
220
|
model=model,
|
219
221
|
),
|
220
|
-
inputs=list(
|
222
|
+
inputs=list(mc_to_scan.iterrows()),
|
221
223
|
max_workers=max_workers,
|
222
224
|
cache=cache,
|
223
225
|
)
|
224
226
|
|
225
227
|
return TimeCourseByPars(
|
226
|
-
parameters=
|
228
|
+
parameters=mc_to_scan,
|
227
229
|
variables=pd.concat({k: v.variables.T for k, v in res.items()}, axis=1).T,
|
228
230
|
fluxes=pd.concat({k: v.fluxes.T for k, v in res.items()}, axis=1).T,
|
229
231
|
)
|
@@ -231,8 +233,9 @@ def time_course(
|
|
231
233
|
|
232
234
|
def time_course_over_protocol(
|
233
235
|
model: Model,
|
236
|
+
*,
|
234
237
|
protocol: pd.DataFrame,
|
235
|
-
|
238
|
+
mc_to_scan: pd.DataFrame,
|
236
239
|
y0: dict[str, float] | None = None,
|
237
240
|
time_points_per_step: int = 10,
|
238
241
|
max_workers: int | None = None,
|
@@ -243,7 +246,7 @@ def time_course_over_protocol(
|
|
243
246
|
"""MC time course.
|
244
247
|
|
245
248
|
Examples:
|
246
|
-
>>> time_course_over_protocol(model, protocol,
|
249
|
+
>>> time_course_over_protocol(model, protocol, mc_to_scan)
|
247
250
|
p t x y
|
248
251
|
0 0.0 0.1 0.00
|
249
252
|
1.0 0.2 0.01
|
@@ -257,22 +260,24 @@ def time_course_over_protocol(
|
|
257
260
|
|
258
261
|
Returns:
|
259
262
|
tuple[concentrations, fluxes] using pandas multiindex
|
260
|
-
Both dataframes are of shape (#time_points * #
|
263
|
+
Both dataframes are of shape (#time_points * #mc_to_scan, #variables)
|
261
264
|
|
262
265
|
"""
|
266
|
+
if y0 is not None:
|
267
|
+
model.update_variables(y0)
|
268
|
+
|
263
269
|
res = parallelise(
|
264
270
|
partial(
|
265
|
-
|
271
|
+
_update_parameters_and_initial_conditions,
|
266
272
|
fn=partial(
|
267
273
|
worker,
|
268
274
|
protocol=protocol,
|
269
|
-
y0=y0,
|
270
275
|
integrator=integrator,
|
271
276
|
time_points_per_step=time_points_per_step,
|
272
277
|
),
|
273
278
|
model=model,
|
274
279
|
),
|
275
|
-
inputs=list(
|
280
|
+
inputs=list(mc_to_scan.iterrows()),
|
276
281
|
max_workers=max_workers,
|
277
282
|
cache=cache,
|
278
283
|
)
|
@@ -281,16 +286,16 @@ def time_course_over_protocol(
|
|
281
286
|
return ProtocolByPars(
|
282
287
|
variables=pd.concat(concs, axis=1).T,
|
283
288
|
fluxes=pd.concat(fluxes, axis=1).T,
|
284
|
-
parameters=
|
289
|
+
parameters=mc_to_scan,
|
285
290
|
protocol=protocol,
|
286
291
|
)
|
287
292
|
|
288
293
|
|
289
294
|
def scan_steady_state(
|
290
295
|
model: Model,
|
291
|
-
parameters: pd.DataFrame,
|
292
|
-
mc_parameters: pd.DataFrame,
|
293
296
|
*,
|
297
|
+
to_scan: pd.DataFrame,
|
298
|
+
mc_to_scan: pd.DataFrame,
|
294
299
|
y0: dict[str, float] | None = None,
|
295
300
|
max_workers: int | None = None,
|
296
301
|
cache: Cache | None = None,
|
@@ -304,7 +309,7 @@ def scan_steady_state(
|
|
304
309
|
>>> scan_steady_state(
|
305
310
|
... model,
|
306
311
|
... parameters=pd.DataFrame({"k1": np.linspace(0, 1, 3)}),
|
307
|
-
...
|
312
|
+
... mc_to_scan=mc_to_scan,
|
308
313
|
... ).variables
|
309
314
|
x y
|
310
315
|
k1
|
@@ -319,8 +324,8 @@ def scan_steady_state(
|
|
319
324
|
|
320
325
|
Args:
|
321
326
|
model: The model to analyze
|
322
|
-
|
323
|
-
|
327
|
+
to_scan: DataFrame containing parameter and initial values to scan over
|
328
|
+
mc_to_scan: DataFrame containing Monte Carlo parameter sets
|
324
329
|
y0: Initial conditions for the solver
|
325
330
|
max_workers: Maximum number of workers for parallel processing
|
326
331
|
cache: Cache object for storing results
|
@@ -332,19 +337,21 @@ def scan_steady_state(
|
|
332
337
|
McSteadyStates: Object containing the steady state solutions for the given parameter
|
333
338
|
|
334
339
|
"""
|
340
|
+
if y0 is not None:
|
341
|
+
model.update_variables(y0)
|
342
|
+
|
335
343
|
res = parallelise(
|
336
344
|
partial(
|
337
|
-
|
345
|
+
_update_parameters_and_initial_conditions,
|
338
346
|
fn=partial(
|
339
347
|
worker,
|
340
|
-
parameters=
|
341
|
-
y0=y0,
|
348
|
+
parameters=to_scan,
|
342
349
|
rel_norm=rel_norm,
|
343
350
|
integrator=integrator,
|
344
351
|
),
|
345
352
|
model=model,
|
346
353
|
),
|
347
|
-
inputs=list(
|
354
|
+
inputs=list(mc_to_scan.iterrows()),
|
348
355
|
cache=cache,
|
349
356
|
max_workers=max_workers,
|
350
357
|
)
|
@@ -353,17 +360,22 @@ def scan_steady_state(
|
|
353
360
|
return McSteadyStates(
|
354
361
|
variables=pd.concat(concs, axis=1).T,
|
355
362
|
fluxes=pd.concat(fluxes, axis=1).T,
|
356
|
-
parameters=
|
357
|
-
|
363
|
+
parameters=to_scan,
|
364
|
+
mc_to_scan=mc_to_scan,
|
358
365
|
)
|
359
366
|
|
360
367
|
|
368
|
+
###############################################################################
|
369
|
+
# MCA
|
370
|
+
###############################################################################
|
371
|
+
|
372
|
+
|
361
373
|
def variable_elasticities(
|
362
374
|
model: Model,
|
363
|
-
variables: list[str],
|
364
|
-
concs: dict[str, float],
|
365
|
-
mc_parameters: pd.DataFrame,
|
366
375
|
*,
|
376
|
+
mc_to_scan: pd.DataFrame,
|
377
|
+
to_scan: list[str] | None = None,
|
378
|
+
variables: dict[str, float] | None = None,
|
367
379
|
time: float = 0,
|
368
380
|
cache: Cache | None = None,
|
369
381
|
max_workers: int | None = None,
|
@@ -377,7 +389,7 @@ def variable_elasticities(
|
|
377
389
|
... model,
|
378
390
|
... variables=["x1", "x2"],
|
379
391
|
... concs={"x1": 1, "x2": 2},
|
380
|
-
...
|
392
|
+
... mc_to_scan=mc_to_scan
|
381
393
|
... )
|
382
394
|
x1 x2
|
383
395
|
0 v1 0.0 0.0
|
@@ -389,9 +401,9 @@ def variable_elasticities(
|
|
389
401
|
|
390
402
|
Args:
|
391
403
|
model: The model to analyze
|
392
|
-
|
393
|
-
|
394
|
-
|
404
|
+
to_scan: List of variables for which to calculate elasticities
|
405
|
+
variables: Custom variable values. Defaults to initial conditions.
|
406
|
+
mc_to_scan: DataFrame containing Monte Carlo parameter sets
|
395
407
|
time: Time point for the analysis
|
396
408
|
cache: Cache object for storing results
|
397
409
|
max_workers: Maximum number of workers for parallel processing
|
@@ -404,18 +416,18 @@ def variable_elasticities(
|
|
404
416
|
"""
|
405
417
|
res = parallelise(
|
406
418
|
partial(
|
407
|
-
|
419
|
+
_update_parameters_and_initial_conditions,
|
408
420
|
fn=partial(
|
409
421
|
mca.variable_elasticities,
|
410
422
|
variables=variables,
|
411
|
-
|
423
|
+
to_scan=to_scan,
|
412
424
|
time=time,
|
413
425
|
displacement=displacement,
|
414
426
|
normalized=normalized,
|
415
427
|
),
|
416
428
|
model=model,
|
417
429
|
),
|
418
|
-
inputs=list(
|
430
|
+
inputs=list(mc_to_scan.iterrows()),
|
419
431
|
cache=cache,
|
420
432
|
max_workers=max_workers,
|
421
433
|
)
|
@@ -424,10 +436,10 @@ def variable_elasticities(
|
|
424
436
|
|
425
437
|
def parameter_elasticities(
|
426
438
|
model: Model,
|
427
|
-
parameters: list[str],
|
428
|
-
concs: dict[str, float],
|
429
|
-
mc_parameters: pd.DataFrame,
|
430
439
|
*,
|
440
|
+
mc_to_scan: pd.DataFrame,
|
441
|
+
to_scan: list[str],
|
442
|
+
variables: dict[str, float],
|
431
443
|
time: float = 0,
|
432
444
|
cache: Cache | None = None,
|
433
445
|
max_workers: int | None = None,
|
@@ -439,9 +451,9 @@ def parameter_elasticities(
|
|
439
451
|
Examples:
|
440
452
|
>>> parameter_elasticities(
|
441
453
|
... model,
|
442
|
-
...
|
454
|
+
... parameters=["p1", "p2"],
|
443
455
|
... concs={"x1": 1, "x2": 2},
|
444
|
-
...
|
456
|
+
... mc_to_scan=mc_to_scan
|
445
457
|
... )
|
446
458
|
p1 p2
|
447
459
|
0 v1 0.0 0.0
|
@@ -453,9 +465,9 @@ def parameter_elasticities(
|
|
453
465
|
|
454
466
|
Args:
|
455
467
|
model: The model to analyze
|
456
|
-
|
457
|
-
|
458
|
-
|
468
|
+
to_scan: List of parameters for which to calculate elasticities
|
469
|
+
variables: Custom variable values. Defaults to initial conditions.
|
470
|
+
mc_to_scan: DataFrame containing Monte Carlo parameter sets
|
459
471
|
time: Time point for the analysis
|
460
472
|
cache: Cache object for storing results
|
461
473
|
max_workers: Maximum number of workers for parallel processing
|
@@ -468,18 +480,18 @@ def parameter_elasticities(
|
|
468
480
|
"""
|
469
481
|
res = parallelise(
|
470
482
|
partial(
|
471
|
-
|
483
|
+
_update_parameters_and_initial_conditions,
|
472
484
|
fn=partial(
|
473
485
|
mca.parameter_elasticities,
|
474
|
-
|
475
|
-
|
486
|
+
to_scan=to_scan,
|
487
|
+
variables=variables,
|
476
488
|
time=time,
|
477
489
|
displacement=displacement,
|
478
490
|
normalized=normalized,
|
479
491
|
),
|
480
492
|
model=model,
|
481
493
|
),
|
482
|
-
inputs=list(
|
494
|
+
inputs=list(mc_to_scan.iterrows()),
|
483
495
|
cache=cache,
|
484
496
|
max_workers=max_workers,
|
485
497
|
)
|
@@ -488,10 +500,10 @@ def parameter_elasticities(
|
|
488
500
|
|
489
501
|
def response_coefficients(
|
490
502
|
model: Model,
|
491
|
-
parameters: list[str],
|
492
|
-
mc_parameters: pd.DataFrame,
|
493
503
|
*,
|
494
|
-
|
504
|
+
mc_to_scan: pd.DataFrame,
|
505
|
+
to_scan: list[str],
|
506
|
+
variables: dict[str, float] | None = None,
|
495
507
|
cache: Cache | None = None,
|
496
508
|
normalized: bool = True,
|
497
509
|
displacement: float = 1e-4,
|
@@ -506,7 +518,7 @@ def response_coefficients(
|
|
506
518
|
>>> response_coefficients(
|
507
519
|
... model,
|
508
520
|
... parameters=["vmax1", "vmax2"],
|
509
|
-
...
|
521
|
+
... mc_to_scan=mc_to_scan,
|
510
522
|
... ).variables
|
511
523
|
x1 x2
|
512
524
|
0 vmax_1 0.01 0.01
|
@@ -516,9 +528,9 @@ def response_coefficients(
|
|
516
528
|
|
517
529
|
Args:
|
518
530
|
model: The model to analyze
|
519
|
-
|
520
|
-
|
521
|
-
|
531
|
+
mc_to_scan: DataFrame containing Monte Carlo parameter sets
|
532
|
+
to_scan: List of parameters for which to calculate elasticities
|
533
|
+
variables: Custom variable values. Defaults to initial conditions.
|
522
534
|
cache: Cache object for storing results
|
523
535
|
normalized: Whether to use normalized elasticities
|
524
536
|
displacement: Displacement for finite difference calculations
|
@@ -531,13 +543,15 @@ def response_coefficients(
|
|
531
543
|
ResponseCoefficientsByPars: Object containing the response coefficients for the given parameters
|
532
544
|
|
533
545
|
"""
|
546
|
+
if variables is not None:
|
547
|
+
model.update_variables(variables)
|
548
|
+
|
534
549
|
res = parallelise(
|
535
550
|
fn=partial(
|
536
|
-
|
551
|
+
_update_parameters_and_initial_conditions,
|
537
552
|
fn=partial(
|
538
553
|
mca.response_coefficients,
|
539
|
-
|
540
|
-
y0=y0,
|
554
|
+
to_scan=to_scan,
|
541
555
|
normalized=normalized,
|
542
556
|
displacement=displacement,
|
543
557
|
rel_norm=rel_norm,
|
@@ -547,7 +561,7 @@ def response_coefficients(
|
|
547
561
|
),
|
548
562
|
model=model,
|
549
563
|
),
|
550
|
-
inputs=list(
|
564
|
+
inputs=list(mc_to_scan.iterrows()),
|
551
565
|
cache=cache,
|
552
566
|
max_workers=max_workers,
|
553
567
|
)
|
@@ -557,5 +571,5 @@ def response_coefficients(
|
|
557
571
|
pd.DataFrame, pd.concat({k: v.variables for k, v in res.items()})
|
558
572
|
),
|
559
573
|
fluxes=cast(pd.DataFrame, pd.concat({k: v.fluxes for k, v in res.items()})),
|
560
|
-
parameters=
|
574
|
+
parameters=mc_to_scan,
|
561
575
|
)
|