Is your feature request related to a problem? Please describe.
Currently pickleing or unpickling (even using dill) can fail on MISOR objects. When unpickling
RecursionError: maximum recursion depth exceeded while calling a Python object
or a an error about being unable to pickle PyCapsule objects when pickling.
Describe the solution you'd like
Serializating objects correctly is one of those hard problems that are solveable, but probably beyond my ken (and probably also relies on gurobipy's backwards compatability)
Describe alternatives you've considered
a function strip_optimizer(self) that returns a new, fitted model instance with no optimizer and pinned coefs solves the current issue, but there's no guarantee that feature libraries or derivative methods in the future are pickleable. score and predict don't utilize the optimizer, so this is meets my use case, but doesn't help if someone wants to unpickle a model and post-mortem the optimization step.
Overload __reduce__ in that MIOSR to prevent even attempting to pickle
Overload __reduce__ in that MIOSR to instead pickle a similar object that saves useful post-mortem information from the gurobi objects, but which is non-functional as an optimizer after pickling.
Remove self.model from MIOSR objects' instance dictionaries.
Additional context
If we ever tried to save the cvxpy problems associated with an SR3 optimizer, we may end up with the same issue (depending on how well pickling is supported by that package)
adding @wesg52 in case you have any experience with pickling gurobi objects.
Is your feature request related to a problem? Please describe.
Currently pickleing or unpickling (even using
dill
) can fail onMISOR
objects. When unpicklingor a an error about being unable to pickle
PyCapsule
objects when pickling.Describe the solution you'd like
Serializating objects correctly is one of those hard problems that are solveable, but probably beyond my ken (and probably also relies on gurobipy's backwards compatability)
Describe alternatives you've considered
strip_optimizer(self)
that returns a new, fitted model instance with no optimizer and pinned coefs solves the current issue, but there's no guarantee that feature libraries or derivative methods in the future are pickleable.score
andpredict
don't utilize the optimizer, so this is meets my use case, but doesn't help if someone wants to unpickle a model and post-mortem the optimization step.__reduce__
in thatMIOSR
to prevent even attempting to pickle__reduce__
in thatMIOSR
to instead pickle a similar object that saves useful post-mortem information from the gurobi objects, but which is non-functional as an optimizer after pickling.self.model
fromMIOSR
objects' instance dictionaries.Additional context
If we ever tried to save the cvxpy problems associated with an
SR3
optimizer, we may end up with the same issue (depending on how well pickling is supported by that package)adding @wesg52 in case you have any experience with pickling gurobi objects.