From 4bb3073b85f7fa6a73018329292f788412d5d659 Mon Sep 17 00:00:00 2001 From: Martin Staadecker Date: Sat, 15 Feb 2025 17:54:54 -0500 Subject: [PATCH] Fix dispose() --- pyproject.toml | 2 +- src/pyoframe/model.py | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 40c05bf..b80ead4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = "dev@bravospower.com" }] description = "Blazing fast linear program interface" readme = "README.md" diff --git a/src/pyoframe/model.py b/src/pyoframe/model.py index b03099c..e31092a 100644 --- a/src/pyoframe/model.py +++ b/src/pyoframe/model.py @@ -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):