myokit 1.33.9__py3-none-any.whl → 1.35.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.
- myokit/__init__.py +9 -36
- myokit/__main__.py +76 -142
- myokit/_aux.py +62 -16
- myokit/_bin/example.mmt +1 -2
- myokit/_bin/install-win/menu.json +7 -7
- myokit/_config.py +22 -31
- myokit/_datablock.py +30 -74
- myokit/_datalog.py +49 -72
- myokit/_err.py +25 -24
- myokit/_expressions.py +50 -68
- myokit/_io.py +15 -27
- myokit/_model_api.py +453 -249
- myokit/_myokit_version.py +1 -5
- myokit/_parsing.py +38 -44
- myokit/_progress.py +5 -8
- myokit/_protocol.py +99 -9
- myokit/_sim/__init__.py +7 -24
- myokit/_sim/cable.c +6 -8
- myokit/_sim/cable.py +6 -8
- myokit/_sim/cmodel.h +125 -70
- myokit/_sim/cmodel.py +12 -14
- myokit/_sim/compiler.py +1 -4
- myokit/_sim/cvodessim.c +196 -118
- myokit/_sim/cvodessim.py +130 -103
- myokit/_sim/differential.hpp +4 -4
- myokit/_sim/fiber_tissue.c +4 -8
- myokit/_sim/fiber_tissue.py +11 -13
- myokit/_sim/jacobian.cpp +2 -2
- myokit/_sim/jacobian.py +11 -8
- myokit/_sim/mcl.h +53 -55
- myokit/_sim/opencl.py +21 -27
- myokit/_sim/openclsim.c +3 -7
- myokit/_sim/openclsim.cl +3 -3
- myokit/_sim/openclsim.py +49 -40
- myokit/_sim/pacing.h +36 -16
- myokit/_sim/rhs.c +6 -13
- myokit/_sim/rhs.py +5 -14
- myokit/_sim/sundials.py +1 -4
- myokit/_system.py +10 -16
- myokit/_unit.py +4 -13
- myokit/float.py +0 -3
- myokit/formats/__init__.py +8 -10
- myokit/formats/ansic/__init__.py +0 -3
- myokit/formats/ansic/_ewriter.py +2 -4
- myokit/formats/ansic/_exporter.py +1 -4
- myokit/formats/ansic/template/cable.c +4 -4
- myokit/formats/ansic/template/euler.c +5 -5
- myokit/formats/ansic/template/sim.c +6 -6
- myokit/formats/axon/__init__.py +1 -3
- myokit/formats/axon/_abf.py +12 -17
- myokit/formats/axon/_atf.py +5 -6
- myokit/formats/axon/_importer.py +0 -3
- myokit/formats/cellml/__init__.py +0 -3
- myokit/formats/cellml/_ewriter.py +3 -6
- myokit/formats/cellml/_exporter.py +3 -6
- myokit/formats/cellml/_importer.py +1 -4
- myokit/formats/cellml/v1/__init__.py +0 -4
- myokit/formats/cellml/v1/_api.py +8 -11
- myokit/formats/cellml/v1/_parser.py +2 -5
- myokit/formats/cellml/v1/_writer.py +2 -11
- myokit/formats/cellml/v2/__init__.py +0 -3
- myokit/formats/cellml/v2/_api.py +8 -17
- myokit/formats/cellml/v2/_parser.py +2 -5
- myokit/formats/cellml/v2/_writer.py +1 -4
- myokit/formats/channelml/__init__.py +0 -3
- myokit/formats/channelml/_importer.py +11 -21
- myokit/formats/cpp/__init__.py +1 -3
- myokit/formats/cpp/_ewriter.py +0 -3
- myokit/formats/cuda/__init__.py +0 -3
- myokit/formats/cuda/_ewriter.py +2 -4
- myokit/formats/cuda/_exporter.py +0 -3
- myokit/formats/cuda/template/kernel.cu +8 -5
- myokit/formats/easyml/__init__.py +0 -3
- myokit/formats/easyml/_ewriter.py +9 -11
- myokit/formats/easyml/_exporter.py +2 -5
- myokit/formats/html/__init__.py +0 -3
- myokit/formats/html/_exporter.py +0 -3
- myokit/formats/html/_flatten.py +5 -21
- myokit/formats/latex/__init__.py +0 -3
- myokit/formats/latex/_ewriter.py +1 -4
- myokit/formats/latex/_exporter.py +4 -6
- myokit/formats/mathml/__init__.py +0 -3
- myokit/formats/mathml/_ewriter.py +2 -11
- myokit/formats/mathml/_parser.py +4 -6
- myokit/formats/matlab/__init__.py +0 -3
- myokit/formats/matlab/_ewriter.py +1 -4
- myokit/formats/matlab/_exporter.py +2 -5
- myokit/formats/matlab/template/main.m +3 -2
- myokit/formats/opencl/__init__.py +0 -3
- myokit/formats/opencl/_ewriter.py +2 -4
- myokit/formats/opencl/_exporter.py +2 -5
- myokit/formats/opencl/template/cable.c +10 -10
- myokit/formats/opencl/template/kernel.cl +1 -1
- myokit/formats/opencl/template/minilog.py +1 -1
- myokit/formats/python/__init__.py +0 -3
- myokit/formats/python/_ewriter.py +2 -5
- myokit/formats/python/_exporter.py +0 -3
- myokit/formats/python/template/sim.py +14 -14
- myokit/formats/sbml/__init__.py +0 -3
- myokit/formats/sbml/_api.py +50 -44
- myokit/formats/sbml/_importer.py +1 -4
- myokit/formats/sbml/_parser.py +2 -5
- myokit/formats/stan/__init__.py +0 -3
- myokit/formats/stan/_ewriter.py +2 -4
- myokit/formats/stan/_exporter.py +2 -5
- myokit/formats/stan/template/cell.stan +3 -3
- myokit/formats/sympy/__init__.py +0 -3
- myokit/formats/sympy/_ereader.py +1 -4
- myokit/formats/sympy/_ewriter.py +2 -5
- myokit/formats/wcp/__init__.py +0 -3
- myokit/formats/wcp/_wcp.py +2 -8
- myokit/formats/xml/__init__.py +0 -3
- myokit/formats/xml/_exporter.py +0 -3
- myokit/formats/xml/_split.py +0 -3
- myokit/gui/__init__.py +80 -246
- myokit/gui/datablock_viewer.py +103 -86
- myokit/gui/datalog_viewer.py +214 -66
- myokit/gui/explorer.py +15 -21
- myokit/gui/ide.py +171 -144
- myokit/gui/progress.py +9 -9
- myokit/gui/source.py +406 -375
- myokit/gui/vargrapher.py +2 -12
- myokit/lib/deps.py +12 -13
- myokit/lib/guess.py +3 -4
- myokit/lib/hh.py +20 -18
- myokit/lib/markov.py +21 -20
- myokit/lib/multi.py +1 -3
- myokit/lib/plots.py +20 -9
- myokit/pacing.py +0 -3
- myokit/pype.py +7 -18
- myokit/tests/__init__.py +3 -6
- myokit/tests/ansic_event_based_pacing.py +1 -4
- myokit/tests/ansic_fixed_form_pacing.py +3 -6
- myokit/tests/data/beeler-1977-model-compare-b.mmt +2 -2
- myokit/tests/data/clancy-1999-fitting.mmt +1 -0
- myokit/tests/test_aux.py +13 -28
- myokit/tests/test_cellml_v1_api.py +4 -19
- myokit/tests/test_cellml_v1_parser.py +0 -15
- myokit/tests/test_cellml_v1_writer.py +0 -9
- myokit/tests/test_cellml_v2_api.py +4 -19
- myokit/tests/test_cellml_v2_parser.py +0 -15
- myokit/tests/test_cellml_v2_writer.py +0 -9
- myokit/tests/test_cmodel.py +16 -22
- myokit/tests/test_compiler_detection.py +1 -11
- myokit/tests/test_component.py +108 -56
- myokit/tests/test_config.py +34 -67
- myokit/tests/test_datablock.py +1 -9
- myokit/tests/test_datalog.py +19 -24
- myokit/tests/test_dependency_checking.py +8 -23
- myokit/tests/test_expressions.py +0 -9
- myokit/tests/test_float.py +1 -5
- myokit/tests/test_formats.py +0 -9
- myokit/tests/test_formats_axon.py +1 -9
- myokit/tests/test_formats_cellml.py +0 -15
- myokit/tests/test_formats_channelml.py +0 -15
- myokit/tests/test_formats_easyml.py +0 -14
- myokit/tests/test_formats_exporters.py +1 -16
- myokit/tests/test_formats_expression_writers.py +1 -17
- myokit/tests/test_formats_html.py +0 -3
- myokit/tests/test_formats_importers.py +1 -16
- myokit/tests/test_formats_mathml_content.py +0 -9
- myokit/tests/test_formats_mathml_presentation.py +0 -9
- myokit/tests/test_formats_opencl.py +0 -10
- myokit/tests/test_formats_sbml.py +0 -15
- myokit/tests/test_formats_sympy.py +0 -9
- myokit/tests/test_formats_wcp.py +1 -3
- myokit/tests/test_io.py +27 -27
- myokit/tests/test_jacobian_calculator.py +6 -14
- myokit/tests/test_jacobian_tracer.py +0 -9
- myokit/tests/test_lib_deps.py +0 -9
- myokit/tests/test_lib_guess.py +0 -9
- myokit/tests/test_lib_hh.py +18 -12
- myokit/tests/test_lib_markov.py +21 -13
- myokit/tests/test_lib_multi.py +0 -9
- myokit/tests/test_lib_plots.py +13 -8
- myokit/tests/test_meta.py +0 -3
- myokit/tests/test_model.py +390 -96
- myokit/tests/test_model_building.py +44 -96
- myokit/tests/test_opencl_info.py +5 -14
- myokit/tests/test_pacing_factory.py +0 -3
- myokit/tests/test_pacing_system_c.py +1 -23
- myokit/tests/test_pacing_system_py.py +0 -9
- myokit/tests/test_parsing.py +139 -56
- myokit/tests/test_progress_reporters.py +0 -3
- myokit/tests/test_protocol.py +0 -9
- myokit/tests/test_protocol_floating_point.py +1 -10
- myokit/tests/test_protocol_time_series.py +82 -0
- myokit/tests/test_pype.py +0 -9
- myokit/tests/test_quantity.py +0 -9
- myokit/tests/test_rhs_benchmarker.py +1 -9
- myokit/tests/test_sbml_api.py +27 -42
- myokit/tests/test_sbml_parser.py +4 -19
- myokit/tests/test_simulation_1d.py +45 -25
- myokit/tests/test_simulation_cvodes.py +321 -55
- myokit/tests/test_simulation_cvodes_from_disk.py +0 -3
- myokit/tests/test_simulation_fiber_tissue.py +39 -12
- myokit/tests/test_simulation_log_interval.py +1 -431
- myokit/tests/test_simulation_opencl.py +69 -48
- myokit/tests/test_simulation_opencl_log_interval.py +1 -3
- myokit/tests/test_simulation_opencl_vs_cvode.py +1 -10
- myokit/tests/test_simulation_opencl_vs_sim1d.py +1 -10
- myokit/tests/test_system_info.py +1 -11
- myokit/tests/test_tools.py +0 -9
- myokit/tests/test_unit.py +1 -10
- myokit/tests/test_user_functions.py +0 -10
- myokit/tests/test_variable.py +231 -27
- myokit/tools.py +5 -21
- myokit/units.py +5 -3
- {myokit-1.33.9.dist-info → myokit-1.35.0.dist-info}/METADATA +12 -15
- myokit-1.35.0.dist-info/RECORD +391 -0
- {myokit-1.33.9.dist-info → myokit-1.35.0.dist-info}/WHEEL +1 -1
- {myokit-1.33.9.dist-info → myokit-1.35.0.dist-info}/entry_points.txt +0 -1
- myokit/_exec_new.py +0 -15
- myokit/_exec_old.py +0 -15
- myokit/_sim/cvodesim.c +0 -1551
- myokit/_sim/cvodesim.py +0 -674
- myokit/_sim/icsim.cpp +0 -563
- myokit/_sim/icsim.py +0 -363
- myokit/_sim/psim.cpp +0 -656
- myokit/_sim/psim.py +0 -493
- myokit/lib/common.py +0 -1094
- myokit/tests/test_lib_common.py +0 -130
- myokit/tests/test_simulation_cvode.py +0 -612
- myokit/tests/test_simulation_ic.py +0 -108
- myokit/tests/test_simulation_p.py +0 -223
- myokit-1.33.9.dist-info/RECORD +0 -403
- /myokit/formats/opencl/template/{test → test.sh} +0 -0
- {myokit-1.33.9.dist-info → myokit-1.35.0.dist-info}/LICENSE.txt +0 -0
- {myokit-1.33.9.dist-info → myokit-1.35.0.dist-info}/top_level.txt +0 -0
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
#
|
|
3
|
-
# Tests the ICSimulation class.
|
|
4
|
-
#
|
|
5
|
-
# This file is part of Myokit.
|
|
6
|
-
# See http://myokit.org for copyright, sharing, and licensing details.
|
|
7
|
-
#
|
|
8
|
-
from __future__ import absolute_import, division
|
|
9
|
-
from __future__ import print_function, unicode_literals
|
|
10
|
-
|
|
11
|
-
import os
|
|
12
|
-
import unittest
|
|
13
|
-
import numpy as np
|
|
14
|
-
|
|
15
|
-
import myokit
|
|
16
|
-
|
|
17
|
-
from myokit.tests import DIR_DATA, CancellingReporter, WarningCollector
|
|
18
|
-
|
|
19
|
-
# Unit testing in Python 2 and 3
|
|
20
|
-
try:
|
|
21
|
-
unittest.TestCase.assertRaisesRegex
|
|
22
|
-
except AttributeError:
|
|
23
|
-
unittest.TestCase.assertRaisesRegex = unittest.TestCase.assertRaisesRegexp
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class ICSimulationTest(unittest.TestCase):
|
|
27
|
-
"""
|
|
28
|
-
Tests the :class:`ICSimulation`.
|
|
29
|
-
"""
|
|
30
|
-
def test_basic(self):
|
|
31
|
-
# Test basic usage.
|
|
32
|
-
# Load model
|
|
33
|
-
m, p, _ = myokit.load(os.path.join(DIR_DATA, 'lr-1991.mmt'))
|
|
34
|
-
n = m.count_states()
|
|
35
|
-
|
|
36
|
-
# Run a simulation
|
|
37
|
-
with WarningCollector() as c:
|
|
38
|
-
s = myokit.ICSimulation(m, p)
|
|
39
|
-
self.assertIn('`ICSimulation` is deprecated', c.text())
|
|
40
|
-
|
|
41
|
-
self.assertEqual(s.time(), 0)
|
|
42
|
-
self.assertEqual(s.state(), m.state())
|
|
43
|
-
self.assertEqual(s.default_state(), m.state())
|
|
44
|
-
self.assertTrue(np.all(s.derivatives() == np.eye(n)))
|
|
45
|
-
d, e = s.run(20, log_interval=5)
|
|
46
|
-
self.assertEqual(s.time(), 20)
|
|
47
|
-
self.assertNotEqual(s.state(), m.state())
|
|
48
|
-
self.assertEqual(s.default_state(), m.state())
|
|
49
|
-
self.assertFalse(np.all(s.derivatives() == np.eye(n)))
|
|
50
|
-
|
|
51
|
-
# Create a datablock from the simulation log
|
|
52
|
-
b = s.block(d, e)
|
|
53
|
-
|
|
54
|
-
# Calculate eigenvalues
|
|
55
|
-
b.eigenvalues('derivatives')
|
|
56
|
-
|
|
57
|
-
# Log with missing time value
|
|
58
|
-
d2 = d.clone()
|
|
59
|
-
del d2['engine.time']
|
|
60
|
-
self.assertRaisesRegex(ValueError, 'time', s.block, d2, e)
|
|
61
|
-
|
|
62
|
-
# Wrong size derivatives array
|
|
63
|
-
self.assertRaisesRegex(ValueError, 'shape', s.block, d, e[:-1])
|
|
64
|
-
|
|
65
|
-
# Time can't be negative
|
|
66
|
-
self.assertRaises(ValueError, s.run, -1)
|
|
67
|
-
|
|
68
|
-
# Test running without a protocol
|
|
69
|
-
s.set_protocol(None)
|
|
70
|
-
s.run(1)
|
|
71
|
-
|
|
72
|
-
# Test step size is > 0
|
|
73
|
-
self.assertRaises(ValueError, s.set_step_size, 0)
|
|
74
|
-
|
|
75
|
-
# Test negative log interval is ignored
|
|
76
|
-
s.run(1, log_interval=-1)
|
|
77
|
-
|
|
78
|
-
def test_progress_reporter(self):
|
|
79
|
-
# Test running with a progress reporter.
|
|
80
|
-
m, p, x = myokit.load(os.path.join(DIR_DATA, 'lr-1991.mmt'))
|
|
81
|
-
|
|
82
|
-
# Test using a progress reporter
|
|
83
|
-
with WarningCollector() as c:
|
|
84
|
-
s = myokit.ICSimulation(m, p)
|
|
85
|
-
with myokit.tools.capture() as c:
|
|
86
|
-
s.run(110, progress=myokit.ProgressPrinter())
|
|
87
|
-
c = c.text().splitlines()
|
|
88
|
-
self.assertTrue(len(c) > 0)
|
|
89
|
-
|
|
90
|
-
# Not a progress reporter
|
|
91
|
-
self.assertRaisesRegex(
|
|
92
|
-
ValueError, 'ProgressReporter', s.run, 5, progress=12)
|
|
93
|
-
|
|
94
|
-
# Cancel from reporter
|
|
95
|
-
self.assertRaises(
|
|
96
|
-
myokit.SimulationCancelledError, s.run, 1,
|
|
97
|
-
progress=CancellingReporter(0))
|
|
98
|
-
|
|
99
|
-
def test_invalid_model(self):
|
|
100
|
-
# Test running with an invalid model.
|
|
101
|
-
m = myokit.Model()
|
|
102
|
-
with WarningCollector() as c:
|
|
103
|
-
self.assertRaises(
|
|
104
|
-
myokit.MissingTimeVariableError, myokit.ICSimulation, m)
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if __name__ == '__main__':
|
|
108
|
-
unittest.main()
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
#
|
|
3
|
-
# Tests the PSimulation class.
|
|
4
|
-
#
|
|
5
|
-
# This file is part of Myokit.
|
|
6
|
-
# See http://myokit.org for copyright, sharing, and licensing details.
|
|
7
|
-
#
|
|
8
|
-
from __future__ import absolute_import, division
|
|
9
|
-
from __future__ import print_function, unicode_literals
|
|
10
|
-
|
|
11
|
-
import os
|
|
12
|
-
import unittest
|
|
13
|
-
|
|
14
|
-
import myokit
|
|
15
|
-
import numpy as np
|
|
16
|
-
|
|
17
|
-
from myokit.tests import DIR_DATA, CancellingReporter, WarningCollector
|
|
18
|
-
|
|
19
|
-
# Unit testing in Python 2 and 3
|
|
20
|
-
try:
|
|
21
|
-
unittest.TestCase.assertRaisesRegex
|
|
22
|
-
except AttributeError:
|
|
23
|
-
unittest.TestCase.assertRaisesRegex = unittest.TestCase.assertRaisesRegexp
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class PSimulationTest(unittest.TestCase):
|
|
27
|
-
"""
|
|
28
|
-
Tests the PSimulation.
|
|
29
|
-
"""
|
|
30
|
-
def test_simple(self):
|
|
31
|
-
|
|
32
|
-
# Load model
|
|
33
|
-
m = os.path.join(DIR_DATA, 'lr-1991.mmt')
|
|
34
|
-
m, p, x = myokit.load(m)
|
|
35
|
-
|
|
36
|
-
# Create simulation
|
|
37
|
-
with WarningCollector() as c:
|
|
38
|
-
s = myokit.PSimulation(
|
|
39
|
-
m, p, variables=['membrane.V'],
|
|
40
|
-
parameters=['ina.gNa', 'ica.gCa'])
|
|
41
|
-
self.assertIn('`PSimulation` is deprecated', c.text())
|
|
42
|
-
|
|
43
|
-
# Test state & default state
|
|
44
|
-
self.assertEqual(s.state(), s.default_state())
|
|
45
|
-
|
|
46
|
-
# Test derivatives method
|
|
47
|
-
dp = s.derivatives()
|
|
48
|
-
self.assertEqual(dp.shape, (8, 2))
|
|
49
|
-
self.assertTrue(np.all(dp == 0))
|
|
50
|
-
|
|
51
|
-
# Run a tiny simulation
|
|
52
|
-
self.assertEqual(s.time(), 0)
|
|
53
|
-
s.set_step_size(0.002)
|
|
54
|
-
d, dp = s.run(10, log_interval=2)
|
|
55
|
-
self.assertEqual(s.time(), 10)
|
|
56
|
-
|
|
57
|
-
# Test derivatives method
|
|
58
|
-
dp = s.derivatives()
|
|
59
|
-
self.assertEqual(dp.shape, (8, 2))
|
|
60
|
-
self.assertFalse(np.all(dp == 0))
|
|
61
|
-
|
|
62
|
-
# Test state & default state before & after reset
|
|
63
|
-
self.assertNotEqual(s.state(), s.default_state())
|
|
64
|
-
s.reset()
|
|
65
|
-
self.assertEqual(s.state(), s.default_state())
|
|
66
|
-
self.assertEqual(s.time(), 0)
|
|
67
|
-
|
|
68
|
-
# Test derivatives method after reset
|
|
69
|
-
dp = s.derivatives()
|
|
70
|
-
self.assertEqual(dp.shape, (8, 2))
|
|
71
|
-
self.assertTrue(np.all(dp == 0))
|
|
72
|
-
|
|
73
|
-
# Test pre-pacing --> Not implemented!
|
|
74
|
-
#s.pre(2)
|
|
75
|
-
#self.assertEqual(s.state(), s.default_state())
|
|
76
|
-
|
|
77
|
-
# Create without variables or parameters
|
|
78
|
-
with WarningCollector() as c:
|
|
79
|
-
self.assertRaisesRegex(
|
|
80
|
-
ValueError, 'variables', myokit.PSimulation, m, p,
|
|
81
|
-
parameters=['ina.gNa'])
|
|
82
|
-
self.assertRaisesRegex(
|
|
83
|
-
ValueError, 'parameters', myokit.PSimulation, m, p,
|
|
84
|
-
variables=['membrane.V'])
|
|
85
|
-
|
|
86
|
-
# Run without validated model
|
|
87
|
-
m2 = m.clone()
|
|
88
|
-
m2.add_component('bert')
|
|
89
|
-
with WarningCollector() as c:
|
|
90
|
-
s = myokit.PSimulation(
|
|
91
|
-
m2, p, variables=['membrane.V'],
|
|
92
|
-
parameters=['ina.gNa', 'ica.gCa'])
|
|
93
|
-
s.set_step_size(0.002)
|
|
94
|
-
d, dp = s.run(10, log_interval=2)
|
|
95
|
-
|
|
96
|
-
# Variable or parameter given twice
|
|
97
|
-
with WarningCollector() as c:
|
|
98
|
-
self.assertRaisesRegex(
|
|
99
|
-
ValueError, 'Duplicate variable', myokit.PSimulation, m, p,
|
|
100
|
-
variables=['membrane.V', 'membrane.V'], parameters=['ina.gNa'])
|
|
101
|
-
self.assertRaisesRegex(
|
|
102
|
-
ValueError, 'Duplicate parameter', myokit.PSimulation, m, p,
|
|
103
|
-
variables=['membrane.V'], parameters=['ina.gNa', 'ina.gNa'])
|
|
104
|
-
|
|
105
|
-
# Bound variable or parameter
|
|
106
|
-
self.assertRaisesRegex(
|
|
107
|
-
ValueError, 'bound', myokit.PSimulation, m, p,
|
|
108
|
-
variables=['engine.pace'], parameters=['ina.gNa'])
|
|
109
|
-
self.assertRaisesRegex(
|
|
110
|
-
ValueError, 'bound', myokit.PSimulation, m, p,
|
|
111
|
-
variables=['membrane.V'], parameters=['engine.pace'])
|
|
112
|
-
|
|
113
|
-
# Constant variable
|
|
114
|
-
self.assertRaisesRegex(
|
|
115
|
-
ValueError, 'constant', myokit.PSimulation, m, p,
|
|
116
|
-
variables=['ica.gCa'], parameters=['ina.gNa'])
|
|
117
|
-
|
|
118
|
-
# Non-constant parameter
|
|
119
|
-
self.assertRaisesRegex(
|
|
120
|
-
ValueError, 'literal constant', myokit.PSimulation, m, p,
|
|
121
|
-
variables=['membrane.V'], parameters=['cell.RTF'])
|
|
122
|
-
|
|
123
|
-
# Variables given as objects
|
|
124
|
-
myokit.PSimulation(
|
|
125
|
-
m, p, variables=[m.get('membrane.V')],
|
|
126
|
-
parameters=[m.get('ina.gNa')])
|
|
127
|
-
|
|
128
|
-
# Negative times
|
|
129
|
-
self.assertRaisesRegex(
|
|
130
|
-
ValueError, 'negative', s.run, -1)
|
|
131
|
-
|
|
132
|
-
# Negative or zero step size
|
|
133
|
-
self.assertRaisesRegex(
|
|
134
|
-
ValueError, 'zero', s.set_step_size, 0)
|
|
135
|
-
self.assertRaisesRegex(
|
|
136
|
-
ValueError, 'zero', s.set_step_size, -1)
|
|
137
|
-
|
|
138
|
-
# Set unset protocol
|
|
139
|
-
s.set_protocol(None)
|
|
140
|
-
s.set_protocol(p)
|
|
141
|
-
|
|
142
|
-
def test_block(self):
|
|
143
|
-
# Test :meth:`PSimulation.block()`.
|
|
144
|
-
|
|
145
|
-
m, p, x = myokit.load(os.path.join(DIR_DATA, 'lr-1991.mmt'))
|
|
146
|
-
with WarningCollector() as c:
|
|
147
|
-
s = myokit.PSimulation(
|
|
148
|
-
m, p, variables=['membrane.V'],
|
|
149
|
-
parameters=['ina.gNa', 'ica.gCa'])
|
|
150
|
-
s.set_step_size(0.002)
|
|
151
|
-
d, dp = s.run(10, log_interval=2)
|
|
152
|
-
|
|
153
|
-
b = s.block(d, dp)
|
|
154
|
-
self.assertIsInstance(b, myokit.DataBlock2d)
|
|
155
|
-
self.assertEqual(b.len0d(), len(d) - 1)
|
|
156
|
-
self.assertTrue(np.all(b.time() == d.time()))
|
|
157
|
-
|
|
158
|
-
# Log without time
|
|
159
|
-
e = myokit.DataLog(d)
|
|
160
|
-
del e[e.time_key()]
|
|
161
|
-
self.assertRaisesRegex(ValueError, 'must contain', s.block, e, dp)
|
|
162
|
-
|
|
163
|
-
# Wrong size derivatives array
|
|
164
|
-
self.assertRaisesRegex(ValueError, 'shape', s.block, d, dp[:, :-1])
|
|
165
|
-
|
|
166
|
-
def test_set_constant(self):
|
|
167
|
-
# Test :meth:`PSimulation.set_constant()` and
|
|
168
|
-
# :meth:`PSimulation.set_parameters()`
|
|
169
|
-
|
|
170
|
-
m, p, x = myokit.load(os.path.join(DIR_DATA, 'lr-1991.mmt'))
|
|
171
|
-
with WarningCollector() as c:
|
|
172
|
-
s = myokit.PSimulation(
|
|
173
|
-
m, p, variables=['membrane.V'], parameters=['ina.gNa'])
|
|
174
|
-
s.set_constant('ica.gCa', 1)
|
|
175
|
-
s.set_constant(m.get('ica.gCa'), 1)
|
|
176
|
-
|
|
177
|
-
# Variable is not a literal
|
|
178
|
-
self.assertRaisesRegex(
|
|
179
|
-
ValueError, 'literal', s.set_constant, 'membrane.V', 1)
|
|
180
|
-
|
|
181
|
-
# Variable is in parameters list
|
|
182
|
-
self.assertRaisesRegex(
|
|
183
|
-
ValueError, 'parameter', s.set_constant, 'ina.gNa', 1)
|
|
184
|
-
|
|
185
|
-
# Set parameter values
|
|
186
|
-
s.set_parameters([1])
|
|
187
|
-
self.assertRaisesRegex(
|
|
188
|
-
ValueError, '1 values', s.set_parameters, [1, 2])
|
|
189
|
-
s.set_parameters({'ina.gNa': 1})
|
|
190
|
-
s.set_parameters({m.get('ina.gNa'): 1})
|
|
191
|
-
self.assertRaisesRegex(
|
|
192
|
-
ValueError, 'Unknown', s.set_parameters, {'bert': 2})
|
|
193
|
-
self.assertRaisesRegex(
|
|
194
|
-
ValueError, 'parameter', s.set_parameters, {'ica.gCa': 2})
|
|
195
|
-
|
|
196
|
-
def test_progress_reporter(self):
|
|
197
|
-
# Test running with a progress reporter.
|
|
198
|
-
|
|
199
|
-
m, p, x = myokit.load(os.path.join(DIR_DATA, 'lr-1991.mmt'))
|
|
200
|
-
with WarningCollector() as c:
|
|
201
|
-
s = myokit.PSimulation(
|
|
202
|
-
m, p, variables=['membrane.V'], parameters=['ina.gNa'])
|
|
203
|
-
with myokit.tools.capture() as c:
|
|
204
|
-
s.run(2, progress=myokit.ProgressPrinter())
|
|
205
|
-
c = c.text().splitlines()
|
|
206
|
-
self.assertEqual(len(c), 2)
|
|
207
|
-
self.assertEqual(
|
|
208
|
-
c[0], '[0.0 minutes] 50.0 % done, estimated 0 seconds remaining')
|
|
209
|
-
self.assertEqual(
|
|
210
|
-
c[1], '[0.0 minutes] 100.0 % done, estimated 0 seconds remaining')
|
|
211
|
-
|
|
212
|
-
# Not a progress reporter
|
|
213
|
-
self.assertRaisesRegex(
|
|
214
|
-
ValueError, 'ProgressReporter', s.run, 1, progress=12)
|
|
215
|
-
|
|
216
|
-
# Cancel from reporter
|
|
217
|
-
self.assertRaises(
|
|
218
|
-
myokit.SimulationCancelledError, s.run, 1,
|
|
219
|
-
progress=CancellingReporter(0))
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
if __name__ == '__main__':
|
|
223
|
-
unittest.main()
|