Пример #1
0
    def saveTemplate(self, filename=None, template_options=None):
        '''
        Save the project as a YAML formatted file. Uses the filename stored in
        opts['configure']['output prefix'], use setConfigureOption('output prefix',f)
        to set this name.
        '''
        if filename is None:
            filename = self.opts['configure']['output prefix'] + '.yml'

        from pywst.common.wst_config import Path
        _SPE = True
        Path.SuppressPathExpansion, _SPE = _SPE, Path.SuppressPathExpansion
        try:
            fid = open(filename, 'wt')
            templ = ConfigBlock("%s configuration template" % self.module)
            for k in self.module_blocks:
                templ.declare(k, self.opts[k]())
            if template_options is not None:
                templ.set_value(template_options)
            fid.write(templ.generate_yaml_template(indent_spacing=2, width=95))
            fid.close()
        except:
            print 'Error saving "%s"' % filename
            raise
        finally:
            Path.SuppressPathExpansion, _SPE = _SPE, Path.SuppressPathExpansion

        print "Writing template file " + filename
        return True
Пример #2
0
 def saveVisOutput(self, outfilename, config, module_blocks,
                   template_options):
     fid = open(outfilename, 'wt')
     templ = ConfigBlock("# YML input file for visualization")
     for k in module_blocks:
         templ.declare(k, config[k]())
     if template_options is not None:
         templ.set_value(template_options)
     fid.write(templ.generate_yaml_template(indent_spacing=2, width=95))
     fid.close()
Пример #3
0
def default_pyomo_config():
    config = ConfigBlock("Pyomo configuration file")

    config.declare('paranoia_level', ConfigValue(
        0, int,
        'Pyomo paranoia and error checking level',
        """Higher levels of paranoia enable additional error checking and
        warning messages that may assist users in identifying likely
        modeling problems.
        Default=0""",
        visibility=ADVANCED_OPTION ) )

    return config
Пример #4
0
 def saveOutput(self, outfilename, config, module_blocks, template_options):
     fid = open(outfilename, 'wt')
     templ = ConfigBlock("%s output" % self.module)
     for k in module_blocks:
         templ.declare(k, config[k]())
     if template_options is not None:
         templ.set_value(template_options)
     if self.opts['configure']['debug']:
         fid.write('---\n')
     fid.write(templ.generate_yaml_template(indent_spacing=2, width=95))
     if self.opts['configure']['debug']:
         fid.write('---\n')
         fid.write("#%s input\n" % self.module)
         out = self.opts.display(content_filter='userdata')
         fid.write(out)
     fid.close()
Пример #5
0
    def test_getattr_setattr(self):
        config = ConfigBlock()
        foo = config.declare('foo', ConfigBlock(implicit=True, implicit_domain=int))
        foo.declare('explicit_bar', ConfigValue(0, int))

        self.assertEqual(1, len(foo))
        self.assertEqual(0, foo['explicit_bar'])
        self.assertEqual(0, foo.explicit_bar)
        foo.explicit_bar = 10
        self.assertEqual(1, len(foo))
        self.assertEqual(10, foo['explicit_bar'])
        self.assertEqual(10, foo.explicit_bar)

        foo.implicit_bar = 20
        self.assertEqual(2, len(foo))
        self.assertEqual(20, foo['implicit bar'])
        self.assertEqual(20, foo.implicit_bar)

        try:
            config.baz = 10
        except ValueError:
            pass
        except:
            raise
        else:
            self.fail("Expected implicit assignment to explicit block to raise ValueError")

        try:
            a = config.baz
        except AttributeError:
            pass
        except:
            raise
        else:
            self.fail("Expected implicit assignment to explicit block to raise ValueError")
Пример #6
0
def _get_GDPopt_config():
    _supported_strategies = {
        'LOA',  # Logic-based outer approximation
        'GLOA',  # Global logic-based outer approximation
        'LBB',  # Logic-based branch-and-bound
    }
    CONFIG = ConfigBlock("GDPopt")
    CONFIG.declare(
        "iterlim",
        ConfigValue(default=100,
                    domain=NonNegativeInt,
                    description="Iteration limit."))
    CONFIG.declare(
        "time_limit",
        ConfigValue(
            default=600,
            domain=PositiveInt,
            description="Time limit (seconds, default=600)",
            doc="Seconds allowed until terminated. Note that the time limit can "
            "currently only be enforced between subsolver invocations. You may "
            "need to set subsolver time limits as well."))
    CONFIG.declare(
        "strategy",
        ConfigValue(default="LOA",
                    domain=In(_supported_strategies),
                    description="Decomposition strategy to use."))
    CONFIG.declare(
        "tee",
        ConfigValue(default=False,
                    description="Stream output to terminal.",
                    domain=bool))
    CONFIG.declare(
        "logger",
        ConfigValue(
            default='pyomo.contrib.gdpopt',
            description="The logger object or name to use for reporting.",
            domain=a_logger))
    _add_OA_configs(CONFIG)
    _add_BB_configs(CONFIG)
    _add_subsolver_configs(CONFIG)
    _add_tolerance_configs(CONFIG)
    return CONFIG
Пример #7
0
    def test_implicit_entries(self):
        config = ConfigBlock()
        try:
            config['test'] = 5
            self.fail("Expected ConfigBlock to throw a ValueError for implicit declarations")
        except ValueError:
            self.assertEqual(
                sys.exc_info()[1].args, 
                ("Key 'test' not defined in Config Block '' and Block disallows implicit entries",) )

        config = ConfigBlock(implicit=True)
        config['implicit_1'] = 5
        config.declare( 'formal', ConfigValue( 42, int ) )
        config['implicit_2'] = 5
        print(config.display())
        self.assertEqual( 3, len(config) )
        self.assertEqual( ['implicit_1','formal','implicit_2'], 
                          list(config.iterkeys()) )
        config.reset()
        self.assertEqual( 1, len(config) )
        self.assertEqual( ['formal'], 
                          list(config.iterkeys()) )
Пример #8
0
def default_config_block(solver, init=False):
    config, blocks = ProblemConfigFactory('default').config_block(init)

    #
    # Solver
    #
    solver = ConfigBlock()
    solver.declare('solver name', ConfigValue('glpk', str, 'Solver name',
                                              None))
    solver.declare(
        'solver executable',
        ConfigValue(
            default=None,
            domain=str,
            description="The solver executable used by the solver interface.",
            doc=
            ("The solver executable used by the solver interface. "
             "This option is only valid for those solver interfaces that "
             "interact with a local executable through the shell. If unset, "
             "the solver interface will attempt to find an executable within "
             "the search path of the shell's environment that matches a name "
             "commonly associated with the solver interface.")))
    solver.declare(
        'io format',
        ConfigValue(
            None, str,
            'The type of IO used to execute the solver. Different solvers support different types of IO, but the following are common options: lp - generate LP files, nl - generate NL files, python - direct Python interface, os - generate OSiL XML files.',
            None))
    solver.declare(
        'manager',
        ConfigValue('serial', str,
                    'The technique that is used to manage solver executions.',
                    None))
    solver.declare(
        'pyro host',
        ConfigValue(
            None, str,
            "The hostname to bind on when searching for a Pyro nameserver.",
            None))
    solver.declare(
        'pyro port',
        ConfigValue(
            None, int,
            "The port to bind on when searching for a Pyro nameserver.", None))
    solver.declare(
        'options',
        ConfigBlock(implicit=True,
                    implicit_domain=ConfigValue(None, str, 'Solver option',
                                                None),
                    description="Options passed into the solver"))
    solver.declare(
        'options string',
        ConfigValue(None, str, 'String describing solver options', None))
    solver.declare(
        'suffixes',
        ConfigList([], ConfigValue(
            None, str, 'Suffix', None
        ), 'Solution suffixes that will be extracted by the solver (e.g., rc, dual, or slack). The use of this option is not required when a suffix has been declared on the model using Pyomo\'s Suffix component.',
                   None))
    blocks['solver'] = solver
    #
    solver_list = config.declare(
        'solvers',
        ConfigList(
            [],
            solver,  #ConfigValue(None, str, 'Solver', None),
            'List of solvers.  The first solver in this list is the master solver.',
            None))
    #
    # Make sure that there is one solver in the list.
    #
    # This will be the solver into which we dump command line options.
    # Note that we CANNOT declare the argparse options on the base block
    # definition above, as we use that definition as the DOMAIN TYPE for
    # the list of solvers.  As that information is NOT copied to
    # derivative blocks, the initial solver entry we are creating would
    # be missing all argparse information. Plus, if we were to have more
    # than one solver defined, we wouldn't want command line options
    # going to both.
    solver_list.append()
    solver_list[0].get('solver name').\
        declare_as_argument('--solver', dest='solver')
    solver_list[0].get('solver executable').\
        declare_as_argument('--solver-executable',
                            dest="solver_executable", metavar="FILE")
    solver_list[0].get('io format').\
        declare_as_argument('--solver-io', dest='io_format', metavar="FORMAT")
    solver_list[0].get('manager').\
        declare_as_argument('--solver-manager', dest="smanager_type",
                            metavar="TYPE")
    solver_list[0].get('pyro host').\
        declare_as_argument('--pyro-host', dest="pyro_host")
    solver_list[0].get('pyro port').\
        declare_as_argument('--pyro-port', dest="pyro_port")
    solver_list[0].get('options string').\
        declare_as_argument('--solver-options', dest='options_string',
                            metavar="STRING")
    solver_list[0].get('suffixes').\
        declare_as_argument('--solver-suffix', dest="solver_suffixes")

    #
    # Postprocess
    #
    config.declare(
        'postprocess',
        ConfigList(
            [], ConfigValue(None, str, 'Module', None),
            'Specify a Python module that gets executed after optimization.',
            None)).declare_as_argument(dest='postprocess')

    #
    # Postsolve
    #
    postsolve = config.declare('postsolve', ConfigBlock())
    postsolve.declare(
        'print logfile',
        ConfigValue(False, bool,
                    'Print the solver logfile after performing optimization.',
                    None)).declare_as_argument('-l', '--log', dest="log")
    postsolve.declare(
        'save results',
        ConfigValue(None, str,
                    'Specify the filename to which the results are saved.',
                    None)).declare_as_argument('--save-results',
                                               dest="save_results",
                                               metavar="FILE")
    postsolve.declare(
        'show results',
        ConfigValue(False, bool,
                    'Print the results object after optimization.',
                    None)).declare_as_argument(dest="show_results")
    postsolve.declare(
        'results format',
        ConfigValue(None, str, 'Specify the results format:  json or yaml.',
                    None)).declare_as_argument(
                        '--results-format',
                        dest="results_format",
                        metavar="FORMAT").declare_as_argument(
                            '--json',
                            dest="results_format",
                            action="store_const",
                            const="json",
                            help="Store results in JSON format")
    postsolve.declare(
        'summary',
        ConfigValue(
            False, bool,
            'Summarize the final solution after performing optimization.',
            None)).declare_as_argument(dest="summary")
    blocks['postsolve'] = postsolve

    #
    # Runtime
    #
    runtime = blocks['runtime']
    runtime.declare(
        'only instance',
        ConfigValue(False, bool, "Generate a model instance, and then exit",
                    None)).declare_as_argument('--instance-only',
                                               dest='only_instance')
    runtime.declare(
        'stream output',
        ConfigValue(
            False, bool,
            "Stream the solver output to provide information about the solver's progress.",
            None)).declare_as_argument('--stream-output',
                                       '--stream-solver',
                                       dest="tee")
    #
    return config, blocks
