mxlpy 0.13.0__py3-none-any.whl → 0.14.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/simulator.py
CHANGED
@@ -10,6 +10,7 @@ Classes:
|
|
10
10
|
|
11
11
|
from __future__ import annotations
|
12
12
|
|
13
|
+
import warnings
|
13
14
|
from dataclasses import dataclass, field
|
14
15
|
from typing import TYPE_CHECKING, Literal, Self, cast, overload
|
15
16
|
|
@@ -319,6 +320,7 @@ class Simulator:
|
|
319
320
|
variables: list[pd.DataFrame] | None
|
320
321
|
dependent: list[pd.DataFrame] | None
|
321
322
|
simulation_parameters: list[dict[str, float]] | None
|
323
|
+
use_jacobian: bool
|
322
324
|
|
323
325
|
# For resets (e.g. update variable)
|
324
326
|
_integrator_type: IntegratorType
|
@@ -330,6 +332,7 @@ class Simulator:
|
|
330
332
|
y0: dict[str, float] | None = None,
|
331
333
|
integrator: IntegratorType = DefaultIntegrator,
|
332
334
|
*,
|
335
|
+
use_jacobian: bool = False,
|
333
336
|
test_run: bool = True,
|
334
337
|
) -> None:
|
335
338
|
"""Initialize the Simulator.
|
@@ -339,6 +342,7 @@ class Simulator:
|
|
339
342
|
y0: Initial conditions for the model variables.
|
340
343
|
If None, the initial conditions are obtained from the model.
|
341
344
|
integrator: The integrator to use for the simulation.
|
345
|
+
use_jacobian: Whether to use the Jacobian for the simulation.
|
342
346
|
test_run (bool, optional): If True, performs a test run for better error messages
|
343
347
|
|
344
348
|
"""
|
@@ -350,6 +354,7 @@ class Simulator:
|
|
350
354
|
self.variables = None
|
351
355
|
self.dependent = None
|
352
356
|
self.simulation_parameters = None
|
357
|
+
self.use_jacobian = use_jacobian
|
353
358
|
|
354
359
|
if test_run:
|
355
360
|
self.model.get_right_hand_side(self.y0, time=0)
|
@@ -361,16 +366,29 @@ class Simulator:
|
|
361
366
|
|
362
367
|
from mxlpy.symbolic import to_symbolic_model
|
363
368
|
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
369
|
+
_jacobian = None
|
370
|
+
if self.use_jacobian:
|
371
|
+
try:
|
372
|
+
# NOTE: this implementation is not correct in the sense
|
373
|
+
# that it does not take parameter updates into account
|
374
|
+
# jac = (
|
375
|
+
# to_symbolic_model(self.model)
|
376
|
+
# .jacobian()
|
377
|
+
# .subs(self.model._parameters)
|
378
|
+
# )
|
379
|
+
# _jacobian = lambdify(
|
380
|
+
# ("time", self.model.get_variable_names()),
|
381
|
+
# jac,
|
382
|
+
# )
|
383
|
+
|
384
|
+
# NOTE: this implementation is correct, but slow as hell
|
385
|
+
jac = to_symbolic_model(self.model).jacobian()
|
386
|
+
_jacobian = lambda t, y: lambdify( # noqa: E731
|
387
|
+
("time", self.model.get_variable_names()),
|
388
|
+
jac.subs(self.model._parameters), # noqa: SLF001
|
389
|
+
)(t, y)
|
390
|
+
except Exception as e: # noqa: BLE001
|
391
|
+
warnings.warn(str(e), stacklevel=2)
|
374
392
|
|
375
393
|
y0 = self.y0
|
376
394
|
self.integrator = self._integrator_type(
|
@@ -16,7 +16,7 @@ mxlpy/plot.py,sha256=4uu-6d8LH-GWX-sG_TlSpkSsnikv1DLTtnjJzA7nuRA,24670
|
|
16
16
|
mxlpy/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
17
17
|
mxlpy/report.py,sha256=h7dhcBzPFydLPxdsEXokzDf7Ce4PirXMsvLqlDZLSWM,7181
|
18
18
|
mxlpy/scan.py,sha256=-1SLyXJOX3U3CxeP1dEC4ytAoBMCH0Ql89wGvsG3LbI,18858
|
19
|
-
mxlpy/simulator.py,sha256=
|
19
|
+
mxlpy/simulator.py,sha256=vuTLuVanCIGAEqW8NUdGQvVKgoyvd45O-xBsbUoKaCI,21372
|
20
20
|
mxlpy/types.py,sha256=RRhi1s6T9Yy8uZdLkWi7pvQTLmyPOlCgGTF8URYQGVA,14149
|
21
21
|
mxlpy/experimental/__init__.py,sha256=kZTE-92OErpHzNRqmgSQYH4CGXrogGJ5EL35XGZQ81M,206
|
22
22
|
mxlpy/experimental/diff.py,sha256=4bztagJzFMsQJM7dlun_kv-WrWssM8CIw7gcL63hFf8,8952
|
@@ -44,7 +44,7 @@ mxlpy/surrogates/_torch.py,sha256=E_1eDUlPSVFwROkdMDCqYwwHE-61pjNMJWotnhjzge0,58
|
|
44
44
|
mxlpy/symbolic/__init__.py,sha256=3hQjCMw8-6iOxeUdfnCg8449fF_BRF2u6lCM1GPpkRY,222
|
45
45
|
mxlpy/symbolic/strikepy.py,sha256=r6nRtckV1nxKq3i1bYYWZOkzwZ5XeKQuZM5ck44vUo0,20010
|
46
46
|
mxlpy/symbolic/symbolic_model.py,sha256=YL9noEeP3_0DoKXwMPELtfmPuP6mgNcLIJgDRCkyB7A,2434
|
47
|
-
mxlpy-0.
|
48
|
-
mxlpy-0.
|
49
|
-
mxlpy-0.
|
50
|
-
mxlpy-0.
|
47
|
+
mxlpy-0.14.0.dist-info/METADATA,sha256=WyKwohN13eTY0JZRyWaNpVFJfAD4z0gviWZ212aAKbo,4564
|
48
|
+
mxlpy-0.14.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
49
|
+
mxlpy-0.14.0.dist-info/licenses/LICENSE,sha256=bEzjyjy1stQhfRDVaVHa3xV1x-V8emwdlbMvYO8Zo84,35073
|
50
|
+
mxlpy-0.14.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|