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)[source]
Bases:
ABCBase class to handle
VariableandConstraintcreation.- Parameters:
- use_files(variables_filepath, constraints_filepath=None, **design_space_kw)[source]
Tell factory to generate design space from the provided files.
- _run_variables(compensating_elements, reference_elements)[source]
Set up all the required variables.
- _run_constraints(compensating_elements, reference_elements)[source]
Set up all the required constraints.
- run(compensating_elements, reference_elements)[source]
Set up variables and constraints.
- Parameters:
- Return type:
- _get_initial_value_from_kw(variable, reference_element)[source]
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, reference_element, reference_elements)[source]
Select limits for given variable.
Call this method for classic limits.
- Parameters:
- Return type:
- Returns:
Lower and upper limit for current variable.
- _run_from_file(compensating_elements, reference_elements=None)[source]
Use the
DesignSpace.from_files()constructor.
- _abc_impl = <_abc._abc_data object at 0x75e5157e9ac0>
- class AbsPhaseAmplitude(design_space_kw)[source]
Bases:
DesignSpaceFactoryOptimise over \(\phi_{0,\,\mathrm{abs}}\) and \(k_e\).
- variables_names = ('phi_0_abs', 'k_e')
- _abc_impl = <_abc._abc_data object at 0x75e5158cd500>
- class RelPhaseAmplitude(design_space_kw)[source]
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 0x75e5158cd780>
- class SyncPhaseAmplitude(design_space_kw)[source]
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 0x75e5158cc180>
- class AbsPhaseAmplitudeWithConstrainedSyncPhase(design_space_kw)[source]
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 0x75e5158cdd00>
- class RelPhaseAmplitudeWithConstrainedSyncPhase(design_space_kw)[source]
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 0x75e5158cc2c0>
- class Everything(design_space_kw)[source]
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',)
- _abc_impl = <_abc._abc_data object at 0x75e5158cca40>
- class Unconstrained(design_space_kw)[source]
Bases:
AbsPhaseAmplitudeDeprecated alias to
AbsPhaseAmplitude.Deprecated since version 0.6.16: Prefer
AbsPhaseAmplitude.- _abc_impl = <_abc._abc_data object at 0x75e5158cc340>
- class UnconstrainedRel(design_space_kw)[source]
Bases:
RelPhaseAmplitudeDeprecated alias to
RelPhaseAmplitude.Deprecated since version 0.6.16: Prefer
RelPhaseAmplitude.- _abc_impl = <_abc._abc_data object at 0x75e5158f2000>
- class SyncPhaseAsVariable(design_space_kw)[source]
Bases:
SyncPhaseAmplitudeDeprecated alias to
SyncPhaseAmplitude.Deprecated since version 0.6.16: Prefer
SyncPhaseAmplitude.- _abc_impl = <_abc._abc_data object at 0x75e5158cc440>
- class ConstrainedSyncPhase(design_space_kw)[source]
Bases:
AbsPhaseAmplitudeWithConstrainedSyncPhaseDeprecated alias to
AbsPhaseAmplitudeWithConstrainedSyncPhase.Deprecated since version 0.6.16: Prefer
AbsPhaseAmplitudeWithConstrainedSyncPhase.- _abc_impl = <_abc._abc_data object at 0x75e5158cd840>
- 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'>}