Пример #9
0
def minlp_config_block(init=False):
    config = ConfigBlock(
        "Configuration for a canonical model construction and optimization sequence"
    )
    blocks = {}

    #
    # Data
    #
    data = config.declare('data', ConfigBlock())
    data.declare(
        'files',
        ConfigList([], ConfigValue(None, str, 'Filename', None),
                   'Model data files', None))
    data.declare(
        'namespaces',
        ConfigList(
            [], ConfigValue(None, str, 'Namespace', None),
            'A namespace that is used to select data in Pyomo data files.',
            None)).declare_as_argument('--namespace',
                                       dest='namespaces',
                                       action='append')
    blocks['data'] = data

    #
    # Model
    #
    model = config.declare('model', ConfigBlock())
    model.declare(
        'filename',
        ConfigValue(None, str, 'The Python module that specifies the model',
                    None))
    model.declare(
        'object name',
        ConfigValue(
            None, str,
            'The name of the model object that is created in the specified Pyomo module',
            None)).declare_as_argument('--model-name', dest='model_name')
    model.declare('type', ConfigValue(None, str, 'The problem type', None))
    model.declare(
        'options',
        ConfigBlock(implicit=True,
                    description='Options used to construct the model'))
    model.declare(
        'linearize expressions',
        ConfigValue(
            False, bool,
            'An option intended for use on linear or mixed-integer models in which expression trees in a model (constraints or objectives) are compacted into a more memory-efficient and concise form.',
            None))
    model.declare(
        'save file',
        ConfigValue(
            None, str,
            "The filename to which the model is saved. The suffix of this filename specifies the file format.",
            None))
    model.declare(
        'save format',
        ConfigValue(
            None, str,
            "The format that the model is saved. When specified, this overrides the format implied by the 'save file' option.",
            None))
    model.declare(
        'symbolic solver labels',
        ConfigValue(
            False, bool,
            'When interfacing with the solver, use symbol names derived from the model. For example, \"my_special_variable[1_2_3]\" instead of \"v1\". Useful for debugging. When using the ASL interface (--solver-io=nl), generates corresponding .row (constraints) and .col (variables) files. The ordering in these files provides a mapping from ASL index to symbolic model names.',
            None)).declare_as_argument(dest='symbolic_solver_labels')
    model.declare(
        'file determinism',
        ConfigValue(
            1, int,
            'When interfacing with a solver using file based I/O, set the effort level for ensuring the file creation process is determistic. The default (1) sorts the index of components when transforming the model. Anything less than 1 disables index sorting. Anything greater than 1 additionaly sorts by component name to override declartion order.',
            None)).declare_as_argument(dest='file_determinism')
    blocks['model'] = model

    #
    # Transform
    #
    transform = ConfigBlock()
    transform.declare(
        'name', ConfigValue(None, str, 'Name of the model transformation',
                            None))
    transform.declare(
        'options',
        ConfigBlock(implicit=True, description='Transformation options'))
    blocks['transform'] = transform
    #
    transform_list = config.declare(
        'transform',
        ConfigList([], ConfigValue(None, str, 'Transformation',
                                   None), 'List of model transformations',
                   None)).declare_as_argument(dest='transformations')
    if init:
        transform_list.append()

    #
    # Preprocess
    #
    config.declare(
        'preprocess',
        ConfigList([], ConfigValue(
            None, str, 'Module', None
        ), 'Specify a Python module that gets immediately executed (before the optimization model is setup).',
                   None)).declare_as_argument(dest='preprocess')

    #
    # Runtime
    #
    runtime = config.declare('runtime', ConfigBlock())
    runtime.declare(
        'logging',
        ConfigValue(None, str,
                    'Logging level:  quiet, warning, info, verbose, debug',
                    None)).declare_as_argument(dest="logging", metavar="LEVEL")
    runtime.declare(
        'logfile',
        ConfigValue(None, str, 'Redirect output to the specified file.',
                    None)).declare_as_argument(dest="output", metavar="FILE")
    runtime.declare(
        'catch errors',
        ConfigValue(
            False, bool,
            'Trigger failures for exceptions to print the program stack.',
            None)).declare_as_argument('-c', '--catch-errors', dest="catch")
    runtime.declare(
        'disable gc',
        ConfigValue(False, bool, 'Disable the garbage collecter.',
                    None)).declare_as_argument('--disable-gc',
                                               dest='disable_gc')
    runtime.declare(
        'interactive',
        ConfigValue(
            False, bool,
            'After executing Pyomo, launch an interactive Python shell. If IPython is installed, this shell is an IPython shell.',
            None))
    runtime.declare('keep files',
                    ConfigValue(False, bool, 'Keep temporary files',
                                None)).declare_as_argument('-k',
                                                           '--keepfiles',
                                                           dest='keepfiles')
    runtime.declare(
        'paths',
        ConfigList([], ConfigValue(None, str, 'Path', None),
                   'Give a path that is used to find the Pyomo python files.',
                   None)).declare_as_argument('--path', dest='path')
    runtime.declare(
        'profile count',
        ConfigValue(
            0, int,
            'Enable profiling of Python code. The value of this option is the number of functions that are summarized.',
            None)).declare_as_argument(dest='profile_count', metavar='COUNT')
    runtime.declare(
        'profile memory',
        ConfigValue(
            0, int,
            "Report memory usage statistics for the generated instance and any associated processing steps. A value of 0 indicates disabled. A value of 1 forces the print of the total memory after major stages of the pyomo script. A value of 2 forces summary memory statistics after major stages of the pyomo script. A value of 3 forces detailed memory statistics during instance creation and various steps of preprocessing. Values equal to 4 and higher currently provide no additional information. Higher values automatically enable all functionality associated with lower values, e.g., 3 turns on detailed and summary statistics.",
            None))
    runtime.declare(
        'report timing',
        ConfigValue(
            False, bool,
            'Report various timing statistics during model construction.',
            None)).declare_as_argument(dest='report_timing')
    runtime.declare(
        'tempdir',
        ConfigValue(
            None, str,
            'Specify the directory where temporary files are generated.',
            None)).declare_as_argument(dest='tempdir')
    blocks['runtime'] = runtime
    #
    return config, blocks
