Skip to content

Commit

Permalink
Apply @blnicho 's csuggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmundt committed Feb 20, 2024
1 parent 159295e commit 044f847
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 23 deletions.
44 changes: 36 additions & 8 deletions doc/OnlineDocs/developer_reference/solvers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ available are:
Backwards Compatible Mode
^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: python
.. testcode::

import pyomo.environ as pyo
from pyomo.contrib.solver.util import assert_optimal_termination
Expand All @@ -52,13 +52,20 @@ Backwards Compatible Mode
assert_optimal_termination(status)
model.pprint()

.. testoutput::
:hide:

2 Var Declarations
...
3 Declarations: x y obj

Future Capability Mode
^^^^^^^^^^^^^^^^^^^^^^

There are multiple ways to utilize the future compatibility mode: direct import
There are multiple ways to utilize the future capability mode: direct import
or changed ``SolverFactory`` version.

.. code-block:: python
.. testcode::

# Direct import
import pyomo.environ as pyo
Expand All @@ -81,9 +88,16 @@ or changed ``SolverFactory`` version.
status.display()
model.pprint()

.. testoutput::
:hide:

solution_loader: ...
...
3 Declarations: x y obj

Changing the ``SolverFactory`` version:

.. code-block:: python
.. testcode::

# Change SolverFactory version
import pyomo.environ as pyo
Expand All @@ -105,6 +119,18 @@ Changing the ``SolverFactory`` version:
status.display()
model.pprint()

.. testoutput::
:hide:

solution_loader: ...
...
3 Declarations: x y obj

.. testcode::
:hide:

from pyomo.__future__ import solver_factory_v1

Linear Presolve and Scaling
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -118,11 +144,13 @@ options for certain solvers. Currently, these options are only available for
The ``writer_config`` configuration option can be used to manipulate presolve
and scaling options:

.. code-block:: python
.. testcode::

from pyomo.contrib.solver.ipopt import Ipopt
opt = Ipopt()
opt.config.writer_config.display()

>>> from pyomo.contrib.solver.ipopt import Ipopt
>>> opt = Ipopt()
>>> opt.config.writer_config.display()
.. testoutput::

show_section_timing: false
skip_trivial_constraints: true
Expand Down
2 changes: 1 addition & 1 deletion pyomo/__future__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def solver_factory(version=None):
This allows users to query / set the current implementation of the
SolverFactory that should be used throughout Pyomo. Valid options are:
- ``1``: the original Pyomo SolverFactor
- ``1``: the original Pyomo SolverFactory
- ``2``: the SolverFactory from APPSI
- ``3``: the SolverFactory from pyomo.contrib.solver
Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/solver/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def add_variables(self, variables: List[_GeneralVarData]):
"""

@abc.abstractmethod
def add_params(self, params: List[_ParamData]):
def add_parameters(self, params: List[_ParamData]):
"""
Add parameters to the model
"""
Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/solver/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def __init__(
default=True,
description="""
If False, new/old parameters will not be automatically detected on subsequent
solves. Use False only when manually updating the solver with opt.add_params() and
solves. Use False only when manually updating the solver with opt.add_parameters() and
opt.remove_params() or when you are certain parameters are not being added to /
removed from the model.""",
),
Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/solver/gurobi.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def _add_variables(self, variables: List[_GeneralVarData]):
self._vars_added_since_update.update(variables)
self._needs_updated = True

def _add_params(self, params: List[_ParamData]):
def _add_parameters(self, params: List[_ParamData]):
pass

def _reinit(self):
Expand Down
10 changes: 5 additions & 5 deletions pyomo/contrib/solver/persistent.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ def add_variables(self, variables: List[_GeneralVarData]):
self._add_variables(variables)

@abc.abstractmethod
def _add_params(self, params: List[_ParamData]):
def _add_parameters(self, params: List[_ParamData]):
pass

def add_params(self, params: List[_ParamData]):
def add_parameters(self, params: List[_ParamData]):
for p in params:
self._params[id(p)] = p
self._add_params(params)
self._add_parameters(params)

@abc.abstractmethod
def _add_constraints(self, cons: List[_GeneralConstraintData]):
Expand Down Expand Up @@ -191,7 +191,7 @@ def add_block(self, block):
if p.mutable:
for _p in p.values():
param_dict[id(_p)] = _p
self.add_params(list(param_dict.values()))
self.add_parameters(list(param_dict.values()))
self.add_constraints(
list(
block.component_data_objects(Constraint, descend_into=True, active=True)
Expand Down Expand Up @@ -403,7 +403,7 @@ def update(self, timer: HierarchicalTimer = None):
if config.update_params:
self.update_params()

self.add_params(new_params)
self.add_parameters(new_params)
timer.stop('params')
timer.start('vars')
self.add_variables(new_vars)
Expand Down
4 changes: 2 additions & 2 deletions pyomo/contrib/solver/sol_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def parse_sol_file(

#
# Some solvers (minto) do not write a message. We will assume
# all non-blank lines up the 'Options' line is the message.
# all non-blank lines up to the 'Options' line is the message.
# For backwards compatibility and general safety, we will parse all
# lines until "Options" appears. Anything before "Options" we will
# consider to be the solver message.
Expand Down Expand Up @@ -168,7 +168,7 @@ def parse_sol_file(
# The fourth entry is table "length", e.g., memory size.
number_of_string_lines = int(line[5])
suffix_name = sol_file.readline().strip()
# Add any of arbitrary string lines to the "other" list
# Add any arbitrary string lines to the "other" list
for line in range(number_of_string_lines):
sol_data.other.append(sol_file.readline())
if data_type == 0: # Var
Expand Down
8 changes: 4 additions & 4 deletions pyomo/contrib/solver/tests/unit/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_abstract_member_list(self):
'remove_block',
'add_block',
'available',
'add_params',
'add_parameters',
'remove_constraints',
'add_variables',
'solve',
Expand All @@ -110,7 +110,7 @@ def test_class_method_list(self):
'_load_vars',
'add_block',
'add_constraints',
'add_params',
'add_parameters',
'add_variables',
'available',
'is_persistent',
Expand Down Expand Up @@ -138,7 +138,7 @@ def test_init(self):
self.assertTrue(self.instance.is_persistent())
self.assertEqual(self.instance.set_instance(None), None)
self.assertEqual(self.instance.add_variables(None), None)
self.assertEqual(self.instance.add_params(None), None)
self.assertEqual(self.instance.add_parameters(None), None)
self.assertEqual(self.instance.add_constraints(None), None)
self.assertEqual(self.instance.add_block(None), None)
self.assertEqual(self.instance.remove_variables(None), None)
Expand All @@ -164,7 +164,7 @@ def test_context_manager(self):
self.assertTrue(self.instance.is_persistent())
self.assertEqual(self.instance.set_instance(None), None)
self.assertEqual(self.instance.add_variables(None), None)
self.assertEqual(self.instance.add_params(None), None)
self.assertEqual(self.instance.add_parameters(None), None)
self.assertEqual(self.instance.add_constraints(None), None)
self.assertEqual(self.instance.add_block(None), None)
self.assertEqual(self.instance.remove_variables(None), None)
Expand Down

0 comments on commit 044f847

Please sign in to comment.