Skip to content

Commit

Permalink
Merge pull request Pyomo#3 from jsiirola/finalize-split
Browse files Browse the repository at this point in the history
Transfer the phpyro solver manager from Pyomo
  • Loading branch information
jsiirola authored Feb 16, 2021
2 parents 05571b4 + f43c33e commit 852153b
Show file tree
Hide file tree
Showing 18 changed files with 424 additions and 81 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
*.egg-info

# Documentation builds
doc/OnlineDocs/_build
doc/OnlineDocs/**/*.spy
doc/_build
doc/**/*.spy

# Running pyomo / tests / solvers occasionally leaves extra files
TEST-pysp.xml
*.out
pyomo/dataportal/parse_table_datacmds.py
gurobi.log

# Results from nosetests --with-coverage
Expand Down
8 changes: 3 additions & 5 deletions pysp/bbph/archive/bbph.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import pyomo.environ
from pysp import ph, phinit, phutils
from pyomo.core.base import maximize, minimize
import pyomo.solvers.plugins.smanager.phpyro
import pysp.plugins.phpyro
from pysp import phsolverserverutils

import os
Expand Down Expand Up @@ -180,8 +180,7 @@ def __init__(self, options, BranchTupleList=None, Parent=None, isTerminal=False)
def _collect_node_variable_bounds(self, ph, tree_node):

if not isinstance(ph._solver_manager,
pyomo.solvers.plugins.\
smanager.phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):

tree_node._variable_bounds = \
collect_node_variable_bounds(tree_node)
Expand Down Expand Up @@ -421,8 +420,7 @@ def Process_Node(self, GIB, NoBranchEpsilon):
# transmit the var bounds
if self.BranchTupleList is not None:
if isinstance(phobject._solver_manager,
pyomo.solvers.plugins.smanager.\
phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):
ahs = phsolverserverutils.transmit_external_function_invocation(
phobject,
thisfile,
Expand Down
5 changes: 2 additions & 3 deletions pysp/bbph/brancher.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import pyomo.common.plugin
from pysp import phextension
import pyomo.solvers.plugins.smanager.phpyro
import pysp.plugins.phpyro
from pysp import phsolverserverutils

from six import iteritems
Expand Down Expand Up @@ -279,8 +279,7 @@ def Process_var(stage, tree_node, variable_id):
def _collect_node_variable_bounds(self, ph, tree_node):

if not isinstance(ph._solver_manager,
pyomo.solvers.plugins.\
smanager.phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):

tree_node._variable_bounds = \
collect_node_variable_bounds(tree_node)
Expand Down
2 changes: 1 addition & 1 deletion pysp/convert/ddsip.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ def convert_external(output_directory,
keep_scenario_files=False,
verbose=False):
import pyomo.environ
import pyomo.solvers.plugins.smanager.phpyro
import pysp.plugins.phpyro

if io_options is None:
io_options = {}
Expand Down
2 changes: 1 addition & 1 deletion pysp/convert/smps.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ def convert_external(output_directory,
keep_auxiliary_files=False,
verbose=False):
import pyomo.environ
import pyomo.solvers.plugins.smanager.phpyro
import pysp.plugins.phpyro

if io_options is None:
io_options = {}
Expand Down
4 changes: 2 additions & 2 deletions pysp/drive_lagrangian_cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def run(args=None):
##########################================================#########
# to import plugins
import pyomo.environ
import pyomo.solvers.plugins.smanager.phpyro
import pyomo.solvers.plugins.smanager.pyro
import pysp.plugins.phpyro

def partialLagrangeParametric(args=None):
print("lagrangeParam begins ")
Expand Down Expand Up @@ -309,7 +309,7 @@ class Object(object): pass
"type="+options.solver_manager_type+
" specified in call to PH constructor")
if isinstance(solver_manager,
pyomo.solvers.plugins.smanager.phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):
raise ValueError("PHPyro can not be used as the solver manager")

try:
Expand Down
4 changes: 2 additions & 2 deletions pysp/lagrangeMorePR.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def run(args=None):

# to import plugins
import pyomo.environ
import pyomo.solvers.plugins.smanager.phpyro
import pysp.plugins.phpyro

def LagrangeMorePR(args=None):
print("lagrangeMorePR begins %s" % datetime_string())
Expand Down Expand Up @@ -439,7 +439,7 @@ class Object(object): pass
"type="+options.solver_manager_type+
" specified in call to PH constructor")
if isinstance(solver_manager,
pyomo.solvers.plugins.smanager.phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):
raise ValueError("PHPyro can not be used as the solver manager")