Пример #10
0
def minlp_config_block(init=False):
    config = ConfigBlock("Configuration for a canonical model construction and optimization sequence")
    blocks={}
       
    #
    # Data
    #
    data = config.declare('data', ConfigBlock())
    data.declare('files', ConfigList(
                [],
                ConfigValue(None, str, 'Filename', None),
                'Model data files',
                None) )
    data.declare('namespaces', ConfigList(
                [],
                ConfigValue(None, str, 'Namespace', None),
                'A namespace that is used to select data in Pyomo data files.',
                None) ).declare_as_argument('--namespace', dest='namespaces', action='append')
    blocks['data'] = data

    #
    # Model
    #
    model = config.declare('model', ConfigBlock())
    model.declare('filename', ConfigValue(
                None,
                str,
                'The Python module that specifies the model',
                None ) )
    model.declare('object name', ConfigValue(
                None, 
                str,
                'The name of the model object that is created in the specified Pyomo module',
                None ) ).declare_as_argument('--model-name', dest='model_name') 
    model.declare('type', ConfigValue(
                None,
                str,
                'The problem type',
                None ) )
    model.declare('options', ConfigBlock(
                implicit=True,
                description='Options used to construct the model') )
    model.declare('linearize expressions', ConfigValue(
                False,
                bool,
                'An option intended for use on linear or mixed-integer models in which expression trees in a model (constraints or objectives) are compacted into a more memory-efficient and concise form.',
                None) )
    model.declare('save file', ConfigValue(
                None,
                str,
                "The filename to which the model is saved. The suffix of this filename specifies the file format.",
                None) )
    model.declare('save format', ConfigValue(
                None,
                str,
                "The format that the model is saved. When specified, this overrides the format implied by the 'save file' option.",
                None) )
    model.declare('symbolic solver labels', ConfigValue(
                False,
                bool,
                'When interfacing with the solver, use symbol names derived from the model. For example, \"my_special_variable[1_2_3]\" instead of \"v1\". Useful for debugging. When using the ASL interface (--solver-io=nl), generates corresponding .row (constraints) and .col (variables) files. The ordering in these files provides a mapping from ASL index to symbolic model names.',
                None) ).declare_as_argument(dest='symbolic_solver_labels')
    model.declare('file determinism', ConfigValue(
                1,
                int,
                'When interfacing with a solver using file based I/O, set the effort level for ensuring the file creation process is determistic. The default (1) sorts the index of components when transforming the model. Anything less than 1 disables index sorting. Anything greater than 1 additionaly sorts by component name to override declartion order.',
                None) ).declare_as_argument(dest='file_determinism')
    blocks['model'] = model

    #
    # Transform
    #
    transform = ConfigBlock()
    transform.declare('name', ConfigValue(
                None, 
                str,
                'Name of the model transformation',
                None ) )
    transform.declare('options', ConfigBlock(
                implicit=True,
                description='Transformation options'
                ) )
    blocks['transform'] = transform
    #
    transform_list = config.declare('transform', ConfigList(
                [],
                ConfigValue(None, str, 'Transformation', None),
                'List of model transformations',
                None) ).declare_as_argument(dest='transformations')
    if init:
        transform_list.append()

    #
    # Preprocess
    #
    config.declare('preprocess', ConfigList(
                [],
                ConfigValue(None, str, 'Module', None),
                'Specify a Python module that gets immediately executed (before the optimization model is setup).',
                None) ).declare_as_argument(dest='preprocess')

    #
    # Runtime
    #
    runtime = config.declare('runtime', ConfigBlock())
    runtime.declare('logging', ConfigValue(
                None, 
                str,
                'Logging level:  quiet, warning, info, verbose, debug',
                None) ).declare_as_argument(dest="logging", metavar="LEVEL")
    runtime.declare('logfile', ConfigValue(
                None, 
                str,
                'Redirect output to the specified file.',
                None) ).declare_as_argument(dest="output", metavar="FILE")
    runtime.declare('catch errors', ConfigValue(
                False, 
                bool,
                'Trigger failures for exceptions to print the program stack.',
                None) ).declare_as_argument('-c', '--catch-errors', dest="catch")
    runtime.declare('disable gc', ConfigValue(
                False, 
                bool,
                'Disable the garbage collecter.',
                None) ).declare_as_argument('--disable-gc', dest='disable_gc')
    runtime.declare('interactive', ConfigValue(
                False, 
                bool,
                'After executing Pyomo, launch an interactive Python shell. If IPython is installed, this shell is an IPython shell.',
                None) )
    runtime.declare('keep files', ConfigValue(
                False, 
                bool,
                'Keep temporary files',
                None) ).declare_as_argument('-k', '--keepfiles', dest='keepfiles')
    runtime.declare('paths', ConfigList(
                [], 
                ConfigValue(None, str, 'Path', None),
                'Give a path that is used to find the Pyomo python files.',
                None) ).declare_as_argument('--path', dest='path')
    runtime.declare('profile count', ConfigValue(
                0, 
                int,
                'Enable profiling of Python code. The value of this option is the number of functions that are summarized.',
                None) ).declare_as_argument(dest='profile_count', metavar='COUNT')
    runtime.declare('profile memory', ConfigValue(
                0, 
                int,
                "Report memory usage statistics for the generated instance and any associated processing steps. A value of 0 indicates disabled. A value of 1 forces the print of the total memory after major stages of the pyomo script. A value of 2 forces summary memory statistics after major stages of the pyomo script. A value of 3 forces detailed memory statistics during instance creation and various steps of preprocessing. Values equal to 4 and higher currently provide no additional information. Higher values automatically enable all functionality associated with lower values, e.g., 3 turns on detailed and summary statistics.",
                None) )
    runtime.declare('report timing', ConfigValue(
                False, 
                bool,
                'Report various timing statistics during model construction.',
                None) ).declare_as_argument(dest='report_timing')
    runtime.declare('tempdir', ConfigValue(
                None, 
                str,
                'Specify the directory where temporary files are generated.',
                None) ).declare_as_argument(dest='tempdir')
    blocks['runtime'] = runtime
    #
    return config, blocks
Пример #11
0
def default_config_block(solver, init=False):
    config, blocks = ProblemConfigFactory('default').config_block(init)

    #
    # Solver
    #
    solver = ConfigBlock()
    solver.declare('solver name', ConfigValue(
                'glpk',
                str,
                'Solver name',
                None) ).declare_as_argument('--solver', dest='solver')
    solver.declare('solver executable', ConfigValue(
        default=None,
        domain=str,
        description="The solver executable used by the solver interface.",
        doc=("The solver executable used by the solver interface. "
             "This option is only valid for those solver interfaces that "
             "interact with a local executable through the shell. If unset, "
             "the solver interface will attempt to find an executable within "
             "the search path of the shell's environment that matches a name "
             "commonly associated with the solver interface.")).\
                   declare_as_argument('--solver-executable',
                                       dest="solver_executable", metavar="FILE"))
    solver.declare('io format', ConfigValue(
                None,
                str,
                'The type of IO used to execute the solver. Different solvers support different types of IO, but the following are common options: lp - generate LP files, nl - generate NL files, python - direct Python interface, os - generate OSiL XML files.',
                None) ).declare_as_argument('--solver-io', dest='io_format', metavar="FORMAT")
    solver.declare('manager', ConfigValue(
                'serial',
                str,
                'The technique that is used to manage solver executions.',
                None) ).declare_as_argument('--solver-manager', dest="smanager_type", metavar="TYPE")
    solver.declare('pyro host', ConfigValue(
                None,
                str,
                "The hostname to bind on when searching for a Pyro nameserver.",
                None) ).declare_as_argument('--pyro-host', dest="pyro_host")
    solver.declare('pyro port', ConfigValue(
                None,
                int,
                "The port to bind on when searching for a Pyro nameserver.",
                None) ).declare_as_argument('--pyro-port', dest="pyro_port")
    solver.declare('options', ConfigBlock(
                implicit=True,
                implicit_domain=ConfigValue(
                    None,
                    str,
                    'Solver option',
                    None),
                description="Options passed into the solver") )
    solver.declare('options string', ConfigValue(
                None,
                str,
                'String describing solver options',
                None) ).declare_as_argument('--solver-options', dest='options_string', metavar="STRING")
    solver.declare('suffixes', ConfigList(
                [],
                ConfigValue(None, str, 'Suffix', None),
                'Solution suffixes that will be extracted by the solver (e.g., rc, dual, or slack). The use of this option is not required when a suffix has been declared on the model using Pyomo\'s Suffix component.',
                None) ).declare_as_argument('--solver-suffix', dest="solver_suffixes")
    blocks['solver'] = solver
    #
    solver_list = config.declare('solvers', ConfigList(
                [],
                solver, #ConfigValue(None, str, 'Solver', None),
                'List of solvers.  The first solver in this list is the master solver.',
                None) )
    solver_list.append()

    #
    # Postprocess
    #
    config.declare('postprocess', ConfigList(
                [],
                ConfigValue(None, str, 'Module', None),
                'Specify a Python module that gets executed after optimization.',
                None) ).declare_as_argument(dest='postprocess')

    #
    # Postsolve
    #
    postsolve = config.declare('postsolve', ConfigBlock())
    postsolve.declare('print logfile', ConfigValue(
                False,
                bool,
                'Print the solver logfile after performing optimization.',
                None) ).declare_as_argument('-l', '--log', dest="log")
    postsolve.declare('save results', ConfigValue(
                None,
                str,
                'Specify the filename to which the results are saved.',
                None) ).declare_as_argument('--save-results', dest="save_results", metavar="FILE")
    postsolve.declare('show results', ConfigValue(
                False,
                bool,
                'Print the results object after optimization.',
                None) ).declare_as_argument(dest="show_results")
    postsolve.declare('results format', ConfigValue(
                None,
                str,
                'Specify the results format:  json or yaml.',
                None) ).declare_as_argument('--results-format', dest="results_format", metavar="FORMAT").declare_as_argument('--json', dest="results_format", action="store_const", const="json", help="Store results in JSON format")
    postsolve.declare('summary', ConfigValue(
                False,
                bool,
                'Summarize the final solution after performing optimization.',
                None) ).declare_as_argument(dest="summary")
    blocks['postsolve'] = postsolve

    #
    # Runtime
    #
    runtime = blocks['runtime']
    runtime.declare('only instance', ConfigValue(
                False,
                bool,
                "Generate a model instance, and then exit",
                None) ).declare_as_argument('--instance-only', dest='only_instance')
    runtime.declare('stream output', ConfigValue(
                False,
                bool,
                "Stream the solver output to provide information about the solver's progress.",
                None) ).declare_as_argument('--stream-output', '--stream-solver', dest="tee")
    #
    return config, blocks
Пример #12
0
    fid.close()

# tevasim
target = 'tevasim_config.yml'
if target in targets or not targets:
    if target in targets: targets.remove(target)
    run(wst + ['tevasim', '--template', target])

target = 'tevasim_config.tex'
if target in targets or not targets:
    if target in targets: targets.remove(target)
    sys.stdout.write("Writing documentation file %s\n" % target)
    fid = open(target, 'w')
    tevasim = ConfigBlock('tevasim configuration template')
    for k in ('network', 'scenario', 'configure'):
        tevasim.declare(k, config[k]())
    fid.write(tevasim.generate_documentation())
    fid.close()

# sim2Impact
target = 'sim2Impact_config.yml'
if target in targets or not targets:
    if target in targets: targets.remove(target)
    run(wst + ['sim2Impact', '--template', target])

target = 'sim2Impact_config.tex'
if target in targets or not targets:
    if target in targets: targets.remove(target)
    sys.stdout.write("Writing documentation file %s\n" % target)
    fid = open(target, 'w')
    sim2Impact = ConfigBlock('sim2Impact configuration template')