saving the state of the system post-simulation

289 views
Skip to first unread message

Ayse

unread,
Jan 12, 2018, 8:18:05 AM1/12/18
to Dedalus Users

Hi guys,

Is there any function in Dedalus which can save the state of the system after a simulation ends?  I am thinking of something compatible with the load_state function, which saves distributed field and writes down all the information about the state of the system.

For to clarify more, something as adding a file_handler and setting it to the last iteration does not help me since I need to save the state after another function ask the state to be saved. So this other function may skip many full simulations and decide to save after a certain condition is met.

Thank you in advance,

Ayse

Evan H. Anders

unread,
Jan 12, 2018, 8:47:37 AM1/12/18
to dedalus-users
Hi Ayse,

The trick that we use for this is to add a checkpointing file handler at the end of the simulation run, then force it to take *one* more timestep to trigger the file handler to save the state.  We use a Checkpointing wrapper on the file handler class (attached, largely coded by Jeff Oishi a year+ ago), import the Checkpoint class from this file, and then add some lines like this at the end of the simulation:

                final_checkpoint = Checkpoint(data_dir, checkpoint_name='final_checkpoint')
                final_checkpoint.set_checkpoint(solver, wall_dt=1, mode="overwrite") # can also use mode='append' if you want to store multiple
                solver.step(dt)

This works for us, and is how we restart our simulations.  If there's a more elegant way, I'd love to know about it too!

Best,
Evan



--
You received this message because you are subscribed to the Google Groups "Dedalus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dedalus-users+unsubscribe@googlegroups.com.
To post to this group, send email to dedalu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dedalus-users/6729d70b-287c-4911-bd7b-c1cd4e5ad8c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

checkpointing.py

Ayse

unread,
Jan 12, 2018, 9:33:22 AM1/12/18
to Dedalus Users

Hi Evan,

Thank you for your quick reply. Is it possible for you to send me a very simple working example that shows how to use this check-pointing to save and restart?

Best,
Ayse


On Friday, January 12, 2018 at 2:47:37 PM UTC+1, Evan H. Anders wrote:
Hi Ayse,

The trick that we use for this is to add a checkpointing file handler at the end of the simulation run, then force it to take *one* more timestep to trigger the file handler to save the state.  We use a Checkpointing wrapper on the file handler class (attached, largely coded by Jeff Oishi a year+ ago), import the Checkpoint class from this file, and then add some lines like this at the end of the simulation:

                final_checkpoint = Checkpoint(data_dir, checkpoint_name='final_checkpoint')
                final_checkpoint.set_checkpoint(solver, wall_dt=1, mode="overwrite") # can also use mode='append' if you want to store multiple
                solver.step(dt)

This works for us, and is how we restart our simulations.  If there's a more elegant way, I'd love to know about it too!

Best,
Evan


On Fri, Jan 12, 2018 at 6:18 AM, Ayse <ays...@gmail.com> wrote:

Hi guys,

Is there any function in Dedalus which can save the state of the system after a simulation ends?  I am thinking of something compatible with the load_state function, which saves distributed field and writes down all the information about the state of the system.

For to clarify more, something as adding a file_handler and setting it to the last iteration does not help me since I need to save the state after another function ask the state to be saved. So this other function may skip many full simulations and decide to save after a certain condition is met.

Thank you in advance,

Ayse

--
You received this message because you are subscribed to the Google Groups "Dedalus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dedalus-user...@googlegroups.com.

Evan H. Anders

unread,
Jan 12, 2018, 9:50:23 AM1/12/18
to dedalus-users
Hey Ayse,

