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):
1686
1686
def __exit__ (self , t , v , traceback ):
1687
1687
pass
1688
1688
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
+
1689
1701
1690
1702
class SolverFactoryClass (Factory ):
1691
1703
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):
744
744
745
745
def default_variable_value (self ):
746
746
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):
140
140
class TestLegacySolverWrapper (unittest .TestCase ):
141
141
def test_class_method_list (self ):
142
142
expected_list = [
143
+ 'api_version' ,
143
144
'available' ,
144
145
'config_block' ,
145
146
'default_variable_value' ,
Original file line number Diff line number Diff line change 27
27
from pyomo .common .gc_manager import PauseGC
28
28
from pyomo .common .modeling import unique_component_name
29
29
from pyomo .common .dependencies import dill , dill_available , multiprocessing
30
+ from pyomo .common .enums import SolverAPIVersion
30
31
31
32
from pyomo .core import (
32
33
Block ,
54
55
from pyomo .gdp .plugins .gdp_to_mip_transformation import GDP_to_MIP_Transformation
55
56
from pyomo .gdp .util import _to_dict
56
57
from 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
59
58
from pyomo .repn import generate_standard_repn
60
59
61
60
from weakref import ref as weakref_ref
@@ -92,11 +91,8 @@ def Solver(val):
92
91
return SolverFactory (val )
93
92
if not hasattr (val , 'solve' ):
94
93
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" )
100
96
return val
101
97
102
98
You can’t perform that action at this time.
0 commit comments