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.
Files changed (229) hide show
  1. myokit/__init__.py +9 -36
  2. myokit/__main__.py +76 -142
  3. myokit/_aux.py +62 -16
  4. myokit/_bin/example.mmt +1 -2
  5. myokit/_bin/install-win/menu.json +7 -7
  6. myokit/_config.py +22 -31
  7. myokit/_datablock.py +30 -74
  8. myokit/_datalog.py +49 -72
  9. myokit/_err.py +25 -24
  10. myokit/_expressions.py +50 -68
  11. myokit/_io.py +15 -27
  12. myokit/_model_api.py +453 -249
  13. myokit/_myokit_version.py +1 -5
  14. myokit/_parsing.py +38 -44
  15. myokit/_progress.py +5 -8
  16. myokit/_protocol.py +99 -9
  17. myokit/_sim/__init__.py +7 -24
  18. myokit/_sim/cable.c +6 -8
  19. myokit/_sim/cable.py +6 -8
  20. myokit/_sim/cmodel.h +125 -70
  21. myokit/_sim/cmodel.py +12 -14
  22. myokit/_sim/compiler.py +1 -4
  23. myokit/_sim/cvodessim.c +196 -118
  24. myokit/_sim/cvodessim.py +130 -103
  25. myokit/_sim/differential.hpp +4 -4
  26. myokit/_sim/fiber_tissue.c +4 -8
  27. myokit/_sim/fiber_tissue.py +11 -13
  28. myokit/_sim/jacobian.cpp +2 -2
  29. myokit/_sim/jacobian.py +11 -8
  30. myokit/_sim/mcl.h +53 -55
  31. myokit/_sim/opencl.py +21 -27
  32. myokit/_sim/openclsim.c +3 -7
  33. myokit/_sim/openclsim.cl +3 -3
  34. myokit/_sim/openclsim.py +49 -40
  35. myokit/_sim/pacing.h +36 -16
  36. myokit/_sim/rhs.c +6 -13
  37. myokit/_sim/rhs.py +5 -14
  38. myokit/_sim/sundials.py +1 -4
  39. myokit/_system.py +10 -16
  40. myokit/_unit.py +4 -13
  41. myokit/float.py +0 -3
  42. myokit/formats/__init__.py +8 -10
  43. myokit/formats/ansic/__init__.py +0 -3
  44. myokit/formats/ansic/_ewriter.py +2 -4
  45. myokit/formats/ansic/_exporter.py +1 -4
  46. myokit/formats/ansic/template/cable.c +4 -4
  47. myokit/formats/ansic/template/euler.c +5 -5
  48. myokit/formats/ansic/template/sim.c +6 -6
  49. myokit/formats/axon/__init__.py +1 -3
  50. myokit/formats/axon/_abf.py +12 -17
  51. myokit/formats/axon/_atf.py +5 -6
  52. myokit/formats/axon/_importer.py +0 -3
  53. myokit/formats/cellml/__init__.py +0 -3
  54. myokit/formats/cellml/_ewriter.py +3 -6
  55. myokit/formats/cellml/_exporter.py +3 -6
  56. myokit/formats/cellml/_importer.py +1 -4
  57. myokit/formats/cellml/v1/__init__.py +0 -4
  58. myokit/formats/cellml/v1/_api.py +8 -11
  59. myokit/formats/cellml/v1/_parser.py +2 -5
  60. myokit/formats/cellml/v1/_writer.py +2 -11
  61. myokit/formats/cellml/v2/__init__.py +0 -3
  62. myokit/formats/cellml/v2/_api.py +8 -17
  63. myokit/formats/cellml/v2/_parser.py +2 -5
  64. myokit/formats/cellml/v2/_writer.py +1 -4
  65. myokit/formats/channelml/__init__.py +0 -3
  66. myokit/formats/channelml/_importer.py +11 -21
  67. myokit/formats/cpp/__init__.py +1 -3
  68. myokit/formats/cpp/_ewriter.py +0 -3
  69. myokit/formats/cuda/__init__.py +0 -3
  70. myokit/formats/cuda/_ewriter.py +2 -4
  71. myokit/formats/cuda/_exporter.py +0 -3
  72. myokit/formats/cuda/template/kernel.cu +8 -5
  73. myokit/formats/easyml/__init__.py +0 -3
  74. myokit/formats/easyml/_ewriter.py +9 -11
  75. myokit/formats/easyml/_exporter.py +2 -5
  76. myokit/formats/html/__init__.py +0 -3
  77. myokit/formats/html/_exporter.py +0 -3
  78. myokit/formats/html/_flatten.py +5 -21
  79. myokit/formats/latex/__init__.py +0 -3
  80. myokit/formats/latex/_ewriter.py +1 -4
  81. myokit/formats/latex/_exporter.py +4 -6
  82. myokit/formats/mathml/__init__.py +0 -3
  83. myokit/formats/mathml/_ewriter.py +2 -11
  84. myokit/formats/mathml/_parser.py +4 -6
  85. myokit/formats/matlab/__init__.py +0 -3
  86. myokit/formats/matlab/_ewriter.py +1 -4
  87. myokit/formats/matlab/_exporter.py +2 -5
  88. myokit/formats/matlab/template/main.m +3 -2
  89. myokit/formats/opencl/__init__.py +0 -3
  90. myokit/formats/opencl/_ewriter.py +2 -4
  91. myokit/formats/opencl/_exporter.py +2 -5
  92. myokit/formats/opencl/template/cable.c +10 -10
  93. myokit/formats/opencl/template/kernel.cl +1 -1
  94. myokit/formats/opencl/template/minilog.py +1 -1
  95. myokit/formats/python/__init__.py +0 -3
  96. myokit/formats/python/_ewriter.py +2 -5
  97. myokit/formats/python/_exporter.py +0 -3
  98. myokit/formats/python/template/sim.py +14 -14
  99. myokit/formats/sbml/__init__.py +0 -3
  100. myokit/formats/sbml/_api.py +50 -44
  101. myokit/formats/sbml/_importer.py +1 -4
  102. myokit/formats/sbml/_parser.py +2 -5
  103. myokit/formats/stan/__init__.py +0 -3
  104. myokit/formats/stan/_ewriter.py +2 -4
  105. myokit/formats/stan/_exporter.py +2 -5
  106. myokit/formats/stan/template/cell.stan +3 -3
  107. myokit/formats/sympy/__init__.py +0 -3
  108. myokit/formats/sympy/_ereader.py +1 -4
  109. myokit/formats/sympy/_ewriter.py +2 -5
  110. myokit/formats/wcp/__init__.py +0 -3
  111. myokit/formats/wcp/_wcp.py +2 -8
  112. myokit/formats/xml/__init__.py +0 -3
  113. myokit/formats/xml/_exporter.py +0 -3
  114. myokit/formats/xml/_split.py +0 -3
  115. myokit/gui/__init__.py +80 -246
  116. myokit/gui/datablock_viewer.py +103 -86
  117. myokit/gui/datalog_viewer.py +214 -66
  118. myokit/gui/explorer.py +15 -21
  119. myokit/gui/ide.py +171 -144
  120. myokit/gui/progress.py +9 -9
  121. myokit/gui/source.py +406 -375
  122. myokit/gui/vargrapher.py +2 -12
  123. myokit/lib/deps.py +12 -13
  124. myokit/lib/guess.py +3 -4
  125. myokit/lib/hh.py +20 -18
  126. myokit/lib/markov.py +21 -20
  127. myokit/lib/multi.py +1 -3
  128. myokit/lib/plots.py +20 -9
  129. myokit/pacing.py +0 -3
  130. myokit/pype.py +7 -18
  131. myokit/tests/__init__.py +3 -6
  132. myokit/tests/ansic_event_based_pacing.py +1 -4
  133. myokit/tests/ansic_fixed_form_pacing.py +3 -6
  134. myokit/tests/data/beeler-1977-model-compare-b.mmt +2 -2
  135. myokit/tests/data/clancy-1999-fitting.mmt +1 -0
  136. myokit/tests/test_aux.py +13 -28
  137. myokit/tests/test_cellml_v1_api.py +4 -19
  138. myokit/tests/test_cellml_v1_parser.py +0 -15
  139. myokit/tests/test_cellml_v1_writer.py +0 -9
  140. myokit/tests/test_cellml_v2_api.py +4 -19
  141. myokit/tests/test_cellml_v2_parser.py +0 -15
  142. myokit/tests/test_cellml_v2_writer.py +0 -9
  143. myokit/tests/test_cmodel.py +16 -22
  144. myokit/tests/test_compiler_detection.py +1 -11
  145. myokit/tests/test_component.py +108 -56
  146. myokit/tests/test_config.py +34 -67
  147. myokit/tests/test_datablock.py +1 -9
  148. myokit/tests/test_datalog.py +19 -24
  149. myokit/tests/test_dependency_checking.py +8 -23
  150. myokit/tests/test_expressions.py +0 -9
  151. myokit/tests/test_float.py +1 -5
  152. myokit/tests/test_formats.py +0 -9
  153. myokit/tests/test_formats_axon.py +1 -9
  154. myokit/tests/test_formats_cellml.py +0 -15
  155. myokit/tests/test_formats_channelml.py +0 -15
  156. myokit/tests/test_formats_easyml.py +0 -14
  157. myokit/tests/test_formats_exporters.py +1 -16
  158. myokit/tests/test_formats_expression_writers.py +1 -17
  159. myokit/tests/test_formats_html.py +0 -3
  160. myokit/tests/test_formats_importers.py +1 -16
  161. myokit/tests/test_formats_mathml_content.py +0 -9
  162. myokit/tests/test_formats_mathml_presentation.py +0 -9
  163. myokit/tests/test_formats_opencl.py +0 -10
  164. myokit/tests/test_formats_sbml.py +0 -15
  165. myokit/tests/test_formats_sympy.py +0 -9
  166. myokit/tests/test_formats_wcp.py +1 -3
  167. myokit/tests/test_io.py +27 -27
  168. myokit/tests/test_jacobian_calculator.py +6 -14
  169. myokit/tests/test_jacobian_tracer.py +0 -9
  170. myokit/tests/test_lib_deps.py +0 -9
  171. myokit/tests/test_lib_guess.py +0 -9
  172. myokit/tests/test_lib_hh.py +18 -12
  173. myokit/tests/test_lib_markov.py +21 -13
  174. myokit/tests/test_lib_multi.py +0 -9
  175. myokit/tests/test_lib_plots.py +13 -8
  176. myokit/tests/test_meta.py +0 -3
  177. myokit/tests/test_model.py +390 -96
  178. myokit/tests/test_model_building.py +44 -96
  179. myokit/tests/test_opencl_info.py +5 -14
  180. myokit/tests/test_pacing_factory.py +0 -3
  181. myokit/tests/test_pacing_system_c.py +1 -23
  182. myokit/tests/test_pacing_system_py.py +0 -9
  183. myokit/tests/test_parsing.py +139 -56
  184. myokit/tests/test_progress_reporters.py +0 -3
  185. myokit/tests/test_protocol.py +0 -9
  186. myokit/tests/test_protocol_floating_point.py +1 -10
  187. myokit/tests/test_protocol_time_series.py +82 -0
  188. myokit/tests/test_pype.py +0 -9
  189. myokit/tests/test_quantity.py +0 -9
  190. myokit/tests/test_rhs_benchmarker.py +1 -9
  191. myokit/tests/test_sbml_api.py +27 -42
  192. myokit/tests/test_sbml_parser.py +4 -19
  193. myokit/tests/test_simulation_1d.py +45 -25
  194. myokit/tests/test_simulation_cvodes.py +321 -55
  195. myokit/tests/test_simulation_cvodes_from_disk.py +0 -3
  196. myokit/tests/test_simulation_fiber_tissue.py +39 -12
  197. myokit/tests/test_simulation_log_interval.py +1 -431
  198. myokit/tests/test_simulation_opencl.py +69 -48
  199. myokit/tests/test_simulation_opencl_log_interval.py +1 -3
  200. myokit/tests/test_simulation_opencl_vs_cvode.py +1 -10
  201. myokit/tests/test_simulation_opencl_vs_sim1d.py +1 -10
  202. myokit/tests/test_system_info.py +1 -11
  203. myokit/tests/test_tools.py +0 -9
  204. myokit/tests/test_unit.py +1 -10
  205. myokit/tests/test_user_functions.py +0 -10
  206. myokit/tests/test_variable.py +231 -27
  207. myokit/tools.py +5 -21
  208. myokit/units.py +5 -3
  209. {myokit-1.33.9.dist-info → myokit-1.35.0.dist-info}/METADATA +12 -15
  210. myokit-1.35.0.dist-info/RECORD +391 -0
  211. {myokit-1.33.9.dist-info → myokit-1.35.0.dist-info}/WHEEL +1 -1
  212. {myokit-1.33.9.dist-info → myokit-1.35.0.dist-info}/entry_points.txt +0 -1
  213. myokit/_exec_new.py +0 -15
  214. myokit/_exec_old.py +0 -15
  215. myokit/_sim/cvodesim.c +0 -1551
  216. myokit/_sim/cvodesim.py +0 -674
  217. myokit/_sim/icsim.cpp +0 -563
  218. myokit/_sim/icsim.py +0 -363
  219. myokit/_sim/psim.cpp +0 -656
  220. myokit/_sim/psim.py +0 -493
  221. myokit/lib/common.py +0 -1094
  222. myokit/tests/test_lib_common.py +0 -130
  223. myokit/tests/test_simulation_cvode.py +0 -612
  224. myokit/tests/test_simulation_ic.py +0 -108
  225. myokit/tests/test_simulation_p.py +0 -223
  226. myokit-1.33.9.dist-info/RECORD +0 -403
  227. /myokit/formats/opencl/template/{test → test.sh} +0 -0
  228. {myokit-1.33.9.dist-info → myokit-1.35.0.dist-info}/LICENSE.txt +0 -0
  229. {myokit-1.33.9.dist-info → myokit-1.35.0.dist-info}/top_level.txt +0 -0
@@ -26,21 +26,12 @@
26
26
  # This file is part of Myokit.
27
27
  # See http://myokit.org for copyright, sharing, and licensing details.
28
28
  #
29
- from __future__ import absolute_import, division
30
- from __future__ import print_function, unicode_literals
31
-
32
29
  import unittest
33
30
 
34
31
  import myokit
35
32
 
36
33
  from myokit.tests.ansic_event_based_pacing import AnsicEventBasedPacing
37
34
 
38
- # Unit testing in Python 2 and 3
39
- try:
40
- unittest.TestCase.assertRaisesRegex
41
- except AttributeError:
42
- unittest.TestCase.assertRaisesRegex = unittest.TestCase.assertRaisesRegexp
43
-
44
35
 
45
36
  class ProtocolFloatingPointTest(unittest.TestCase):
46
37
 
@@ -125,7 +116,7 @@ class ProtocolFloatingPointTest(unittest.TestCase):
125
116
 
126
117
  class PacingSystemFloatingPointTest(unittest.TestCase):
127
118
  """
128
- Test float behaviour in the Python PacingSystem implementation, using the
119
+ Test float behavior in the Python PacingSystem implementation, using the
129
120
  log_for_interval method.
130
121
  """
131
122
 
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env python3
2
+ #
3
+ # Tests the time series protocol class
4
+ #
5
+ # This file is part of Myokit.
6
+ # See http://myokit.org for copyright, sharing, and licensing details.
7
+ #
8
+ import unittest
9
+ import pickle
10
+
11
+ import myokit
12
+
13
+
14
+ class TimeSeriesProtocolTest(unittest.TestCase):
15
+ """
16
+ Tests the TimeSeriesProtocol class.
17
+ """
18
+
19
+ def test_eq(self):
20
+ # Equality testing
21
+ p1 = myokit.TimeSeriesProtocol([1, 2], [2, 4])
22
+ p2 = myokit.TimeSeriesProtocol([1, 2], [2, 4])
23
+ self.assertEqual(p1, p2)
24
+ self.assertNotEqual(p1, 1)
25
+ self.assertEqual(p1, p1)
26
+
27
+ def test_pickle(self):
28
+ # Pickling and unpickling
29
+ p1 = myokit.TimeSeriesProtocol([1, 2], [2, 4])
30
+ p2 = pickle.loads(pickle.dumps(p1))
31
+ self.assertEqual(p1, p2)
32
+
33
+ def test_constructor(self):
34
+ p = myokit.TimeSeriesProtocol([1], [2])
35
+ self.assertEqual(p.times(), [1])
36
+ self.assertEqual(p.values(), [2])
37
+
38
+ p = myokit.TimeSeriesProtocol([1, 2], [1, 2])
39
+ self.assertEqual(p.times(), [1, 2])
40
+ self.assertEqual(p.values(), [1, 2])
41
+
42
+ p = myokit.TimeSeriesProtocol([2, 1], [2, 1])
43
+ self.assertEqual(p.times(), [1, 2])
44
+ self.assertEqual(p.values(), [1, 2])
45
+
46
+ self.assertRaises( # No specific error from class!!
47
+ TypeError, myokit.TimeSeriesProtocol, 1, 2)
48
+ self.assertRaisesRegex(
49
+ ValueError, 'same size', myokit.TimeSeriesProtocol, [1, 2], [2])
50
+ self.assertRaisesRegex(
51
+ ValueError, 'nknown interpolation', myokit.TimeSeriesProtocol,
52
+ [1, 2], [2, 4], method='cubic'
53
+ )
54
+
55
+ def test_values(self):
56
+ values = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
57
+ times = [0, 0, 1, 1, 1, 2, 2, 2, 3, 4, 5, 7]
58
+ values = list(range(len(times)))
59
+ pacing = myokit.TimeSeriesProtocol(times, values)
60
+
61
+ def test(value, index):
62
+ self.assertEqual(pacing.pace(value), index)
63
+
64
+ test(-1, 0)
65
+ test(0, 1)
66
+ test(1, 4)
67
+ test(2, 7)
68
+ test(3, 8)
69
+ test(4, 9)
70
+ test(5, 10)
71
+ test(7, 11)
72
+ test(8, 11)
73
+ test(1.5, 4.5)
74
+ test(1.75, 4.75)
75
+ test(6, 10.5)
76
+ test(5.5, 10.25)
77
+
78
+
79
+ if __name__ == '__main__':
80
+ import warnings
81
+ warnings.simplefilter('always')
82
+ unittest.main()
myokit/tests/test_pype.py CHANGED
@@ -5,9 +5,6 @@
5
5
  # This file is part of Myokit.
