optimisation.objective.quantity_is_between module

This module holds an objective that is a quantity must be within some bounds.

Todo

Implement loss functions.

class QuantityIsBetween(name: str, weight: float, get_key: str, get_kwargs: dict[str, Element | str | bool], limits: tuple[float], descriptor: str | None = None, loss_function: str | None = None)

Bases: Objective

Quantity must be within some bounds.

__init__(name: str, weight: float, get_key: str, get_kwargs: dict[str, Element | str | bool], limits: tuple[float], descriptor: str | None = None, loss_function: str | None = None) None

Set complementary get() flags, reference value.

Parameters:
  • get_key (str) – Name of the quantity to get, which must be an attribute of SimulationOutput.

  • get_kwargs (dict[str, Element | str | bool]) – Keyword arguments for the get() method. We do not check its validity, but in general you will want to define the keys elt and pos. If objective concerns a phase, you may want to precise the to_deg key. You also should explicit the to_numpy key.

  • limits (tuple[float]) – Lower and upper bound for the value.

  • loss_function (str | None, optional) – Indicates how the residues are handled whe the quantity is outside the limits. The default is None.

_abc_impl = <_abc._abc_data object>
_base_str() str

Return a base text for output.

_compute_residues(value: float) float

Compute the residues.

_value_getter(simulation_output: SimulationOutput) float

Get desired value using SimulationOutput.get() method.

current_value(simulation_output: SimulationOutput) str

Give value of current objective and residue.

evaluate(simulation_output: SimulationOutput) float

Compute residue of this objective.

Parameters:

simulation_output (SimulationOutput | float) – Object containing simulation results of the broken linac.

Returns:

residue – Difference between current evaluation and ideal_value value for self.name, scaled by self.weight.

Return type:

float