mirror of https://github.com/gsi-upm/soil
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
985 B
Python
44 lines
985 B
Python
from .serialization import deserialize
|
|
import os
|
|
import time
|
|
|
|
|
|
def for_sim(simulation, names, dir_path=None):
|
|
exporters = []
|
|
for name in names:
|
|
mod = deserialize(name, known_modules=['soil.exporters'])
|
|
exporters.append(mod(simulation))
|
|
return exporters
|
|
|
|
|
|
class Base:
|
|
|
|
def __init__(self, simulation):
|
|
self.sim = simulation
|
|
|
|
def start(self):
|
|
pass
|
|
|
|
def end(self):
|
|
pass
|
|
|
|
def env(self):
|
|
pass
|
|
|
|
|
|
class Dummy(Base):
|
|
|
|
def start(self):
|
|
with open(os.path.join(self.sim.outdir, 'dummy')) as f:
|
|
f.write('simulation started @ {}'.format(time.time()))
|
|
|
|
def env(self, env):
|
|
with open(os.path.join(self.sim.outdir, 'dummy-trial-{}'.format(env.name))) as f:
|
|
for i in env.history_to_tuples():
|
|
f.write(','.join(i))
|
|
|
|
|
|
def end(self):
|
|
with open(os.path.join(self.sim.outdir, 'dummy')) as f:
|
|
f.write('simulation ended @ {}'.format(time.time()))
|