Changeset 3680


Ignore:
Timestamp:
Feb 20, 2011 7:18:02 PM (9 years ago)
Author:
wehart
Message:

First steps towards fixing the conversion utilities.

Location:
coopr.pyomo/trunk/coopr/pyomo
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • coopr.pyomo/trunk/coopr/pyomo/scripting/convert.py

    r3679 r3680  
    1212
    1313
    14 from optparse import OptionParser
     14import argparse
    1515from coopr.opt import ProblemFormat
    1616from coopr.opt.base import SolverFactory
     
    1818
    1919import util
     20import pyomo
    2021
    21 def create_parser(name):
     22def create_parser(cmd):
    2223    #
    2324    #
     
    2526    #
    2627    #
    27     parser = OptionParser()
    28     parser.add_option("--path",
    29         help="Give a path that is used to find the Pyomo python files",
    30         action="store",
    31         dest="path",
    32         type="string",
    33         default=".")
    34     parser.add_option("--help-components",
    35             help="Print information about modeling components supported by Pyomo",
    36             action="store_true",
    37             dest="help_components",
    38             default=False)
    39     parser.add_option('-q','--quiet',
    40         help='Disable all log messages except for those that refer to errors.',
    41         action='store_true',
    42         dest='quiet',
    43         default=False)
    44     parser.add_option('-w','--warning',
    45         help='Enable warning log messages for coopr and pyutilib.',
    46         action='store_true',
    47         dest='warning',
    48         default=False)
    49     parser.add_option('-i','--info',
    50         help='Enable informative log messages for coopr and pyutilib.',
    51         action='store_true',
    52         dest='info',
    53         default=False)
    54     parser.add_option('-v','--verbose',
    55         help="Indicate that debugging log messages should be printed.  This     option can be specified multiple times to add log messages for other parts of   coopr and pyutilib.",
    56         nargs=0,
    57         action='append',
    58         dest='verbose',
    59         default=[])
    60     parser.add_option('-d', '--debug',
    61         help='This option indicates that debugging is performed.  This implies  the verbose flag, but it also allows exceptions to trigger a failure in which   the program stack is printed.',
    62         action='store_true',
    63         dest='debug',
    64         default=False)
    65     parser.add_option("-k","--keepfiles",
    66             help="Keep temporary files",
    67             action="store_true",
    68             dest="keepfiles",
    69             default=False)
    70     parser.add_option("--tempdir",
    71             help="Specify the directory where temporary files are generated",
    72             action="store",
    73             dest="tempdir",
    74             default=None)
    75     parser.add_option("--logfile",
    76             help="Redirect output to the specified logfile",
    77             action="store",
    78             dest="logfile",
    79             default=None)
    80     parser.add_option("--profile",
    81             help="Enable profiling of Python code.  The value of this option is the number of functions that are summarized.",
    82             action="store",
    83             dest="profile",
    84             default=0)
    85     parser.add_option("--preprocess",
    86             help="Specify a Python module that gets immediately executed (before the optimization model is setup).  If this option is specified multiple times, then the modules are executed in the specified order.",
    87             action="append",
    88             dest="preprocess",
    89             default=[])
    90     parser.add_option("--model-name",
    91             help="The name of the model object that is created in the specified Pyomo module",
    92             action="store",
    93             dest="model_name",
    94             type="string",
    95             default="model")
    96     parser.add_option("--model-options",
    97             help="Options passed into a create_model() function to construct the model",
    98             action="append",
    99             dest="model_options",
    100             type="string",
    101             default=[])
    102     parser.add_option("--disable-gc",
    103             help="Disable the garbage collecter",
    104             action="store_true",
    105             dest="disable_gc",
    106             default=False)
    107     parser.add_option("--save-model",
    108             help="Specify the filename to which the model is saved.  The suffix of this filename specifies the file format.  If debugging is on, then this defaults to writing the file 'unknown.lp'.",
    109             action="store",
    110             dest="save_model",
    111             default=True)
    112 
    113     parser.usage=name+" [options] <model.py> [<model.dat>]"
     28    parser = argparse.ArgumentParser(
     29                usage = '%s [options] <model.py> [<model.dat>]' % cmd
     30                )
     31    pyomo.add_model_group(parser)
     32    pyomo.add_logging_group(parser)
     33    pyomo.add_misc_group(parser)
     34    parser.add_argument('model_file', action='store', nargs='?', default='', help='A Python      module that defines a Pyomo model')
     35    parser.add_argument('data_files', action='store', nargs='*', default=[], help='Pyomo data    files that defined data used to create a model instance')
    11436    return parser
    115 
    11637
    11738format = None
    11839
    119 def convert(options=Options(), args=(), parser=None):
     40def convert(options=Options(), parser=None):
    12041    global format
    12142    options.verbose = False
     
    12445        util.print_components(options)
    12546        return Container()
    126     if not util.setup_environment(options, args):
     47    if not util.setup_environment(options):
    12748        return                                               #pragma:nocover
    128     if not util.apply_preprocessing(options, parser, args):
     49    if not util.apply_preprocessing(options, parser):
    12950        return
    130     model = util.create_model(options, args)
     51    model = util.create_model(options)
    13152    return model
    13253
  • coopr.pyomo/trunk/coopr/pyomo/tests/examples/test_pyomo.py

    r3674 r3680  
    1010scriptdir = dirname(dirname(dirname(dirname(dirname(abspath(__file__))))))+os.sep
    1111
    12 from coopr.pyomo import *
     12import coopr.pyomo
    1313import pyutilib.services
    1414import pyutilib.subprocess
     
    2626def filter_fn(line):
    2727    return line.startswith('Disjunct')
     28
    2829
    2930class Test(unittest.TestCase):
     
    8990        """Run pyomo with --instance-only option"""
    9091        output = self.pyomo('--instance-only pmedian.py pmedian.dat', file=currdir+'test8.out')
    91         self.failUnlessEqual(type(output.instance), AbstractModel)
     92        self.failUnlessEqual(type(output.instance), coopr.pyomo.AbstractModel)
    9293        os.remove(currdir+'test8.out')
    9394
     
    9596        """Run pyomo with --disable-gc option"""
    9697        output = self.pyomo('--disable-gc pmedian.py pmedian.dat', file=currdir+'test9.out')
    97         self.failUnlessEqual(type(output.instance), AbstractModel)
     98        self.failUnlessEqual(type(output.instance), coopr.pyomo.AbstractModel)
    9899        os.remove(currdir+'test9.out')
    99100
Note: See TracChangeset for help on using the changeset viewer.