try:
Expand Down
2 changes: 1 addition & 1 deletion pysp/lagrangeutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _tear_down_ef(ef_instance, scenario_instances):

def solve_ph_code(ph, options):
import pyomo.environ
import pyomo.solvers.plugins.smanager.phpyro
import pysp.plugins.phpyro

# consolidate the code to solve the problem for the "global" ph object
# return a solver code (string from the solver if EF, "PH" if PH) and the objective fct val
Expand Down
72 changes: 25 additions & 47 deletions pysp/ph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,8 +1212,7 @@ def release_components(self):
return

if isinstance(self._solver_manager,
pyomo.solvers.plugins.smanager.\
phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):

phsolverserverutils.release_phsolverservers(self)

Expand All @@ -1236,8 +1235,7 @@ def activate_ph_objective_proximal_terms(self):
_PHBase.activate_ph_objective_proximal_terms(self)

if isinstance(self._solver_manager,
pyomo.solvers.plugins.smanager.\
phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):

phsolverserverutils.activate_ph_objective_proximal_terms(self)

Expand All @@ -1254,8 +1252,7 @@ def deactivate_ph_objective_proximal_terms(self):
_PHBase.deactivate_ph_objective_proximal_terms(self)

if isinstance(self._solver_manager,
pyomo.solvers.plugins.smanager.\
phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):

phsolverserverutils.deactivate_ph_objective_proximal_terms(self)

Expand All @@ -1272,8 +1269,7 @@ def activate_ph_objective_weight_terms(self):
_PHBase.activate_ph_objective_weight_terms(self)

if isinstance(self._solver_manager,
pyomo.solvers.plugins.smanager.\
phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):

phsolverserverutils.activate_ph_objective_weight_terms(self)

Expand All @@ -1290,8 +1286,7 @@ def deactivate_ph_objective_weight_terms(self):
_PHBase.deactivate_ph_objective_weight_terms(self)

if isinstance(self._solver_manager,
pyomo.solvers.plugins.smanager.\
phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):

phsolverserverutils.deactivate_ph_objective_weight_terms(self)

Expand Down Expand Up @@ -1428,8 +1423,7 @@ def report_scenario_objectives(self):
def _push_w_to_instances(self):

if isinstance(self._solver_manager,
pyomo.solvers.plugins.smanager.\
phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):

phsolverserverutils.transmit_weights(self)

Expand All @@ -1440,8 +1434,7 @@ def _push_w_to_instances(self):
def _push_rho_to_instances(self):

if isinstance(self._solver_manager,
pyomo.solvers.plugins.smanager.\
phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):

phsolverserverutils.transmit_rhos(self)

Expand All @@ -1452,8 +1445,7 @@ def _push_rho_to_instances(self):
def _push_xbar_to_instances(self):

if isinstance(self._solver_manager,
pyomo.solvers.plugins.smanager.\
phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):

phsolverserverutils.transmit_xbars(self)

Expand All @@ -1464,8 +1456,7 @@ def _push_xbar_to_instances(self):
def _push_fix_queue_to_instances(self):

if isinstance(self._solver_manager,
pyomo.solvers.plugins.smanager.\
phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):

phsolverserverutils.transmit_fixed_variables(self)
for tree_node in self._scenario_tree._tree_nodes:
Expand All @@ -1485,8 +1476,7 @@ def _push_fix_queue_to_instances(self):
def restoreCachedSolutions(self, cache_id, release_cache=False):

if isinstance(self._solver_manager,
pyomo.solvers.plugins.smanager.\
phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):

phsolverserverutils.restore_cached_scenario_solutions(self, cache_id, release_cache)

Expand All @@ -1500,8 +1490,7 @@ def cacheSolutions(self, cache_id=None):
cache_id = str(uuid.uuid4())

if isinstance(self._solver_manager,
pyomo.solvers.plugins.smanager.\
phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):

phsolverserverutils.cache_scenario_solutions(self, cache_id)

Expand Down Expand Up @@ -1695,8 +1684,7 @@ def compute_and_report_inner_bound_using_xhat(self):
else:

