combine_solutions module
Take the best compensation settings among several runs.
Basic usage:
./combine_solutions.py -d /path/to/sim1/ /path/to/sim2/ /path/to/sim3
This is useful when different strategies are best on different fault scenarios.
The compensation settings are sorted against a column in the
evaluations.csv files.
Reminder on the directory structure and conventions:
- simulation_1 <- project folder
- 000000_ref <- simulation folder (holds a fault scenario) | 0_Envelope1D | 1_TraceWin000001 | 0_Envelope1D | 1_TraceWin…evaluations.csv
- simulation_2
- 000000_ref000001…
- combine_bests(paths, criterion_to_minimize='Lost power over whole linac in W.', out_folder='', copy=False)[source]
Compare several solutions, and concatenate the best one.
To determine the best solution for every fault scenario, we open each simulation’s
evaluations.csv, look at the value of the columncriterion_to_minimizeand keep the simulation with the lowest.- Parameters:
paths (
Sequence[Path|str]) – Project folders (whereevaluations.csvand every simulation is).criterion_to_minimize (
str, default:'Lost power over whole linac in W.') – Theevaluations.csvcolumn against which simulations are compared. The default is"Lost power over whole linac in W."(we keep simulations with the lowest lost power).out_folder (
Path|str, default:'') – Where every best simulation folder will be gathered. If not provided, we create acombined/folder in the last common ancestor of all provided paths.copy (
bool, default:False) – To create hard-copies of the original simulation folders instead of creating a symlink.
- Return type:
- _infer_an_output_folder(paths, output_folder_name='combined')[source]
Return output folder in the last common parent of
paths.
- _select_best_simulations(paths, criterion_to_minimize)[source]
Give the name of the best solution according to
criterion_to_minimize- Parameters:
- Return type:
- Returns:
best_simulation_folders – For each fault scenario, holds the path to the best simulation folder.
combined – A
evaluations.csvwhere each row holds the values for the best simulation. You must ensure that allevaluations.csvhave the same columns.
- _concat_evaluations_files(evaluations, best_solutions)[source]
Concatenate the evaluations, taking only the best.
- Parameters:
evaluations (
dict[str,DataFrame]) – Keys are user-defined names for every simulation. Values are correspondingevaluations.csvfiles; their columns must be the same. They must have the same indexes.best_solutions (
Sequence[Path]) – For every calculation, defines theevaluationwe want to keep. The lenght must be the same as the length of every object inevaluations. Contained strings must all be keys ofevaluations.
- Return type:
- Returns:
Same columns as
evaluations. Every row contains theevaluations.csvrow of the best solution.
- _gather_best_simulations_in_same_place(best_simulation_folders, out_folder, create_symlinks_instead_of_hard_copies, dirs_exist_ok=True)[source]
Concatenate the best simulation folders in a single place.
- _copy_or_create_symlink(src, dst, create_symlinks_instead_of_hard_copies, dirs_exist_ok)[source]
Copy
srctodstor create symlinks.
- _load_evaluation(evaluation_folder, evaluation_namecol=None, new_name=None)[source]
Load the file and rename column header.
- Parameters:
evaluation_folder (
Path) – Folder where theevaluations.csvfile is.evaluation_namecol (
Sequence[str] |None, default:None) – Name of the column in theevaluations.csvfor the sorting; if not provided, we keep all the columns.new_name (
Sequence[str] |None, default:None) – If provided, the loaded columns will be renamed with this. The length ofnew_namemust matchevaluation_namecol.
- Return type:
- Returns:
Holds all the values of
evaluation_namecolinevaluation_path.