Hmmm. I don't have a very simple working example on hand, unfortunately.  I usually use this in fully compressible convection sims (our repo of this just went public yesterday, https://bitbucket.org/exoweather/polytrope/overview, but the code is a little bit of a mess and hard ish to understand).  I think that's the most public working example of this we have.  The driver file is FC_poly.py (https://bitbucket.org/exoweather/polytrope/src/488c455091f9d25229af52d2533d0da27eb0421c/FC_poly.py?at=default&fileviewer=file-view-default), and lines 160-165 are where we restart from checkpoint (or use initial conditions), and then lines 286-299 are the ones where we set up the final checkpointing.

So you could run the script like (I can do this quickly on my local processor, doesn't get past transient, but it runs):

python3 FC_poly.py --Rayleigh=1e2 --nz=32 --nx=64 --run_time_buoy=20

and then restart from where you left off afterwards by doing:

python3 FC_poly.py --Rayleigh=1e2 --nz=32 --nx=64 --run_time_buoy=20 --restart=FC_poly_2D_nrhocz3_Ra1e2_Pr1_eps1e-4_a4/final_checkpoint/final_checkpoint_s1.h5

and it'll pick up from where it left off.  Basically if you ctrl+f "checkpoint" on the FC_poly.py file, you'll find all the lines used to make this happen (there aren't many), but there are a lot of extra cruft lines in that file for other options.

Sorry that's not the cleanest answer, let me know if I can clarify!
Evan

To unsubscribe from this group and stop receiving emails from it, send an email to dedalus-users+unsubscribe@googlegroups.com.

To post to this group, send email to dedalu...@googlegroups.com.

Ayse

unread,
Jan 12, 2018, 11:53:39 AM1/12/18
to Dedalus Users
Hi again Evan,

Thank you. I will play with it, if I stuck I will write again.

Have a nice day

Ayse

Jeffrey S. Oishi

unread,
Jun 27, 2018, 1:52:07 PM6/27/18
to dedalus-users
Hi Ayse and all,

I just wanted to follow up on this. Here is a simple solution to do this that does not require any extra code. 

If you have a file handler for your system, say one called checkpoint, you can simply do 

# for example
checkpoint = solver.add_file_handler('checkpoint', etc)
checkpoint.add_system(solver.state)

while solver.ok:
    <main loop goes here>

# write last checkpoint
end_world_time = solver.get_world_time()
end_wall_time = end_world_time - solver.start_time
solver.evaluator.evaluate_handlers([checkpoint,], timestep = dt, sim_time = solver.sim_time, world_time=end_world_time, wall_time=end_wall_time, iteration=solver.iteration)


I've assumed your solver is called solver. Please note that the filehandler must be in a list when passing it to evalue_handlers. 

Please let me know if you have any questions.

Jeff



Ayse Yesil

unread,
Jul 5, 2018, 6:11:09 AM7/5/18
to Dedalus Users
Hi Jeff,

Thank you for the follow up. I will have a look and come back to this post.

Cheers

Louis-Alexandre Couston

unread,
Jan 20, 2023, 4:52:11 AM1/20/23
to Dedalus Users
Hi Jeff,

Can we still do this trick in d3 to save data of the final step as a checkpoint file?

It's returning an error about solver not having the get_world_time() argument.

Thanks,
Louis

Jeffrey S. Oishi

unread,
Jan 20, 2023, 9:22:21 AM1/20/23
to dedalu...@googlegroups.com
Hi Louis,

Yes, and it's much simpler now:

solver.evaluate_handlers_now(dt)

where dt is the current timestep.

Jeff
> To view this discussion on the web visit https://groups.google.com/d/msgid/dedalus-users/3e0cf854-3185-4b5b-b493-b0f056a1c9e7n%40googlegroups.com.

Louis-Alexandre Couston

unread,
Jan 20, 2023, 9:42:14 AM1/20/23
to dedalu...@googlegroups.com
oh that's great! Thanks :)

You received this message because you are subscribed to a topic in the Google Groups "Dedalus Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dedalus-users/fUj_q91F9bo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dedalus-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dedalus-users/CAAOZTN-hyZ0kTWBXjqcVCW_%2B5CEU_MmUQEvY%2BWzC%2BRE64EiC9Q%40mail.gmail.com.

Gustavo Estay

unread,
Jun 26, 2023, 4:23:24 PM6/26/23
to Dedalus Users
Hello,

Just for future reference, it seems that from May 17, 2023, solver.evaluate_handlers_now(dt) is deprecated and is equivalent to evaluate_handlers(handlers=handlers, dt=dt).

Best,
Gustavo
Reply all
Reply to author
Forward
0 new messages