File tree Expand file tree Collapse file tree 4 files changed +28
-7
lines changed Expand file tree Collapse file tree 4 files changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -1686,6 +1686,18 @@ def __enter__(self):
16861686 def __exit__ (self , t , v , traceback ):
16871687 pass
16881688
1689+ @classmethod
1690+ def api_version (self ):
1691+ """
1692+ Return the public API supported by this interface.
1693+
1694+ Returns
1695+ -------
1696+ ~pyomo.common.enums.SolverAPIVersion
1697+ A solver API enum object
1698+ """
1699+ return SolverAPIVersion .V1
1700+
16891701
16901702class SolverFactoryClass (Factory ):
16911703 def register (self , name , doc = None ):
Original file line number Diff line number Diff line change @@ -744,3 +744,15 @@ def warm_start_capable(self):
744744
745745 def default_variable_value (self ):
746746 return None
747+
748+ @classmethod
749+ def api_version (self ):
750+ """
751+ Return the public API supported by this interface.
752+
753+ Returns
754+ -------
755+ ~pyomo.common.enums.SolverAPIVersion
756+ A solver API enum object
757+ """
758+ return SolverAPIVersion .V1
Original file line number Diff line number Diff line change @@ -140,6 +140,7 @@ def test_context_manager(self):
140140class TestLegacySolverWrapper (unittest .TestCase ):
141141 def test_class_method_list (self ):
142142 expected_list = [
143+ 'api_version' ,
143144 'available' ,
144145 'config_block' ,
145146 'default_variable_value' ,
Original file line number Diff line number Diff line change 2727from pyomo .common .gc_manager import PauseGC
2828from pyomo .common .modeling import unique_component_name
2929from pyomo .common .dependencies import dill , dill_available , multiprocessing
30+ from pyomo .common .enums import SolverAPIVersion
3031
3132from pyomo .core import (
3233 Block ,
5455from pyomo .gdp .plugins .gdp_to_mip_transformation import GDP_to_MIP_Transformation
5556from pyomo .gdp .util import _to_dict
5657from pyomo .opt import SolverFactory , TerminationCondition
57- from pyomo .contrib .solver .common .base import SolverBase as NewSolverBase
58- from pyomo .contrib .solver .common .base import LegacySolverWrapper
5958from pyomo .repn import generate_standard_repn
6059
6160from weakref import ref as weakref_ref
@@ -92,11 +91,8 @@ def Solver(val):
9291 return SolverFactory (val )
9392 if not hasattr (val , 'solve' ):
9493 raise ValueError ("Expected a string or solver object (with solve() method)" )
95- if isinstance (val , NewSolverBase ) and not isinstance (val , LegacySolverWrapper ):
96- raise ValueError (
97- "Please pass an old-style solver object, using the "
98- "LegacySolverWrapper mechanism if necessary."
99- )
94+ if not hasattr (val , 'api_version' ) or val .api_version () is not SolverAPIVersion .V1 :
95+ raise ValueError ("Solver object should support the V1 solver API version" )
10096 return val
10197
10298
You can’t perform that action at this time.
0 commit comments