Skip to content

Commit

Permalink
Sum to 1 for all views; implement warnings correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
James Marshall committed Sep 30, 2019
1 parent ab14ba2 commit e94b556
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
1 change: 0 additions & 1 deletion mumot/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""MuMoT warning, exception and error classes."""


class MuMoTWarning(Warning):
"""Class to report MuMoT-specific warnings.
"""
Expand Down
4 changes: 2 additions & 2 deletions mumot/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Function
)
from sympy.parsing.latex import parse_latex
from warnings import warn

from . import (
controllers,
Expand Down Expand Up @@ -1803,8 +1804,7 @@ def _getSingleAgentRules(self):
if reactant in allConstantReactants:
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'\
f'E.g., in rule ' + str(rule.lhsReactants) + ' -> ' + str(rule.rhsReactants) + ' constant reactants should not appear on the right-handside.'
print(warningMsg)
#raise exceptions.MuMoTWarning(warningMsg)
warn(warningMsg, exceptions.MuMoTWarning)
break # print maximum one warning

# Add to the target of the first non-empty item the new born coming from empty-set or constant reactants
Expand Down
13 changes: 6 additions & 7 deletions mumot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import numpy as np
from sympy.parsing.latex import parse_latex
from warnings import warn

from . import (
consts,
Expand Down Expand Up @@ -101,7 +102,8 @@ def _format_advanced_option(optionName: str, inputValue, initValues, extraParam=
"""
if optionName == 'initialState':
(allReactants, _) = extraParam
fixSumTo1 = extraParam2[0]
#fixSumTo1 = extraParam2[0] # until we have better information, all views should sum to 1, then use system size to scale
fixSumTo1 = True
idleReactant = extraParam2[1]
initialState = {}
# handle initialState dictionary (either convert or generate a default one)
Expand Down Expand Up @@ -148,8 +150,7 @@ def _format_advanced_option(optionName: str, inputValue, initValues, extraParam=
idleValue = initialState[idleReactant][0]
if idleValue > 1:
wrn_msg = f"WARNING! the initial value of reactant {idleReactant} has been changed to {new_val}\n"
print(wrn_msg)
#raise exceptions.MuMoTWarning(wrn_msg)
warn(wrn_msg, exceptions.MuMoTWarning)
initialState[idleReactant][0] = new_val
# the idleValue have range min-max reset to [0,1]
initialState[idleReactant][1] = 0
Expand All @@ -171,8 +172,7 @@ def _format_advanced_option(optionName: str, inputValue, initValues, extraParam=
new_val = max(0, pop[0] + (1 - sumValues))
if not _almostEqual(pop[0], new_val):
wrn_msg = f"WARNING! the initial value of reactant {reactant} has been changed to {new_val}\n"
print(wrn_msg)
#raise exceptions.MuMoTWarning(wrn_msg)
warn(wrn_msg, exceptions.MuMoTWarning)
sumValues -= pop[0]
sumValues += new_val
initialState[reactant][0] = new_val
Expand All @@ -193,8 +193,7 @@ def _format_advanced_option(optionName: str, inputValue, initValues, extraParam=
for reactant in allReactants
if reactant != reactantToFix])
wrn_msg = f"WARNING! the initial value of reactant {reactantToFix} has been changed to {new_val}\n"
print(wrn_msg)
#raise exceptions.MuMoTWarning(wrn_msg)
warn(wrn_msg, exceptions.MuMoTWarning)
initialState[reactantToFix][0] = new_val
return [initialState, fixedBool]
# print("Initial State is " + str(initialState))
Expand Down
7 changes: 3 additions & 4 deletions mumot/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
symbols,
)
from sympy.parsing.latex import parse_latex
from warnings import warn

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

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

0 comments on commit e94b556

Please sign in to comment.