예제 #1
0
 def _declare_options(cls, options=None):
     if options is None:
         options = PySPConfigBlock()
     safe_declare_common_option(options,
                                "verbose",
                                ap_group=_rho_group_label)
     return options
예제 #2
0
    def test_declared(self):
        b = PySPConfigBlock()
        safe_register_common_option(b, "verbose")
        b.display()
        b.display()
        out = StringIO()
        b.display(ostream=out)
        self.assertEqual(out.getvalue(), "verbose: false\n")
        self.assertEqual(b.check_usage(), True)
        self.assertEqual(b.check_usage(error=False), True)
        b.verbose = True
        out = StringIO()
        b.display(ostream=out)
        self.assertEqual(out.getvalue(), "verbose: true\n")
        with self.assertRaises(ValueError):
            b.check_usage()
        with self.assertRaises(ValueError):
            b.check_usage()
        self.assertEqual(b.check_usage(error=False), False)
        b.verbose
        self.assertEqual(b.check_usage(), True)
        self.assertEqual(b.check_usage(error=False), True)
        verbose_about = \
"""PySPConfigValue: verbose
  -    type: <%s 'bool'>
  - default: False
  -    doc: Generate verbose output for both initialization and
            execution.""" % ('class' if six.PY3 else 'type')
        self.assertEqual(b.about("verbose"), verbose_about)
예제 #3
0
    def _declare_options(cls, options=None):
        if options is None:
            options = PySPConfigBlock()

        safe_declare_common_option(options, "extension_precedence")

        return options
예제 #4
0
def convertschuripopt_register_options(options=None):
    if options is None:
        options = PySPConfigBlock()
    safe_register_common_option(options, "disable_gc")
    safe_register_common_option(options, "profile")
    safe_register_common_option(options, "traceback")
    safe_register_common_option(options, "verbose")
    safe_register_common_option(options, "symbolic_solver_labels")
    safe_register_unique_option(
        options, "output_directory",
        PySPConfigValue(
            ".",
            domain=_domain_must_be_str,
            description=("The directory in which all SchurIpopt files "
                         "will be stored. Default is '.'."),
            doc=None,
            visibility=0))
    safe_register_unique_option(
        options, "ignore_bundles",
        PySPConfigValue(
            False,
            domain=bool,
            description=("Ignore bundles when converting the SP to "
                         "SchurIpopt input files."),
            doc=None,
            visibility=0))
    safe_register_common_option(options, "scenario_tree_manager")
    ScenarioTreeManagerClientSerial.register_options(options)
    ScenarioTreeManagerClientPyro.register_options(options)

    return options
예제 #5
0
def compile_scenario_tree_register_options(options=None):
    if options is None:
        options = PySPConfigBlock()
    safe_register_common_option(options, "disable_gc")
    safe_register_common_option(options, "profile")
    safe_register_common_option(options, "traceback")
    safe_register_unique_option(
        options, "output_directory",
        PySPConfigValue(
            ".",
            domain=_domain_must_be_str,
            description=("The directory in which to store all output files. "
                         "Default is '.'."),
            doc=None,
            visibility=0))
    safe_register_unique_option(
        options, "compiled_reference_model_filename",
        PySPConfigValue(
            "PySP_CompiledReferenceModel.py",
            domain=_domain_must_be_str,
            description=(
                "The filename to use for the new reference model that uses "
                "the compiled scenarios. This will be prefixed by the "
                "output directory name where compiled scenarios are stored. "
                "Default is 'PySP_CompiledReferenceModel.py'."),
            doc=None,
            visibility=0))
    safe_register_common_option(options, "scenario_tree_manager")
    ScenarioTreeManagerClientSerial.register_options(options)
    ScenarioTreeManagerClientPyro.register_options(options)

    return options
