1
0
mirror of https://github.com/gsi-upm/soil synced 2024-11-22 03:02:28 +00:00

Update easy function

This commit is contained in:
J. Fernando Sánchez 2023-04-14 20:21:34 +02:00
parent b3e77cbff5
commit 1d882dcff6
5 changed files with 10 additions and 12 deletions

View File

@ -2,6 +2,8 @@ This example can be run like with command-line options, like this:
```bash ```bash
python cars.py --level DEBUG -e summary --csv python cars.py --level DEBUG -e summary --csv
#or
soil cars.py -e summary
``` ```
This will set the `CSV` (save the agent and model data to a CSV) and `summary` (print the a summary of the data to stdout) exporters, and set the log level to DEBUG. This will set the `CSV` (save the agent and model data to a CSV) and `summary` (print the a summary of the data to stdout) exporters, and set the log level to DEBUG.

View File

@ -223,4 +223,4 @@ simulation = Simulation(name="RideHailing",
model_params=dict(n_passengers=2)) model_params=dict(n_passengers=2))
if __name__ == "__main__": if __name__ == "__main__":
simulation.run() easy(simulation)

View File

@ -33,7 +33,6 @@ def main(
num_processes=1, num_processes=1,
output="soil_output", output="soil_output",
*, *,
do_run=False,
debug=False, debug=False,
pdb=False, pdb=False,
**kwargs, **kwargs,
@ -234,10 +233,7 @@ def main(
if args.only_convert: if args.only_convert:
print(sim.to_yaml()) print(sim.to_yaml())
continue continue
if do_run:
res.append(sim.run(until=args.until)) res.append(sim.run(until=args.until))
else:
res.append(sim)
except Exception as ex: except Exception as ex:
if args.pdb: if args.pdb:
@ -258,7 +254,7 @@ def main(
@contextmanager @contextmanager
def easy(cfg, pdb=False, debug=False, **kwargs): def easy(cfg, pdb=False, debug=False, **kwargs):
try: try:
yield main(cfg, debug=debug, pdb=pdb, **kwargs)[0] return main(cfg, debug=debug, pdb=pdb, **kwargs)[0]
except Exception as e: except Exception as e:
if os.environ.get("SOIL_POSTMORTEM"): if os.environ.get("SOIL_POSTMORTEM"):
from .debugging import post_mortem from .debugging import post_mortem
@ -269,4 +265,4 @@ def easy(cfg, pdb=False, debug=False, **kwargs):
if __name__ == "__main__": if __name__ == "__main__":
main(do_run=True) main()

View File

@ -2,8 +2,8 @@ from . import main as init_main
def main(): def main():
init_main(do_run=True) init_main()
if __name__ == "__main__": if __name__ == "__main__":
init_main(do_run=True) init_main()

View File

@ -137,7 +137,7 @@ class TimedActivation(BaseScheduler):
if not self.model.running or self.time == INFINITY: if not self.model.running or self.time == INFINITY:
return return
self.logger.debug("Queue length: {ql}", ql=len(self._queue)) self.logger.debug(f"Queue length: %s", len(self._queue))
while self._queue: while self._queue:
((when, _id, cond), agent) = self._queue[0] ((when, _id, cond), agent) = self._queue[0]
@ -157,7 +157,7 @@ class TimedActivation(BaseScheduler):
agent._last_return = None agent._last_return = None
agent._last_except = None agent._last_except = None
self.logger.debug("Stepping agent {agent}", agent=agent) self.logger.debug("Stepping agent %s", agent)
self._next.pop(agent.unique_id, None) self._next.pop(agent.unique_id, None)
try: try: