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

Simulation method to request simulation termination #213

Closed
bemcdonnell opened this issue Oct 18, 2019 · 0 comments
Closed

Simulation method to request simulation termination #213

bemcdonnell opened this issue Oct 18, 2019 · 0 comments

Comments

@bemcdonnell
Copy link
Member

Looking to add a basic function to terminate a simulation through using a method that requests a simulation to end with the Simulation object. Right now if you want to cleanly end a simulation early you need to exit the iterator within the simulation for loop like this:

with Simulation("model") as sim:
    for ind, step in enumerate(sim):
        if ind == 9:
            break

So if we have a callback set for before_step that could have some basic functionality to end a simulation (like if you are deviating too far out some ideal depth or something).

with Simulation("model") as sim:
    nodeXYZ = Nodes(sim)["nodeZYX"]

    def before_step_callback():
        if nodeXYZ.depth > 8:
            sim.terminate_simulation()

    # Setting Callbacks
    sim.add_before_step(before_step_callback)

    for ind, step in enumerate(sim):
        # Now simulation will end early if the depth is > 8
        pass

Benefits - if you are running optimization it could save you computational time.
Cons - if you like wasting money, you don't get to waste money anymore...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants