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
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
def setUp(self): self._tempfiles = [] self._setUpPyro() [_poll(proc) for proc in _taskworker_processes] self.options = PySPConfigBlock() ScenarioTreeManagerClientPyro.register_options( self.options, registered_worker_name="ScenarioTreeManagerWorkerTest" )
def _init(self, factory): _setUpPyro() [_poll(proc) for proc in _taskworker_processes] options = ScenarioTreeManagerClientPyro.register_options() options.pyro_port = _pyomo_ns_port options.pyro_required_scenariotreeservers = 3 options.pyro_handshake_at_startup = True sp = ScenarioTreeManagerClientPyro(options, factory=factory) sp.initialize() return sp
def pyro_sample_sp(self, size, **kwds): assert size > 0 model = self.reference_model.clone() scenario_tree_model = \ self._create_scenario_tree_model(size) factory = ScenarioTreeInstanceFactory( model=self.reference_model, scenario_tree=scenario_tree_model) options = \ ScenarioTreeManagerClientPyro.register_options() for key in kwds: options[key] = kwds[key] manager = ScenarioTreeManagerClientPyro(options, factory=factory) try: init = manager.initialize(async_call=True) pcuids = ComponentMap() for param in self.stochastic_data: pcuids[param] = ComponentUID(param) init.complete() for scenario in manager.scenario_tree.scenarios: data = [] for param, dist in self.stochastic_data.items(): data.append((pcuids[param], dist.sample())) manager.invoke_function( "_update_data", thisfile, invocation_type=InvocationType.OnScenario(scenario.name), function_args=(data, ), oneway_call=True) manager.reference_model = model except: manager.close() raise return manager
def _init(self, factory): _setUpPyro() [_poll(proc) for proc in _taskworker_processes] options = ScenarioTreeManagerClientPyro.register_options() options.pyro_port = _pyomo_ns_port options.pyro_required_scenariotreeservers = 3 options.pyro_handshake_at_startup = True sp = ScenarioTreeManagerClientPyro( options, factory=factory) sp.initialize() return sp
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 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
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
def pyro_sample_sp(self, size, **kwds): assert size > 0 model = self.reference_model.clone() scenario_tree_model = \ self._create_scenario_tree_model(size) factory = ScenarioTreeInstanceFactory( model=self.reference_model, scenario_tree=scenario_tree_model) options = \ ScenarioTreeManagerClientPyro.register_options() for key in kwds: options[key] = kwds[key] manager = ScenarioTreeManagerClientPyro( options, factory=factory) try: init = manager.initialize(async_call=True) pcuids = ComponentMap() for param in self.stochastic_data: pcuids[param] = ComponentUID(param) init.complete() for scenario in manager.scenario_tree.scenarios: data = [] for param, dist in self.stochastic_data.items(): data.append((pcuids[param], dist.sample())) manager.invoke_function( "_update_data", thisfile, invocation_type=InvocationType.OnScenario(scenario.name), function_args=(data,), oneway_call=True) manager.reference_model = model except: manager.close() raise return manager
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
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
# on InvocationType for more information. # def solve_model(worker, scenario): from pyomo.opt import SolverFactory with SolverFactory("glpk") as opt: opt.solve(scenario._instance) return value(scenario._instance.obj) if __name__ == "__main__": # generate an absolute path to this file thisfile = os.path.abspath(__file__) # generate a list of options we can configure options = ScenarioTreeManagerClientPyro.register_options() # # Set a few options # # the pysp_instance_creation_callback function # will be detected and used options.model_location = thisfile # setting this option to None implies there # is a pysp_scenario_tree_model_callback function # defined in the model file options.scenario_tree_location = None # use verbose output options.verbose = True #
# def solve_model(worker, scenario): from pyomo.opt import SolverFactory with SolverFactory("glpk") as opt: opt.solve(scenario._instance) return value(scenario._instance.obj) if __name__ == "__main__": # generate an absolute path to this file thisfile = os.path.abspath(__file__) # generate a list of options we can configure options = ScenarioTreeManagerClientPyro.register_options() # To see detailed information about options #for name in options.keys(): # print(options.about(name)) # To see a more compact display of options #options.display() # # Set a few options # # the pysp_instance_creation_callback function # will be detected and used options.model_location = thisfile
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