예제 #6
0
def scenariotreeserver_register_options(options=None):
    if options is None:
        options = PySPConfigBlock()
    safe_register_common_option(options, "disable_gc")
    safe_register_common_option(options, "profile")
    safe_register_common_option(options, "traceback")
    safe_register_common_option(options, "verbose")
    safe_register_common_option(options, "pyro_host")
    safe_register_common_option(options, "pyro_port")
    safe_register_unique_option(
        options, "mpi",
        PySPConfigValue(False,
                        domain=bool,
                        description=("Activate MPI based functionality. "
                                     "Requires the mpi4py module."),
                        doc=None,
                        visibility=0))
    safe_register_unique_option(
        options, "import_module",
        PySPConfigValue(
            (),
            domain=_domain_tuple_of_str,
            description=(
                "The name of a user-defined python module to import that, "
                "e.g., registers a user-defined scenario tree worker class."),
            doc=None,
            visibility=0))

    return options
예제 #7
0
def runschuripopt_register_options(options=None):
    if options is None:
        options = PySPConfigBlock()
    safe_register_common_option(options, "verbose")
    safe_register_common_option(options, "disable_gc")
    safe_register_common_option(options, "profile")
    safe_register_common_option(options, "traceback")
    safe_register_common_option(options, "output_scenario_tree_solution")
    safe_register_common_option(options, "output_solver_log")
    safe_register_common_option(options, "keep_solver_files")
    safe_register_common_option(options, "symbolic_solver_labels")
    ScenarioTreeManagerFactory.register_options(options)
    SchurIpoptSolver.register_options(options)
    # used to populate the implicit SchurIpopt options
    safe_register_unique_option(
        options,
        "solver_options",
        PySPConfigValue((),
                        domain=_domain_tuple_of_str_or_dict,
                        description=("Solver options to pass to SchurIpopt "
                                     "(e.g., relax_integrality=yes). This "
                                     "option can be used multiple times "
                                     "from the command line to specify more "
                                     "than one SchurIpopt option."),
                        doc=None,
                        visibility=0),
        ap_kwds={'action': 'append'},
        ap_group=_schuripopt_group_label)

    return options
예제 #8
0
def runddsip_register_options(options=None):
    if options is None:
        options = PySPConfigBlock()
    DDSIPSolver.register_options(options)
    ScenarioTreeManagerFactory.register_options(options)
    safe_register_common_option(options, "verbose")
    safe_register_common_option(options, "disable_gc")
    safe_register_common_option(options, "profile")
    safe_register_common_option(options, "traceback")
    safe_register_common_option(options, "output_scenario_tree_solution")
    safe_register_common_option(options, "keep_solver_files")
    safe_register_common_option(options, "output_solver_log")
    safe_register_common_option(options, "symbolic_solver_labels")
    # used to populate the implicit DDSIP options
    safe_register_unique_option(
        options,
        "solver_options",
        PySPConfigValue(
            (),
            domain=_domain_tuple_of_str_or_dict,
            description=("Unregistered solver options that will be passed "
                         "to DDSIP via the config file (e.g., NODELIM=4, "
                         "CPLEX_1067=1). This option can be used multiple "
                         "times from the command line to specify more "
                         "than one DDSIP option."),
            doc=None,
            visibility=0),
        ap_kwds={'action': 'append'},
        ap_group=_ddsip_group_label)

    return options
예제 #9
0
    def _declare_options(cls, options=None):
        if options is None:
            options = PySPConfigBlock()

        #
        # solve and I/O related
        #
        safe_declare_common_option(options,
                                   "symbolic_solver_labels")
        safe_declare_common_option(options,
                                   "solver_options")
        safe_declare_common_option(options,
                                   "solver")
        safe_declare_common_option(options,
                                   "solver_io")
        safe_declare_common_option(options,
                                   "solver_manager")
        safe_declare_common_option(options,
                                   "disable_warmstart")
        safe_declare_common_option(options,
                                   "disable_advanced_preprocessing")
        safe_declare_common_option(options,
                                   "output_solver_log")
        safe_declare_common_option(options,
                                   "keep_solver_files")
        safe_declare_common_option(options,
                                   "comparison_tolerance_for_fixed_variables")

        return options
