Save model results object directly to file -- pickle?

377 views
Skip to first unread message

acastillo

unread,
Jan 8, 2015, 1:41:41 PM1/8/15
to pyomo...@googlegroups.com
Hi, 

Is there an easy way to save the results object directly to a file? This is so that I may load the results object later on to use in initializing another model, without having to re-run the entire process.

I tried Python's pickle as follows:
....

results = opti.solve(instance,tee=True)

pickle.dump(results,open("tmp_results.p","wb"))

And get the following error to console:

Traceback (most recent call last):

  File "/Users/anyacastillo/Documents/workspace/ferc/uc/__init__.py", line 39, in <module>

    pickle.dump(results,open("tmp_results.p","wb"))

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1370, in dump

    Pickler(file, protocol).dump(obj)

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 224, in dump

    self.save(obj)

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 306, in save

    rv = reduce(self.proto)

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy_reg.py", line 84, in _reduce_ex

    dict = getstate()

  File "/Library/Python/2.7/site-packages/coopr/opt/results/results_.py", line 99, in __getstate__

    var['canonical_label'] = _canonical_label(sMap.getObject(symbol))

  File "/Library/Python/2.7/site-packages/coopr/opt/results/results_.py", line 73, in _canonical_label

    elif int(idx) == idx:

TypeError: int() argument must be a string or a number, not 'instancemethod'


Peter Bailey

unread,
Jan 8, 2015, 2:14:16 PM1/8/15
to pyomo...@googlegroups.com
I am also interested in such a method. I would also be OK with saving and restoring a model instance object.

acastillo

unread,
Jan 8, 2015, 2:20:04 PM1/8/15
to pyomo...@googlegroups.com
Hi Peter,

I believe the best approach may be for us to pickle the results object instead of the model instance object because pickle cannot serialize functions, for example, which may be attributes in your model definition.

Hopefully the pyomo group has some feedback for us to act on :)

Watson, Jean-Paul

unread,
Jan 8, 2015, 2:23:28 PM1/8/15
to pyomo...@googlegroups.com
It worries me greatly that an “idx” argument could ever be of type “instancemethod”. We are in the throes of wrapping up the Pyomo 4.0 release, and will look at this either Friday or Saturday. There is no reason why the results object should not be pickle-able.

Not the instance, for matter. But you definitely want to pickle results, not instances.

jpw 

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Watson, Jean-Paul

unread,
Feb 2, 2015, 4:06:30 PM2/2/15
to pyomo...@googlegroups.com
Hi all,

Thanks mostly to Gabe, we’ve corrected this pickle problem – which was definitely a real problem. 

The only down side is that it is in the Pyomo 4.0 trunk, rather than in a formal release. We will probably patch-release 4.0 again in the near future, but we can’t make a commitment as to a specific date. 

Thus, if you are comfortable (or already are) running on trunk, then please give the fix a spin!

jpw

From: acastillo <anya.c...@gmail.com>
Reply-To: "pyomo...@googlegroups.com" <pyomo...@googlegroups.com>
Date: Thursday, January 8, 2015 at 12:20 PM
To: "pyomo...@googlegroups.com" <pyomo...@googlegroups.com>
Reply all
Reply to author
Forward
0 new messages