Validator of algorithm parameters

This module validates the parameters passed to an algorithm.

encore.validators.algorithm_parameters.build_parameters_model(defaults: dict) type[BaseModel]

Dynamically create a Pydantic model that validates user parameters against defaults.

Parameters:

defaults (dict) – Dictionary mapping the name of each parameter and the default value used to infer the type.

Returns:

Pydantic model.

Return type:

Pydantic Model

encore.validators.algorithm_parameters.collect_parameters(algorithm_cfg: dict) dict

Collects the default values from an algorithm config dict as defined in the YAML config file.

Parameters:

algorithm_cfg (dict) – Dictionary with the definition of an algorithm.

Returns:

Dictionary mapping the name of each parameter and the default value used to infer the type.

Return type:

dict

encore.validators.algorithm_parameters.validate(algorithm: str, user_parameters: dict) dict

Validates the parameters for an algorithm using as ground truth the config file for the algorithm.

Parameters:
  • algorithm (str) – Name of the algorithm, is the key in the config file.

  • user_parameters (dict) – Dictionary with parameters to validates. Maps user_parameters[‘parameter_name’] = parameter_value. The name of each parameter is defined in the config file.

Returns:

Dictionary with the validated parameter to value mapping.

Return type:

dict

Raises:
  • RuntimeError – If the YAML config file can not be loaded.

  • RuntimeError – If the algorithm name could not be found in the YAML config file.

encore.validators.algorithm_parameters.validate_user_parameters(user_parameters: dict, defaults: dict)

Validate user parameters against defaults.

Parameters:
  • user_parameters (dict) – Dictionary mapping parameter_name with value given by the user.

  • defaults (dict) – Dictionary mapping the name of each parameter and the default value used to infer the type.

Raises:

RuntimeError – When the user parameters failed to validate.

Returns:

Validated output model.

Return type:

Pydantic Validated Model