Code Monkey home page Code Monkey logo

mpi-sppy's Introduction

Github Actions Status Jenkins Status codecov Documentation Status Build services GitHub contributors Merged PRs

a COIN-OR project

Pyomo Overview

Pyomo is a Python-based open-source software package that supports a diverse set of optimization capabilities for formulating and analyzing optimization models. Pyomo can be used to define symbolic problems, create concrete problem instances, and solve these instances with standard solvers. Pyomo supports a wide range of problem types, including:

  • Linear programming
  • Quadratic programming
  • Nonlinear programming
  • Mixed-integer linear programming
  • Mixed-integer quadratic programming
  • Mixed-integer nonlinear programming
  • Mixed-integer stochastic programming
  • Generalized disjunctive programming
  • Differential algebraic equations
  • Mathematical programming with equilibrium constraints
  • Constraint programming

Pyomo supports analysis and scripting within a full-featured programming language. Further, Pyomo has also proven an effective framework for developing high-level optimization and analysis tools. For example, the mpi-sppy package provides generic solvers for stochastic programming. mpi-sppy leverages the fact that Pyomo's modeling objects are embedded within a full-featured high-level programming language, which allows for transparent parallelization of subproblems using Python parallel communication libraries.

Pyomo was formerly released as the Coopr software library.

Pyomo is available under the BSD License - see the LICENSE.md file.

Pyomo is currently tested with the following Python implementations:

  • CPython: 3.8, 3.9, 3.10, 3.11, 3.12
  • PyPy: 3.9

Testing and support policy:

At the time of the first Pyomo release after the end-of-life of a minor Python version, we will remove testing for that Python version.

Installation

PyPI PyPI version PyPI downloads

pip install pyomo

Anaconda Anaconda version Anaconda downloads

conda install -c conda-forge pyomo

Tutorials and Examples

Getting Help

To get help from the Pyomo community ask a question on one of the following:

Developers

Pyomo development moved to this repository in June 2016 from Sandia National Laboratories. Developer discussions are hosted by Google Groups.

The Pyomo Development team holds weekly coordination meetings on Tuesdays 12:30 - 14:00 (MT). Please contact [email protected] to request call-in information.

By contributing to this software project, you are agreeing to the following terms and conditions for your contributions:

  1. You agree your contributions are submitted under the BSD license.
  2. You represent you are authorized to make the contributions and grant the license. If your employer has rights to intellectual property that includes your contributions, you represent that you have received permission to make contributions and grant the required license on behalf of that employer.

Related Packages

See https://pyomo.readthedocs.io/en/latest/related_packages.html.

mpi-sppy's People

Contributors

aymericpclegros avatar bknueven avatar briancknight avatar dlwoodruff avatar dtmildebrath avatar garg02 avatar jeanpaulwatson avatar matthew-signorotti avatar michaelbynum avatar pdb5627 avatar salancelot avatar sylvainczx avatar tvalenciaz avatar ulysse-n avatar xiaotie-chen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mpi-sppy's Issues

Update_W fails to update dual weights in presence of arbitrary nonanticipative variables

To start, I am running the latest main branch (presently 52cc831).

In Pyomo it is sometimes convenient to introduce arbitrary decision variables and just let the solver ignore them. I have done this in the attached example -- the variable sales[0] is arbitrary, and I introduced it solely to avoid needing special logic for setting up the root node in the scenario tree.

inventory.tar.gz

When I execute run.sh, I encounter an issue in the Update_W function of spbase.py:

https://github.com/Pyomo/mpi-sppy/blob/main/mpisppy/phbase.py#L224

The issue is that the arbitrary decision variable is not assigned a value by the solver, so the code attempts to subtract a float from None. It is evident to me that somebody else has already encountered this issue given the commented print lines preceding the subtraction.

Intuitively, if I force sales[0] == 0 (a constraint that is commented out in inventory.py), then there is no issue. Unintuitively, the issue also goes away if I change --bundles-per-rank=0 to --bundles-per-rank=1 or --bundles-per-rank=3.

It took me a while to figure out why mpi-sppy was complaining. I suppose it would be nice for such a condition to be automatically detected and handled. Alternatively, it would probably save someone some time down the road if the resulting TypeError were captured and given some additional messaging. Something like "Check that your instance does not have arbitrary decision variables."

logging and verbosity

