From 1d882dcff6f749a28c6932eb875f58937e58aad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Fri, 14 Apr 2023 20:21:34 +0200 Subject: [PATCH] Update easy function --- examples/events_and_messages/README.md | 2 ++ examples/events_and_messages/cars_sim.py | 2 +- soil/__init__.py | 10 +++------- soil/__main__.py | 4 ++-- soil/time.py | 4 ++-- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/examples/events_and_messages/README.md b/examples/events_and_messages/README.md index c5b77df..cd8b155 100644 --- a/examples/events_and_messages/README.md +++ b/examples/events_and_messages/README.md @@ -2,6 +2,8 @@ This example can be run like with command-line options, like this: ```bash 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. diff --git a/examples/events_and_messages/cars_sim.py b/examples/events_and_messages/cars_sim.py index 5e93138..9b3d1a4 100644 --- a/examples/events_and_messages/cars_sim.py +++ b/examples/events_and_messages/cars_sim.py @@ -223,4 +223,4 @@ simulation = Simulation(name="RideHailing", model_params=dict(n_passengers=2)) if __name__ == "__main__": - simulation.run() \ No newline at end of file + easy(simulation) \ No newline at end of file diff --git a/soil/__init__.py b/soil/__init__.py index 13109cf..158f524 100644 --- a/soil/__init__.py +++ b/soil/__init__.py @@ -33,7 +33,6 @@ def main( num_processes=1, output="soil_output", *, - do_run=False, debug=False, pdb=False, **kwargs, @@ -234,10 +233,7 @@ def main( if args.only_convert: print(sim.to_yaml()) continue - if do_run: - res.append(sim.run(until=args.until)) - else: - res.append(sim) + res.append(sim.run(until=args.until)) except Exception as ex: if args.pdb: @@ -258,7 +254,7 @@ def main( @contextmanager def easy(cfg, pdb=False, debug=False, **kwargs): try: - yield main(cfg, debug=debug, pdb=pdb, **kwargs)[0] + return main(cfg, debug=debug, pdb=pdb, **kwargs)[0] except Exception as e: if os.environ.get("SOIL_POSTMORTEM"): from .debugging import post_mortem @@ -269,4 +265,4 @@ def easy(cfg, pdb=False, debug=False, **kwargs): if __name__ == "__main__": - main(do_run=True) + main() diff --git a/soil/__main__.py b/soil/__main__.py index 0c76791..0c40ec3 100644 --- a/soil/__main__.py +++ b/soil/__main__.py @@ -2,8 +2,8 @@ from . import main as init_main def main(): - init_main(do_run=True) + init_main() if __name__ == "__main__": - init_main(do_run=True) + init_main() diff --git a/soil/time.py b/soil/time.py index 5f9983f..12f993f 100644 --- a/soil/time.py +++ b/soil/time.py @@ -137,7 +137,7 @@ class TimedActivation(BaseScheduler): if not self.model.running or self.time == INFINITY: return - self.logger.debug("Queue length: {ql}", ql=len(self._queue)) + self.logger.debug(f"Queue length: %s", len(self._queue)) while self._queue: ((when, _id, cond), agent) = self._queue[0] @@ -157,7 +157,7 @@ class TimedActivation(BaseScheduler): agent._last_return = 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) try: