switch_model/utilities/__init__.py
def create_model(module_list=None, args=sys.argv[1:]):
    """

    Construct a Pyomo AbstractModel using the Switch modules or packages
    in the given list and return the model. The following utility methods
    are attached to the model as class methods to simplify their use:
    min_data_check(), load_inputs(), pre_solve(), post_solve().

    This is implemented as calling the following functions for each module
    that has them defined:

    define_dynamic_lists(model): Add lists to the model that other modules can
    register with. Used for power balance equations, cost components of the
    objective function, etc.

    define_components(model): Add components to the model object (parameters,
    sets, decisions variables, expressions, and/or constraints). Also register
    with relevant dynamic_lists.

    define_dynamic_components(model): Add dynamic components to the model that
    depend on the contents of dyanmics lists. Power balance constraints and
    the objective function are defined in this manner.

    See financials and balancing.load_zones for examples of dynamic definitions.

    All modules can request access to command line parameters and set their
    default values for those options. If this codebase is being used more like
    a library than a stand-alone executable, this behavior can cause problems.
    For example, running this model with PySP's runph tool will cause errors
    where a runph argument such as --instance-directory is unknown to the
    switch modules, so parse_args() generates an error. This behavior can be
    avoided calling this function with an empty list for args:
    create_model(module_list, args=[])

    """
    model = CustomModel()

    # Load modules
    if module_list is None:
        module_list = get_module_list(args)
    model.module_list = module_list
    for m in module_list:
        importlib.import_module(m)

    # Bind utility functions to the model as class objects
    # Should we be formally extending their class instead?
    _add_min_data_check(model)
    model.get_modules = types.MethodType(get_modules, model)
    model.load_inputs = types.MethodType(load_inputs, model)
    model.pre_solve = types.MethodType(pre_solve, model)
    model.post_solve = types.MethodType(post_solve, model)

    # Define and parse model configuration options
    argparser = _ArgumentParser(allow_abbrev=False)
    for module in model.get_modules():
        if hasattr(module, 'define_arguments'):
            module.define_arguments(argparser)
    model.options = argparser.parse_args(args)

    # Define model components
    for module in model.get_modules():
        if hasattr(module, 'define_dynamic_lists'):
            module.define_dynamic_lists(model)
    for module in model.get_modules():
        if hasattr(module, 'define_components'):
            module.define_components(model)
    for module in model.get_modules():
        if hasattr(module, 'define_dynamic_components'):
            module.define_dynamic_components(model)

    return model


    Construct a Pyomo AbstractModel using the Switch modules or packages
    in the given list and return the model. The following utility methods
    are attached to the model as class methods to simplify their use:
    min_data_check(), load_inputs(), pre_solve(), post_solve().

    This is implemented as calling the following functions for each module
    that has them defined:

    define_dynamic_lists(model): Add lists to the model that other modules can
    register with. Used for power balance equations, cost components of the
    objective function, etc.

    define_components(model): Add components to the model object (parameters,
    sets, decisions variables, expressions, and/or constraints). Also register
    with relevant dynamic_lists.

    define_dynamic_components(model): Add dynamic components to the model that
    depend on the contents of dyanmics lists. Power balance constraints and
    the objective function are defined in this manner.

    See financials and balancing.load_zones for examples of dynamic definitions.

    All modules can request access to command line parameters and set their
    default values for those options. If this codebase is being used more like
    a library than a stand-alone executable, this behavior can cause problems.
    For example, running this model with PySP's runph tool will cause errors
    where a runph argument such as --instance-directory is unknown to the
    switch modules, so parse_args() generates an error. This behavior can be
    avoided calling this function with an empty list for args:
    create_model(module_list, args=[])

    
Construct a Pyomo AbstractModel using the Switch modules or packages
in the given list and return the model. The following utility methods
are attached to the model as class methods to simplify their use:
min_data_check(), load_inputs(), pre_solve(), post_solve().

This is implemented as calling the following functions for each module
that has them defined.

Add lists to the model that other modules can
register with. Used for power balance equations, cost components of the
objective function, etc.

Add components to the model object (parameters,
sets, decisions variables, expressions, and/or constraints). Also register
with relevant dynamic_lists.

Add dynamic components to the model that
depend on the contents of dyanmics lists. Power balance constraints and
the objective function are defined in this manner.

See financials and balancing.load_zones for examples of dynamic definitions.

