switch_model/utilities/__init__.py
def load_inputs(model, inputs_dir=None, attach_data_portal=False):
    """
    Load input data for an AbstractModel using the modules in the given
    list and return a model instance. This is implemented as calling the
    load_inputs() function of each module, if the module has that function.
    """
    if inputs_dir is None:
        inputs_dir = getattr(model.options, "inputs_dir", "inputs")

    # Load data; add a fancier load function to the data portal
    if model.options.verbose:
        print("Reading data...")
    timer = StepTimer()
    data = DataPortal(model=model)
    data.load_aug = types.MethodType(load_aug, data)
    load_registered_inputs(data, inputs_dir)
    for module in model.get_modules():
        if hasattr(module, 'load_inputs'):
            module.load_inputs(model, data, inputs_dir)
    if model.options.verbose:
        print(f"Data read in {timer.step_time_as_str()}.\n")

    # At some point, pyomo deprecated 'create' in favor of 'create_instance'.
    # Determine which option is available and use that.
    if model.options.verbose:
        print("Creating instance...")
    if hasattr(model, 'create_instance'):
        instance = model.create_instance(data)
        # We want our functions from CustomModel to be accessible
        # Somehow simply setting the class to CustomModel allows us to do this
        # This is the same thing that happens in the Pyomo library at the end of
        # model.create_instance(). Note that Pyomo's ConcreteModel is basically the same as
        # our CustomModel so we're not causing any issues by changing from ConcreteModel
        # to CustomModel
        instance.__class__ = CustomModel
    else:
        instance = model.create(data)
    if model.options.verbose:
        print(f"Instance created from data in {timer.step_time_as_str()}.\n")

    if attach_data_portal:
        instance.DataPortal = data
    else:
        del data
    return instance

    Load input data for an AbstractModel using the modules in the given
    list and return a model instance. This is implemented as calling the
    load_inputs() function of each module, if the module has that function.
    
Load input data for an AbstractModel using the modules in the given
list and return a model instance. This is implemented as calling the
load_inputs() function of each module, if the module has that function.
Load input data for an AbstractModel using the modules in the given list and return a model instance . This is implemented as calling the load_inputs () function of each module if the module has that function .
def load_inputs(model, inputs_dir=None, attach_data_portal=False):
    if inputs_dir is None:
        inputs_dir = getattr(model.options, "inputs_dir", "inputs")
    if model.options.verbose:
        print("Reading data...")
    timer = StepTimer()
    data = DataPortal(model=model)
    data.load_aug = types.MethodType(load_aug, data)
    load_registered_inputs(data, inputs_dir)
    for module in model.get_modules():
        if hasattr(module, 'load_inputs'):
            module.load_inputs(model, data, inputs_dir)
    if model.options.verbose:
        print(f"Data read in {timer.step_time_as_str()}.\n")
    if model.options.verbose:
        print("Creating instance...")
    if hasattr(model, 'create_instance'):
        instance = model.create_instance(data)
        instance.__class__ = CustomModel
    else:
        instance = model.create(data)
    if model.options.verbose:
        print(f"Instance created from data in {timer.step_time_as_str()}.\n")
    if attach_data_portal:
        instance.DataPortal = data
    else:
        del data
    return instance
def load_inputs ( model , inputs_dir = None , attach_data_portal = False ) : if inputs_dir is None : inputs_dir = getattr ( model . options , "inputs_dir" , "inputs" ) if model . options . verbose : print ( "Reading data..." ) timer = StepTimer ( ) data = DataPortal ( model = model ) data . load_aug = types . MethodType ( load_aug , data ) load_registered_inputs ( data , inputs_dir ) for module in model . get_modules ( ) : if hasattr ( module , 'load_inputs' ) : module . load_inputs ( model , data , inputs_dir ) if model . options . verbose : print ( f"Data read in {timer.step_time_as_str()}.\n" ) if model . options . verbose : print ( "Creating instance..." ) if hasattr ( model , 'create_instance' ) : instance = model . create_instance ( data ) instance . __class__ = CustomModel else : instance = model . create ( data ) if model . options . verbose : print ( f"Instance created from data in {timer.step_time_as_str()}.\n" ) if attach_data_portal : instance . DataPortal = data else : del data return instance
Load input data for an AbstractModel using the modules in the given
list and return a model instance.
Load input data for an AbstractModel using the modules in the given list and return a model instance .
"""
    Load input data for an AbstractModel using the modules in the given
    list and return a model instance. This is implemented as calling the
    load_inputs() function of each module, if the module has that function.
    """ # Load data; add a fancier load function to the data portal # At some point, pyomo deprecated 'create' in favor of 'create_instance'. # Determine which option is available and use that. # We want our functions from CustomModel to be accessible # Somehow simply setting the class to CustomModel allows us to do this # This is the same thing that happens in the Pyomo library at the end of # model.create_instance(). Note that Pyomo's ConcreteModel is basically the same as # our CustomModel so we're not causing any issues by changing from ConcreteModel # to CustomModel
model
inputs_dir
attach_data_portal