예제 #10
0
def runadmm_register_options(options=None):
    if options is None:
        options = PySPConfigBlock()
    ADMMSolver.register_options(options)
    ScenarioTreeManagerFactory.register_options(options)
    safe_register_common_option(options, "verbose")
    safe_register_common_option(options, "disable_gc")
    safe_register_common_option(options, "profile")
    safe_register_common_option(options, "traceback")
    safe_register_common_option(options, "output_solver_log")
    safe_register_common_option(options, "output_scenario_tree_solution")
    safe_register_unique_option(
        options,
        "default_rho",
        PySPConfigValue(
            1.0,
            domain=_domain_positive,
            description=("The default rho value for all non-anticipative "
                         "variables. Default is 1.0."),
            doc=None,
            visibility=0),
        ap_args=("-r", "--default-rho"),
        ap_group=_admm_group_label)

    return options
예제 #11
0
파일: jsonio.py 프로젝트: sgjkkx/pyomo
class JSONSolutionSaverExtension(PySPConfiguredExtension, PySPConfiguredObject,
                                 SingletonPlugin):

    implements(IPySPSolutionSaverExtension)

    _declared_options = \
        PySPConfigBlock("Options declared for the "
                        "JSONSolutionSaverExtension class")

    safe_declare_common_option(_declared_options, "output_name")
    safe_declare_common_option(_declared_options, "save_stages")

    _default_prefix = "jsonsaver_"

    #
    # Note: Do not try to user super() or access the
    #       class name inside the __init__ method when
    #       a class derives from a SingletonPlugin. Due to
    #       how Pyutilib implements its Singleton type,
    #       the __class__ cell will be empty.
    #       (See: https://stackoverflow.com/questions/
    #             13126727/how-is-super-in-python-3-implemented)
    #
    def __init__(self):
        PySPConfiguredExtension.__init__(self)

    def save(self, manager):

        if self.get_option("output_name") is not None:
            stage_solutions = []
            # Do NOT open file in 'binary' mode when dumping JSON
            # (produces an error in Python3)
            with open(self.get_option('output_name'), 'w') as f:
                cntr = 0
                for stage in manager.scenario_tree.stages:
                    if (self.get_option('save_stages') <= 0) or \
                       (cntr+1 <= self.get_option('save_stages')):
                        cntr += 1
                        node_solutions = {}
                        for tree_node in stage.nodes:
                            _node_solution = extract_node_solution(tree_node)
                            if _node_solution is None:
                                print(
                                    "No solution appears to be stored in node with "
                                    "name %s. No solution will be saved." %
                                    (tree_node.name))
                                return False
                            node_solutions[tree_node.name] = _node_solution
                        stage_solutions.append(node_solutions)
                    else:
                        break
                json.dump(stage_solutions, f, indent=2, sort_keys=True)
            print("Saved scenario tree solution for %s time stages "
                  "to file %s" % (cntr, self.get_option('output_name')))
            return True

        print("No value was set for %s option 'output_name'. "
              "Nothing will be saved." % (type(self).__name__))
        return False
예제 #12
0
파일: jsonio.py 프로젝트: wannasmile/pyomo
    def _declare_options(cls, options=None):
        if options is None:
            options = PySPConfigBlock()

        safe_declare_common_option(options, "input_name")
        safe_declare_common_option(options, "load_stages")

        return options
예제 #13
0
 def _declare_options(cls, options=None):
     if options is None:
         options = PySPConfigBlock()
     safe_declare_common_option(options,
                                "verbose",
                                ap_group=_admm_group_label)
     ScenarioTreeManagerSolverFactory.register_options(
         options, options_prefix="subproblem_", setup_argparse=False)
     return options
예제 #14
0
    def _declare_options(cls, options=None):
        if options is None:
            options = PySPConfigBlock()

        safe_declare_common_option(options, "preprocess_fixed_variables")
        safe_declare_common_option(options, "symbolic_solver_labels")
        safe_declare_common_option(options, "output_times")
        safe_declare_common_option(options, "verbose")

        return options
