Skip to content

Commit e2fb22d

Browse files
authored
Merge pull request #355 from lasp/feature/allow-function-as-dispersion-variable
Allow functions as dispersion variables
2 parents 0392057 + 42c16b4 commit e2fb22d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/utilities/MonteCarlo/Controller.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -826,10 +826,16 @@ def __call__(cls, params):
826826

827827
# apply the dispersions and the random seeds
828828
for variable, value in list(modifications.items()):
829-
disperseStatement = "simInstance." + variable + "=" + value
829+
expresion = "simInstance." + variable
830+
dispersionExpresion = None
831+
if eval("callable(" + expresion + ")"):
832+
dispersionExpresion = expresion + "(" + value + ")"
833+
else:
834+
dispersionExpresion = expresion + "=" + value
835+
830836
if simParams.verbose:
831-
print("Executing parameter modification -> ", disperseStatement)
832-
exec(disperseStatement)
837+
print("Executing parameter modification -> ", dispersionExpresion)
838+
exec(dispersionExpresion)
833839

834840
# setup data logging
835841
if len(simParams.retentionPolicies) > 0:
@@ -921,4 +927,3 @@ def populateSeeds(simInstance, modifications):
921927
if ".RNGSeed" in variable:
922928
rngStatement = "simInstance." + variable + "=" + value
923929
exec(rngStatement)
924-

0 commit comments

Comments
 (0)