Changeset 3679


Ignore:
Timestamp:
Feb 20, 2011 6:16:48 PM (9 years ago)
Author:
wehart
Message:

A major rework of command-line options that are supported for the
pyomo command. This now uses the argparse package, which is supported in
future Python releases.

Location:
coopr.pyomo/trunk/coopr/pyomo/scripting
Files:
3 edited

Legend:

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

    r3617 r3679  
    3737            dest="help_components",
    3838            default=False)
    39     parser.add_option('-d', "--debug",
    40             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.',
    41             action="store_true",
    42             dest="debug",
    43             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)
    4454    parser.add_option('-v','--verbose',
    45         help="Indicate that debugging log messages should be printed.  This option also triggers the '-i' and '-w' options.  This option can be          specified multiple times to add log messages for other parts of coopr and pyutilib.",
     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.",
    4656        nargs=0,
    4757        action='append',
    4858        dest='verbose',
    4959        default=[])
    50     parser.add_option('-w', '--warning',
    51         help="Indicate that warning log messages should be printed.  This option can be specified multiple times to add log messages for other parts of  coopr and pyutilib.",
    52         nargs=0,
    53         action='append',
    54         dest='warning',
    55         default=[])
    56     parser.add_option('-i', '--info',
    57         help="Indicate that informative log messages should be printed.  This option also triggers the '-w' option.  This option can be specified        multiple times to add log messages for other parts of coopr and pyutilib.",
    58         nargs=0,
    59         action='append',
    60         dest='info',
    61         default=[])
    62 
     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)
    6365    parser.add_option("-k","--keepfiles",
    6466            help="Keep temporary files",
     
    7173            dest="tempdir",
    7274            default=None)
    73     parser.add_option("-q","--quiet",
    74             help="Turn off solver output",
    75             action="store_true",
    76             dest="quiet",
    77             default=False)
    7875    parser.add_option("--logfile",
    7976            help="Redirect output to the specified logfile",
  • coopr.pyomo/trunk/coopr/pyomo/scripting/pyomo.py

    r3617 r3679  
    1010
    1111
    12 from optparse import OptionParser, OptionGroup
     12import argparse
    1313from coopr.opt.base import SolverFactory
    1414from coopr.opt.parallel import SolverManagerFactory
     
    3636import gc
    3737
     38
     39def add_model_group(parser):
     40    group = parser.add_argument_group('Model Options')
     41
     42    group.add_argument('--preprocess', '--load',
     43        help='Specify a Python module that gets immediately executed (before '\
     44             'the optimization model is setup).  If this option is specified '\
     45             'multiple times, then the modules are executed in the specified '\
     46             'order.',
     47        action='append',
     48        dest='preprocess',
     49        default=[])
     50    group.add_argument('--instance-only',
     51        help='Generate a model instance, and then return',
     52        action='store_true',
     53        dest='only_instance',
     54        default=False)
     55    group.add_argument('--model-name',
     56        help='The name of the model object that is created in the specified ' \
     57             'Pyomo module',
     58        action='store',
     59        dest='model_name',
     60        default='model')
     61    group.add_argument('--model-options',
     62        help='Options passed into a create_model() function to construct the '\
     63             'model',
     64        action='append',
     65        dest='model_options',
     66        default=[])
     67    group.add_argument("--flatten-expressions", "--linearize-expressions",
     68        help="EXPERIMENTAL: An option intended for use on linear or mixed-integer models " \
     69             "in which expression trees in a model (constraints or objectives) are compacted " \
     70             "into a more memory-efficient and concise form. The trees themselves are eliminated. ",
     71        action="store_true",
     72        dest="linearize_expressions",
     73        default=False)
     74    group.add_argument("--skip-canonical-repn",
     75            help="Do not create the canonical representation. This is not necessary for solvers (e.g., ASL-based) that do not require it.",
     76            action="store_true",
     77            dest="skip_canonical_repn",
     78            default=False)
     79    group.add_argument('--save-model',
     80        help='Specify the filename to which the model is saved.  The suffix ' \
     81             'of this filename specifies the file format.  If debugging is '  \
     82             "on, then this defaults to writing the file 'unknown.lp'.",
     83        action='store',
     84        dest='save_model',
     85        default=None)
     86
     87
     88def add_logging_group(parser):
     89    group = parser.add_argument_group('Logging Options')
     90
     91    group.add_argument('-q','--quiet',
     92        help='Disable all log messages except for those that refer to errors.',
     93        action='store_true',
     94        dest='quiet',
     95        default=False)
     96    group.add_argument('-w','--warning',
     97        help='Enable warning log messages for coopr and pyutilib.',
     98        action='store_true',
     99        dest='warning',
     100        default=False)
     101    group.add_argument('-i','--info',
     102        help='Enable informative log messages for coopr and pyutilib.',
     103        action='store_true',
     104        dest='info',
     105        default=False)
     106    group.add_argument('-v','--verbose',
     107        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.",
     108        action='count',
     109        dest='verbose',
     110        default=0)
     111    group.add_argument('-d', '--debug',
     112        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.',
     113        action='store_true',
     114        dest='debug',
     115        default=False)
     116
     117
     118def add_solver_group(parser):
     119    solver_help=\
     120        "This option specifies the type of solver that is used "\
     121        "to solve the Pyomo model instance.  The following solver "\
     122        "types are are currently supported:"
     123    solver_list = SolverFactory.services()
     124    solver_list = sorted( filter(lambda x: '_' != x[0], solver_list) )
     125    solver_help += " %s." % ', '.join(solver_list)
     126
     127    parser.add_argument('--help-solvers',
     128        help='Print information about the solvers that are available',
     129        action='store_true',
     130        dest='help_solvers',
     131        default=False)
     132
     133    group = parser.add_argument_group('Solver Options')
     134
     135    group.add_argument('--solver',
     136        help=solver_help,
     137        action='store',
     138        dest='solver',
     139        #choices=solver_list,
     140        default='glpk')
     141    group.add_argument('--solver-manager',
     142        help='Specify the technique that is used to manage solver executions.',
     143        action='store',
     144        dest='smanager_type',
     145        #type='choice',
     146        choices=SolverManagerFactory.services(),
     147        default='serial')
     148    group.add_argument('--solver-mipgap',
     149        help='The solver termination mipgap',
     150        action='store',
     151        dest='solver_mipgap',
     152        type=float,
     153        default=None)
     154    group.add_argument('--solver-options',
     155        help='Options passed into the solver',
     156        action='append',
     157        dest='solver_options',
     158        default=[])
     159    group.add_argument('--solver-suffixes',
     160        help='One or more solution suffixes to be extracted by the solver',
     161        action='append',
     162        dest='solver_suffixes',
     163        default=[])
     164    group.add_argument('--timelimit',
     165        help='Limit to the number of seconds that the solver is run',
     166        action='store',
     167        dest='timelimit',
     168        type=int,
     169        default=0)
     170
     171def add_postsolve_group(parser):
     172    group = parser.add_argument_group('Post-Solve Options')
     173
     174    group.add_argument('--postprocess',
     175        help='Specify a Python module that gets executed after optimization. ' \
     176             'If this option is specified multiple times, then the modules '  \
     177             'are executed in the specified order.',
     178        action='append',
     179        dest='postprocess',
     180        default=[])
     181    group.add_argument('-l','--log',
     182        help='Print the solver logfile after performing optimization',
     183        action='store_true',
     184        dest='log',
     185        default=False)
     186    group.add_argument('--logfile',
     187        help='Redirect output to the specified logfile',
     188        action='store',
     189        dest='logfile',
     190        default=None)
     191    group.add_argument('--save-results',
     192        help='Specify the filename to which the results are saved.',
     193        action='store',
     194        dest='save_results',
     195        default=None)
     196    group.add_argument('--stream-output',
     197        help='Stream the solver output to provide information about the '     \
     198             "solver's progress.",
     199        action='store_true',
     200        dest='tee',
     201        default=False)
     202    group.add_argument('-s','--summary',
     203        help='Summarize the final solution after performing optimization',
     204        action='store_true',
     205        dest='summary',
     206        default=False)
     207
     208def add_misc_group(parser):
     209    parser.add_argument('--help-components',
     210        help='Print information about modeling components supported by Pyomo',
     211        action='store_true',
     212        dest='help_components',
     213        default=False)
     214
     215    group = parser.add_argument_group('Miscellaneous Options')
     216
     217    group.add_argument('--disable-gc',
     218        help='Disable the garbage collecter',
     219        action='store_true',
     220        dest='disable_gc',
     221        default=False)
     222    group.add_argument('--interactive',
     223        help='After executing Pyomo, launch an interactive Python shell.  If IPython is installed, this shell is an IPython shell.',
     224        action='store_true',
     225        dest='interactive',
     226        default=False)
     227    group.add_argument('-k','--keepfiles',
     228        help='Keep temporary files',
     229        action='store_true',
     230        dest='keepfiles',
     231        default=False)
     232    group.add_argument('--path',
     233        help='Give a path that is used to find the Pyomo python files',
     234        action='store',
     235        dest='path',
     236        default='.')
     237    group.add_argument('--profile',
     238        help='Enable profiling of Python code.  The value of this option is ' \
     239             'the number of functions that are summarized.',
     240        action='store',
     241        dest='profile',
     242        type=int,
     243        default=0)
     244    if pympler_available is True:
     245       group.add_argument("--profile-memory",
     246                            help="If Pympler is available, report memory usage statistics for the generated instance and any associated processing steps. A value of 0 indicates disabled. A value of 1 forces summary memory statistics after major stages of the pyomo script. A value of 2 forces detailed memory statistics during instance creation and various steps of preprocessing. Values equal to 3 and higher currently provide no additional information. Higher values automatically enable all functionality associated with lower values, e.g., 2 turns on detailed and summary statistics.",
     247                            action="store",
     248                            dest="profile_memory",
     249                            type=int,
     250                            default=0)
     251
     252    group.add_argument('--tempdir',
     253        help='Specify the directory where temporary files are generated',
     254        action='store',
     255        dest='tempdir',
     256        default=None)
     257   
     258
    38259def create_parser():
    39260    #
     
    42263    #
    43264    #
    44     solver_help=\
    45     "This option specifies the type of solver that is used "\
    46     "to solve the Pyomo model instance.  The following solver "\
    47     "types are are currently supported:"
    48     solver_list = SolverFactory.services()
    49     solver_list = sorted( filter(lambda x: '_' != x[0], solver_list) )
    50     solver_help += " %s.  Default: glpk." % ', '.join(solver_list)
    51 
    52     parser = OptionParser()
    53     parser.usage = 'pyomo [options] <model.py> [<model.dat>]'
    54 
    55     modelOpts = OptionGroup( parser, 'Model Options')
    56     solverOpts = OptionGroup( parser, 'Solver Options')
    57     outputOpts = OptionGroup( parser, 'Output Options')
    58     otherOpts  = OptionGroup( parser, 'Other Options')
    59     parser.add_option_group( modelOpts )
    60     parser.add_option_group( solverOpts )
    61     parser.add_option_group( outputOpts )
    62     parser.add_option_group( otherOpts )
    63 
    64 
    65     modelOpts.add_option('--preprocess', '--load',
    66         help='Specify a Python module that gets immediately executed (before '\
    67              'the optimization model is setup).  If this option is specified '\
    68              'multiple times, then the modules are executed in the specified '\
    69              'order.',
    70         action='append',
    71         dest='preprocess',
    72         default=[])
    73     otherOpts.add_option('--instance-only',
    74         help='Generate a model instance, and then return',
    75         action='store_true',
    76         dest='only_instance',
    77         default=False)
    78     modelOpts.add_option('--model-name',
    79         help='The name of the model object that is created in the specified ' \
    80              'Pyomo module',
    81         action='store',
    82         dest='model_name',
    83         type='string',
    84         default='model')
    85     modelOpts.add_option('--model-options',
    86         help='Options passed into a create_model() function to construct the '\
    87              'model',
    88         action='append',
    89         dest='model_options',
    90         type='string',
    91         default=[])
    92     modelOpts.add_option("--flatten-expressions", "--linearize-expressions",
    93         help="EXPERIMENTAL: An option intended for use on linear or mixed-integer models " \
    94              "in which expression trees in a model (constraints or objectives) are compacted " \
    95              "into a more memory-efficient and concise form. The trees themselves are eliminated. ",
    96         action="store_true",
    97         dest="linearize_expressions",
    98         default=False)
    99 
    100     solverOpts.add_option('--postprocess',
    101         help='Specify a Python module that gets executed after optimization.' \
    102              'If this option is specified multiple times, then the modules '  \
    103              'are executed in the specified order.',
    104         action='append',
    105         dest='postprocess',
    106         default=[])
    107     solverOpts.add_option('--solver',
    108         help=solver_help,
    109         action='store',
    110         dest='solver',
    111         type='string',
    112         #choices=solver_list,
    113         default='glpk')
    114     solverOpts.add_option('--solver-manager',
    115         help='Specify the technique that is used to manage solver executions.',
    116         action='store',
    117         dest='smanager_type',
    118         type='choice',
    119         choices=SolverManagerFactory.services(),
    120         default='serial')
    121     solverOpts.add_option('--solver-mipgap',
    122         help='The solver termination mipgap',
    123         action='store',
    124         dest='solver_mipgap',
    125         type='float',
    126         default=None)
    127     solverOpts.add_option('--solver-options',
    128         help='Options passed into the solver',
    129         action='append',
    130         dest='solver_options',
    131         type='string',
    132         default=[])
    133     solverOpts.add_option('--solver-suffixes',
    134         help='One or more solution suffixes to be extracted by the solver',
    135         action='append',
    136         dest='solver_suffixes',
    137         type='string',
    138         default=[])
    139     solverOpts.add_option('--timelimit',
    140         help='Limit to the number of seconds that the solver is run',
    141         action='store',
    142         dest='timelimit',
    143         type='int',
    144         default=0)
    145 
    146     outputOpts.add_option('-d', '--debug',
    147         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.',
    148         action='store_true',
    149         dest='debug',
    150         default=False)
    151     outputOpts.add_option('-l','--log',
    152         help='Print the solver logfile after performing optimization',
    153         action='store_true',
    154         dest='log',
    155         default=False)
    156     outputOpts.add_option('--logfile',
    157         help='Redirect output to the specified logfile',
    158         action='store',
    159         dest='logfile',
    160         type='string',
    161         default=None)
    162     outputOpts.add_option('-q','--quiet',
    163         help='Turn off solver output',
    164         action='store_true',
    165         dest='quiet',
    166         default=False)
    167     outputOpts.add_option('--save-model',
    168         help='Specify the filename to which the model is saved.  The suffix ' \
    169              'of this filename specifies the file format.  If debugging is '  \
    170              "on, then this defaults to writing the file 'unknown.lp'.",
    171         action='store',
    172         dest='save_model',
    173         type='string',
    174         default=None)
    175     outputOpts.add_option('--save-results',
    176         help='Specify the filename to which the results are saved.',
    177         action='store',
    178         dest='save_results',
    179         type='string',
    180         default=None)
    181     outputOpts.add_option('--stream-output',
    182         help='Stream the solver output to provide information about the '     \
    183              "solver's progress.",
    184         action='store_true',
    185         dest='tee',
    186         default=False)
    187     outputOpts.add_option('-s','--summary',
    188         help='Summarize the final solution after performing optimization',
    189         action='store_true',
    190         dest='summary',
    191         default=False)
    192     outputOpts.add_option('-v','--verbose',
    193         help="Indicate that debugging log messages should be printed.  This option also triggers the '-i' and '-w' options.  This option can be specified multiple times to add log messages for other parts of coopr and pyutilib.",
    194         nargs=0,
    195         action='append',
    196         dest='verbose',
    197         default=[])
    198     outputOpts.add_option('-w', '--warning',
    199         help="Indicate that warning log messages should be printed.  This option can be specified multiple times to add log messages for other parts of coopr and pyutilib.",
    200         nargs=0,
    201         action='append',
    202         dest='warning',
    203         default=[])
    204     outputOpts.add_option('-i', '--info',
    205         help="Indicate that informative log messages should be printed.  This option also triggers the '-w' option.  This option can be specified multiple times to add log messages for other parts of coopr and pyutilib.",
    206         nargs=0,
    207         action='append',
    208         dest='info',
    209         default=[])
    210 
    211     otherOpts.add_option('--disable-gc',
    212         help='Disable the garbage collecter',
    213         action='store_true',
    214         dest='disable_gc',
    215         default=False)
    216     parser.add_option('--help-components',
    217         help='Print information about modeling components supported by Pyomo',
    218         action='store_true',
    219         dest='help_components',
    220         default=False)
    221     parser.add_option('--help-solvers',
    222         help='Print information about the solvers that are available',
    223         action='store_true',
    224         dest='help_solvers',
    225         default=False)
    226     otherOpts.add_option('--interactive',
    227         help='After executing Pyomo, launch an interactive Python shell.  If IPython is installed, this shell is an IPython shell.',
    228         action='store_true',
    229         dest='interactive',
    230         default=False)
    231     otherOpts.add_option('-k','--keepfiles',
    232         help='Keep temporary files',
    233         action='store_true',
    234         dest='keepfiles',
    235         default=False)
    236     otherOpts.add_option('--path',
    237         help='Give a path that is used to find the Pyomo python files',
    238         action='store',
    239         dest='path',
    240         type='string',
    241         default='.')
    242     otherOpts.add_option('--profile',
    243         help='Enable profiling of Python code.  The value of this option is ' \
    244              'the number of functions that are summarized.',
    245         action='store',
    246         dest='profile',
    247         type='int',
    248         default=0)
    249 
    250     if pympler_available is True:
    251        otherOpts.add_option("--profile-memory",
    252                             help="If Pympler is available, report memory usage statistics for the generated instance and any associated processing steps. A value of 0 indicates disabled. A value of 1 forces summary memory statistics after major stages of the pyomo script. A value of 2 forces detailed memory statistics during instance creation and various steps of preprocessing. Values equal to 3 and higher currently provide no additional information. Higher values automatically enable all functionality associated with lower values, e.g., 2 turns on detailed and summary statistics.",
    253                             action="store",
    254                             dest="profile_memory",
    255                             type="int",
    256                             default=0)
    257 
    258     otherOpts.add_option('--tempdir',
    259         help='Specify the directory where temporary files are generated',
    260         action='store',
    261         dest='tempdir',
    262         type='string',
    263         default=None)
    264    
    265     otherOpts.add_option("--skip-canonical-repn",
    266             help="Do not create the canonical representation. This is not necessary for solvers (e.g., ASL-based) that do not require it.",
    267             action="store_true",
    268             dest="skip_canonical_repn",
    269             default=False)
    270     #
    271     # These options are depricated until we have a specific use-case for them
    272     #
    273     ##if False:
    274     ##  parser.add_option("--seed",
    275     ##        help="Specify a seed to derandomize the solver",
    276     ##        action="store",
    277     ##        dest="seed",
    278     ##        type="int",
    279     ##        default=0)
    280     ##  parser.add_option("--first-feasible",
    281     ##        help="Terminate after the first feasible incumbent",
    282     ##        action="store_true",
    283     ##        dest="ff",
    284     ##        default=False)
    285 
     265    parser = argparse.ArgumentParser(
     266                usage = '%(prog)s [options] <model.py> [<model.dat>]'
     267                )
     268    add_model_group(parser)
     269    add_solver_group(parser)
     270    add_postsolve_group(parser)
     271    add_logging_group(parser)
     272    add_misc_group(parser)
     273    parser.add_argument('model_file', action='store', nargs='?', default='', help='A Python module that defines a Pyomo model')
     274    parser.add_argument('data_files', action='store', nargs='*', default=[], help='Pyomo data files that defined data used to create a model instance')
    286275    return parser
    287276
    288277
    289 def run_pyomo(options=Options(), args=(), parser=None):
     278def run_pyomo(options=Options(), parser=None):
    290279
    291280    if (pympler_available is True) and (options.profile_memory >= 1):
     
    298287        util.print_solver_help(options)
    299288        return Container()
    300     if not util.setup_environment(options, args):
     289    if not util.setup_environment(options):
    301290        return Container()                                   #pragma:nocover
    302     if not util.apply_preprocessing(options, parser, args):
     291    if not util.apply_preprocessing(options, parser):
    303292        return Container()                                   #pragma:nocover
    304293    if (pympler_available is True) and (options.profile_memory >= 1):
     
    308297       summary.print_(summary_before_instance_creation, limit=50)                   
    309298       
    310     model_data = util.create_model(options, args)
     299    model_data = util.create_model(options)
    311300   
    312301    if (pympler_available is True) and (options.profile_memory >= 1):
  • coopr.pyomo/trunk/coopr/pyomo/scripting/util.py

    r3665 r3679  
    103103# Setup Pyomo execution environment
    104104#
    105 def setup_environment(options, args):
     105def setup_environment(options):
    106106    #
    107107    # Disable garbage collection
     
    127127        """
    128128        global filter_excepthook
    129         if len(args) > 0:
    130             model=args[0]
    131             name = "model " + model
     129        if len(options.model_file) > 0:
     130            name = "model " + options.model_file
    132131        else:
    133             model = ""
    134132            name = "model"
    135133
     
    160158            while i < len(tb_list):
    161159                #print "Y",model,tb_list[i][0]
    162                 if model in tb_list[i][0]:
     160                if options.model_file in tb_list[i][0]:
    163161                    break
    164162                i += 1
     
    178176# Execute preprocessing files
    179177#
    180 def apply_preprocessing(options, parser, args):
     178def apply_preprocessing(options, parser):
    181179    global filter_excepthook
    182180    #
     
    185183    #
    186184    #
    187     if len(args) == 0:
     185    if len(options.model_file) == 0:
    188186        parser.print_help()
    189187        return False
     
    197195    #
    198196    filter_excepthook=True
    199     options.usermodel = pyutilib.misc.import_file(args[0])
     197    options.usermodel = pyutilib.misc.import_file(options.model_file)
    200198    filter_excepthook=False
    201199
     
    217215            msg = "Preprocessing function 'pyomo_preprocess' defined in file" \
    218216                  " '%s', but model is already constructed!"
    219             raise SystemExit, msg % args[0]
     217            raise SystemExit, msg % options.model_file
    220218        getattr(options.usermodel, 'pyomo_preprocess')( options=options )
    221219
     
    228226#       create_model(options, model_file=None, data_files=None, modeldata=None)
    229227#
    230 def create_model(options, args):
     228def create_model(options):
    231229    #
    232230    # Verify that files exist
    233231    #
    234     for file in args:
     232    for file in [options.model_file]+options.data_files:
    235233        if not os.path.exists(file):
    236234            raise IOError, "File "+file+" does not exist!"
     
    246244            msg = "Model construction function 'create_model' defined in "    \
    247245                  "file '%s', but model is already constructed!"
    248             raise SystemExit, msg % args[0]
     246            raise SystemExit, msg % options.model_file
    249247        model = getattr(options.usermodel, model_name)
    250248
    251249        if model is None:
    252250            msg = "'%s' object is 'None' in module %s"
    253             raise SystemExit, msg % (model_name, args[0])
     251            raise SystemExit, msg % (model_name, options.model_file)
    254252            sys.exit(0)
    255253
     
    258256           msg = "Neither '%s' nor 'pyomo_create_model' are available in "    \
    259257                 'module %s'
    260            raise SystemExit, msg % ( model_name, args[0] )
     258           raise SystemExit, msg % ( model_name, options.model_file )
    261259       elif len(ep) > 1:
    262260           msg = 'Multiple model construction plugins have been registered!'
     
    295293        modeldata = ModelData()
    296294
    297     if len(args) > 2:
     295    if len(options.data_files) > 1:
    298296        #
    299297        # Load a list of *.dat files
    300298        #
    301         for file in args[1:]:
     299        for file in options.data_files:
    302300            suffix = (file).split(".")[-1]
    303301            if suffix != "dat":
     
    315313           instance = model.create(modeldata)
    316314
    317     elif len(args) == 2:
     315    elif len(options.data_files) == 1:
    318316       #
    319317       # Load a *.dat file or process a *.py data file
    320318       #
    321        suffix = (args[1]).split(".")[-1]
     319       suffix = (options.data_files[0]).split(".")[-1]
    322320       if suffix == "dat":
    323321          if not options.profile_memory is None:
    324              instance = model.create(args[1], profile_memory=options.profile_memory)
     322             instance = model.create(options.data_files[0], profile_memory=options.profile_memory)
    325323          else:
    326              instance = model.create(args[1])
     324             instance = model.create(options.data_files[0])
    327325       elif suffix == "py":
    328           userdata = pyutilib.misc.import_file(args[1])
     326          userdata = pyutilib.misc.import_file(options.data_files[0])
    329327          if "modeldata" in dir(userdata):
    330328                if len(ep) == 1:
     
    335333                if userdata.modeldata is None:
    336334                    msg = "'modeldata' object is 'None' in module %s"
    337                     raise SystemExit, msg % str( args[1] )
     335                    raise SystemExit, msg % str( options.data_files[0] )
    338336
    339337                modeldata=userdata.modeldata
     
    343341                    msg = "Neither 'modeldata' nor 'pyomo_create_model_data"  \
    344342                          'is defined in module %s'
    345                     raise SystemExit, msg % str( args[1] )
     343                    raise SystemExit, msg % str( options.data_files[0] )
    346344
    347345          modeldata.read(model)
     
    351349             instance = model.create(modeldata)
    352350       else:
    353           raise ValueError, "Unknown data file type: "+args[1]
     351          raise ValueError, "Unknown data file type: "+options.data_files[0]
    354352    else:
    355353       if not options.profile_memory is None:
     
    379377        if options.save_model == True:
    380378            if options.format in (ProblemFormat.cpxlp, ProblemFormat.lpxlp):
    381                 fname = (args[1])[:-3]+'lp'
     379                fname = (options.data_files[0])[:-3]+'lp'
    382380            else:
    383                 fname = (args[1])[:-3]+str(options.format)
     381                fname = (options.data_files[0])[:-3]+str(options.format)
    384382            format=options.format
    385383        else:
     
    530528    #
    531529    try:
    532        (_options, nargs) = parser.parse_args(args=args)
     530       _options = parser.parse_args(args=args)
    533531       # Replace the parser options object with a pyutilib.misc.Options object
    534532       options = pyutilib.misc.Options()
     
    549547    logging.getLogger('pyutilib').setLevel(logging.ERROR)
    550548    #
    551     if len(options.warning) > 0:
    552         if len(options.warning) >= 1:
    553             logger.setLevel(logging.WARNING)
    554         if len(options.warning) >= 2:
    555             logging.getLogger('coopr').setLevel(logging.WARNING)
    556         if len(options.warning) >= 3:
    557             logging.getLogger('pyutilib').setLevel(logging.WARNING)
    558     if len(options.info) > 0:
    559         if len(options.info) >= 1:
    560             logger.setLevel(logging.INFO)
    561         if len(options.info) >= 2:
    562             logging.getLogger('coopr').setLevel(logging.INFO)
    563         if len(options.info) >= 3:
    564             logging.getLogger('pyutilib').setLevel(logging.INFO)
    565     if len(options.verbose) > 0:
    566         if len(options.verbose) >= 1:
     549    if options.warning:
     550        logging.getLogger('coopr.pyomo').setLevel(logging.WARNING)
     551        logging.getLogger('coopr').setLevel(logging.WARNING)
     552        logging.getLogger('pyutilib').setLevel(logging.WARNING)
     553    if options.info:
     554        logging.getLogger('coopr.pyomo').setLevel(logging.INFO)
     555        logging.getLogger('coopr').setLevel(logging.INFO)
     556        logging.getLogger('pyutilib').setLevel(logging.INFO)
     557    if options.verbose > 0:
     558        if options.verbose >= 1:
    567559            logger.setLevel(logging.DEBUG)
    568         if len(options.verbose) >= 2:
     560        if options.verbose >= 2:
    569561            logging.getLogger('coopr').setLevel(logging.DEBUG)
    570         if len(options.verbose) >= 3:
     562        if options.verbose >= 3:
    571563            logging.getLogger('pyutilib').setLevel(logging.DEBUG)
    572564    if options.debug:
    573         logger.setLevel(logging.DEBUG)
     565        logging.getLogger('coopr.pyomo').setLevel(logging.DEBUG)
    574566        logging.getLogger('coopr').setLevel(logging.DEBUG)
    575567        logging.getLogger('pyutilib').setLevel(logging.DEBUG)
     
    592584        tfile = TempfileManager.create_tempfile(suffix=".profile")
    593585        tmp = profile.runctx(
    594           command.__name__ + '(options=options,args=nargs,parser=parser)', command.__globals__, locals(), tfile
     586          command.__name__ + '(options=options,parser=parser)', command.__globals__, locals(), tfile
    595587        )
    596588        p = pstats.Stats(tfile).strip_dirs()
     
    614606        #
    615607        try:
    616             ans = command(options=options, args=nargs, parser=parser)
     608            ans = command(options=options, parser=parser)
    617609        except SystemExit, err:
    618610            if __debug__:
     
    630622                    raise
    631623
    632             if len(nargs) > 0:
    633                 model=nargs[0]
    634                 name = "model " + model
     624            if len(options.model_file) > 0:
     625                name = "model " + options.model_file
    635626            else:
    636                 model = ""
    637627                name = "model"
    638628               
Note: See TracChangeset for help on using the changeset viewer.