Configuration
Most of the configuration of LightWin is performed through a .toml
configuration file, which should be given as argument to several objects initialisation.
The configuration file is treated with the help of the tomllib module.
It is processed by the process_config()
function, which checks it’s validity and converts it to a dictionary.
Note
Configuration was previously set up thanks to a .ini
file. This is now deprecated.
The name of every section is not important, as long as every section is correctly passed to process_config()
.
It is however recommended to use explicit names.
Example for the beam
section
[beam_proton] # this could be [bonjoure] or anything
e_rest_mev = 938.27203
q_adim = 1.0
e_mev = 20.0
f_bunch_mhz = 350.0
i_milli_a = 25.
sigma = [
[ 1e-6, -2e-7, 0.0, 0.0, 0.0, 0.0],
[-2e-7, 8e-7, 0.0, 0.0, 0.0, 0.0],
[ 0.0, 0.0, 1e-6, -2e-7, 0.0, 0.0],
[ 0.0, 0.0, -2e-7, 8e-7, 0.0, 0.0],
[ 0.0, 0.0, 0.0, 0.0, 1e-6, -2e-7],
[ 0.0, 0.0, 0.0, 0.0, -2e-7, 8e-7],
]
[beam_proton_no_space_charge] # or [sdaflghsh] but it would be less explicit in my humble opinion
linac = my_ads
e_rest_mev = 938.27203
q_adim = 1.0
e_mev = 20.0
f_bunch_mhz = 350.0
i_milli_a = 0.0
sigma = [
[ 1e-6, -2e-7, 0.0, 0.0, 0.0, 0.0],
[-2e-7, 8e-7, 0.0, 0.0, 0.0, 0.0],
[ 0.0, 0.0, 1e-6, -2e-7, 0.0, 0.0],
[ 0.0, 0.0, -2e-7, 8e-7, 0.0, 0.0],
[ 0.0, 0.0, 0.0, 0.0, 1e-6, -2e-7],
[ 0.0, 0.0, 0.0, 0.0, -2e-7, 8e-7],
]
Note
In order to dynamically keep track of the options that are implemented, the Allowed values column of following tables contains a link to the variable storing the possible values, when relevant.
files
section (mandatory)
This section is mandatory to initialize an Accelerator
through the accelerator_factory()
function.
It must contain the key dat_file
, which is the path to the linac structure file (same format as TraceWin).
Entry |
Type |
Description |
Allowed values |
Mandatory? |
---|---|---|---|---|
|
path |
Path to the |
✅ |
See also: config.files
and the `TraceWin compatibility note`_.
beam
section (mandatory)
Here we define the main properties of the beam at the entrance of the linac.
Note that with TraceWin
, most of these properties are defined within it’s own .ini
file.
The units must be consistent with LightWin’s system of units, see also Units and conventions.
Entry |
Type |
Description |
Allowed values |
Mandatory? |
---|---|---|---|---|
|
float |
Rest energy of particle in \(\mathrm{MeV}\) |
✅ |
|
|
float |
Adimensioned charge of particle |
✅ |
|
|
float |
Energy of particle at entrance in \(\mathrm{MeV}\) |
✅ |
|
|
float |
Beam bunch frequency in \(\mathrm{MHz}\) |
✅ |
|
|
float |
Beam current in \(\mathrm{mA}\) |
❌ |
|
|
list of list of float |
Input \(\sigma\) beam matrix in \(\mathrm{m}\); \(\mathrm{rad}\) |
✅ |
Format for the sigma
entry:
sigma = [
[ 1e-6, -2e-7, 0e+0, 0e+0, 0e+0, 0e+0],
[-2e-7, 8e-7, 0e+0, 0e+0, 0e+0, 0e+0],
[ 0e+0, 0e+0, -2e-7, 8e-7, 0e+0, 0e+0],
[ 0e+0, 0e+0, -2e-7, 8e-7, 0e+0, 0e+0],
[ 0e+0, 0e+0, 0e+0, 0e+0, -2e-7, 8e-7],
[ 0e+0, 0e+0, 0e+0, 0e+0, -2e-7, 8e-7]
]
beam_calculator
section (mandatory)
Entry |
Type |
Description |
Allowed values |
Mandatory? |
---|---|---|---|---|
|
str |
Name of the tool |
|
✅ |
If the desired BeamCalculator
is Envelope1D
:
Entry |
Type |
Description |
Allowed values |
Mandatory? |
---|---|---|---|---|
|
bool |
Simulation realized in absolute phase? |
✅ |
|
|
bool |
Use Cython implementation? |
✅ |
|
|
int |
# of integration steps per cavity cell |
✅ |
|
|
str |
Integration method |
|
✅ |
Note that Envelope3D
takes the same configuration entries, except flag_cython
(not implemented yet) and method
that must be 'RK4'
('leapgrog'
not implemented yet).
If the desired BeamCalculator
is TraceWin
:
Entry |
Type |
Description |
Allowed values |
Mandatory? |
---|---|---|---|---|
|
str |
A |
existing relative (w.r.t |
✅ |
|
str |
Name of machine |
must be a key in the |
❌ |
|
str |
TraceWin solver |
Must be an entry under your machine name in |
✅ |
|
path |
Path to TraceWin’s |
✅ |
|
|
bool |
To avoid TraceWin window |
None |
❌ |
|
int |
To force or not Partran tracking |
|
❌ |
… |
Every TraceWin command line option |
❌ |
Check TraceWin’s documentation for the list of command line arguments.
Note that you also need to create a configuration file that will define the path to the TraceWin
executables.
See data/examples/machine_config_file.toml
for an example.
Todo
List of allowed tracewin arguments in doc
Todo
There are doublons between doc in config.beam_calculator
and here. Maybe keep in module, but make the format better.
The [beam_calculator_post]
follows the same format.
It is used to store a second BeamCalculator
.
This is mainly useful for defining a more precise – but more time-consuming – beam dynamics tool, for example to check your compensation settings.
plots
section (mandatory)
This section defines what quantities will be plotted at the end of the simulation.
Entry |
Type |
Description |
Allowed values |
Mandatory? |
---|---|---|---|---|
|
bool |
Plot evolution of kinetic energy? |
❌ |
|
|
bool |
Plot evolution of absolute phase? |
❌ |
|
|
bool |
Plot cavity parameters? |
❌ |
|
|
bool |
Plot evolution of emittance? |
❌ |
|
|
bool |
Plot Twiss parameters? |
❌ |
|
|
bool |
Plot envelopes? |
❌ |
|
|
bool |
Plot transfer matrix components? |
❌ |
Warning
Plot of transfer matrix currently not working.
wtf
section
wtf
stands for what to fit.
This section parametrizes the failed cavities, as well as how they are fixed.
Entry |
Type |
Description |
Allowed values |
Mandatory? |
---|---|---|---|---|
|
str |
Name of optimisation algorithm |
✅ |
|
|
str |
How compensating cavities are selected |
|
✅ |
|
str |
Indicates if failed is element index/cavity index/name |
|
✅ |
|
list[list[int]] | list[list[str]] |
Index of failed cavities |
✅ |
|
|
str |
Objectives for the optimisation algorithm |
|
✅ |
|
dict |
Keyword arguments passed to the actual optimisation method |
❌ |
Each strategy
entry requires specific additional arguments.
As an example, with the k out of n
method, you need to give LightWin k
, the number of compensating cavities per failed cavity.
The specific documentation can be found in failures.strategy
.
You can type the index of failed cavities on several lines if you want to study several fault scenarios at once.
Example
# Indexes are cavity indexes
idx = cavity
failed = [
[0, 1], # First simulation first cryomodule is down
[0], # Second simulation only first cavity is down
[1, 45] # Third simulation second and 46th cavity are down
]
optimisation.design_space
section
This section parametrizes how the design space will be set, i.e. what are the variables, their limits and initial values, and what are the constraints and their limits.
If you have any doubt, know that all these settings are passed down to DesignSpaceFactory.__init__()
as design_space_kw
.
There are two ways to define the design space limits and initial values; the first is to let LightWin calculate it from the nominal settings of the linac. This approach is easier to use for the first runs.
Entry |
Type |
Description |
Allowed values |
Mandatory? |
---|---|---|---|---|
|
bool |
If files should be used |
|
✅ |
|
str |
What variables/constraints should be used |
✅ |
|
|
float |
Max relative increase of \(\phi_s\) wrt nominal in \(\mathrm{\%}\) |
✅ |
|
|
float |
Max absolute \(\phi_s\) in \(\mathrm{deg}\) |
default |
❌ |
|
float |
Min absolute \(\phi_s\) in \(\mathrm{deg}\) |
default |
❌ |
|
float |
Max decrease of \(k_e\) wrt nominal in \(\mathrm{\%}\) |
✅ |
|
|
float |
Max increase of \(k_e\) wrt nominal in \(\mathrm{\%}\) |
✅ |
|
|
bool |
If max \(k_e\) should be the same for the whole section |
default |
❌ |
When from_file
is True
, you must provide a path to a .csv
file containing, for every element, every variable, its initial value and limits.
If the problem is constrained, you must also provide a .csv
with, for every element, the limits of every constraint.
This approach is more useful when you want to fine-tune the optimisation, as you can manually edit the .csv
, for example to take into account the specific multipacting barriers of a rogue cavity.
To generate the .csv
files with the proper format, look at examples/generate_design_space_files.py
.
Entry |
Type |
Description |
Allowed values |
Mandatory? |
---|---|---|---|---|
|
bool |
If files should be used |
|
✅ |
|
str |
What variables/constraints should be used |
✅ |
|
|
str |
Path to the |
✅ |
|
|
str |
Path to the |
❌ |
Ultimately, these settings will be passed down to DesignSpaceFactory
.
evaluators
section
This section is used to defined FaultScenarioSimulationOutputEvaluator
objects.
They are used to evaluate the absolute or relative quality of compensation settings.
Entry |
Type |
Description |
Allowed values |
Mandatory? |
---|---|---|---|---|
|
str |
Name of the desired evaluators |
|
❌ |
Note
There is also a SimulationOutputEvaluator
object that is used internally by LightWin to determine if a Fault
was correctly fixed.