Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pause/Resume simulation #94

Open
maxfischer2781 opened this issue Jun 23, 2020 · 1 comment
Open

Pause/Resume simulation #94

maxfischer2781 opened this issue Jun 23, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@maxfischer2781
Copy link
Contributor

Short description of the feature
Allow to pause the simulation and later on resume it.

Describe the solution you'd like
Simulation code should be able to pause at any time. This freezes the current simulation state.

async def some_activity():
     if time == 20:
        await usim.resume  # new call to pause simulation until resumed

Each simulation is represented by an object. usim.run returns this object when the simulation is frozen. The object allows unfreezing:

simulation = usim.run(some_activity())
print("Current state:", simulation)
simulation.resume()

Describe alternatives and the context you have considered
There is currently no way to freeze a simulation.

@maxfischer2781 maxfischer2781 added the enhancement New feature or request label Jun 23, 2020
@maxfischer2781 maxfischer2781 added this to To do in SimPy feature parity via automation Jun 23, 2020
@karstenle
Copy link

(Thanks for the work @maxfischer2781)

This would also allow to create functions to run a simulation step by step.

async def _step_activity():
     while True:
        await usim.resume 
        await (time + 1)

def run_in_steps(*activities):
      return usim.run(_step_activity(), *activities)

def step(simulation):
     simulation.resume()

and then use it via

simulation = run_in_steps(*some_activities)
for i in range(100):
     step(simulation)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

No branches or pull requests

2 participants