예제 #15
0
def runsd_register_options(options=None):
    if options is None:
        options = PySPConfigBlock()
    safe_register_common_option(options, "verbose")
    safe_register_common_option(options, "disable_gc")
    safe_register_common_option(options, "profile")
    safe_register_common_option(options, "traceback")
    ScenarioTreeManagerFactory.register_options(options)
    SDSolver.register_options(options)

    return options
예제 #16
0
    def _declare_options(cls, options=None):
        if options is None:
            options = PySPConfigBlock()

        # options for controlling the solver manager
        # (not the scenario tree manager)
        safe_declare_common_option(options, "solver_manager_pyro_host")
        safe_declare_common_option(options, "solver_manager_pyro_port")
        safe_declare_common_option(options, "solver_manager_pyro_shutdown")

        ScenarioTreePreprocessor._declare_options(options)

        return options
예제 #17
0
def runsd_register_options(options=None):
    if options is None:
        options = PySPConfigBlock()
    SDSolver.register_options(options)
    ScenarioTreeManagerFactory.register_options(options)
    safe_register_common_option(options, "verbose")
    safe_register_common_option(options, "disable_gc")
    safe_register_common_option(options, "profile")
    safe_register_common_option(options, "traceback")
    safe_register_common_option(options, "output_scenario_tree_solution")
    safe_register_common_option(options, "keep_solver_files")
    safe_register_common_option(options, "output_solver_log")
    safe_register_common_option(options, "symbolic_solver_labels")
    return options
예제 #18
0
def run_generate_distributed_NL_register_options(options=None):
    if options is None:
        options = PySPConfigBlock()
    safe_register_common_option(options, "disable_gc")
    safe_register_common_option(options, "profile")
    safe_register_common_option(options, "traceback")
    safe_register_common_option(options, "scenario_tree_manager")
    safe_register_common_option(options, "symbolic_solver_labels")
    safe_register_unique_option(
        options,
        "output_directory",
        PySPConfigValue(
            ".",
            domain=_domain_must_be_str,
            description=(
                "The directory in which to store all output files. "
                "Default is '.'."
            ),
            doc=None,
            visibility=0))
    safe_register_unique_option(
        options,
        "linking_suffix_name",
        PySPConfigValue(
            "variable_id",
            domain=_domain_must_be_str,
            description=(
                "The suffix name used to identify common variables "
                "across NL files. Default is 'ipopt_blend_id'."
            ),
            doc=None,
            visibility=0))
    safe_register_unique_option(
        options,
        "objective_suffix_name",
        PySPConfigValue(
            "objective_weight",
            domain=_domain_must_be_str,
            description=(
                "The suffix name used to identify the relative "
                "objective weight for each NL-file subproblem."
                "Default is 'ipopt_blend_weight'."
            ),
            doc=None,
            visibility=0))
    ScenarioTreeManagerClientSerial.register_options(options)
    ScenarioTreeManagerClientPyro.register_options(options)

    return options
 def _declare_options(cls, options=None):
     if options is None:
         options = PySPConfigBlock()
     safe_declare_common_option(options,
                                "max_iterations",
                                ap_group=_admm_group_label)
     safe_declare_unique_option(
         options,
         "primal_residual_relative_tolerance",
         PySPConfigValue(
             1.0e-4,
             domain=_domain_positive,
             description=(
                 "Relative primal-residual tolerance. Default is 1e-4."
             ),
             doc=None,
             visibility=0),
         ap_group=_admm_group_label)
     safe_declare_unique_option(
         options,
         "dual_residual_relative_tolerance",
         PySPConfigValue(
             1.0e-4,
             domain=_domain_positive,
             description=(
                 "Relative dual-residual tolerance. Default is 1e-4."
             ),
             doc=None,
             visibility=0),
         ap_group=_admm_group_label)
     ADMMAlgorithm._declare_options(options)
     for rstype in RhoStrategyFactory.registered_types.values():
         rstype._declare_options(options)
     assert 'adaptive' in RhoStrategyFactory.registered_types
     safe_declare_unique_option(
         options,
         "rho_strategy",
         PySPConfigValue(
             'adaptive',
             domain=_domain_must_be_str,
             description=(
                 "Rho update strategy. Choices are: %s. Default is 'adaptive'."
                 % (str(sorted(RhoStrategyFactory.registered_types.keys())))
             ),
             doc=None,
             visibility=0),
         ap_group=_admm_group_label)
     return options