[#13 in old repository]

DLW: We should convert almost all output to logging to enable:

standardized inclusion of who is doing the output, and
easier control over verbosity
wrap TicTocTimer for easier logging

pysp import

In preparation for Pyomo 6, we need to import pysp as its own package.

Scenario subproblem namespacing

We should attach all the objects we currently attach to scenario subproblems to a single block on those subproblems, perhaps named mpisppy.

This will ensure we have exactly one name clash to worry about, and the internal mpisppy names can be less verbose.

New Persistent Interface

We should try out and then support the not-yet-released automated persistent interface in Pyomo.

example for concrete multi-stage model

Thanks for this great library!

I'm interested in modeling multi-stage problems as ConcreteModels so that I have full flexibility to modify
them in python.

Thanks to the examples I have been able to adjust newsvendor and farmer to my needs. However this are
only two-stage problems and I'm now stuck trying to convert the financial planning example to a direct model.

I have studied the docs but not everything is clear yet, an example for a concrete multi-stage model would help me a lot. Is there such a model in the examples that I overlooked or can someone share such an example?

Thanks

rework PH_Prep

An issue for the code review of phbase is that we need to re-work PH_Prep. It has evolved to a strange state with argument names that are misleading and behavior that is not what one would expect. Unfortunately, there is code using the names and relying on the behavior (APH, and various spokes).

Cannot directly solve EF for multistage

Attempting to directly solve the extensive form of the hydro example (three stages) fails while making the comms (even though this is inherently serial).

import hydro
from mpisppy.opt.ef import ExtensiveForm

options = {"solver": "Gurobi"}
num_scenarios = 9
cb_data = [3, 3]
all_scenario_names = [f"Scen{i+1}" for i in range(num_scenarios)]
scenario_creator_options = {"cb_data": cb_data}
ef = ExtensiveForm(
    options,
    all_scenario_names,
    hydro.scenario_creator,
    scenario_creator_options=scenario_creator_options,
)

The issue is caused by the inadequate knowledge of the tree structure within EF:

Traceback (most recent call last):
  File "test.py", line 16, in <module>
    scenario_creator_options=scenario_creator_options,
  File <path>/mpisppy/opt/ef.py", line 57, in __init__
    cb_data=cb_data,
  File "<path>/mpisppy/spbase.py", line 111, in __init__
    self.create_communicators()
  File "<path>/mpisppy/spbase.py", line 329, in create_communicators
    raise RuntimeError(f"Tree node '{nodename}' not in node list {self.all_nodenames}")
RuntimeError: Tree node 'ROOT_0' not in node list ['ROOT']

scen_name_list is not truly optional

The parameter scen_name_list of mpisppy.scenario_tree.ScenarioNode.__init__ is said to be optional and no longer used, but cannot have a default value and be followed by positional parameters. Constructing a ScenarioNode gives TypeError: __init__() missing 1 required positional argument: 'scen_name_list' unless you supply a value. Is there any reason not to change the constructor signature ASAP?

Improve robustiness when checking for existence of solutions

We need to centralize and expand (perhaps drawing from Egret) how we check for the existence of solutions and a sane termination condition. The conditional in phbase.py is getting rather un-weidly. At a minimum, it should be moved to a util module, and we should carefully consider the full range of returns conditions that we should require.

tictoc timer

In preparation for Pyomo 6, we need to write our own timer. For one thing, we need to be able to have it go silent.

Incumbent spokes and solution recovery

Right now, incumbent spokes store the nonanticipative variables when a new solution is found. They should really store all the Vars on the Pyomo model to ensure that the original solution found can be recovered easily. This may be useful for certain classes of problems, such as those with integer recourse actions.

Refactor XhatTryer / Xhat_Eval

Ideally the replacement for both would

  1. Inherit from SPOpt (not PHBase like XhatTryer does)
  2. Be compatible with both MMW and the spoke incumbent finders (xhatspecific, xhatshufflelooper, xhatlooper)

Bundles to spokes

[#15 in old repository]

DLW: After everything is up and running, we should probably add a feature that allows for transmission of one vector per bundle to the spokes. With large bundles, this could be much more efficient than sending all scenarios.

User-defined Scenario Tree

Currently mpi-sppy handles multi-stage models in a somewhat brittle way which requires the scenario and node names to line up just-so.

lagranger_bounder shared code and rho-scaling

[#57 in old repository]

DLW: lagranger_bounder.py shares code with LagrangianOuterBound; this probably should be factored. Related: we should think about "elevating" the rho-scaling code to ph_base so that extensions and/or other hubs could use it.

PH display timing

Could use some work -- it's basically only valid when each subproblem has its own rank.

subsolvedirectives is never used

We need a hierarchy of solver options and a service function to manage the options. E.g., an EF could look first for EF_solvername but if it is not found, use solvername, etc. DLW has some ideas about this.

Also: many examples (particularly older examples) have something like
options["subsolvedirectives"] = None
but if it was not None, nothing would change. The examples should probably be updated.

More user-friendly bundling

PHBase.PHoptions["bundles_per_rank"] should be (optionally) calculated based on an easier-to-understand number like total number of bundles or bundle size.

RuntimeError: Found infeasible solution which was feasible before

I am encountering the runtime error from the issue title as the progressive hedging algorithm attempts to terminate. The file below contains the text I see written to the terminal.

winterization.stdout.txt

The particular section of code that raises the error is here.

In those lines of code, I see the comment saying "this should be feasible here; if not we've done something wrong". This check was added a little more than a year ago. Have the developers since encountered this issue? Is it possible that the settings I specify are causing this issue?

Question: differing nonant varnames between scenarios

Hi,

I've been wracking my brain trying to figure out why my nonant constraints aren't being respected. So far the best explanation I have is that it is due to some of the nonant variables in the same node having different names in different scenarios. I've looked through the codebase but couldn't quite determine for sure whether this would be an issue or not.

Making all the names match could potentially require quite a large rewrite for me, so I wanted to make sure I am actually on to something before I try it.

Any help is appreciated!

PySP features

  • CVaR
  • Chance constraints
  • Enhanced slamming heuristics (var by var up/down min/max over scenarios or to bounds)
  • Linearized proximal term (PR #43)
  • Cycle detection for PH (what to do about it? Slam, perturb w, etc?)

cplex versus cplex_persistent

I am not sure whose bug this is (pyomo? Cplex? mpi-sppy?), but it could well be mpi-sspy but it might also be cplex, or numeric troubles in Egret.

in examples/acopf
mpiexec -np 2 python -m mpi4py ccopf2wood.py 2 3 2 0 cplex
works, but cplex_persistent does not; I kind of think it works with xpress_persistent.

spoke_sleep_time

In the Pyomo config system version, we should better support command line setting of spoke_sleep_time (note that is a keyword
argument for the spoke constructor); also, the heuristic in spcommunicator might be ignoring.

Create general solution writers

  • New user function for SPBase called write_scenario_solution (like create_scenario).
  • A new service for Hubs which selects the best incumbent and instructs the associated Spoke opt object to call the write_scenario_solution function on SPBase.
  • Default implementation of write_scenario_solution which blurts out the Pyomo model (look at PySP)
  • Create functionality examples

Some code:

def write_solution(spcomm, opt_dict, solution_dir):
from mpisppy.cylinders.xhatshufflelooper_bounder import XhatShuffleInnerBound
from mpisppy.extensions.xhatclosest import XhatClosest
from mpisppy.opt.ph import PH
if spcomm.global_rank == 0:
if spcomm.last_ib_idx is None:
best_strata_rank = -1
print("No incumbent solution to print")
else:
best_strata_rank = spcomm.last_ib_idx
else:
best_strata_rank = None
best_strata_rank = spcomm.fullcomm.bcast(best_strata_rank, root=0)
if spcomm.strata_rank != best_strata_rank:
# Nothing to do
return
## else this spoke/hub is the winner!
# do some checks, to make sure the solution we print will be nonantipative
if best_strata_rank != 0:
assert opt_dict["spoke_class"] in (XhatShuffleInnerBound, )
else: # this is the hub, TODO: also could check for XhatSpecific
assert opt_dict["opt_class"] in (PH, )
assert XhatClosest in opt_dict["opt_kwargs"]["PH_extension_kwargs"]["ext_classes"]
assert "keep_solution" in opt_dict["opt_kwargs"]["PHoptions"]["xhat_closest_options"]
assert opt_dict["opt_kwargs"]["PHoptions"]["xhat_closest_options"]["keep_solution"] is True
## if we've passed the above checks, the scenarios should have the tree solution
## make solution dir if it doesn't exist,
## but only on rank 0
if spcomm.cylinder_rank == 0:
if not os.path.exists(solution_dir):
os.makedirs(solution_dir)
spcomm.cylinder_comm.Barrier()
for sname, s in spcomm.opt.local_scenarios.items():
file_name = os.path.join(solution_dir, sname+'.json')
mds = uc._save_uc_results(s, relaxed=False)
mds.write(file_name)
return

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.