6
6
  # See http://myokit.org for copyright, sharing, and licensing details.
7
7
  #
8
- from __future__ import absolute_import, division
9
- from __future__ import print_function, unicode_literals
10
-
11
8
  import unittest
12
9
 
13
10
  import myokit
@@ -15,12 +12,6 @@ import myokit.pype
15
12
 
16
13
  from myokit.tests import TemporaryDirectory
17
14
 
18
- # Unit testing in Python 2 and 3
19
- try:
20
- unittest.TestCase.assertRaisesRegex
21
- except AttributeError:
22
- unittest.TestCase.assertRaisesRegex = unittest.TestCase.assertRaisesRegexp
23
-
24
15
 
25
16
  class PypeTest(unittest.TestCase):
26
17
 
@@ -5,19 +5,10 @@
5
5
  # This file is part of Myokit.
6
6
  # See http://myokit.org for copyright, sharing, and licensing details.
7
7
  #
8
- from __future__ import absolute_import, division
9
- from __future__ import print_function, unicode_literals
10
-
11
8
  import unittest
12
9
 
13
10
  import myokit
14
11
 
15
- # Unit testing in Python 2 and 3
16
- try:
17
- unittest.TestCase.assertRaisesRegex
18
- except AttributeError:
19
- unittest.TestCase.assertRaisesRegex = unittest.TestCase.assertRaisesRegexp
20
-
21
12
 
