source: coopr.pysp/stable/2.3/coopr/pysp/ef_writer_script.py @ 2317

Last change on this file since 2317 was 2317, checked in by wehart, 10 years ago

Merged revisions 2246-2316 via svnmerge from
https://software.sandia.gov/svn/public/coopr/coopr.pysp/trunk

........

r2246 | wehart | 2010-02-01 21:10:48 -0700 (Mon, 01 Feb 2010) | 2 lines


Tagging coopr.pysp release 2.2

........

r2247 | wehart | 2010-02-01 21:46:08 -0700 (Mon, 01 Feb 2010) | 2 lines


Documentation fix.

........

r2248 | jwatson | 2010-02-03 08:44:59 -0700 (Wed, 03 Feb 2010) | 3 lines


Adding os.path.expanduser wrappers around all directory/filenames, to facilitate correct processing of ~ characters.

........

r2249 | jwatson | 2010-02-03 09:28:25 -0700 (Wed, 03 Feb 2010) | 3 lines


Misc fixes.

........

r2254 | jwatson | 2010-02-03 21:09:38 -0700 (Wed, 03 Feb 2010) | 3 lines


Changed PyomoModelData? call from add_data_mumble() to add().

........

r2255 | jwatson | 2010-02-03 21:38:35 -0700 (Wed, 03 Feb 2010) | 3 lines


Re-factoring of PH options parser code to accomodate MRP work being done by DLW.

........

r2256 | jwatson | 2010-02-03 22:18:11 -0700 (Wed, 03 Feb 2010) | 3 lines


Major speed improvements in the EF writer by avoiding Python deep-copes - saves a few orders of magnitude of run-time.

........

r2260 | jwatson | 2010-02-04 21:44:29 -0700 (Thu, 04 Feb 2010) | 3 lines


Refactoring of ph initialization routines to support sampling and bundling.

........

r2261 | jwatson | 2010-02-04 21:46:37 -0700 (Thu, 04 Feb 2010) | 3 lines


Renaming ph_script module to phinit, which is more accurate with the newly factored, library-like functionality.

........

r2262 | jwatson | 2010-02-04 21:54:50 -0700 (Thu, 04 Feb 2010) | 3 lines


Minor improvement to phinit functionality.

........

r2267 | jwatson | 2010-02-05 15:09:02 -0700 (Fri, 05 Feb 2010) | 3 lines


Initial PySP unit tests!!!

........

r2268 | wehart | 2010-02-05 15:25:52 -0700 (Fri, 05 Feb 2010) | 2 lines


A fix to the tests.

........

r2269 | jwatson | 2010-02-05 15:46:35 -0700 (Fri, 05 Feb 2010) | 3 lines


Added SIZES3 PySP test and added absolute paths to "runph" script.

........

r2270 | jwatson | 2010-02-05 16:01:08 -0700 (Fri, 05 Feb 2010) | 3 lines


PySP tests need absolute output paths!

........

r2271 | jwatson | 2010-02-05 16:20:01 -0700 (Fri, 05 Feb 2010) | 3 lines


Making unit tests for PySP compatible with coverage utilities. Farmer examples work, SIZES3 doesn't for some reason.

........

r2272 | jwatson | 2010-02-05 16:59:46 -0700 (Fri, 05 Feb 2010) | 3 lines


Various fixes to PySP unit tests. Changing name of testphextension to examplephextension - with the test prefix, coverage tests import the module, which causes all kinds of issues.

........

r2275 | jwatson | 2010-02-06 13:45:11 -0700 (Sat, 06 Feb 2010) | 3 lines


Testing improvements. From lpython, the tests run individually just fine. In aggregate, only the first run passes - independent of what test that might be! Something to stare at later....

........

r2277 | jwatson | 2010-02-06 23:30:13 -0700 (Sat, 06 Feb 2010) | 3 lines


Fixed problem with runph --profile option, broken by my recent factoring of phinit.py.

........

r2288 | jwatson | 2010-02-08 13:32:41 -0700 (Mon, 08 Feb 2010) | 3 lines


Significant initialization speed reductions in the WW PH extension for PySP.

........

r2290 | jwatson | 2010-02-08 19:22:32 -0700 (Mon, 08 Feb 2010) | 1 line


Initial commit of multi-stage capacity expansion problem in PySP

........

r2291 | jwatson | 2010-02-08 19:23:24 -0700 (Mon, 08 Feb 2010) | 1 line


Miscellaneous fix to ef writer involving indexed cost variables

........

r2296 | jwatson | 2010-02-09 18:56:48 -0700 (Tue, 09 Feb 2010) | 3 lines


Removing monster-sized LP file from the PySP forestry examples directory.

........

r2297 | jwatson | 2010-02-09 18:59:05 -0700 (Tue, 09 Feb 2010) | 3 lines


The extensive forms in the PySP forestry example were massive - and are now gone.

........

r2298 | jwatson | 2010-02-09 19:03:09 -0700 (Tue, 09 Feb 2010) | 1 line


Removing output logs for PySP network flow example

........

r2299 | jwatson | 2010-02-09 19:04:12 -0700 (Tue, 09 Feb 2010) | 1 line