예제 #20
0
def run_evaluate_xhat_register_options(options=None):
    if options is None:
        options = PySPConfigBlock()
    safe_register_common_option(options,
                               "disable_gc")
    safe_register_common_option(options,
                               "profile")
    safe_register_common_option(options,
                               "traceback")
    safe_register_common_option(options,
                               "scenario_tree_manager")
    safe_register_common_option(options,
                               "output_scenario_tree_solution")
    safe_register_common_option(options,
                               "solution_saver_extension")
    safe_register_common_option(options,
                               "solution_loader_extension")
    safe_register_unique_option(
        options,
        "disable_solution_loader_check",
        PySPConfigValue(
            False,
            domain=bool,
            description=(
                "Indicates that no solution loader extension is required to "
                "run this script, e.g., because the scenario tree manager "
                "is somehow pre-populated with a solution."
            ),
            doc=None,
            visibility=0),
        ap_group=_extension_options_group_title)
    safe_register_unique_option(
        options,
        "output_scenario_costs",
        PySPConfigValue(
            None,
            domain=_domain_must_be_str,
            description=(
                "A file name where individual scenario costs from the solution "
                "will be stored. The format is determined from the extension used "
                "in the filename. Recognized extensions: [.csv, .json, .yaml]"
            ),
            doc=None,
            visibility=0))
    ScenarioTreeManagerSolverClientSerial.register_options(options)
    ScenarioTreeManagerSolverClientPyro.register_options(options)

    return options
예제 #21
0
def _register_scenario_tree_manager_solver_options(*args, **kwds):
    if len(args) == 0:
        options = PySPConfigBlock()
    else:
        if len(args) != 1:
            raise TypeError(
                "register_options(...) takes at most 1 argument (%s given)" %
                (len(args)))
        options = args[0]
        if not isinstance(options, PySPConfigBlock):
            raise TypeError(
                "register_options(...) argument must be of type PySPConfigBlock, "
                "not %s" % (type(options).__name__))

    ScenarioTreeManagerSolverClientSerial.register_options(options, **kwds)
    ScenarioTreeManagerSolverClientPyro.register_options(options, **kwds)

    return options
예제 #22
0
파일: ddsip.py 프로젝트: CanLi1/pyomo-1
def main(args=None):
    #
    # Top-level command that executes everything
    #

    #
    # Import plugins
    #
    import pyomo.environ

    #
    # Parse command-line options.
    #
    options = PySPConfigBlock()
    convertddsip_register_options(options)

    #
    # Prevent the compile_scenario_instances option from
    # appearing on the command line. This script relies on
    # the original constraints being present on the model
    #
    argparse_val = options.get('compile_scenario_instances')._argparse
    options.get('compile_scenario_instances')._argparse = None

    try:
        ap = argparse.ArgumentParser(prog='pyomo.pysp.convert.ddsip')
        options.initialize_argparse(ap)

        # restore the option so the class validation does not
        # raise an exception
        options.get('compile_scenario_instances')._argparse = argparse_val

        options.import_argparse(ap.parse_args(args=args))
    except SystemExit as _exc:
        # the parser throws a system exit if "-h" is specified
        # - catch it to exit gracefully.
        return _exc.code

    return launch_command(run_convertddsip,
                          options,
                          error_label="pyomo.pysp.convert.ddsip: ",
                          disable_gc=options.disable_gc,
                          profile_count=options.profile,
                          traceback=options.traceback)
예제 #23
0
    def _declare_options(cls, options=None):
        if options is None:
            options = PySPConfigBlock()

        #
        # scenario instance construction
        #
        safe_declare_common_option(options, "objective_sense_stage_based")
        safe_declare_common_option(options,
                                   "output_instance_construction_time")
        safe_declare_common_option(options, "compile_scenario_instances")

        #
        # various
        #
        safe_declare_common_option(options, "verbose")
        safe_declare_common_option(options, "profile_memory")

        return options
