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:
A path to a json file that contains the config.
An instance of a
LocalConfigobjectAutomatically, via an environmental variable with the path to a json file.
Get the default config file based on the
_default_config_fileparameter.
The lookup order is as follows:
If you set the
config_obj_or_pathparameter to a path or aLocalConfigobject, this will be used.If this is None, we will try to load the config path from the environmental variable
GAITMAP_CHALLENGES_CONFIG.If this is None, we will try to load the default config file based on the
_default_config_fileparameter.
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_runfunction 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 forsave_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
LocalConfigThe config class that is used for the local config.
reset_configReset the global config to None, so that it can be set again using this
set_configcreate_config_templateCreate a config template file that can be used to create a config file.
configGet 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 theset_configmethod. This means that you can access the config object from anywhere in your code by simplyconfig()fromgaitmap_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 usetpcp.parallel.delayedinstead ofjoblib.delayedto ensure that the config is correctly restored in the child processes.