All modules can request access to command line parameters and set their
default values for those options. If this codebase is being used more like
a library than a stand-alone executable, this behavior can cause problems.
For example, running this model with PySP's runph tool will cause errors
where a runph argument such as --instance-directory is unknown to the
switch modules, so parse_args() generates an error. This behavior can be
avoided calling this function with an empty list for args:
create_model(module_list, args=[])
Construct a Pyomo AbstractModel using the Switch modules or packages in the given list and return the model . The following utility methods are attached to the model as class methods to simplify their use : min_data_check () load_inputs () pre_solve () post_solve () . This is implemented as calling the following functions for each module that has them defined . Add lists to the model that other modules can register with . Used for power balance equations cost components of the objective function etc . Add components to the model object ( parameters sets decisions variables expressions and / or constraints ) . Also register with relevant dynamic_lists . Add dynamic components to the model that depend on the contents of dyanmics lists . Power balance constraints and the objective function are defined in this manner . See financials and balancing . load_zones for examples of dynamic definitions . All modules can request access to command line parameters and set their default values for those options . If this codebase is being used more like a library than a stand - alone executable this behavior can cause problems . For example running this model with PySP ' s runph tool will cause errors where a runph argument such as -- instance - directory is unknown to the switch modules so parse_args () generates an error . This behavior can be avoided calling this function with an empty list for args : create_model ( module_list args = [] )
def create_model(module_list=None, args=sys.argv[1:]):
    model = CustomModel()
    if module_list is None:
        module_list = get_module_list(args)
    model.module_list = module_list
    for m in module_list:
        importlib.import_module(m)
    _add_min_data_check(model)
    model.get_modules = types.MethodType(get_modules, model)
    model.load_inputs = types.MethodType(load_inputs, model)
    model.pre_solve = types.MethodType(pre_solve, model)
    model.post_solve = types.MethodType(post_solve, model)
    argparser = _ArgumentParser(allow_abbrev=False)
    for module in model.get_modules():
        if hasattr(module, 'define_arguments'):
            module.define_arguments(argparser)
    model.options = argparser.parse_args(args)
    for module in model.get_modules():
        if hasattr(module, 'define_dynamic_lists'):
            module.define_dynamic_lists(model)
    for module in model.get_modules():
        if hasattr(module, 'define_components'):
            module.define_components(model)
    for module in model.get_modules():
        if hasattr(module, 'define_dynamic_components'):
            module.define_dynamic_components(model)
    return model
def create_model ( module_list = None , args = sys . argv [ 1 : ] ) : model = CustomModel ( ) if module_list is None : module_list = get_module_list ( args ) model . module_list = module_list for m in module_list : importlib . import_module ( m ) _add_min_data_check ( model ) model . get_modules = types . MethodType ( get_modules , model ) model . load_inputs = types . MethodType ( load_inputs , model ) model . pre_solve = types . MethodType ( pre_solve , model ) model . post_solve = types . MethodType ( post_solve , model ) argparser = _ArgumentParser ( allow_abbrev = False ) for module in model . get_modules ( ) : if hasattr ( module , 'define_arguments' ) : module . define_arguments ( argparser ) model . options = argparser . parse_args ( args ) for module in model . get_modules ( ) : if hasattr ( module , 'define_dynamic_lists' ) : module . define_dynamic_lists ( model ) for module in model . get_modules ( ) : if hasattr ( module , 'define_components' ) : module . define_components ( model ) for module in model . get_modules ( ) : if hasattr ( module , 'define_dynamic_components' ) : module . define_dynamic_components ( model ) return model
Construct a Pyomo AbstractModel using the Switch modules or packages
in the given list and return the model.
Construct a Pyomo AbstractModel using the Switch modules or packages in the given list and return the model .
"""

    Construct a Pyomo AbstractModel using the Switch modules or packages
    in the given list and return the model. The following utility methods
    are attached to the model as class methods to simplify their use:
    min_data_check(), load_inputs(), pre_solve(), post_solve().

    This is implemented as calling the following functions for each module
    that has them defined:

    define_dynamic_lists(model): Add lists to the model that other modules can
    register with. Used for power balance equations, cost components of the
    objective function, etc.

    define_components(model): Add components to the model object (parameters,
    sets, decisions variables, expressions, and/or constraints). Also register
    with relevant dynamic_lists.

    define_dynamic_components(model): Add dynamic components to the model that
    depend on the contents of dyanmics lists. Power balance constraints and
    the objective function are defined in this manner.

    See financials and balancing.load_zones for examples of dynamic definitions.

    All modules can request access to command line parameters and set their
    default values for those options. If this codebase is being used more like
    a library than a stand-alone executable, this behavior can cause problems.
    For example, running this model with PySP's runph tool will cause errors
    where a runph argument such as --instance-directory is unknown to the
    switch modules, so parse_args() generates an error. This behavior can be
    avoided calling this function with an empty list for args:
    create_model(module_list, args=[])

    """ # Load modules # Bind utility functions to the model as class objects # Should we be formally extending their class instead? # Define and parse model configuration options # Define model components
module_list
args