full_specs module

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

class ConfSpec(files: str = '', beam: str = '', beam_calculator: str = '', beam_calculator_post: str = '', plots: str = '', evaluators: str = '', design_space: str = '', wtf: str = '', **kwargs)

Bases: object

Define structure of a configuration object.

Parameters:

MANDATORY_CONFIG_ENTRIES (tuple[str, ...]) – Entries that you must declare for this ConfSpec to work.

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

Declare the attributes.

_get_proper_table(table_id: str, id_type: Literal['configured_object', 'table_entry'] = 'configured_object') TableConfSpec

Get the TableConfSpec named table_id.

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

  • id_type (Literal["configured_object", "table_entry"], optional) – 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).

Returns:

The desired object.

Return type:

TableConfSpec

to_toml_strings(toml_fulldict: dict[str, dict[str, Any]], id_type: Literal['configured_object', 'table_entry'] = 'configured_object', original_toml_folder: Path | None = None, **kwargs) list[str]

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"], optional) – 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 (pathlib.Path | None, optional) – Where the original .toml was; this is used to resolve paths relative to this location.

Returns:

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

Return type:

list[str]

prepare(toml_fulldict: dict[str, dict[str, Any]], toml_folder: Path, id_type: Literal['configured_object', 'table_entry'] = 'configured_object', **kwargs) bool

Check that all the tables in toml_fulldict are valid.

Also edit some values if necessary.

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

  • id_type (Literal["configured_object", "table_entry"], optional) – 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).

Returns:

If the dict is valid or not.

Return type:

bool

property _mandatory_keys_are_present: bool

Ensure that all the mandatory parameters are defined.

generate_dummy_dict(only_mandatory: bool = True) dict[str, dict[str, Any]]

Generate a default dummy dict that should let LightWin work.

class SimplestConfSpec(*, beam: str = 'beam', files: str = 'files', beam_calculator: str = 'beam_calculator')

Bases: ConfSpec

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

Defined for a run without optimization.

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

Define static specifications.

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