22
13
  class QuantityTest(unittest.TestCase):
23
14
  """
@@ -5,20 +5,12 @@
5
5
  # This file is part of Myokit.
6
6
  # See http://myokit.org for copyright, sharing, and licensing details.
7
7
  #
8
- from __future__ import absolute_import, division
9
- from __future__ import print_function, unicode_literals
10
-
11
8
  import unittest
9
+
12
10
  import numpy as np
13
11
 
14
12
  import myokit
15
13
 
16
- # Unit testing in Python 2 and 3
17
- try:
18
- unittest.TestCase.assertRaisesRegex
19
- except AttributeError:
20
- unittest.TestCase.assertRaisesRegex = unittest.TestCase.assertRaisesRegexp
21
-
22
14
 
23
15
  class RhsBenchmarkerTest(unittest.TestCase):
24
16
  """
@@ -5,9 +5,6 @@
5
5
  # This file is part of Myokit.
6
6
  # See http://myokit.org for copyright, sharing, and licensing details.
7
7
  #
8
- from __future__ import absolute_import, division
9
- from __future__ import print_function, unicode_literals
10
-
11
8
  import unittest
12
9
 
13
10
  import myokit
@@ -18,18 +15,6 @@ from myokit.formats.sbml._api import _MyokitConverter as X
18
15
 
19
16
  from myokit.tests import WarningCollector
20
17
 
