config_manager module

Handle simulation parameters.

In particular:
  • what are the initial properties of the beam?

  • which cavities are broken?

  • how should they be fixed?

  • simulation parameters to give to TW for a ‘post’ simulation?

Todo

Maybe make test and config to dict more compact?

Todo

position:
  • element name

  • element number

  • end_section

variable:
  • maybe add this? Unnecessary at this point

Todo

Remove global variables.

MANDATORY_CONFIG_ENTRIES = ('files', 'beam_calculator', 'beam')
OPTIONAL_CONFIG_ENTRIES = ('beam_calculator_post', 'evaluators', 'plots', 'wtf', 'design_space')
_load_correct_toml_entries(config_path: Path, config_keys: dict[str, str]) dict[str, dict[str, str | int | float | bool | list]]

Load the .toml and extract the dicts asked by user.

_make_global(beam: dict, beam_calculator: dict | None = None, **kwargs) None

Update the values of some variables so they can be used everywhere.

_override_some_toml_entries(configuration: dict[str, dict[str, str | int | float | bool | list]], warn_mismatch: bool = False, **override: dict[str, str | int | float | bool | list]) None

Override some entries before testing.

_process_config(toml_entries: dict[str, dict[str, Any]], config_folder: Path) None

Test all the given configuration keys.

process_config(config_path: Path, config_keys: dict[str, str], warn_mismatch: bool = False, override: dict[str, dict[str, str | int | float | bool | list]] | None = None) dict[str, dict[str, Any]]

Load and test the configuration file.

Parameters:
  • config_path (Path) – Path to the configuration file. It must be a `.toml file.

  • config_keys (dict[str, str]) – Associate the name of LightWin’s group of parameters to the entry in the configuration file.

  • warn_mismatch (bool, optional) – Raise a warning if a key in a override sub-dict is not found.

  • override (dict[str, dict[str, dict[str, str | int | float | bool | list]]]) – To override entries in the .toml. If not provided, we keep defaults.

Returns:

configuration – A dictonary holding all the keyword arguments that will be passed to LightWin objects, eg beam_calculator will be passed to BeamCalculator.

Return type:

dict[str, dict[str, Any]]