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
- class SimulationOutputEvaluator(value_getter, ref_simulation_output, ref_value_getter=None, post_treaters=(<function do_nothing at 0x7318f68e3ec0>, ), 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],ndarray|float]) – 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 nominalAccelerator. It is up to the user to verify that theBeamCalculatoris the same between the reference and the fixedSimulationOutput.ref_value_getter (
Callable[[SimulationOutput,SimulationOutput],ndarray|float] |None, default:None) – 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[Callable[[ndarray|float,ndarray|float],ndarray|float]], default:(<function do_nothing at 0x7318f68e3ec0>,)) – A tuple of functions that will be called one after each other and applied onvalue, 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 (
Callable[[ndarray|float],float|bool|None] |None, default:None) – A function that takes post-treatedvalueand test it. It can return a boolean or a float. The default is None.fignum – The Figure number. The default is None, in which case no plot is produced.
descriptor (
str, default:'') – A sentence or two to describe what the test is about.markdown (
str, default:'') – A markdown name for this quantity, used in plots y label.plt_kwargs (
dict[str,Any] |None, default:None) – A dictionary with keyword arguments passed to theplt.Figure.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 0x7318f68e3ec0>,)
- 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.
- _resampled(x_data, y_data, y_ref_data)[source]
Resample data.
- Parameters:
- Return type:
tuple[ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]],ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]],ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]],ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]]
- _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 0x7318f68e3ec0>, ), 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 0x7318f68e3ec0>,))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)
- Return type:
None
- _abc_impl = <_abc._abc_data object at 0x7318f68f6980>