myokit 1.37.2__py3-none-any.whl → 1.37.3__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/_myokit_version.py +1 -1
- myokit/_unit.py +48 -40
- myokit/tests/test_quantity.py +2 -2
- myokit/tests/test_unit.py +28 -7
- {myokit-1.37.2.dist-info → myokit-1.37.3.dist-info}/METADATA +1 -1
- {myokit-1.37.2.dist-info → myokit-1.37.3.dist-info}/RECORD +10 -10
- {myokit-1.37.2.dist-info → myokit-1.37.3.dist-info}/LICENSE.txt +0 -0
- {myokit-1.37.2.dist-info → myokit-1.37.3.dist-info}/WHEEL +0 -0
- {myokit-1.37.2.dist-info → myokit-1.37.3.dist-info}/entry_points.txt +0 -0
- {myokit-1.37.2.dist-info → myokit-1.37.3.dist-info}/top_level.txt +0 -0
myokit/_myokit_version.py
CHANGED
|
@@ -14,7 +14,7 @@ __release__ = True
|
|
|
14
14
|
# incompatibility
|
|
15
15
|
# - Changes to revision indicate bugfixes, tiny new features
|
|
16
16
|
# - There is no significance to odd/even numbers
|
|
17
|
-
__version_tuple__ = 1, 37,
|
|
17
|
+
__version_tuple__ = 1, 37, 3
|
|
18
18
|
|
|
19
19
|
# String version of the version number
|
|
20
20
|
__version__ = '.'.join([str(x) for x in __version_tuple__])
|
myokit/_unit.py
CHANGED
|
@@ -487,56 +487,55 @@ class Unit:
|
|
|
487
487
|
return self.__rtruediv__(other)
|
|
488
488
|
|
|
489
489
|
@staticmethod
|
|
490
|
-
def register(name, unit, quantifiable=False,
|
|
490
|
+
def register(name, unit, quantifiable=False,
|
|
491
|
+
preferred_representation=False):
|
|
491
492
|
"""
|
|
492
|
-
Registers a unit name with the Unit class
|
|
493
|
-
recognised
|
|
493
|
+
Registers a unit name with the :class:`Unit` class so that it will be
|
|
494
|
+
recognised when parsing.
|
|
494
495
|
|
|
495
496
|
Arguments:
|
|
496
497
|
|
|
497
498
|
``name``
|
|
498
|
-
The unit name.
|
|
499
|
+
The unit name. This must be a valid myokit name, i.e.
|
|
500
|
+
``myokit.check_name(name)`` should not raise any errors.
|
|
499
501
|
``unit``
|
|
500
502
|
A valid unit object
|
|
501
503
|
``quantifiable``
|
|
502
504
|
``True`` if this unit should be registered with the unit class as a
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
preferred representation format.
|
|
514
|
-
|
|
515
|
-
"""
|
|
516
|
-
if not isinstance(name, str):
|
|
517
|
-
raise TypeError('Given name must be a string.')
|
|
505
|
+
_quantifiable_ unit, i.e. a unit that can be preceded by an SI
|
|
506
|
+
prefix such as "m" or "G". Typically this should only be done
|
|
507
|
+
for the unquantified symbol notation of SI or SI derived units. For
|
|
508
|
+
example "m", "g", or "Hz" but not "km", "meter", or "bushel".
|
|
509
|
+
``preferred_representation``
|
|
510
|
+
Set to ``True`` to also register ``name`` as the preferred
|
|
511
|
+
representation for ``unit``.
|
|
512
|
+
|
|
513
|
+
"""
|
|
514
|
+
name = myokit.check_name(name)
|
|
518
515
|
if not isinstance(unit, Unit):
|
|
519
516
|
raise TypeError('Given unit must be myokit.Unit')
|
|
520
517
|
Unit._units[name] = unit
|
|
521
518
|
if quantifiable:
|
|
522
519
|
# Overwrite existing entries without warning
|
|
523
520
|
Unit._quantifiable.add(name)
|
|
524
|
-
if
|
|
521
|
+
if preferred_representation:
|
|
525
522
|
# Overwrite existing entries without warning
|
|
526
523
|
Unit._preferred_representations[unit] = name
|
|
527
524
|
|
|
528
525
|
@staticmethod
|
|
529
526
|
def register_preferred_representation(rep, unit):
|
|
530
527
|
"""
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
528
|
+
Sets the preferred representation for the a unit, in terms of already
|
|
529
|
+
defined units.
|
|
530
|
+
|
|
531
|
+
This method can be used to register common representations such as
|
|
532
|
+
"umol/L" and "km/h". The given representation should be parseable by
|
|
533
|
+
Myokit, with the result equalling ``unit``.
|
|
534
534
|
|
|
535
535
|
Arguments:
|
|
536
536
|
|
|
537
537
|
``rep``
|
|
538
|
-
A string
|
|
539
|
-
be something that Myokit can parse.
|
|
538
|
+
A string containing the preferred representation for this unit.
|
|
540
539
|
``unit``
|
|
541
540
|
The unit to register a notation for.
|
|
542
541
|
|
|
@@ -545,9 +544,14 @@ class Unit:
|
|
|
545
544
|
# Overwrite existing entries without warning
|
|
546
545
|
if not isinstance(unit, myokit.Unit):
|
|
547
546
|
raise ValueError(
|
|
548
|
-
'
|
|
549
|
-
' a myokit.Unit')
|
|
550
|
-
|
|
547
|
+
'The second argument to register_preferred_representation must'
|
|
548
|
+
' be a myokit.Unit')
|
|
549
|
+
rep = str(rep)
|
|
550
|
+
if not myokit.parse_unit(rep) == unit:
|
|
551
|
+
raise ValueError(
|
|
552
|
+
f'The representation [{rep}] does not equal {unit._str(True)}'
|
|
553
|
+
' when parsed.')
|
|
554
|
+
Unit._preferred_representations[unit] = rep
|
|
551
555
|
|
|
552
556
|
def __repr__(self):
|
|
553
557
|
"""
|
|
@@ -616,7 +620,8 @@ class Unit:
|
|
|
616
620
|
|
|
617
621
|
def __str__(self):
|
|
618
622
|
|
|
619
|
-
# Strategy 1: Try simple look-up (using
|
|
623
|
+
# Strategy 1: Try simple look-up (using hash based on _str() followed
|
|
624
|
+
# by check of exponents in __eq__ for comparison
|
|
620
625
|
try:
|
|
621
626
|
return '[' + Unit._preferred_representations[self] + ']'
|
|
622
627
|
except KeyError:
|
|
@@ -629,8 +634,8 @@ class Unit:
|
|
|
629
634
|
rep = '[' + test + ']'
|
|
630
635
|
break
|
|
631
636
|
|
|
632
|
-
# Strategy 3: Try finding a representation for the exponent
|
|
633
|
-
# a multiplier to that.
|
|
637
|
+
# Strategy 3: Try finding a representation for the exponent (without a
|
|
638
|
+
# multiplier) and adding a multiplier to that.
|
|
634
639
|
if rep is None:
|
|
635
640
|
|
|
636
641
|
# Because kilos are defined with a multiplier of 1000, the
|
|
@@ -640,17 +645,20 @@ class Unit:
|
|
|
640
645
|
u = Unit(list(self._x), m)
|
|
641
646
|
rep = Unit._preferred_representations.get(u, None)
|
|
642
647
|
|
|
643
|
-
# Add multiplier part
|
|
648
|
+
# Add multiplier part:
|
|
644
649
|
if rep is not None:
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
if m >= 1:
|
|
648
|
-
m = myokit.float.cround(m)
|
|
649
|
-
if m < 1e6:
|
|
650
|
-
m = str(m)
|
|
650
|
+
if '(' in rep:
|
|
651
|
+
rep = None
|
|
651
652
|
else:
|
|
652
|
-
m =
|
|
653
|
-
|
|
653
|
+
m = myokit.float.cround(self._m - m)
|
|
654
|
+
m = 10**m
|
|
655
|
+
if m >= 1:
|
|
656
|
+
m = myokit.float.cround(m)
|
|
657
|
+
if m < 1e6:
|
|
658
|
+
m = str(m)
|
|
659
|
+
else:
|
|
660
|
+
m = '{:<1.0e}'.format(m)
|
|
661
|
+
rep = '[' + rep + ' (' + m + ')]'
|
|
654
662
|
|
|
655
663
|
# Strategy 4: Build a new representation
|
|
656
664
|
if rep is None:
|
myokit/tests/test_quantity.py
CHANGED
|
@@ -107,10 +107,10 @@ class QuantityTest(unittest.TestCase):
|
|
|
107
107
|
# Test has does not change in quantity's lifetime
|
|
108
108
|
|
|
109
109
|
try:
|
|
110
|
-
u = myokit.units.m
|
|
110
|
+
u = myokit.units.m / myokit.units.mol
|
|
111
111
|
q1 = myokit.Quantity(1, u)
|
|
112
112
|
h1 = hash(q1)
|
|
113
|
-
myokit.Unit.register_preferred_representation('
|
|
113
|
+
myokit.Unit.register_preferred_representation('km/kmol', u)
|
|
114
114
|
q2 = myokit.Quantity(1, u)
|
|
115
115
|
h2 = hash(q2)
|
|
116
116
|
self.assertEqual(h1, h2)
|
myokit/tests/test_unit.py
CHANGED
|
@@ -296,24 +296,35 @@ class MyokitUnitTest(unittest.TestCase):
|
|
|
296
296
|
self.assertEqual(x.exponents(), [0, 2, 1.5, 0, 0, 0, -1.23])
|
|
297
297
|
|
|
298
298
|
def test_register_errors(self):
|
|
299
|
-
# Test errors for Unit.register (rest is already used
|
|
300
|
-
|
|
299
|
+
# Test errors for Unit.register (rest of the method is already used
|
|
300
|
+
# throughout other tests).
|
|
301
|
+
self.assertRaises(myokit.InvalidNameError, myokit.Unit.register, 4,
|
|
302
|
+
myokit.Unit())
|
|
301
303
|
self.assertRaises(TypeError, myokit.Unit.register, 'hi', 4)
|
|
302
304
|
|
|
303
305
|
def test_register_preferred_representation(self):
|
|
304
306
|
# Test new representations can be registered
|
|
305
307
|
|
|
306
|
-
u = myokit.units.
|
|
307
|
-
self.assertEqual(str(u), '[m^8]')
|
|
308
|
+
u = myokit.units.K / myokit.units.A
|
|
308
309
|
try:
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
310
|
+
# Register valid unit
|
|
311
|
+
self.assertEqual(str(u), '[K/A]') # also auto registers!
|
|
312
|
+
myokit.Unit.register_preferred_representation('mK/mA', u)
|
|
313
|
+
self.assertEqual(str(u), '[mK/mA]')
|
|
312
314
|
|
|
315
|
+
# Attempt registering something that isn't a unit
|
|
313
316
|
self.assertRaisesRegex(
|
|
314
317
|
ValueError, 'must be a myokit.Unit',
|
|
315
318
|
myokit.Unit.register_preferred_representation, 'x', 123)
|
|
316
319
|
|
|
320
|
+
# Attempt registering a representation that doesn't match the unit
|
|
321
|
+
self.assertRaisesRegex(
|
|
322
|
+
ValueError, r'does not equal \[K/A] when parsed',
|
|
323
|
+
myokit.Unit.register_preferred_representation, 'm', u)
|
|
324
|
+
self.assertRaisesRegex(
|
|
325
|
+
ValueError, r'does not equal \[K/A \(2\)] when parsed',
|
|
326
|
+
myokit.Unit.register_preferred_representation, 'K/A', u * 2)
|
|
327
|
+
|
|
317
328
|
finally:
|
|
318
329
|
# Bypassing the public API, this is bad test design!
|
|
319
330
|
if u in myokit.Unit._preferred_representations:
|
|
@@ -365,6 +376,16 @@ class MyokitUnitTest(unittest.TestCase):
|
|
|
365
376
|
self.assertEqual(str(c), '[V]')
|
|
366
377
|
self.assertEqual(str(d), '[V]')
|
|
367
378
|
|
|
379
|
+
# 1115: Test str() doesn't create representations with more than one
|
|
380
|
+
# multiplier.
|
|
381
|
+
unit1 = myokit.units.mol / (1e3 * myokit.units.g)
|
|
382
|
+
unit2 = 1e-12 * myokit.units.mol / (1e3 * myokit.units.g)
|
|
383
|
+
unit3 = 1e-6 * unit2
|
|
384
|
+
self.assertEqual(str(unit1), '[mol/g (0.001)]')
|
|
385
|
+
self.assertEqual(str(unit2), '[mol/g (1e-15)]')
|
|
386
|
+
# Before fixing 1115, this returned [mol/g (0.001) (1e-12)]
|
|
387
|
+
self.assertEqual(str(unit3), '[mol/g (1e-21)]')
|
|
388
|
+
|
|
368
389
|
def test_repr(self):
|
|
369
390
|
# Test :meth:`Unit.repr()`.
|
|
370
391
|
|
|
@@ -8,12 +8,12 @@ myokit/_err.py,sha256=n8Ggy2VKnyx_h_ySuNe77tIFXzh1yO7sWBvc7YPC2cM,11974
|
|
|
8
8
|
myokit/_expressions.py,sha256=VpxJAax0OHAWj0AnIH5xkGVWLrmVxBP9tykaccV86BU,109246
|
|
9
9
|
myokit/_io.py,sha256=2ll5Yb-sbP4tvc3pPmzhNuv_PaRMPJlNRWb1TzXfELg,8948
|
|
10
10
|
myokit/_model_api.py,sha256=LRHT-RcqyB2UTNrvg7iMXN0D_lpParrks5YKcVZPJJY,194650
|
|
11
|
-
myokit/_myokit_version.py,sha256=
|
|
11
|
+
myokit/_myokit_version.py,sha256=DpsDatFLxBQC5tRXhL6D6VFWDyhKYOxR0wnzl8CvAT4,726
|
|
12
12
|
myokit/_parsing.py,sha256=GTVUwJvqjkQ3rc6BiwMFnzanLivbSUzW796gHCTJrNg,74065
|
|
13
13
|
myokit/_progress.py,sha256=Mi2QU6Vqj4qudhXc76amXM31iID2Mo8Gljw5OH2COZ4,4410
|
|
14
14
|
myokit/_protocol.py,sha256=_N16LGHppIv4yCSPjy0q2f-Oed0yG1wMk0ipTtXnMck,30756
|
|
15
15
|
myokit/_system.py,sha256=IX3Q7_7f9X9aYsxSL2CXJc9bTcFJsJbfq_e2w-OkhOI,4602
|
|
16
|
-
myokit/_unit.py,sha256=
|
|
16
|
+
myokit/_unit.py,sha256=prEupTNDeoqf2suN_i9ffBDGfVkid49gUDBTWTVzTww,30102
|
|
17
17
|
myokit/float.py,sha256=7-BqdABN5Vm4HIgRMHSgcZ4O4Vd085-5hMB6z8zJZtg,3066
|
|
18
18
|
myokit/pacing.py,sha256=_My0GwIPJh4DuUiK_kYDNBcacUaOKsffjbK5LvgK6z8,4552
|
|
19
19
|
myokit/pype.py,sha256=JTKuoiwxGui6iqBXK4gxNlCdtH_IGY0FiZLtmaJ580c,8230
|
|
@@ -268,7 +268,7 @@ myokit/tests/test_protocol.py,sha256=DThz7WImRqUngx91GzVX5niJVhAUy7Z3eOKXNBChLlY
|
|
|
268
268
|
myokit/tests/test_protocol_floating_point.py,sha256=R7It9eIHn1l3T-xHuJNaJw-hnIFOl1TXpmh_xZ5VhCI,12565
|
|
269
269
|
myokit/tests/test_protocol_time_series.py,sha256=ktBkmKNtonorKa--g3nSQZ3nga88IEn_-BHp8n9IflY,2318
|
|
270
270
|
myokit/tests/test_pype.py,sha256=vf3mympasLZwgTUQTSoe8e98Hp31cXo71APjlZEANKE,2402
|
|
271
|
-
myokit/tests/test_quantity.py,sha256=
|
|
271
|
+
myokit/tests/test_quantity.py,sha256=etmbqlqBNt2OZFku_P-s5n8RlA-gxVyRAWjOPq9xD7s,7373
|
|
272
272
|
myokit/tests/test_rhs_benchmarker.py,sha256=Gb3LaAiu8SW__BBM3l0TbMzxML1PpEqm3g8TCteyCZg,3452
|
|
273
273
|
myokit/tests/test_sbml_api.py,sha256=9SIwsAT5lyGYnVZvPjW-EOd6mdIbrGMFpB5e981vAxM,74820
|
|
274
274
|
myokit/tests/test_sbml_export.py,sha256=qdhSZ_zht_yOLJ3OfY2yt1-5uwj48nWn2Xtn5nSH8mo,13351
|
|
@@ -284,7 +284,7 @@ myokit/tests/test_simulation_opencl_vs_cvode.py,sha256=5b-dlUCwh7LieRoAb44OgxvwQ
|
|
|
284
284
|
myokit/tests/test_simulation_opencl_vs_sim1d.py,sha256=QYXZZay_YiHZ1qPO0naGP4U1YtSS0yR1QtEv76GBah0,5216
|
|
285
285
|
myokit/tests/test_system_info.py,sha256=H4vcHTc0HCfVd0mUfVgQDUgwNIwMa9g43rBapGR6NAs,562
|
|
286
286
|
myokit/tests/test_tools.py,sha256=1-Gn7MGrXcINZa1hcgtVevcPYkaksx_bgzgSwwYRNfE,10358
|
|
287
|
-
myokit/tests/test_unit.py,sha256=
|
|
287
|
+
myokit/tests/test_unit.py,sha256=JcfEHnz0fTLm0Bq7RamkxpvjynAE_s4c1Sasfabdesw,14752
|
|
288
288
|
myokit/tests/test_user_functions.py,sha256=r7Xc3eJv-SIELMEGxx77Od2c_eBii5gjTvqarQvgteU,1721
|
|
289
289
|
myokit/tests/test_variable.py,sha256=siV8OKkPpg0QPXeM_FaeQ_aa2dmLGppFCD-PUDacUEY,33331
|
|
290
290
|
myokit/tests/data/beeler-1977-model-compare-a.mmt,sha256=Erkz4rr7irVeOPJRGvDJ-9c0iD1125xq9lLeQ6CwmK8,3022
|
|
@@ -401,9 +401,9 @@ myokit/tests/data/multi/beeler-no-name.mmt,sha256=tBeWcTVag1gAQAvxWlUqH6GQhF1D4D
|
|
|
401
401
|
myokit/tests/data/multi/lr-1991.mmt,sha256=9jzHRAy1nLiBOPioiEpXmsRvIqwEezRY_ve2eHMDbTQ,6013
|
|
402
402
|
myokit/tests/data/multi/not-a-model.csv,sha256=7ek3pQXr2fpjNjFTs-B-T_kEehx8IQ-evdcg24dtMEs,109
|
|
403
403
|
myokit/tests/data/multi/subdir/beeler-no-name.mmt,sha256=tBeWcTVag1gAQAvxWlUqH6GQhF1D4DMnlmuePQn1vBY,3008
|
|
404
|
-
myokit-1.37.
|
|
405
|
-
myokit-1.37.
|
|
406
|
-
myokit-1.37.
|
|
407
|
-
myokit-1.37.
|
|
408
|
-
myokit-1.37.
|
|
409
|
-
myokit-1.37.
|
|
404
|
+
myokit-1.37.3.dist-info/LICENSE.txt,sha256=0WNshB_he7HnJ4ROvVAaX95yz9760DE9ps8PbyvrGvw,1833
|
|
405
|
+
myokit-1.37.3.dist-info/METADATA,sha256=NocrKBZA4t1VCvp0KCNuoSQfAoRzngbbE4XEvtPlkXw,6273
|
|
406
|
+
myokit-1.37.3.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
407
|
+
myokit-1.37.3.dist-info/entry_points.txt,sha256=yP9wy3w0YAAYUD5PYGliYKhnKvEp5l6p4S_XvXsqreM,48
|
|
408
|
+
myokit-1.37.3.dist-info/top_level.txt,sha256=vopnhGEticqud7tKy6L6dvi_n_AMXoiYBEiboRTnsWY,7
|
|
409
|
+
myokit-1.37.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|