use new simulator object instead of reset
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com> # Conflicts: # study.py
This commit is contained in:
parent
d38b8074f4
commit
954d40e758
29
study.py
29
study.py
|
@ -12,7 +12,20 @@ from DAS import *
|
||||||
# https://stackoverflow.com/questions/58026381/logging-nested-functions-using-joblib-parallel-and-delayed-calls
|
# https://stackoverflow.com/questions/58026381/logging-nested-functions-using-joblib-parallel-and-delayed-calls
|
||||||
# and https://github.com/joblib/joblib/issues/1017
|
# and https://github.com/joblib/joblib/issues/1017
|
||||||
|
|
||||||
def runOnce(sim, config, shape):
|
def initLogger(config):
|
||||||
|
"""It initializes the logger."""
|
||||||
|
logger = logging.getLogger("Study")
|
||||||
|
logger.setLevel(config.logLevel)
|
||||||
|
ch = logging.StreamHandler()
|
||||||
|
ch.setLevel(config.logLevel)
|
||||||
|
ch.setFormatter(CustomFormatter())
|
||||||
|
logger.addHandler(ch)
|
||||||
|
return logger
|
||||||
|
|
||||||
|
def runOnce(config, shape):
|
||||||
|
|
||||||
|
sim = Simulator(shape, config)
|
||||||
|
|
||||||
if config.deterministic:
|
if config.deterministic:
|
||||||
shape.setSeed(config.randomSeed+"-"+str(shape))
|
shape.setSeed(config.randomSeed+"-"+str(shape))
|
||||||
random.seed(shape.randomSeed)
|
random.seed(shape.randomSeed)
|
||||||
|
@ -40,24 +53,24 @@ def study():
|
||||||
print("You need to pass a configuration file in parameter")
|
print("You need to pass a configuration file in parameter")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
shape = Shape(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
logger = initLogger(config)
|
||||||
sim = Simulator(shape, config)
|
format = {"entity": "Study"}
|
||||||
sim.initLogger()
|
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
execID = now.strftime("%Y-%m-%d_%H-%M-%S_")+str(random.randint(100,999))
|
execID = now.strftime("%Y-%m-%d_%H-%M-%S_")+str(random.randint(100,999))
|
||||||
|
|
||||||
sim.logger.info("Starting simulations:", extra=sim.format)
|
logger.info("Starting simulations:", extra=format)
|
||||||
start = time.time()
|
start = time.time()
|
||||||
results = Parallel(config.numJobs)(delayed(runOnce)(sim, config, shape) for shape in config.nextShape())
|
results = Parallel(config.numJobs)(delayed(runOnce)(config, shape) for shape in config.nextShape())
|
||||||
end = time.time()
|
end = time.time()
|
||||||
sim.logger.info("A total of %d simulations ran in %d seconds" % (len(results), end-start), extra=sim.format)
|
logger.info("A total of %d simulations ran in %d seconds" % (len(results), end-start), extra=format)
|
||||||
|
|
||||||
if config.dumpXML:
|
if config.dumpXML:
|
||||||
for res in results:
|
for res in results:
|
||||||
res.dump(execID)
|
res.dump(execID)
|
||||||
sim.logger.info("Results dumped into results/%s/" % (execID), extra=sim.format)
|
logger.info("Results dumped into results/%s/" % (execID), extra=format)
|
||||||
|
|
||||||
if config.visualization:
|
if config.visualization:
|
||||||
vis = Visualizer(execID)
|
vis = Visualizer(execID)
|
||||||
|
|
Loading…
Reference in New Issue