예제 #24
0
def generate_scenario_tree_image_register_options(options=None):
    if options is None:
        options = PySPConfigBlock()
    safe_register_unique_option(
        options, "output_file",
        PySPConfigValue(
            "ScenarioStructure.pdf",
            domain=_domain_must_be_str,
            description=("The name of the file in which to store the scenario "
                         "tree image. Default is ScenarioStructure.pdf."),
            doc=None,
            visibility=0))
    safe_register_common_option(options, "verbose")
    safe_register_common_option(options, "model_location")
    safe_register_common_option(options, "scenario_tree_location")
    safe_register_common_option(options, "scenario_tree_random_seed")
    safe_register_common_option(options, "scenario_tree_downsample_fraction")
    safe_register_common_option(options, "scenario_bundle_specification")
    safe_register_common_option(options, "create_random_bundles")
    safe_register_common_option(options, "disable_gc")
    safe_register_common_option(options, "profile")
    safe_register_common_option(options, "traceback")
    return options
예제 #25
0
    def _declare_options(cls, options=None):
        if options is None:
            options = PySPConfigBlock()
        safe_declare_unique_option(
            options,
            "firststage_suffix",
            PySPConfigValue(
                "__DDSIP_FIRSTSTAGE",
                domain=_domain_must_be_str,
                description=("The suffix used to identity first-stage "
                             "variables to DDSIP. Default is "
                             "'__DDSIP_FIRSTSTAGE'"),
                doc=None,
                visibility=0),
            ap_group=_ddsip_group_label)
        safe_declare_unique_option(
            options,
            "config_file",
            PySPConfigValue(
                None,
                domain=_domain_must_be_str,
                description=(
                    "The name of a partial DDSIP configuration file "
                    "that contains option specifications unrelated to "
                    "the problem structure. If specified, the contents "
                    "of this file will be appended to the "
                    "configuration created by this solver interface. "
                    "Default is None."),
                doc=None,
                visibility=0),
            ap_group=_ddsip_group_label)
        safe_declare_common_option(options,
                                   "verbose",
                                   ap_group=_ddsip_group_label)

        return options
예제 #26
0
    def test_implicit(self):
        b = PySPConfigBlock()
        b._implicit_declaration = True
        b.name_a = 1
        b.nameb = 2
        b.display()
        out = StringIO()
        b.display(ostream=out)
        self.assertEqual(out.getvalue(), "name_a: 1\nnameb: 2\n")
        with self.assertRaises(ValueError):
            b.check_usage()
        with self.assertRaises(ValueError):
            b.check_usage()
        self.assertEqual(b.check_usage(error=False), False)
        b.name_a
        b.nameb
        self.assertEqual(b.check_usage(), True)
        self.assertEqual(b.check_usage(error=False), True)
        name_a_about = \
"""ConfigValue: name_a
  -    type: None
  - default: 1
  -    doc: None"""
        self.assertEqual(b.about("name_a"), name_a_about)