if isinstance(self._solver_manager,
pyomo.solvers.plugins.smanager.\
phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):
phsolverserverutils.collect_full_results(
self,
phsolverserverutils.TransmitType.all_stages | \
Expand Down Expand Up @@ -2179,7 +2167,7 @@ def initialize(self,
solution_plugins=None):

import pyomo.environ
import pyomo.solvers.plugins.smanager.phpyro
import pysp.plugins.phpyro
# TODO: Does this import need to be delayed because
# it is in a plugins subdirectory
from pyomo.solvers.plugins.solvers.persistent_solver import \
Expand Down Expand Up @@ -2289,8 +2277,7 @@ def initialize(self,
self._solver_manager = solver_manager

isPHPyro = isinstance(self._solver_manager,
pyomo.solvers.plugins.\
smanager.phpyro.SolverManager_PHPyro)
pysp.plugins.phpyro.SolverManager_PHPyro)

initialization_action_handles = []

Expand Down Expand Up @@ -2731,8 +2718,7 @@ def scenario_in_subproblems(scenario_name, subproblems):
# Preprocess the scenario instances before solving if
# we are not using phpyro
if not isinstance(self._solver_manager,
pyomo.solvers.plugins.smanager.\
phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):
self._preprocess_scenario_instances(subproblems=subproblems)

# STEP -1: clear the auxilliary dictionaries (gaps, solve_times,
Expand Down Expand Up @@ -2790,7 +2776,7 @@ def scenario_in_subproblems(scenario_name, subproblems):
# TODO: suffixes are not handled equally for
# scenario/bundles/serial/phpyro
if isinstance(self._solver_manager,
pyomo.solvers.plugins.smanager.phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):
solver_options = self._scenario_solver_options
if self._mipgap is not None:
solver_options["mipgap"] = float(self._mipgap)
Expand All @@ -2805,8 +2791,7 @@ def scenario_in_subproblems(scenario_name, subproblems):
common_solve_kwds['load_solutions'] = False

if isinstance(self._solver_manager,
pyomo.solvers.plugins.smanager.\
phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):
self._solver_manager.begin_bulk()

if self._scenario_tree.contains_bundles():
Expand All @@ -2823,8 +2808,7 @@ def scenario_in_subproblems(scenario_name, subproblems):
# warm-starting here.
new_action_handle = None
if isinstance(self._solver_manager,
pyomo.solvers.plugins.smanager.\
phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):
new_action_handle = \
self._solver_manager.queue(
action="solve",
Expand Down Expand Up @@ -2867,8 +2851,7 @@ def scenario_in_subproblems(scenario_name, subproblems):
# behaving badly (which does happen).
new_action_handle = None
if isinstance(self._solver_manager,
pyomo.solvers.plugins.smanager.\
phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):

new_action_handle = \
self._solver_manager.queue(
Expand Down Expand Up @@ -2908,8 +2891,7 @@ def scenario_in_subproblems(scenario_name, subproblems):
self._queued_solve_action_handles.add(new_action_handle)

if isinstance(self._solver_manager,
pyomo.solvers.plugins.smanager.\
phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):
self._solver_manager.end_bulk()

return action_handle_scenario_map, \
Expand Down Expand Up @@ -2975,8 +2957,7 @@ def wait_for_and_process_subproblems(self,
num_results_so_far += 1

if isinstance(self._solver_manager,
pyomo.solvers.plugins.smanager.phpyro.\
SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):

if len(bundle_results) == 0:
failures.append(bundle_name)
Expand Down Expand Up @@ -3115,8 +3096,7 @@ def wait_for_and_process_subproblems(self,
num_results_so_far += 1

if isinstance(self._solver_manager,
pyomo.solvers.plugins.smanager.\
phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):

if len(results) == 0:
failures.append(scenario_name)
Expand Down Expand Up @@ -3652,7 +3632,7 @@ def iteration_k_solves(self):
# if linearizing (so an optimization could be
# performed here).
if isinstance(self._solver_manager,
pyomo.solvers.plugins.smanager.phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):

# we only transmit tree node statistics if we are
# linearizing the PH objectives. otherwise, the
Expand Down Expand Up @@ -4448,8 +4428,7 @@ def solve(self):
self.restoreCachedSolutions(self._incumbent_cache_id)

if isinstance(self._solver_manager,
pyomo.solvers.plugins.smanager.\
phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):
phsolverserverutils.collect_full_results(
self,
phsolverserverutils.TransmitType.all_stages | \
Expand Down Expand Up @@ -4577,8 +4556,7 @@ def solve(self):
# servers as this function is being called at the end of ph
# (for now)
if not isinstance(self._solver_manager,
pyomo.solvers.plugins.smanager.\
phpyro.SolverManager_PHPyro):
pysp.plugins.phpyro.SolverManager_PHPyro):
self.deactivate_ph_objective_weight_terms()
self.deactivate_ph_objective_proximal_terms()

Expand Down
Loading

0 comments on commit 852153b

Please # to comment.