Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dispose() #100

Merged
merged 1 commit into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading