full_specs module

Gather in a single object all the parameters for LW to run.

class ConfSpec(files='', beam='', beam_calculator='', beam_calculator_post='', plots='', evaluators='', design_space='', wtf='', **kwargs)[source]

Bases: object

Define structure of a configuration object.

Parameters:
  • MANDATORY_CONFIG_ENTRIES – Entries that you must declare for this ConfSpec to work.

  • files (str, default: '')

  • beam (str, default: '')

  • beam_calculator (str, default: '')

  • beam_calculator_post (str, default: '')

  • plots (str, default: '')

  • evaluators (str, default: '')

  • design_space (str, default: '')

  • wtf (str, default: '')

MANDATORY_CONFIG_ENTRIES: tuple[str, ...] = ()
__init__(files='', beam='', beam_calculator='', beam_calculator_post='', plots='', evaluators='', design_space='', wtf='', **kwargs)[source]

Declare the attributes.

Parameters:
  • files (str, default: '')

  • beam (str, default: '')

  • beam_calculator (str, default: '')

  • beam_calculator_post (str, default: '')

  • plots (str, default: '')

  • evaluators (str, default: '')

  • design_space (str, default: '')

  • wtf (str, default: '')

Return type:

None

_get_proper_table(table_id, id_type='configured_object')[source]

Get the TableConfSpec named table_id.

Parameters:
  • table_id (str) – Name of the desired table.

  • id_type (Literal['configured_object', 'table_entry'], default: 'configured_object') – If table_id is the name of the object (eg 'beam') or of the table entry in the TOML (eg 'my_proton_beam', without brackets).

Return type:

TableConfSpec

Returns:

The desired object.

to_toml_strings(toml_fulldict, id_type='configured_object', original_toml_folder=None, **kwargs)[source]

Convert the given dict in string that can be put in a TOML.

Parameters:
  • toml_fulldict (dict[str, dict[str, Any]]) – Holds the full configuration.

  • id_type (Literal['configured_object', 'table_entry'], default: 'configured_object') – If toml_fulldict keys are name of the object (eg 'beam') or of the table entry in the TOML (eg 'my_proton_beam', without brackets).

  • original_toml_folder (Path | None, default: None) – Where the original TOML was; this is used to resolve paths relative to this location.

Return type:

list[str]

Returns:

The TOML content that can be directly written to a TOML file.

prepare(toml_fulldict, toml_folder, id_type='configured_object', **kwargs)[source]

Check that all the tables in toml_fulldict are valid.

Also edit some values if necessary.

Parameters:
  • toml_fulldict (ConfigKw) – Holds the full configuration.

  • id_type (Literal['configured_object', 'table_entry'], default: 'configured_object') – If toml_fulldict keys are name of the object (eg 'beam') or of the table entry in the TOML (eg 'my_proton_beam'). Do not put the brackets present in the TOML file.

  • toml_folder (Path)

Return type:

bool

Returns:

If the dict is valid or not.

property _mandatory_keys_are_present: bool

Ensure that all the mandatory parameters are defined.

generate_dummy_dict(only_mandatory=True)[source]

Generate a default dummy dict that should let LightWin work.

Parameters:

only_mandatory (bool, default: True)

Return type:

dict[str, dict[str, Any]]

class SimplestConfSpec(*, beam='beam', files='files', beam_calculator='beam_calculator')[source]

Bases: ConfSpec

Hold all the LightWin inputs, their types, allowed values, etc.

Defined for a run without optimization.

Parameters:
  • beam (str, default: 'beam')

  • files (str, default: 'files')

  • beam_calculator (str, default: 'beam_calculator')

MANDATORY_CONFIG_ENTRIES: tuple[str, ...] = ('beam', 'files', 'beam_calculator')
__init__(*, beam='beam', files='files', beam_calculator='beam_calculator')[source]

Define static specifications.

In the future, may add different mandatory specs, for example if failures are to be fixed or not.

Parameters:
  • beam (str, default: 'beam')

  • files (str, default: 'files')

  • beam_calculator (str, default: 'beam_calculator')

Return type:

None