#unfortunately, as openopt is now, this needs to be defined again
#each time it is solved
It is followed by function for prob redefinition:
def setupF2dProblem(init_point, maxIterates):
...
return prob
Let me explain the situation once again. Maybe, you have already noticed the error messages when trying to use prob instance one more time: r=p.solve(...). This problem is due to Python issue 1515: deepcopy doesn't copy instance methods (url)
prob instance contains lots of function handlers, referring to each other, and while running p.solve(...) they seriously changes to other values, and some new fields (function handlers, flags True/False, some new values - Python lists, arrays etc) appear. It's impossible for me to remove all the changes done and successfully keep cleaning the prob instance of all that stuff after solving finish. It may cause inpredictable bugs, appearing once time-to-time, and hunting for this kind is very difficult.
So I decided to wait until Python developers will fix the bug. They informed me of the url for issue 1515 during Python bug day, when I have committed the bugreport (some weeks later pastebin.com will remove the code). So, they recommended me temporary solution - to add the line
d[types.MethodType] = _deepcopy_atomicto copy.py file (like it's mentioned in the url provided), but modifying Python core sources is inappropriate solution for the case - I can't demand the one from each OO user (moreover, not all of them has write access to Python core files). I haven't tried it by myself as well, so I don't know does it helps or no.
So, it would be nice to increase the bug severity from "normal" (as it is assigned for now) to something bigger, maybe Python developers would increase their efforts to fix the one. Let me also attach in comment the bugreport, since it will disappear soon from pastebin.com.
1 comment:
#
import cgitb
#
cgitb.enable(format='text')
#
#
from copy import deepcopy
#
# openopt can be downloaded here: http://scipy.org/scipy/scikits/wiki/OpenOptInstall
#
# but you should have numpy installed (mb from software update channels)
#
from scikits.openopt import NLP
#
p = NLP(lambda x: x**2, 1)
#
p3 = deepcopy(p, None)
#
#p2 = deepcopy(p) - doesn't work as well
Post a Comment