Removing a big network flow EF

........

r2300 | jwatson | 2010-02-09 19:05:08 -0700 (Tue, 09 Feb 2010) | 3 lines


Removing PySP cap example EF to free up space.

........

r2301 | jwatson | 2010-02-09 19:14:26 -0700 (Tue, 09 Feb 2010) | 1 line


Performance improvements to PH obtained by processing scenario sub-problem results as they come in, instead of waiting for them after a solver barrier sync

........

  • Property svn:executable set to *
File size: 5.0 KB
Line 
1#  _________________________________________________________________________
2#
3#  Coopr: A COmmon Optimization Python Repository
4#  Copyright (c) 2009 Sandia Corporation.
5#  This software is distributed under the BSD License.
6#  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
7#  the U.S. Government retains certain rights in this software.
8#  For more information, see the Coopr README.txt file.
9#  _________________________________________________________________________
10
11
12import sys
13import os
14from optparse import OptionParser
15
16import pyutilib.services
17import textwrap
18import traceback
19import cProfile
20import pstats
21import gc
22
23from coopr.pysp.ef import *
24
25#
26# Setup command-line options
27#
28
29parser = OptionParser()
30parser.add_option("--model-directory",
31                  help="The directory in which all model (reference and scenario) definitions are stored. Default is \".\".",
32                  action="store",
33                  dest="model_directory",
34                  type="string",
35                  default=".")
36parser.add_option("--instance-directory",
37                  help="The directory in which all instance (reference and scenario) definitions are stored. Default is \".\".",
38                  action="store",
39                  dest="instance_directory",
40                  type="string",
41                  default=".")
42parser.add_option("--generate-weighted-cvar",
43                  help="Add a weighted CVaR term to the primary objective",
44                  action="store_true",
45                  dest="generate_weighted_cvar",
46                  default=False)
47parser.add_option("--cvar-weight",
48                  help="The weight associated with the CVaR term in the risk-weighted objective formulation.",
49                  action="store",
50                  dest="cvar_weight",
51                  type="float",
52                  default=1.0)
53parser.add_option("--risk-alpha",
54                  help="The probability threshold associated with cvar (or any future) risk-oriented performance metrics.",
55                  action="store",
56                  dest="risk_alpha",
57                  type="float",
58                  default=0.95)
59parser.add_option("--output-file",
60                  help="Specify the name of the extensive form output file",
61                  action="store",
62                  dest="output_file",
63                  type="string",
64                  default="efout.lp")
65parser.add_option("--profile",
66                  help="Enable profiling of Python code.  The value of this option is the number of functions that are summarized.",
67                  action="store",
68                  dest="profile",
69                  default=0)
70parser.usage="efwriter [options]"
71
72def run_ef_writer(options, args):
73
74   # if the user enabled the addition of the weighted cvar term to the objective,
75   # then validate the associated parameters.
76   generate_weighted_cvar = False
77   cvar_weight = None
78   risk_alpha = None
79
80   if options.generate_weighted_cvar is True:
81
82      generate_weighted_cvar = True
83      cvar_weight = options.cvar_weight
84      risk_alpha = options.risk_alpha
85
86   write_ef_from_scratch(os.path.expanduser(options.model_directory), os.path.expanduser(options.instance_directory), os.path.expanduser(options.output_file), \
87                         generate_weighted_cvar, cvar_weight, risk_alpha)
88
89   return
90
91def run(args=None):
92
93    #
94    # Top-level command that executes the extensive form writer.
95    # This is segregated from run_ef_writer to enable profiling.
96    #
97
98    # for a one-pass execution, garbage collection doesn't make
99    # much sense - so I'm disabling it. Because: It drops the run-time
100    # by a factor of 3-4 on bigger instances.
101    gc.disable()       
102
103    #
104    # Parse command-line options.
105    #
106    try:
107       (options, args) = parser.parse_args(args=args)
108    except SystemExit:
109       # the parser throws a system exit if "-h" is specified - catch
110       # it to exit gracefully.
111       return
112
113    if options.profile > 0:
114        #
115        # Call the main ef writer with profiling.
116        #
117        tfile = pyutilib.services.TempfileManager.create_tempfile(suffix=".profile")
118        tmp = cProfile.runctx('run_ef_writer(options,args)',globals(),locals(),tfile)
119        p = pstats.Stats(tfile).strip_dirs()
120        p.sort_stats('time', 'cum')
121        options.profile = eval(options.profile)
122        p = p.print_stats(options.profile)
123        p.print_callers(options.profile)
124        p.print_callees(options.profile)
125        p = p.sort_stats('cum','calls')
126        p.print_stats(options.profile)
127        p.print_callers(options.profile)
128        p.print_callees(options.profile)
129        p = p.sort_stats('calls')
130        p.print_stats(options.profile)
131        p.print_callers(options.profile)
132        p.print_callees(options.profile)
133        pyutilib.services.TempfileManager.clear_tempfiles()
134        ans = [tmp, None]
135    else:
136        #
137        # Call the main EF writer without profiling.
138        #
139        ans = run_ef_writer(options, args)
140
141    gc.enable()
142    return ans
143
Note: See TracBrowser for help on using the repository browser.