Dear all,
I am trying to run a complex continuation problem for which I want to save intermediate steps of computation.
I am trying to use methods in PyDSTool such as saveObjects and loadObjects to handle my objects but I cannot make it work.
Following instructions on the user manual I have a bunch of objects such as: DSargs for a system specification, a 'traj', 'pts' and 'ode' objects related to a trajectory, set of points and an instance of a CVODE generator, and finally a PyCont (ContClass) object PC that I obtain to compute continuation curves like EC1, LC1 (i.e. PC has PC['EC1'], PC['LC1']).
TypeErrorTraceback(mostrecentcalllast)<ipython-input-48-7aecd6dfb4a2>in<module>()1#dst.saveObjects('chain3.sav',['DSargs','traj','pts','ode','PC'])---->2dst.saveObjects('chain3.sav',[DSargs,traj,pts,ode,PC])345#import save_utils as svu/home/maurizio/Downloads/PyDSTool/utils.pycinsaveObjects(objlist,filename,force)612# protocol (e.g. binary format)613ifnotforce:-->614ifos.path.isfile(filename):615raiseValueError("File '"+filename+"' already exists")616pklfile=open(filename,'wb')/usr/lib64/python2.7/genericpath.pycinisfile(path)27"""Test whether a path is a regular file"""28try:--->29st=os.stat(path)30exceptos.error:31returnFalseTypeError:coercingtoUnicode:needstringorbuffer,listfound
Thanks for your help.
M
Last edit: Maurizio De Pitta' 2016-06-21
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
No I didn't... I am still missing some basic knowledge on Python introspection.
However after I reverse the order according to the help, it seems that ContClass objects are not handled by this method still.
Indeed I get the following (where 'PC' is a ContClass object obtain by PC = dst.ContClass(ode)):
dst.saveObjects([DSargs,ode,traj,pts,PC],'chain3.sav',force=True)---------------------------------------------------------------------------TypeErrorTraceback(mostrecentcalllast)<ipython-input-65-aa7a1dfec388>in<module>()---->1dst.saveObjects([DSargs,ode,traj,pts,PC],'chain3.sav',force=True)/home/maurizio/Downloads/PyDSTool/utils.pycinsaveObjects(objlist,filename,force)628forobjinobjlist:629try:-->630pickle.dump(obj,pklfile,opt)631except:632ifhasattr(obj,'name'):TypeError:expectedstringorUnicodeobject,NoneTypefoundFailedtosaveobject'ContClass of model chain3'
If I leave out the PC object from my list instead, everything seem to work fine.
Last edit: Maurizio De Pitta' 2016-06-21
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I actually had the same problem when trying to save my curves for plotting them later.
I'm not sure but I think the problem comes from the fact that PyCont curves hold a reference to some binary code ( Auto module or the C-integrator).
My current workaround for saving my work is to save the "sol" attributes of each curve separately:
dst.saveObjects([PC['EQ_1'].sol,PC['EQ_2'].sol],'chain3.sav',force=True)
To plot them afterwards, I just loaded the sol objects, created a dummy PyCont curve of the same type as the one I saved and replaced the "sol" attribute of the newly created dummy curve with the one I loaded.
It worked for me for plotting the curve in another session and might also work for computing continuation your curve in another session.
Maybe this could help you, as long as the bug is fixed. Note that it would not save your continuation parameter ( StepSize, , tolerance, etc...) though.
Best,
Florian
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Florian,
thanks for the suggestion. I will try that out.
I shall point out that my original post was motivated by the fact that I am interactively building my bifurcation diagrams by ipython notebook (iPyN), and sometimes, in order to optimally tune the continuation, I want to recompute the curve. I was not originally able to recompute a curve or a branch after the first instance as the error message was telling me that the 'curve XX already existed'.
However I found out (on the User manual) that to recompute the curve it is sufficient to specify 'force=True' in the definition of args.
Example:
You are about to continue and equilibrium point along a curve EP-C. Then on the initialization of the curve (called EQ1) make sure to use force=True:
Hi Florian,
just a quick update to confirm that the workaround that you suggested indeed works. Just you need to make sure to reconstruct exactly the PC ContClass object and then assign what you previously saved to it, i.e.
Save it as: dst.saveObjects([PC['EQ_1'].sol,PC['EQ_2'].sol],'chain3.sav',force=True)
By the way, I'm not sure you need to "pick one of the special points and set it as initial point to extend the curve".
As far as I understand it, the only information about the existing curve is in the "sol" attribute.
Just setting this again should be sufficient.
Best,
Florian
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Un update on this issue. If you use dill module now, you may pickle any PyDSTool Object and reload them in a new session to perform any operation, i.e. integration or continuation.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Can you confirm that dill will serialize the PyCont classes? Because I didn't think they used to. Has dill undergone an update that might have improved its capabilities?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
importdillaspickledefsavedata(data,filename='./data.pkl'):"""Save list of variables in 'data' in file 'filenameUse:savedata(data, filename='./data.pkl')Input:- data : [var1,var2,...] list of variables names (NO strings! but real names)- filename : string for file name (usually with extension 'pkl')Maurizio De Pitta', The University of Chicago, August 18th, 2014."""withopen(filename,"wb")asf:pickle.dump(len(data),f)forvalueindata:pickle.dump(value,f)defloaddata(filename,verbose=False):""" load list of variables in 'data' in file 'filename Use: data = loaddata(filename) Input: - filename : string for file name (usually with extension 'pkl') Output: - data : list of objects Maurizio De Pitta', The University of Chicago, August 18th, 2014. """data=[]withopen(filename,"rb")asf:for_inrange(pickle.load(f)):data.append(pickle.load(f))ifverbose:print"loaded: ",datareturndata
So for example, I want to save DS integrator object, traj object and PC PyCont class object out of my run:
# Save datasavedata([DS,traj,PC],'myds.pkl')# Load dataimportPyDSToolasds# Might need to import module in the same way it was imported in the "save" scope (but not checked)DS,traj,PC=loaddata('myds.pkl')
M
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Dear all,
I am trying to run a complex continuation problem for which I want to save intermediate steps of computation.
I am trying to use methods in PyDSTool such as
saveObjectsandloadObjectsto handle my objects but I cannot make it work.Following instructions on the user manual I have a bunch of objects such as: DSargs for a system specification, a 'traj', 'pts' and 'ode' objects related to a trajectory, set of points and an instance of a CVODE generator, and finally a PyCont (ContClass) object
PCthat I obtain to compute continuation curves like EC1, LC1 (i.e. PC hasPC['EC1'], PC['LC1']).I then wanna save in myfile.sav and use:
But I get the following error:
Thanks for your help.
M
Last edit: Maurizio De Pitta' 2016-06-21
You need to reverse the parameter ordering. Did you try help(saveObjects)? :)
No I didn't... I am still missing some basic knowledge on Python introspection.
However after I reverse the order according to the help, it seems that ContClass objects are not handled by this method still.
Indeed I get the following (where 'PC' is a ContClass object obtain by
PC = dst.ContClass(ode)):If I leave out the PC object from my list instead, everything seem to work fine.
Last edit: Maurizio De Pitta' 2016-06-21
Could you open an issue ticket on github about PyCont not being picklable? It should not be super-hard to fix that when I have time.
Hi,
I actually had the same problem when trying to save my curves for plotting them later.
I'm not sure but I think the problem comes from the fact that PyCont curves hold a reference to some binary code ( Auto module or the C-integrator).
My current workaround for saving my work is to save the "sol" attributes of each curve separately:
dst.saveObjects([PC['EQ_1'].sol,PC['EQ_2'].sol],'chain3.sav',force=True)
To plot them afterwards, I just loaded the sol objects, created a dummy PyCont curve of the same type as the one I saved and replaced the "sol" attribute of the newly created dummy curve with the one I loaded.
It worked for me for plotting the curve in another session and might also work for computing continuation your curve in another session.
Maybe this could help you, as long as the bug is fixed. Note that it would not save your continuation parameter ( StepSize, , tolerance, etc...) though.
Best,
Florian
Hi Florian,
thanks for the suggestion. I will try that out.
I shall point out that my original post was motivated by the fact that I am interactively building my bifurcation diagrams by ipython notebook (iPyN), and sometimes, in order to optimally tune the continuation, I want to recompute the curve. I was not originally able to recompute a curve or a branch after the first instance as the error message was telling me that the 'curve XX already existed'.
However I found out (on the User manual) that to recompute the curve it is sufficient to specify 'force=True' in the definition of args.
Example:
You are about to continue and equilibrium point along a curve EP-C. Then on the initialization of the curve (called
EQ1) make sure to useforce=True:In this fashion I can run my iPyN cell again and again till I fine tuned my solution.
Last edit: Maurizio De Pitta' 2016-06-21
Hi Florian,
just a quick update to confirm that the workaround that you suggested indeed works. Just you need to make sure to reconstruct exactly the PC ContClass object and then assign what you previously saved to it, i.e.
Save it as:
dst.saveObjects([PC['EQ_1'].sol,PC['EQ_2'].sol],'chain3.sav',force=True)Reconstruct it as:
Then I confirm that once picked one of the special points in the curves and set it as initial point to extend the curve, everything works.
Thanks.
M
Last edit: Maurizio De Pitta' 2016-06-21
Hi Maurizio,
I'm glad it helped you.
By the way, I'm not sure you need to "pick one of the special points and set it as initial point to extend the curve".
As far as I understand it, the only information about the existing curve is in the "sol" attribute.
Just setting this again should be sufficient.
Best,
Florian
Un update on this issue. If you use
dillmodule now, you may pickle any PyDSTool Object and reload them in a new session to perform any operation, i.e. integration or continuation.Can you confirm that
dillwill serialize the PyCont classes? Because I didn't think they used to. Has dill undergone an update that might have improved its capabilities?Hi Rob,
I can confirm it.
Here are my two save/load routines:
So for example, I want to save
DSintegrator object,trajobject andPCPyCont class object out of my run:M