-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* start a special extension to write lp files, etc. for each scenario * fix a potential bug in the use of proper bundles * the lp and nonant writer extension seems to be working * deal with some proper bundle issues raised by, and for, the sizes example * add a test and a little doc for the scenario lp writer extension * the scenario_lpfiles extension * remove some notes * use a Pyomo function to convert variable names per Ben's suggestion
- Loading branch information
1 parent
7b95078
commit c3d31d5
Showing
7 changed files
with
147 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
############################################################################### | ||
# mpi-sppy: MPI-based Stochastic Programming in PYthon | ||
# | ||
# Copyright (c) 2024, Lawrence Livermore National Security, LLC, Alliance for | ||
# Sustainable Energy, LLC, The Regents of the University of California, et al. | ||
# All rights reserved. Please see the files COPYRIGHT.md and LICENSE.md for | ||
# full copyright and license information. | ||
############################################################################### | ||
""" Extension to write an lp file for each scenario and a json file for | ||
the nonant structure for each scenario (yes, for two stage problems this | ||
json file will be the same for all scenarios.) | ||
""" | ||
|
||
import json | ||
import mpisppy.extensions.extension | ||
import pyomo.core.base.label as pyomo_label | ||
|
||
|
||
def lpize(varname): | ||
# convert varname to the string that will appear in the lp file | ||
# return varname.replace("[", "(").replace("]", ")").replace(",", "_").replace(".","_") | ||
return pyomo_label.cpxlp_label_from_name(varname) | ||
|
||
|
||
class Scenario_lpfiles(mpisppy.extensions.extension.Extension): | ||
|
||
def __init__(self, ph): | ||
self.ph = ph | ||
|
||
def pre_iter0(self): | ||
for k, s in self.ph.local_subproblems.items(): | ||
s.write(f"{k}.lp", io_options={'symbolic_solver_labels': True}) | ||
nonants_by_node = {nd.name: [lpize(var.name) for var in nd.nonant_vardata_list] for nd in s._mpisppy_node_list} | ||
with open(f"{k}_nonants.json", "w") as jfile: | ||
json.dump(nonants_by_node, jfile) | ||
|
||
def post_iter0(self): | ||
return | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters