Skip to content

Commit

Permalink
Fix dispose() (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
staadecker authored Feb 15, 2025
1 parent c6b3497 commit acb57fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pyoframe"
version = "0.1.3"
version = "0.1.4"
authors = [{ name = "Bravos Power", email = "[email protected]" }]
description = "Blazing fast linear program interface"
readme = "README.md"
Expand Down
19 changes: 9 additions & 10 deletions src/pyoframe/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,27 +335,26 @@ def dispose(self):
Once this method is called, this model is no longer usable.
This method will not work if you still have variables that reference parts of this model.
This method will not work if you have a variable that references self.poi.
Unfortunately, this is a limitation from the underlying solver interface library.
See https://github.com/metab0t/PyOptInterface/issues/36 for context.
Examples:
>>> m = pf.Model()
>>> m.X = pf.Variable()
>>> m.X = pf.Variable(ub=1)
>>> m.maximize = m.X
>>> m.optimize()
>>> m.X.solution
1.0
>>> m.dispose()
>>> m.X
>>> m.X.solution
Traceback (most recent call last):
...
AttributeError: 'Model' object has no attribute 'X'
AttributeError: 'Model' object has no attribute 'poi'
"""
import gc

for attr in dir(self):
if not attr.startswith("__"):
try:
delattr(self, attr)
except AttributeError:
pass
del self.poi
gc.collect()

def _set_param(self, name, value):
Expand Down

0 comments on commit acb57fc

Please sign in to comment.