all

compression_safeguards.safeguards.combinators.all

Logical all (and) combinator safeguard.

Classes:

  • AllSafeguards

    The AllSafeguards guarantees that, for each element, all of the combined

AllSafeguards

AllSafeguards(
    *,
    safeguards: Collection[
        dict[str, JSON]
        | PointwiseSafeguard
        | StencilSafeguard
    ],
)

Bases: Safeguard

flowchart LR compression_safeguards.safeguards.combinators.all.AllSafeguards[AllSafeguards] compression_safeguards.safeguards.abc.Safeguard[Safeguard] compression_safeguards.safeguards.abc.Safeguard --> compression_safeguards.safeguards.combinators.all.AllSafeguards click compression_safeguards.safeguards.combinators.all.AllSafeguards href "" "compression_safeguards.safeguards.combinators.all.AllSafeguards" click compression_safeguards.safeguards.abc.Safeguard href "" "compression_safeguards.safeguards.abc.Safeguard"

The AllSafeguards guarantees that, for each element, all of the combined safeguards' guarantees are upheld.

At the moment, only pointwise and stencil safeguards and combinations thereof can be combined by this all-combinator. The combinator is a pointwise or a stencil safeguard, depending on the safeguards it combines.

Parameters:
Raises:
  • TypeCheckError

    if any parameter has the wrong type.

  • ValueError

    if the safeguards collection is empty.

  • ...

    if instantiating a safeguard raises an exception.

Methods:

  • check

    Check if, for all elements, all of the combined safeguards succeed the

  • check_pointwise

    Check for which elements all of the combined safeguards succeed the

  • compute_safe_intervals

    Compute the intersection of the safe intervals of the combined

  • compute_footprint

    Compute the footprint of the foot array, e.g. for expanding data

  • compute_inverse_footprint

    Compute the inverse footprint of the foot array, e.g. for expanding

  • get_config

    Returns the configuration of the safeguard.

kind class-attribute

kind: str = 'all'

safeguards property

The set of safeguards that this any combinator has been configured to uphold.

late_bound property

late_bound: Set[Parameter]

The set of late-bound parameters that this safeguard has.

Late-bound parameters are only bound when checking and applying the safeguard, in contrast to the normal early-bound parameters that are configured during safeguard initialisation.

Late-bound parameters can be used for parameters that depend on the specific data that is to be safeguarded.

check

check(
    data: ndarray[S, dtype[T]],
    approximation: ndarray[S, dtype[T]],
    *,
    late_bound: Bindings,
    where: Literal[True] | ndarray[S, dtype[bool]] = True,
) -> bool

Check if, for all elements, all of the combined safeguards succeed the check.

Parameters:
  • data (ndarray[S, dtype[T]]) –

    Original data array, relative to which the approximation is checked.

  • approximation (ndarray[S, dtype[T]]) –

    Approximation of the data array.

  • late_bound (Bindings) –

    Bindings for late-bound parameters, including for this safeguard.

  • where (Literal[True] | ndarray[S, dtype[bool]], default: True ) –

    Only check at data points where the condition is True.

Returns:
  • ok( bool ) –

    True if the check succeeded.

Raises:
  • ...

    if checking a safeguard raises an exception.

check_pointwise

check_pointwise(
    data: ndarray[S, dtype[T]],
    approximation: ndarray[S, dtype[T]],
    *,
    late_bound: Bindings,
    where: Literal[True] | ndarray[S, dtype[bool]] = True,
) -> ndarray[S, dtype[bool]]

Check for which elements all of the combined safeguards succeed the check.

Parameters:
  • data (ndarray[S, dtype[T]]) –

    Original data array, relative to which the approximation is checked.

  • approximation (ndarray[S, dtype[T]]) –

    Approximation of the data array.

  • late_bound (Bindings) –

    Bindings for late-bound parameters, including for this safeguard.

  • where (Literal[True] | ndarray[S, dtype[bool]], default: True ) –

    Only check at data points where the condition is True.

Returns:
  • ok( ndarray[S, dtype[bool]] ) –

    Pointwise, True if the check succeeded for this element.

Raises:
  • ...

    if checking a safeguard raises an exception.

compute_safe_intervals

compute_safe_intervals(
    data: ndarray[S, dtype[T]],
    *,
    late_bound: Bindings,
    where: Literal[True] | ndarray[S, dtype[bool]] = True,
) -> IntervalUnion[T, int, int]

Compute the intersection of the safe intervals of the combined safeguards, i.e. where all of them are safe.

Parameters:
  • data (ndarray[S, dtype[T]]) –

    Data for which the safe intervals should be computed.

  • late_bound (Bindings) –

    Bindings for late-bound parameters, including for this safeguard.

  • where (Literal[True] | ndarray[S, dtype[bool]], default: True ) –

    Only compute the safe intervals at pointwise checks where the condition is True.

Returns:
Raises:
  • ...

    if computing the safe intervals for a safeguard raises an exception.

compute_footprint

compute_footprint(
    foot: ndarray[S, dtype[bool]],
    *,
    late_bound: Bindings,
    where: Literal[True] | ndarray[S, dtype[bool]] = True,
) -> ndarray[S, dtype[bool]]

Compute the footprint of the foot array, e.g. for expanding data points into the pointwise checks that they contribute to.

Parameters:
  • foot (ndarray[S, dtype[bool]]) –

    Array for which the footprint is computed.

  • late_bound (Bindings) –

    Bindings for late-bound parameters, including for this safeguard.

  • where (Literal[True] | ndarray[S, dtype[bool]], default: True ) –

    Only compute the inverse footprint at pointwise checks where the condition is True.

Returns:

compute_inverse_footprint

compute_inverse_footprint(
    foot: ndarray[S, dtype[bool]],
    *,
    late_bound: Bindings,
    where: Literal[True] | ndarray[S, dtype[bool]] = True,
) -> ndarray[S, dtype[bool]]

Compute the inverse footprint of the foot array, e.g. for expanding pointwise check fails into the points that could have contributed to the failures.

Parameters:
  • foot (ndarray[S, dtype[bool]]) –

    Array for which the inverse footprint is computed.

  • late_bound (Bindings) –

    Bindings for late-bound parameters, including for this safeguard.

  • where (Literal[True] | ndarray[S, dtype[bool]], default: True ) –

    Only compute the inverse footprint at pointwise checks where the condition is True.

Returns:

get_config

get_config() -> dict[str, JSON]

Returns the configuration of the safeguard.

Returns:
  • config( dict[str, JSON] ) –

    Configuration of the safeguard.