21
- # Unit testing in Python 2 and 3
22
- try:
23
- unittest.TestCase.assertRaisesRegex
24
- except AttributeError: # pragma: no python 3 cover
25
- unittest.TestCase.assertRaisesRegex = unittest.TestCase.assertRaisesRegexp
26
-
27
- # Strings in Python 2 and 3
28
- try:
29
- basestring
30
- except NameError: # pragma: no python 2 cover
31
- basestring = str
32
-
33
18
 
34
19
  class TestCompartment(unittest.TestCase):
35
20
  """
@@ -1214,7 +1199,7 @@ class SBMLTestMyokitModel(unittest.TestCase):
1214
1199
  c.set_initial_value(myokit.Name(p))
1215
1200
  mm = sm.myokit_model()
1216
1201
  self.assertTrue(mm.has_component('comp'))
1217
- self.assertEqual(mm.get('comp.size').rhs().code(), 'myokit.parameter')
1202
+ self.assertEqual(mm.get('comp.size').rhs().code(), 'global.parameter')
1218
1203
  self.assertFalse(mm.get('comp.size').is_state())
1219
1204
 
1220
1205
  # Check setting size as value
@@ -1241,7 +1226,7 @@ class SBMLTestMyokitModel(unittest.TestCase):
1241
1226
  c.set_value(myokit.Name(p))
1242
1227
  mm = sm.myokit_model()
1243
1228
  self.assertTrue(mm.has_component('comp'))
1244
- self.assertEqual(mm.get('comp.size').rhs().code(), 'myokit.parameter')
1229
+ self.assertEqual(mm.get('comp.size').rhs().code(), 'global.parameter')
1245
1230
  self.assertFalse(mm.get('comp.size').is_state())
1246
1231
 
1247
1232
  # Check setting size as rate
@@ -1289,9 +1274,9 @@ class SBMLTestMyokitModel(unittest.TestCase):
1289
1274
  m = m.myokit_model()
1290
1275
 
1291
1276
  # Check that model created parameters in 'global' component
1292
- self.assertTrue(m.has_variable('myokit.z'))
1293
- self.assertTrue(m.has_variable('myokit.boat'))
1294
- self.assertTrue(m.has_variable('myokit.c'))
1277
+ self.assertTrue(m.has_variable('global.z'))
1278
+ self.assertTrue(m.has_variable('global.boat'))
1279
+ self.assertTrue(m.has_variable('global.c'))
1295
1280
 
1296
1281
  # Check that total number of parameters is 4 (3 parameters and time)
1297
1282
  self.assertEqual(m.count_variables(), 4)
@@ -1303,7 +1288,7 @@ class SBMLTestMyokitModel(unittest.TestCase):
1303
1288
  p = m.add_parameter('param')
1304
1289
  p.set_initial_value(myokit.Number(7))
1305
1290
  mm = m.myokit_model()
1306
- pp = mm.get('myokit.param')
1291
+ pp = mm.get('global.param')
1307
1292
  self.assertFalse(pp.is_state())
1308
1293
  self.assertEqual(pp.rhs(), myokit.Number(7))
1309
1294
 
@@ -1311,7 +1296,7 @@ class SBMLTestMyokitModel(unittest.TestCase):
1311
1296
  self.assertIsNone(pp.unit())
1312
1297
  p.set_units(myokit.units.pF)
1313
1298
  mm = m.myokit_model()
1314
- pp = mm.get('myokit.param')
1299
+ pp = mm.get('global.param')
1315
1300
  self.assertFalse(pp.is_state())
1316
1301
  self.assertEqual(pp.rhs(), myokit.Number(7))
1317
1302
  self.assertEqual(pp.unit(), myokit.units.pF)
@@ -1331,7 +1316,7 @@ class SBMLTestMyokitModel(unittest.TestCase):
1331
1316
  p = m.add_parameter('param')
1332
1317
  p.set_value(myokit.Plus(myokit.Number(7), myokit.Number(3)))
1333
1318
  mm = m.myokit_model()
1334
- pp = mm.get('myokit.param')
1319
+ pp = mm.get('global.param')
1335
1320
  self.assertFalse(pp.is_state())
1336
1321
  self.assertEqual(
1337
1322
  pp.rhs(), myokit.Plus(myokit.Number(7), myokit.Number(3)))
@@ -1340,7 +1325,7 @@ class SBMLTestMyokitModel(unittest.TestCase):
1340
1325
  self.assertIsNone(pp.unit())
1341
1326
  p.set_units(myokit.units.pF)
1342
1327
  mm = m.myokit_model()
1343
- pp = mm.get('myokit.param')
1328
+ pp = mm.get('global.param')
1344
1329
  self.assertFalse(pp.is_state())
1345
1330
  self.assertEqual(pp.rhs().code(), '7 + 3')
1346
1331
  self.assertEqual(pp.unit(), myokit.units.pF)
@@ -1361,24 +1346,24 @@ class SBMLTestMyokitModel(unittest.TestCase):
1361
1346
  p.set_value(myokit.Number(3.2), is_rate=True)
1362
1347
  with WarningCollector():
1363
1348
  mm = m.myokit_model()
1364
- pp = mm.get('myokit.param')
1349
+ pp = mm.get('global.param')
1365
1350
  self.assertTrue(pp.is_state())
1366
1351
  self.assertEqual(pp.rhs(), myokit.Number(3.2))
1367
- self.assertEqual(pp.state_value(), 0)
1352
+ self.assertEqual(pp.initial_value(as_float=True), 0)
1368
1353
 
1369
1354
  # With initial value
1370
1355
  p.set_initial_value(myokit.Number(1))
1371
1356
  mm = m.myokit_model()
1372
- pp = mm.get('myokit.param')
1357
+ pp = mm.get('global.param')
1373
1358
  self.assertTrue(pp.is_state())
1374
1359
  self.assertEqual(pp.rhs(), myokit.Number(3.2))
1375
- self.assertEqual(pp.state_value(), 1)
1360
+ self.assertEqual(pp.initial_value(as_float=True), 1)
1376
1361
 
1377
1362
  # Test units
1378
1363
  self.assertIsNone(pp.unit())
1379
1364
  p.set_units(myokit.units.pF)
1380
1365
  mm = m.myokit_model()
1381
- pp = mm.get('myokit.param')
1366
+ pp = mm.get('global.param')
1382
1367
  self.assertTrue(pp.is_state())
1383
1368
  self.assertEqual(pp.rhs(), myokit.Number(3.2))
1384
1369
  self.assertEqual(pp.unit(), myokit.units.pF)
@@ -1478,7 +1463,7 @@ class SBMLTestMyokitModel(unittest.TestCase):
1478
1463
  mm = m.myokit_model()
1479
1464
  ms = mm.get('comp.spec_1_amount')
1480
1465
  self.assertFalse(ms.is_state())
1481
- self.assertEqual(ms.rhs().code(), 'myokit.p1')
1466
+ self.assertEqual(ms.rhs().code(), 'global.p1')
1482
1467
 
1483
1468
  # Species in concentration: unreferenced parameter
1484
1469
  p2 = sbml.Parameter(m, 'p2')
@@ -1542,13 +1527,13 @@ class SBMLTestMyokitModel(unittest.TestCase):
1542
1527
  ms = mm.get('comp.spec_1_amount')
1543
1528
  self.assertTrue(ms.is_state())
1544
1529
  self.assertEqual(ms.rhs(), myokit.Number(3))
1545
- self.assertEqual(ms.state_value(), 0)
1530
+ self.assertEqual(ms.initial_value(as_float=True), 0)
1546
1531
  s1.set_initial_value(myokit.Number(7))
1547
1532
  mm = m.myokit_model()
1548
1533
  ms = mm.get('comp.spec_1_amount')
1549
1534
  self.assertTrue(ms.is_state())
1550
1535
  self.assertEqual(ms.rhs(), myokit.Number(3))
1551
- self.assertEqual(ms.state_value(), 7)
1536
+ self.assertEqual(ms.initial_value(as_float=True), 7)
1552
1537
 
1553
1538
  # Species in concentration
1554
1539
  s2 = m.add_species(c, 'spec_2', is_amount=False)
@@ -1562,7 +1547,7 @@ class SBMLTestMyokitModel(unittest.TestCase):
1562
1547
  sa = mm.get('comp.spec_2_amount')
1563
1548
  self.assertTrue(sa.is_state())
1564
1549
  self.assertEqual(sa.rhs().code(), '4 * comp.size')
1565
- self.assertEqual(sa.state_value(), 0)
1550
+ self.assertEqual(sa.initial_value(as_float=True), 0)
1566
1551
 
1567
1552
  # I: Set compartment size
1568
1553
  m = sbml.Model()
@@ -1577,13 +1562,13 @@ class SBMLTestMyokitModel(unittest.TestCase):
1577
1562
  ms = mm.get('comp.spec_1_amount')
1578
1563
  self.assertTrue(ms.is_state())
1579
1564
  self.assertEqual(ms.rhs(), myokit.Number(3))
1580
- self.assertEqual(ms.state_value(), 0)
1565
+ self.assertEqual(ms.initial_value(as_float=True), 0)
1581
1566
  s1.set_initial_value(myokit.Number(7))
1582
1567
  mm = m.myokit_model()
1583
1568
  ms = mm.get('comp.spec_1_amount')
1584
1569
  self.assertTrue(ms.is_state())
1585
1570
  self.assertEqual(ms.rhs(), myokit.Number(3))
1586
- self.assertEqual(ms.state_value(), 7)
1571
+ self.assertEqual(ms.initial_value(as_float=True), 7)
1587
1572
 
1588
1573
  # Species in concentration
1589
1574
  s2 = m.add_species(c, 'spec_2', is_amount=False)
@@ -1599,7 +1584,7 @@ class SBMLTestMyokitModel(unittest.TestCase):
1599
1584
  sa = mm.get('comp.spec_2_amount')
1600
1585
  self.assertTrue(sa.is_state())
1601
1586
  self.assertEqual(sa.rhs().code(), '4 * comp.size')
1602
- self.assertEqual(sa.state_value(), 6 * 2)
1587
+ self.assertEqual(sa.initial_value(as_float=True), 6 * 2)
1603
1588
 
1604
1589
  def test_species_units(self):
1605
1590
  # Tests whether species units are set properly.
@@ -1968,7 +1953,7 @@ class SBMLTestMyokitModel(unittest.TestCase):
1968
1953
  self.assertEqual(var.eval(), 5)
1969
1954
 
1970
1955
  var = mm.get('c.sr2')
1971
- self.assertEqual(var.state_value(), 0)
1956
+ self.assertEqual(var.initial_value(as_float=True), 0)
1972
1957
  self.assertEqual(var.eval(), 3.82)
1973
1958
 
1974
1959
  def test_reaction_stoichiometries_exist(self):
@@ -2061,7 +2046,7 @@ class SBMLTestMyokitModel(unittest.TestCase):
2061
2046
  self.assertEqual(var.eval(), 15.23)
2062
2047
 
2063
2048
  var = mm.get('c.sr2')
2064
- self.assertEqual(var.state_value(), 3.5)
2049
+ self.assertEqual(var.initial_value(as_float=True), 3.5)
2065
2050
  self.assertEqual(var.eval(), 9.23)
2066
2051
 
2067
2052
  # Bad value
@@ -2168,10 +2153,10 @@ class SBMLTestMyokitModel(unittest.TestCase):
2168
2153
  m = m.myokit_model()
2169
2154
 
2170
2155
  # Check that time variable exists
2171
- self.assertTrue(m.has_variable('myokit.time'))
2156
+ self.assertTrue(m.has_variable('global.time'))
2172
2157
 
2173
2158
  # Check that unit is set
2174
- var = m.get('myokit.time')
2159
+ var = m.get('global.time')
2175
2160
  self.assertEqual(var.unit(), myokit.units.ampere)
2176
2161
 
2177
2162
  # Check that initial value is set
@@ -2189,10 +2174,10 @@ class SBMLTestMyokitModel(unittest.TestCase):
2189
2174
  p = s.add_parameter('param')
2190
2175
  p.set_value(myokit.Plus(myokit.Number(1), myokit.Name(s.time())))
2191
2176
  m = s.myokit_model()
2192
- t = m.get('myokit.time')
2177
+ t = m.get('global.time')
2193
2178
  self.assertEqual(t.unit(), myokit.units.ms)
2194
2179
  self.assertEqual(
2195
- m.get('myokit.param').rhs(),
2180
+ m.get('global.param').rhs(),
2196
2181
  myokit.Plus(myokit.Number(1), myokit.Name(m.time())))
2197
2182
 
2198
2183
 
@@ -5,9 +5,6 @@
5
5
  # This file is part of Myokit.
6
6
  # See http://myokit.org for copyright, sharing, and licensing details.
7
7
  #
8
- from __future__ import absolute_import, division
9
- from __future__ import print_function, unicode_literals
10
-
11
8
  import unittest
12
9
 
13
10
  import myokit
@@ -17,18 +14,6 @@ from myokit.formats.sbml import SBMLParser, SBMLParsingError
17
14
 
18
15
  from myokit.tests import WarningCollector
19
16
 
20
- # Unit testing in Python 2 and 3
21
- try:
22
- unittest.TestCase.assertRaisesRegex
23
- except AttributeError: # pragma: no python 3 cover
24
- unittest.TestCase.assertRaisesRegex = unittest.TestCase.assertRaisesRegexp
25
-
26
- # Strings in Python 2 and 3
27
- try:
28
- basestring
29
- except NameError: # pragma: no python 2 cover
30
- basestring = str
31
-
32
17
 
33
18
  class TestSBMLParser(unittest.TestCase):
34
19
  """
@@ -913,12 +898,12 @@ class TestSBMLParser(unittest.TestCase):
913
898
  # Check species reactions (no unecessary zeros and all terms present)
914
899
  model_mmt = m.myokit_model().code()
915
900
  S1_rhs = \
916
- 'dot(S1_amount) = -(r1 * (size * myokit.k1 * S1_concentration)) ' \
917
- + '- size * myokit.k1 * S1_concentration'
901
+ 'dot(S1_amount) = -(r1 * (size * global.k1 * S1_concentration)) ' \
902
+ + '- size * global.k1 * S1_concentration'
918
903
  self.assertTrue(S1_rhs in model_mmt)
919
- S2_rhs = 'dot(S2_amount) = r2 * (size * myokit.k1 * S1_concentration)'
904
+ S2_rhs = 'dot(S2_amount) = r2 * (size * global.k1 * S1_concentration)'
920
905
  self.assertTrue(S2_rhs in model_mmt)
921
- S3_rhs = 'dot(S3_amount) = size * myokit.k1 * S1_concentration'
906
+ S3_rhs = 'dot(S3_amount) = size * global.k1 * S1_concentration'
922
907
  self.assertTrue(S3_rhs in model_mmt)
923
908
 
924
909
  def test_parse_rule(self):
@@ -5,24 +5,15 @@
5
5
  # This file is part of Myokit.
