Example #1
0
    else:
        val = pyomo.scripting.util.get_config_values(_options.model_or_config_file)
        config.set_value( val )
    #
    # Note that we pass-in pre-parsed options.  The run_command()
    # function knows to not perform a parse, but instead to simply
    # used these parsed values.
    #
    return pyomo.scripting.util.run_command(command=run_convert, parser=convert_parser, options=config, name='convert')

#
# Add a subparser for the pyomo command
#
convert_parser = create_parser(add_subparser('convert',
        func=convert_exec,
        help='Convert a Pyomo model to another format',
        add_help=False,
        description='This pyomo subcommand is used to create a new model file in a specified format from a Pyomo model.'
        ))



def create_temporary_parser(output=False, generate=False):
    #
    # We create a dummy parser and subparser, to help make the 'help'
    # output seem sensible.
    #
    parser = argparse.ArgumentParser(formatter_class=CustomHelpFormatter)
    _subparsers = parser.add_subparsers()
    _parser = _subparsers.add_parser('convert')
    _parser.formatter_class=CustomHelpFormatter
    if generate:
Example #2
0
            config.model.filename = _options.model_or_config_file
            config.data.files = _options.data_files
        else:
            val = pyomo.scripting.util.get_config_values(_options.model_or_config_file)
            config.set_value(val)

    if config is None:
        raise RuntimeError("Failed to create config object")

    from pyomo.scripting.pyomo_command import run_pyomo
    #
    # Note that we pass-in pre-parsed options.  The run_command()
    # function knows to not perform a parse, but instead to simply
    # used these parsed values.
    #
    return pyomo.scripting.util.run_command(command=run_pyomo,
                                            parser=_parser,
                                            options=config,
                                            name='pyomo solve')

#
# Add a subparser for the solve command
#
solve_parser = create_parser(add_subparser('solve',
    func=solve_exec,
    help='Optimize a model',
    add_help=False,
    description='This pyomo subcommand is used to analyze optimization models.'
    ))

Example #3
0
            try:
                DownloadFactory(target, downloader=self.downloader)
                result = ' OK '
            except SystemExit:
                result = 'FAIL'
                returncode = 1
            except:
                result = 'FAIL'
                returncode = 1
            results.append(result_fmt % (result, target))
        logger.info("Finished downloading Pyomo extensions.")
        logger.info(
            "The following extensions were downloaded:\n    " +
            "\n    ".join(results))
        return returncode


#
# Add a subparser for the download-extensions command
#
_group_downloader = GroupDownloader()
solve_parser = _group_downloader.create_parser(
    add_subparser(
        'download-extensions',
        func=_group_downloader.call,
        help='Download compiled extension modules',
        add_help=False,
        description='This downloads all registered (compiled) extension modules'
    ))

Example #4
0
        for target in ExtensionBuilderFactory:
            try:
                ExtensionBuilderFactory(target)
                result = ' OK '
            except SystemExit:
                result = 'FAIL'
                returncode = 1
            except:
                result = 'FAIL'
                returncode = 1
            results.append(result_fmt % (result, target))
        logger.info("Finished building Pyomo extensions.")
        logger.info(
            "The following extensions were built:\n    " +
            "\n    ".join(results))
        return returncode

#
# Add a subparser for the download-extensions command
#
_extension_builder = ExtensionBuilder()
_parser = _extension_builder.create_parser(
    add_subparser(
        'build-extensions',
        func=_extension_builder.call,
        help='Build compiled extension modules',
        add_help=False,
        description='This builds all registered (compileable) extension modules'
    ))

Example #5
0
    window.show()
    kc = window.jupyter_widget.kernel_client
    time.sleep(2.5)  # can't find any other good way to ensure Qt finished
    # startup. Just making sure the cell execution finishes
    # does not seems to be enough, and trying to check
    # QtAppliction() != None before moving on also does not
    # seem to work. 4 seconds may be too long, but I'm being
    # careful. I split the time between waiting for the console
    # window to show and waiting to start the model viewer so it
    # may not seem to take so long to the user.
    # May be related to:
    # https://github.com/ipython/ipython/issues/5629
    kc.execute("""
from pyomo.contrib.viewer.ui import get_mainwindow
import pyomo.environ as pyo
ui, model = get_mainwindow()""",
               silent=True)
    app.aboutToQuit.connect(window.shutdown_kernel)
    app.exec_()


# Add a subparser for the download-extensions command
add_subparser('model-viewer',
              func=main,
              help='Run the Pyomo model viewer',
              add_help=False,
              description='This runs the Pyomo model viewer')

if __name__ == "__main__":
    main()
Example #6
0
            print("NO  %s" % package)


def pyomo_subcommand(options):
    return install_extras(options.args, quiet=options.quiet)


_parser = add_subparser(
    'install-extras',
    func=pyomo_subcommand,
    help='Install "extra" packages that Pyomo can leverage.',
    description="""
This pyomo subcommand uses PIP to install optional third-party Python
packages that Pyomo could leverage from PyPI.  The installation of some
packages may fail, but this subcommand ignore these failures and
provides a summary describing which packages were installed.
""",
    epilog="""
Since pip options begin with a dash, the --pip-args option can only be
used with the equals syntax.  --pip-args may appear multiple times on
the command line.  For example:\n\n
    pyomo install-extras --pip-args="--upgrade"
""",
    formatter_class=CustomHelpFormatter,
)

_parser.add_argument(
    '-q', '--quiet',
    action='store_true',
    dest='quiet',
    default=False,
    help="Suppress some terminal output",