switch_model/utilities/load_data.py
def load_registered_inputs(switch_data, inputs_dir):
    """
    Gets called to load all the inputs that are registered.
    """
    for file, components in _registered_components.items():
        # We use lists since load_aug is going to convert to a list in any case
        params = [c for c in components if isinstance(c, Param)]
        optional_params = [p for p in params if p.input_optional]
        index = [c for c in components if isinstance(c, Set)]

        if len(index) + len(params) != len(components):
            raise Exception(
                "This should not happen. Did you specify an input file for an element that is not a Set or Param?")

        kwargs = {'filename': os.path.join(inputs_dir, file)}

        if len(index) > 1:
            raise Exception(f"Can't define multiple sets from the same file. {str(index)}")
        elif len(index) == 1:
            index = index[0]
            optional = index.input_optional # entire file is optional if the index is optional
        else:
            index = None
            optional = all(c.input_optional for c in components) # file is optional if each param is optional and no index

        if len(params) == 0:
            kwargs["set"] = index  # when only defining the index, we must use 'set'
        else:
            kwargs["param"] = params
            if index is not None:
                kwargs["index"] = index

        # Load the data
        load_data(switch_data, optional=optional, auto_select=True, optional_params=optional_params, **kwargs)

    # Remove all the elements to reset the dictionary
    _registered_components.clear()

    Gets called to load all the inputs that are registered.
    
Gets called to load all the inputs that are registered.
Gets called to load all the inputs that are registered .
def load_registered_inputs(switch_data, inputs_dir):
    for file, components in _registered_components.items():
        params = [c for c in components if isinstance(c, Param)]
        optional_params = [p for p in params if p.input_optional]
        index = [c for c in components if isinstance(c, Set)]
        if len(index) + len(params) != len(components):
            raise Exception(
                "This should not happen. Did you specify an input file for an element that is not a Set or Param?")
        kwargs = {'filename': os.path.join(inputs_dir, file)}
        if len(index) > 1:
            raise Exception(f"Can't define multiple sets from the same file. {str(index)}")
        elif len(index) == 1:
            index = index[0]
            optional = index.input_optional 
        else:
            index = None
            optional = all(c.input_optional for c in components) 
        if len(params) == 0:
            kwargs["set"] = index  
        else:
            kwargs["param"] = params
            if index is not None:
                kwargs["index"] = index
        load_data(switch_data, optional=optional, auto_select=True, optional_params=optional_params, **kwargs)
    _registered_components.clear()
def load_registered_inputs ( switch_data , inputs_dir ) : for file , components in _registered_components . items ( ) : params = [ c for c in components if isinstance ( c , Param ) ] optional_params = [ p for p in params if p . input_optional ] index = [ c for c in components if isinstance ( c , Set ) ] if len ( index ) + len ( params ) != len ( components ) : raise Exception ( "This should not happen. Did you specify an input file for an element that is not a Set or Param?" ) kwargs = { 'filename' : os . path . join ( inputs_dir , file ) } if len ( index ) > 1 : raise Exception ( f"Can't define multiple sets from the same file. {str(index)}" ) elif len ( index ) == 1 : index = index [ 0 ] optional = index . input_optional else : index = None optional = all ( c . input_optional for c in components ) if len ( params ) == 0 : kwargs [ "set" ] = index else : kwargs [ "param" ] = params if index is not None : kwargs [ "index" ] = index load_data ( switch_data , optional = optional , auto_select = True , optional_params = optional_params , ** kwargs ) _registered_components . clear ( )
Gets called to load all the inputs that are registered.
Gets called to load all the inputs that are registered .
"""
    Gets called to load all the inputs that are registered.
    """ # We use lists since load_aug is going to convert to a list in any case # entire file is optional if the index is optional # file is optional if each param is optional and no index # when only defining the index, we must use 'set' # Load the data # Remove all the elements to reset the dictionary
switch_data
inputs_dir