set_config#

gaitmap_challenges.config.set_config(config_obj_or_path: ~typing.Optional[~typing.Union[str, ~pathlib.Path, ~gaitmap_challenges.config._ConfigT]] = None, debug: ~typing.Optional[bool] = None, _config_type: ~typing.Type[~gaitmap_challenges.config._ConfigT] = <class 'gaitmap_challenges.config.LocalConfig'>, _default_config_file: ~typing.Optional[~typing.Union[str, ~pathlib.Path]] = None) _ConfigT[source]#

Set a global config.

This config can be set using one of the following methods:

  1. A path to a json file that contains the config.

  2. An instance of a LocalConfig object

  3. Automatically, via an environmental variable with the path to a json file.

  4. Get the default config file based on the _default_config_file parameter.

The lookup order is as follows:

  1. If you set the config_obj_or_path parameter to a path or a LocalConfig object, this will be used.

  2. If this is None, we will try to load the config path from the environmental variable GAITMAP_CHALLENGES_CONFIG.

  3. If this is None, we will try to load the default config file based on the _default_config_file parameter.

If none of this works, an error will be raised.

Parameters:
config_obj_or_pathOptional[Union[str, Path, LocalConfig]], optional

The config object or path to the config file.

debugOptional[bool], optional

Whether you want to execute a challenge in debug mode. This can also be set using the environmental variable GAITMAP_CHALLENGES_DEBUG. If the ENV var is set, it will overwrite the value of this parameter. If neither the ENV var nor this parameter is set, the default value is True.

The debug setting is primarily used by the save_run function to determine how the results should be saved. Note, that setting this to False, will not ensure that results are saved in a non-debug mode. Depending on the used settings for save_run, results might still be saved in debug mode.

_config_typeType[LocalConfig], optional

The expected settings type. This setting is usually not required, but can be used, if you need to extend the config class to include additional settings. In this case, we would recommend to create your own wrapper around this function, that sets the _config_type.

_default_config_file

The default config file that should be used, if no other config is specified. This is usually not required, but can be used, if you want to provide a fallback config for your application. In this case, we would recommend to create your own wrapper around this function, that sets the _default_config_file.

See also

LocalConfig

The config class that is used for the local config.

reset_config

Reset the global config to None, so that it can be set again using this set_config

create_config_template

Create a config template file that can be used to create a config file.

config

Get the global config object.

Notes

The config concept in this package uses a global variable called gaitmap_challenges.config._GLOBAL_CONFIG. This variable is set to the config object resolved when calling the set_config method. This means that you can access the config object from anywhere in your code by simply config() from gaitmap_challenges.

One caveat of using a global variable is, that by default, the config is not persistent between multiple processes when using multi-processing (e.g. when using joblib). We use a workaround implemented in the tpcp package. So ideally, you don’t need to worry about this. However, in case you manually call joblib within your algorithms or code, instead of using tpcp methods to run parallel code, you might need to use tpcp.parallel.delayed instead of joblib.delayed to ensure that the config is correctly restored in the child processes.