Skip to content

Commit e94b556

Browse files
author
James Marshall
committed
Sum to 1 for all views; implement warnings correctly
1 parent ab14ba2 commit e94b556

4 files changed

Lines changed: 11 additions & 14 deletions

File tree

mumot/exceptions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""MuMoT warning, exception and error classes."""
22

3-
43
class MuMoTWarning(Warning):
54
"""Class to report MuMoT-specific warnings.
65
"""

mumot/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
Function
2626
)
2727
from sympy.parsing.latex import parse_latex
28+
from warnings import warn
2829

2930
from . import (
3031
controllers,
@@ -1803,8 +1804,7 @@ def _getSingleAgentRules(self):
18031804
if reactant in allConstantReactants:
18041805
warningMsg = 'WARNING! Constant reactants appearing on the right-handside are ignored. Every constant reactant on the left-handside (implicitly) corresponds to the same constant reactant on the right-handside.\n'\
18051806
f'E.g., in rule ' + str(rule.lhsReactants) + ' -> ' + str(rule.rhsReactants) + ' constant reactants should not appear on the right-handside.'
1806-
print(warningMsg)
1807-
#raise exceptions.MuMoTWarning(warningMsg)
1807+
warn(warningMsg, exceptions.MuMoTWarning)
18081808
break # print maximum one warning
18091809

18101810
# Add to the target of the first non-empty item the new born coming from empty-set or constant reactants

mumot/utils.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import numpy as np
66
from sympy.parsing.latex import parse_latex
7+
from warnings import warn
78

89
from . import (
910
consts,
@@ -101,7 +102,8 @@ def _format_advanced_option(optionName: str, inputValue, initValues, extraParam=
101102
"""
102103
if optionName == 'initialState':
103104
(allReactants, _) = extraParam
104-
fixSumTo1 = extraParam2[0]
105+
#fixSumTo1 = extraParam2[0] # until we have better information, all views should sum to 1, then use system size to scale
106+
fixSumTo1 = True
105107
idleReactant = extraParam2[1]
106108
initialState = {}
107109
# handle initialState dictionary (either convert or generate a default one)
@@ -148,8 +150,7 @@ def _format_advanced_option(optionName: str, inputValue, initValues, extraParam=
148150
idleValue = initialState[idleReactant][0]
149151
if idleValue > 1:
150152
wrn_msg = f"WARNING! the initial value of reactant {idleReactant} has been changed to {new_val}\n"
151-
print(wrn_msg)
152-
#raise exceptions.MuMoTWarning(wrn_msg)
153+
warn(wrn_msg, exceptions.MuMoTWarning)
153154
initialState[idleReactant][0] = new_val
154155
# the idleValue have range min-max reset to [0,1]
155156
initialState[idleReactant][1] = 0
@@ -171,8 +172,7 @@ def _format_advanced_option(optionName: str, inputValue, initValues, extraParam=
171172
new_val = max(0, pop[0] + (1 - sumValues))
172173
if not _almostEqual(pop[0], new_val):
173174
wrn_msg = f"WARNING! the initial value of reactant {reactant} has been changed to {new_val}\n"
174-
print(wrn_msg)
175-
#raise exceptions.MuMoTWarning(wrn_msg)
175+
warn(wrn_msg, exceptions.MuMoTWarning)
176176
sumValues -= pop[0]
177177
sumValues += new_val
178178
initialState[reactant][0] = new_val
@@ -193,8 +193,7 @@ def _format_advanced_option(optionName: str, inputValue, initValues, extraParam=
193193
for reactant in allReactants
194194
if reactant != reactantToFix])
195195
wrn_msg = f"WARNING! the initial value of reactant {reactantToFix} has been changed to {new_val}\n"
196-
print(wrn_msg)
197-
#raise exceptions.MuMoTWarning(wrn_msg)
196+
warn(wrn_msg, exceptions.MuMoTWarning)
198197
initialState[reactantToFix][0] = new_val
199198
return [initialState, fixedBool]
200199
# print("Initial State is " + str(initialState))

mumot/views.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
symbols,
3333
)
3434
from sympy.parsing.latex import parse_latex
35+
from warnings import warn
3536

3637
from . import (
3738
consts,
@@ -3912,8 +3913,7 @@ def _constructorSpecificParams(self, MAParams):
39123913
# self._errorMessage.value = "Only Moving-Particle netType is available when rules contain the emptyset."
39133914
if not self._netType == consts.NetworkType.DYNAMIC:
39143915
wrnMsg = "Only Moving-Particle netType is available when rules contain the emptyset or constant reactants."
3915-
print(wrnMsg)
3916-
#raise exceptions.MuMoTWarning()
3916+
warn(wrnMsg, exceptions.MuMoTWarning)
39173917
self._netType = consts.NetworkType.DYNAMIC
39183918
if self._controller: # updating value and disabling widget
39193919
if self._controller._widgetsExtraParams.get('netType') is not None:
@@ -3928,8 +3928,7 @@ def _constructorSpecificParams(self, MAParams):
39283928
wrnMsg = "WARNING! net-param value " + str(self._netParam) + " is invalid for Moving-Particles. Valid range is [0,1] indicating the particles' communication range. \n"
39293929
self._netParam = 0.1
39303930
wrnMsg += "New default values is '_netParam'=" + str(self._netParam)
3931-
print(wrnMsg)
3932-
#raise exceptions.MuMoTWarning(wrnMsg)
3931+
warn(wrnMsg, exceptions.MuMoTWarning)
39333932

39343933
def _build_bookmark(self, includeParams=True) -> str:
39353934
log_str = "bookmark = " if not self._silent else ""

0 commit comments

Comments
 (0)