← Back to team overview

yade-users team mailing list archive

Re: Resuming long interrupted calculations

 

Hello Olivier,

next time, please ask questions via launchpad interface [1].

By default, O.save only saves attributes of C++ core. It does not save
python-defined stuff (functions, variables), nor custom
O.anythingNotCPlusPlus.
However, see documentation of utils.saveVars [2] / utils.loadVars [3]. They
allow you to save custom data in the .xml file and use it after O.load,.
Something like:

###
resume = False # change to Ture for the "resume" run

someVar = 1 # default value, overwritten below

def incrementSomeVar():
    global someVar
    someVar += 1

O.engines += [
    PyRunner(iterPeriod=1,command="incrementSomeVar()"),
    PyRunner(iterPeriod=10,command="save()"),
]

def save():
    saveVars("mySavedVars",someVar=someVar)
    O.save("test.xml")

if resume:
    O.load("test.xml")
    loadVars("mySavedVars")
else:
    saveVars("mySavedVars",someVar=someVar)
from yade.params.mySavedVars import *

print("TEST 1:",O.iter,someVar)
O.run(25,True) # simulating interruption
print("TEST 2:",O.iter,someVar)
###

Cheers
Jan

[1] https://launchpad.net/yade, "Ask a question" button
[2] https://yade-dem.org/doc/yade.utils.html#yade.utils.saveVars
[3] https://yade-dem.org/doc/yade.utils.html#yade.utils.loadVars



út 20. 7. 2021 v 15:17 odesílatel GILLIA Olivier 202613 <
olivier.gillia@xxxxxx> napsal:

> Hello everybody,
>
>
>
> I am running some long lasting simulations, and quite often the
> calculation is interrupted for some reasons (maintenance operation on the
> computer, electric shutdown,…). I would like to be able to resume the
> calculation.
>
>
>
> For this, the O.save() function sounds good. I regularly save the
> configuration to disc (overwriting the previous one), so I can use it to
> recover the Omega and restart the simulation. But there are two problems :
>
> 1-      starting in a new .py file I will miss the other function I have
> defined in the main .py file.
>
> 2-      Some variables are not included in the O.save file (for example
> variables that serves to know at what point is the loading, which is a
> cycling load).
>
>
>
> For the problem 1- I can program something in the same main launching file
> .py file, with a “resume” mode (dealt with some “if iResume: … else: …”)
>
>
>
> For the point 2-, I have tried to integrate my useful variables (t_phase,
> t_deb_phase, t_deb_cycle, n_phase, n_cycle, n_cycle_todo,…) in the omega
> (O.t_phase, O.t_deb_phase…) but the variables are not saved in the file on
> the disc (seen in the xml format).
>
>
>
> Does someone has an idea how I can proceed to recover my cycling variables
> before relaunching the calculation ?
>
>
>
> Thank you
>
>
>
> *Olivier Gillia*
>
> CEA/Grenoble - Bureau D1-210
>
> 17 rue des Martyrs
>
> 38054 GRENOBLE Cedex 09
>
> +33 6 64 65 60 96
>
> +33 4 38 78 62 07
>
> Liten.cea.fr
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-users
> Post to     : yade-users@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~yade-users
> More help   : https://help.launchpad.net/ListHelp
>

References