예제 #27
0
파일: misc.py 프로젝트: smars8/pyomo
def parse_command_line(args,
                       register_options_callback,
                       with_extensions=None,
                       **kwds):
    import pyomo.pysp.plugins
    pyomo.pysp.plugins.load()
    from pyomo.pysp.util.config import _domain_tuple_of_str

    registered_extensions = {}
    if with_extensions is not None:
        for name in with_extensions:
            plugins = ExtensionPoint(with_extensions[name])
            for plugin in plugins(all=True):
                registered_extensions.setdefault(name,[]).\
                    append(plugin.__class__.__module__)

    def _get_argument_parser(options):
        # if we modify this and don't copy it,
        # the this output will appear twice the second
        # time this function gets called
        _kwds = dict(kwds)
        if len(registered_extensions) > 0:
            assert with_extensions is not None
            epilog = _kwds.pop('epilog',"")
            if epilog != "":
                epilog += "\n\n"
            epilog += "Registered Extensions:\n"
            for name in registered_extensions:
                epilog += " - "+str(with_extensions[name].__name__)+": "
                epilog += str(registered_extensions[name])+"\n"
            _kwds['epilog'] = epilog
        ap = argparse.ArgumentParser(
            add_help=False,
            formatter_class=argparse.RawDescriptionHelpFormatter,
            **_kwds)
        options.initialize_argparse(ap)
        ap.add_argument("-h", "--help", dest="show_help",
                        action="store_true", default=False,
                        help="show this help message and exit")
        return ap

    #
    # Register options
    #
    options = PySPConfigBlock()
    register_options_callback(options)

    if with_extensions is not None:
        for name in with_extensions:
            configval = options.get(name, None)
            assert configval is not None
            assert configval._domain is _domain_tuple_of_str

    ap = _get_argument_parser(options)
    # First parse known args, then import any extension plugins
    # specified by the user, regenerate the options block and
    # reparse to pick up plugin specific registered options
    opts, _ = ap.parse_known_args(args=args)
    options.import_argparse(opts)
    extensions = {}
    if with_extensions is None:
        if opts.show_help:
            pass
    else:
        if all(len(options.get(name).value()) == 0
               for name in with_extensions) and \
               opts.show_help:
            ap.print_help()
            sys.exit(0)
        for name in with_extensions:
            extensions[name] = load_extensions(
                options.get(name).value(),
                with_extensions[name])

    # regenerate the options
    options = PySPConfigBlock()
    register_options_callback(options)
    for name in extensions:
        for plugin in extensions[name]:
            if isinstance(plugin, PySPConfiguredObject):
                plugin.register_options(options)
        # do a dummy access to option to prevent
        # a warning about it not being used
        options.get(name).value()

    ap = _get_argument_parser(options)
    opts = ap.parse_args(args=args)
    options.import_argparse(opts)
    for name in extensions:
        for plugin in extensions[name]:
            if isinstance(plugin, PySPConfiguredObject):
                plugin.set_options(options)
    if opts.show_help:
        ap.print_help()
        sys.exit(0)

    if with_extensions:
        for name in extensions:
            extensions[name] = sort_extensions_by_precedence(extensions[name])
        return options, extensions
    else:
        return options
예제 #28
0
파일: ddsip.py 프로젝트: CanLi1/pyomo-1
def convertddsip_register_options(options=None):
    if options is None:
        options = PySPConfigBlock()
    safe_register_common_option(options, "disable_gc")
    safe_register_common_option(options, "profile")
    safe_register_common_option(options, "traceback")
    safe_register_common_option(options, "verbose")
    safe_register_common_option(options, "symbolic_solver_labels")
    safe_register_unique_option(
        options, "output_directory",
        PySPConfigValue(".",
                        domain=_domain_must_be_str,
                        description=("The directory in which all DDSIP files "
                                     "will be stored. Default is '.'."),
                        doc=None,
                        visibility=0))
    safe_register_unique_option(
        options, "first_stage_suffix",
        PySPConfigValue(
            "__DDSIP_FIRSTSTAGE",
            domain=_domain_must_be_str,
            description=("The suffix used to identify first-stage variables. "
                         "Default: '__DDSIP_FIRSTSTAGE'"),
            doc=None,
            visibility=0))
    safe_register_unique_option(
        options, "enforce_derived_nonanticipativity",
        PySPConfigValue(
            False,
            domain=bool,
            description=(
                "Adds nonanticipativity constraints for variables flagged "
                "as derived within their respective time stage (except for "
                "the final time stage). The default behavior behavior is "
                "to treat derived variables as belonging to the final "
                "time stage."),
            doc=None,
            visibility=0))
    safe_register_unique_option(
        options, "disable_consistency_checks",
        PySPConfigValue(
            False,
            domain=bool,
            description=(
                "Disables consistency checks that attempt to find issues "
                "with the DDSIP conversion. By default, these checks are run "
                "after conversion takes place and leave behind a temporary "
                "directory with per-scenario output files if the checks fail. "
                "This option is not recommended, but can be used if the "
                "consistency checks are prohibitively slow."),
            doc=None,
            visibility=0))
    safe_register_unique_option(
        options, "keep_scenario_files",
        PySPConfigValue(
            False,
            domain=bool,
            description=(
                "Keeps around the per-scenario DDSIP files created for testing "
                "whether a conversion is valid (whether or not the validation "
                "checks are performed). These files can be useful for "
                "debugging purposes."),
            doc=None,
            visibility=0))
    safe_register_common_option(options, "scenario_tree_manager")
    ScenarioTreeManagerClientSerial.register_options(options)
    ScenarioTreeManagerClientPyro.register_options(options)

    return options
예제 #29
0
 def _declare_options(cls, options=None):
     if options is None:
         options = PySPConfigBlock()
     return options
예제 #30
0
파일: pysp2smps.py 프로젝트: smars8/pyomo
def pysp2smps_register_options(options=None):
    if options is None:
        options = PySPConfigBlock()
    safe_register_common_option(options, "disable_gc")
    safe_register_common_option(options, "profile")
    safe_register_common_option(options, "traceback")
    safe_register_common_option(options, "verbose")
    safe_register_common_option(options, "symbolic_solver_labels")
    safe_register_common_option(options, "file_determinism")
    safe_register_unique_option(
        options,
        "explicit",
        PySPConfigValue(
            False,
            domain=bool,
            description=(
                "Generate SMPS files using explicit scenarios "
                "(or bundles). ** This option is deprecated. It is "
                "the default behavior. ** "
            ),
            doc=None,
            visibility=0))
    safe_register_unique_option(
        options,
        "core_format",
        PySPConfigValue(
            "mps",
            domain=_domain_must_be_str,
            description=(
                "The format used to generate the core SMPS problem file. "
                "Choices are: [mps, lp]. The default format is MPS."
            ),
            doc=None,
            visibility=0),
        ap_kwds={'choices': ['mps','lp']})
    safe_register_unique_option(
        options,
        "output_directory",
        PySPConfigValue(
            ".",
            domain=_domain_must_be_str,
            description=(
                "The directory in which all SMPS related output files "
                "will be stored. Default is '.'."
            ),
            doc=None,
            visibility=0))
    safe_register_unique_option(
        options,
        "basename",
        PySPConfigValue(
            None,
            domain=_domain_must_be_str,
            description=(
                "The basename to use for all SMPS related output "
                "files. ** Required **"
            ),
            doc=None,
            visibility=0))
    safe_register_unique_option(
        options,
        "disable_consistency_checks",
        PySPConfigValue(
            False,
            domain=bool,
            description=(
                "Disables consistency checks that attempt to find issues "
                "with the SMPS conversion. By default, these checks are run "
                "after conversion takes place and leave behind a temporary "
                "directory with per-scenario output files if the checks fail. "
                "This option is not recommended, but can be used if the "
                "consistency checks are prohibitively slow."
            ),
            doc=None,
            visibility=0))
    safe_register_unique_option(
        options,
        "keep_scenario_files",
        PySPConfigValue(
            False,
            domain=bool,
            description=(
                "Keeps around the per-scenario SMPS files created for testing "
                "whether a conversion is valid (whether or not the validation "
                "checks are performed). These files can be useful for "
                "debugging purposes."
            ),
            doc=None,
            visibility=0))
    safe_register_unique_option(
        options,
        "keep_auxiliary_files",
        PySPConfigValue(
            False,
            domain=bool,
            description=(
                "Keep auxiliary files for the template scenario that are normally "
                "used for testing the validity of the SMPS conversion. "
                "These include the .row, .col, .sto.struct, and .[mps,lp].det files."
            ),
            doc=None,
            visibility=0))
    safe_register_common_option(options, "scenario_tree_manager")
    ScenarioTreeManagerClientSerial.register_options(options)
    ScenarioTreeManagerClientPyro.register_options(options)

    return options