From caebfc411a4e3bb43db57cf5c2082e2c7e5e41d0 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Thu, 22 Aug 2024 13:28:24 -0400 Subject: [PATCH] Replace _BlockData with BlockData (#144) Pyomo recently made ComponentData classes public (https://github.com/Pyomo/pyomo/pull/3221) which will be part of the upcoming release. Currently, this causes the following error to occur in OMLT: ``` TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases ``` The Pyomo team is working to try to address this issue, however OMLT should update its code to address this as otherwise deprecation warnings will be emitted when using the old class names. The fix is to replace all instances of `_BlockData` with `BlockData` (just removing the underscore) - this applies to any other instance of Pyomo component data objects as well (although I could only find 2 instances of these in the OMLT code). **Legal Acknowledgement**\ By contributing to this software project, I agree my contributions are submitted under the BSD license. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer. Co-authored-by: jalving --- docs/api_doc/omlt.block.rst | 2 +- src/omlt/block.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/api_doc/omlt.block.rst b/docs/api_doc/omlt.block.rst index bb111700..4824f793 100644 --- a/docs/api_doc/omlt.block.rst +++ b/docs/api_doc/omlt.block.rst @@ -8,7 +8,7 @@ OMLT Block :show-inheritance: .. note:: - `OmltBlock` is the name used to declare the custom Pyomo block which is exposed to the user. The block functionality is given by `OmltBlockData` which inherits from Pyomo `_BlockData`. + `OmltBlock` is the name used to declare the custom Pyomo block which is exposed to the user. The block functionality is given by `OmltBlockData` which inherits from Pyomo `BlockData`. .. autoclass:: omlt.block.OmltBlockData :members: diff --git a/src/omlt/block.py b/src/omlt/block.py index e18b7138..e056c806 100644 --- a/src/omlt/block.py +++ b/src/omlt/block.py @@ -25,11 +25,11 @@ class is used in combination with a formulation object to construct the """ import pyomo.environ as pyo -from pyomo.core.base.block import _BlockData, declare_custom_block +from pyomo.core.base.block import BlockData, declare_custom_block @declare_custom_block(name="OmltBlock") -class OmltBlockData(_BlockData): +class OmltBlockData(BlockData): def __init__(self, component): super().__init__(component) self.__formulation = None