simulation_output_evaluator module
Define an object to evaluate quality of a set of cavity settings.
Note
We do not directly evaluate a SetOfCavitySettings though, but
rather a SimulationOutput.
Todo
different factories for evaluation during the fit and evaluation after
Todo
Clean this.
- _return_value_should_be_plotted(partial_function)[source]
Determine if keyword ‘to_plot’ was passed and is True.
This function only works on functions defined by
functools.partial. If it is not (lambda function, “classic” function), we consider that the plotting was not desired. We check if the ‘to_plot’ keyword was given in the partial definition, and if it is not we also consider that the plot was not wanted.
- _limits_given_in_functoolspartial_args(partial_function)[source]
Extract the limits given to a test function.
- class SimulationOutputEvaluator(value_getter, ref_simulation_output, ref_value_getter=None, post_treaters=(<function do_nothing at 0x73dca29de980>, ), tester=None, descriptor='', markdown='', plt_kwargs=None, raise_error_if_value_getter_returns_none=True)[source]
Bases:
ABCA base class for all the possible types of tests.
- Parameters:
value_getter (Callable[[SimulationOutput], value_t]) – A function that takes the simulation output under study as argument, and returns the value to be studied.
ref_simulation_output (SimulationOutput) – The simulation output of a nominal
Accelerator. It is up to the user to verify that theBeamCalculatoris the same between the reference and the fixedSimulationOutput.ref_value_getter (Callable[[SimulationOutput, SimulationOutput], ref_value_t] | None, optional) – A function that takes the reference simulation ouput and the simulation output under study as arguments, and returns the reference value. In general, only the first argument will be used. The second argument can be used in specific cases, eg for the mismatch factor. The default is None.
post_treaters (Sequence[post_treater_t], optional) – A tuple of functions that will be called one after each other and applied on
value, which is returned byvalue_getter. First argument must bevalue, second argumentref_value. They return an updatevalue, which is passed to the next function inpost_treaters. The default is a tuple containing onlydo_nothing().tester (tester_t | None, optional) – A function that takes post-treated
valueand test it. It can return a boolean or a float. The default is None.fignum (int | None, optional) – The Figure number. The default is None, in which case no plot is produced.
descriptor (str, optional) – A sentence or two to describe what the test is about. The default is an empty string.
markdown (str, optional) – A markdown name for this quantity, used in plots y label. The default is an empty string.
plt_kwargs (dict[str, Any] | None, optional) – A dictionary with keyword arguments passed to the
plt.Figure. The default is None.raise_error_if_value_getter_returns_none (
bool, default:True)
-
value_getter:
Callable[[SimulationOutput],ndarray|float]
-
ref_simulation_output:
SimulationOutput
-
ref_value_getter:
Callable[[SimulationOutput,SimulationOutput],ndarray|float] |None= None
-
post_treaters:
Sequence[Callable[[ndarray|float,ndarray|float],ndarray|float]] = (<function do_nothing at 0x73dca29de980>,)
- run(simulation_output)[source]
Run the test.
It can return a bool (test passed with success or not), or a float. The former is useful for production purposes, when you want to sort the settings in valid/invalid categories. The latter is useful for development purposes, i.e. to identify the most complex cases in a bunch of configurations.
- Parameters:
simulation_output (
SimulationOutput)- Return type:
- _get_ref_data(simulation_output)[source]
Get da reference data.
- Parameters:
simulation_output (
SimulationOutput)- Return type:
- _apply_post_treatments(x_data, y_data, y_ref_data, **plot_kw)[source]
Apply all the
post_treatersfunctions.Can also plot the post-treated data after all or some of the post-treatments have been performed.
- _apply_test(x_data, y_data, **plot_kw)[source]
Apply da testing functions.
Can also plot the test results if asked.
- _add_structure_plot(simulation_output)[source]
Add a plot of the structure in the bottom ax.
- Parameters:
simulation_output (
SimulationOutput)- Return type:
- _save_plot(out_path, fignum=None, to_save=False, **kwargs)[source]
Save the figure if asked, and if
out_pathis defined.
- __init__(value_getter, ref_simulation_output, ref_value_getter=None, post_treaters=(<function do_nothing at 0x73dca29de980>, ), tester=None, descriptor='', markdown='', plt_kwargs=None, raise_error_if_value_getter_returns_none=True)
- Parameters:
value_getter (
Callable[[SimulationOutput],ndarray|float])ref_simulation_output (
SimulationOutput)ref_value_getter (
Callable[[SimulationOutput,SimulationOutput],ndarray|float] |None, default:None)post_treaters (
Sequence[Callable[[ndarray|float,ndarray|float],ndarray|float]], default:(<function do_nothing at 0x73dca29de980>,))tester (
Callable[[ndarray|float],float|bool|None] |None, default:None)descriptor (
str, default:'')markdown (
str, default:'')raise_error_if_value_getter_returns_none (
bool, default:True)
- _abc_impl = <_abc._abc_data object at 0x73dca29aa780>