6
6
  # See http://myokit.org for copyright, sharing, and licensing details.
7
7
  #
8
- from __future__ import absolute_import, division
9
- from __future__ import print_function, unicode_literals
10
-
11
8
  import os
12
9
  import unittest
10
+
13
11
  import numpy as np
14
12
 
15
13
  import myokit
16
14
 
17
15
  from myokit.tests import DIR_DATA, CancellingReporter
18
16
 
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
17
  # Show simulation output
27
18
  debug = False
28
19
 
@@ -31,6 +22,7 @@ class Simulation1dTest(unittest.TestCase):
31
22
  """
32
23
  Test the non-parallel 1d simulation.
33
24
  """
25
+
34
26
  def test_basic(self):
35
27
  # Test basic usage.
36
28
 
@@ -42,23 +34,24 @@ class Simulation1dTest(unittest.TestCase):
42
34
  s = myokit.Simulation1d(m, p, ncells=ncells)
43
35
  s.set_step_size(0.05)
44
36
 
37
+ x0 = m.initial_values(True)
45
38
  self.assertEqual(s.time(), 0)
46
- self.assertEqual(s.state(0), m.state())
47
- self.assertEqual(s.default_state(0), m.state())
39
+ self.assertEqual(s.state(0), x0)
40
+ self.assertEqual(s.default_state(0), x0)
48
41
  d = s.run(5, log_interval=1)
49
42
  self.assertEqual(s.time(), 5)
50
- self.assertNotEqual(s.state(0), m.state())
51
- self.assertEqual(s.default_state(0), m.state())
43
+ self.assertNotEqual(s.state(0), x0)
44
+ self.assertEqual(s.default_state(0), x0)
52
45
 
53
46
  # Test full state getting and reset
54
- self.assertEqual(s.default_state(), m.state() * ncells)
55
- self.assertNotEqual(s.state(), m.state() * ncells)
47
+ self.assertEqual(s.default_state(), x0 * ncells)
48
+ self.assertNotEqual(s.state(), x0 * ncells)
56
49
  s.reset()
57
50
  self.assertEqual(s.state(), s.default_state())
58
51
 
59
52
  # Test pre updates the default state.
60
53
  s.pre(1)
61
- self.assertNotEqual(s.default_state(0), m.state())
54
+ self.assertNotEqual(s.default_state(0), x0)
62
55
 
63
56
  # Test running without a protocol
64
57
  s.set_protocol(None)
@@ -103,6 +96,31 @@ class Simulation1dTest(unittest.TestCase):
103
96
  s.set_time(100)
104
97
  self.assertEqual(s.time(), 100)
105
98
 
99
+ def test_initial_value_expressions(self):
100
+ # Test if initial value expressions are converted to floats
101
+ m = myokit.parse_model('''
102
+ [[model]]
103
+ c.x = 1 + sqrt(3)
104
+ c.y = 1 / c.p
105
+ c.z = 3
106
+
107
+ [c]
108
+ t = 0 bind time
109
+ dot(x) = 1 label membrane_potential
110
+ dot(y) = 2
111
+ dot(z) = 3
112
+ p = log(3)
113
+ q = 0 bind diffusion_current
114
+ ''')
115
+ s = myokit.Simulation1d(m, ncells=2)
116
+ x = s.state()
117
+ self.assertIsInstance(x[0], float)
118
+ self.assertIsInstance(x[1], float)
119
+ self.assertIsInstance(x[2], float)
120
+ self.assertEqual(x[:3], x[3:])
121
+ self.assertEqual(x, m.initial_values(True) * 2)
122
+ self.assertEqual(x, s.default_state())
123
+
106
124
  def test_with_progress_reporter(self):
107
125
  # Test running with a progress reporter.
108
126
  m, p, _ = myokit.load(os.path.join(DIR_DATA, 'lr-1991.mmt'))
@@ -130,7 +148,8 @@ class Simulation1dTest(unittest.TestCase):
130
148
  n = 4
131
149
 
132
150
  s = myokit.Simulation1d(m, p, n)
133
- self.assertEqual(s.state(), m.state() * n)
151
+ x0 = m.initial_values(True)
152
+ self.assertEqual(s.state(), x0 * n)
134
153
 
135
154
  # Test setting a full state
136
155
  sx = [0] * 8 * n
@@ -142,8 +161,8 @@ class Simulation1dTest(unittest.TestCase):
142
161
  sx = [0] * 8
143
162
  s.set_state(sx)
144
163
  self.assertEqual(s.state(), sx * n)
145
- s.set_state(m.state())
146
- self.assertEqual(s.state(), m.state() * n)
164
+ s.set_state(x0)
165
+ self.assertEqual(s.state(), x0 * n)
147
166
 
148
167
  # Test setting a single state
149
168
  j = 1
@@ -152,7 +171,7 @@ class Simulation1dTest(unittest.TestCase):
152
171
  if i == j:
153
172
  self.assertEqual(s.state(i), sx)
154
173
  else:
155
- self.assertEqual(s.state(i), m.state())
174
+ self.assertEqual(s.state(i), x0)
156
175
 
157
176
  # Invalid cell index
158
177
  s.set_state(sx, 0)
@@ -167,7 +186,7 @@ class Simulation1dTest(unittest.TestCase):
167
186
  n = 4
168
187
 
169
188
  s = myokit.Simulation1d(m, p, n)
170
- self.assertEqual(s.state(), m.state() * n)
189
+ self.assertEqual(s.state(), m.initial_values(True) * n)
171
190
 
172
191
  # Test setting a full state
173
192
  sx = [0] * 8 * n
@@ -179,8 +198,9 @@ class Simulation1dTest(unittest.TestCase):
179
198
  sx = [0] * 8
180
199
  s.set_default_state(sx)
181
200
  self.assertEqual(s.default_state(), sx * n)
182
- s.set_default_state(m.state())
183
- self.assertEqual(s.default_state(), m.state() * n)
201
+ sy = m.initial_values(True)
202
+ s.set_default_state(sy)
203
+ self.assertEqual(s.default_state(), sy * n)
184
204
 
185
205
  # Test setting a single state
186
206
  j = 1
@@ -189,7 +209,7 @@ class Simulation1dTest(unittest.TestCase):
189
209
  if i == j:
190
210
  self.assertEqual(s.default_state(i), sx)
191
211
  else:
192
- self.assertEqual(s.default_state(i), m.state())
212
+ self.assertEqual(s.default_state(i), sy)
193
213
 
194
214
  # Invalid cell index
195
215
  s.set_default_state(sx, 0)