factory module
Define factory and presets to handle variables, constraints, limits, etc..
Note
If you add your own DesignSpaceFactory preset, do not forget to add it to
the list of supported presets in optimisation.design_space_specs.
- class DesignSpaceFactory(design_space_kw: dict[str, float | bool | str | Path])
Bases:
ABCBase class to handle
VariableandConstraintcreation.- Parameters:
- __post_init__()
Declare complementary variables.
- _check_can_be_retuned(compensating_elements: list[Element]) None
Check that given elements can be retuned.
- use_files(variables_filepath: Path, constraints_filepath: Path | None = None, **design_space_kw: float | bool | str | Path) None
Tell factory to generate design space from the provided files.
- Parameters:
variables_filepath (pathlib.Path) – Path to the
variables.csvfile.constraints_filepath (pathlib.Path | None) – Path to the
constraints.csvfile. The default is None.
- _run_variables(compensating_elements: list[Element], reference_elements: list[Element]) list[Variable]
Set up all the required variables.
- _run_constraints(compensating_elements: list[Element], reference_elements: list[Element]) list[Constraint]
Set up all the required constraints.
- run(compensating_elements: list[Element], reference_elements: list[Element]) DesignSpace
Set up variables and constraints.
- _get_initial_value_from_kw(variable: Literal['k_e', 'phi_0_rel', 'phi_0_abs', 'phi_s'], reference_element: Element) float
Select initial value for given variable.
The default behavior is to return the value of
variablefromreference_element, which is a good starting point for optimisation.
- _get_limits_from_kw(variable: Literal['k_e', 'phi_0_rel', 'phi_0_abs', 'phi_s'], reference_element: Element, reference_elements: list[Element]) tuple[float, float]
Select limits for given variable.
Call this method for classic limits.
- Parameters:
- Returns:
Lower and upper limit for current variable.
- Return type:
- _run_from_file(compensating_elements: list[Element], reference_elements: list[Element] | None = None) DesignSpace
Use the
DesignSpace.from_files()constructor.- Parameters:
- Return type:
- _abc_impl = <_abc._abc_data object at 0x7f36f7608c00>
- class AbsPhaseAmplitude(design_space_kw: dict[str, float | bool | str | Path])
Bases:
DesignSpaceFactoryOptimise over \(\phi_{0,\,\mathrm{abs}}\) and \(k_e\).
- variables_names = ('phi_0_abs', 'k_e')
- _abc_impl = <_abc._abc_data object at 0x7f36f7609400>
- class RelPhaseAmplitude(design_space_kw: dict[str, float | bool | str | Path])
Bases:
DesignSpaceFactoryOptimise over \(\phi_{0,\,\mathrm{rel}}\) and \(k_e\).
The same as
AbsPhaseAmplitude, but the phase variable is \(\phi_{0,\,\mathrm{rel}}\) instead of \(\phi_{0,\,\mathrm{abs}}\). It may be better for convergence, because it makes cavities more independent.- variables_names = ('phi_0_rel', 'k_e')
- _abc_impl = <_abc._abc_data object at 0x7f36f760a080>
- class SyncPhaseAmplitude(design_space_kw: dict[str, float | bool | str | Path])
Bases:
DesignSpaceFactoryOptimise over \(\phi_s\) and \(k_e\).
Synchronous phases outside of the bounds will not ocurr, without setting any
Constraint. This kind of optimisation takes more time as we need, for every iteration of theOptimisationAlgorithm, to find the \(\phi_{0,\,\mathrm{rel}}\) that corresponds to the desired \(\phi_s\).- variables_names = ('phi_s', 'k_e')
- _abc_impl = <_abc._abc_data object at 0x7f36f760b3c0>
- class AbsPhaseAmplitudeWithConstrainedSyncPhase(design_space_kw: dict[str, float | bool | str | Path])
Bases:
DesignSpaceFactoryOptimise \(\phi_{0,\,\mathrm{abs}}\), \(k_e\). \(\phi_s\) is constrained.
Warning
The selected
OptimisationAlgorithmmust support the constraints.- variables_names = ('phi_0_abs', 'k_e')
- constraints_names = ('phi_s',)
- _abc_impl = <_abc._abc_data object at 0x7f36f760b540>
- class RelPhaseAmplitudeWithConstrainedSyncPhase(design_space_kw: dict[str, float | bool | str | Path])
Bases:
DesignSpaceFactoryOptimise \(\phi_{0,\,\mathrm{rel}}\), \(k_e\). \(\phi_s\) is constrained.
Warning
The selected
OptimisationAlgorithmmust support the constraints.- variables_names = ('phi_0_rel', 'k_e')
- constraints_names = ('phi_s',)
- _abc_impl = <_abc._abc_data object at 0x7f36f7609d40>
- class Everything(design_space_kw: dict[str, float | bool | str | Path])
Bases:
DesignSpaceFactoryThis class creates all possible variables and constraints.
This is not to be used in an optimisation problem, but rather to save in a
.csvall the limits and initial values for every variable/constraint.- variables_names = ('k_e', 'phi_s', 'phi_0_abs', 'phi_0_rel')
- constraints_names = ('phi_s',)
- run(*args, **kwargs) DesignSpace
Launch normal run but with an info message.
- _abc_impl = <_abc._abc_data object at 0x7f36f760b500>
- class Unconstrained(design_space_kw: dict[str, float | bool | str | Path])
Bases:
AbsPhaseAmplitudeDeprecated alias to
AbsPhaseAmplitude.Deprecated since version 0.6.16: Prefer
AbsPhaseAmplitude.- _abc_impl = <_abc._abc_data object at 0x7f36f760b380>
- class UnconstrainedRel(design_space_kw: dict[str, float | bool | str | Path])
Bases:
RelPhaseAmplitudeDeprecated alias to
RelPhaseAmplitude.Deprecated since version 0.6.16: Prefer
RelPhaseAmplitude.- _abc_impl = <_abc._abc_data object at 0x7f36f96c5bc0>
- class SyncPhaseAsVariable(design_space_kw: dict[str, float | bool | str | Path])
Bases:
SyncPhaseAmplitudeDeprecated alias to
SyncPhaseAmplitude.Deprecated since version 0.6.16: Prefer
SyncPhaseAmplitude.- _abc_impl = <_abc._abc_data object at 0x7f36f76094c0>
- class ConstrainedSyncPhase(design_space_kw: dict[str, float | bool | str | Path])
Bases:
AbsPhaseAmplitudeWithConstrainedSyncPhaseDeprecated alias to
AbsPhaseAmplitudeWithConstrainedSyncPhase.Deprecated since version 0.6.16: Prefer
AbsPhaseAmplitudeWithConstrainedSyncPhase.- _abc_impl = <_abc._abc_data object at 0x7f36f7834780>
- DESIGN_SPACE_FACTORY_PRESETS = { 'abs_phase_amplitude': <class 'lightwin.optimisation.design_space.factory.AbsPhaseAmplitude'>, 'abs_phase_amplitude_with_constrained_sync_phase': <class 'lightwin.optimisation.design_space.factory.AbsPhaseAmplitudeWithConstrainedSyncPhase'>, 'constrained_sync_phase': <class 'lightwin.optimisation.design_space.factory.AbsPhaseAmplitudeWithConstrainedSyncPhase'>, 'everything': <class 'lightwin.optimisation.design_space.factory.Everything'>, 'rel_phase_amplitude': <class 'lightwin.optimisation.design_space.factory.RelPhaseAmplitude'>, 'rel_phase_amplitude_with_constrained_sync_phase': <class 'lightwin.optimisation.design_space.factory.RelPhaseAmplitudeWithConstrainedSyncPhase'>, 'sync_phase_amplitude': <class 'lightwin.optimisation.design_space.factory.SyncPhaseAmplitude'>, 'sync_phase_as_variable': <class 'lightwin.optimisation.design_space.factory.SyncPhaseAmplitude'>, 'unconstrained': <class 'lightwin.optimisation.design_space.factory.AbsPhaseAmplitude'>, 'unconstrained_rel': <class 'lightwin.optimisation.design_space.factory.RelPhaseAmplitude'>}
- get_design_space_factory(design_space_preset: str, **design_space_kw: float | bool) DesignSpaceFactory
Select proper factory, instantiate it and return it.
- Parameters:
- Return type: