abc

compression_safeguards.safeguards.stencil.abc

Abstract base class for the stencil safeguards.

Classes:

StencilSafeguard

Bases: Safeguard, ABC

flowchart LR compression_safeguards.safeguards.stencil.abc.StencilSafeguard[StencilSafeguard] compression_safeguards.safeguards.abc.Safeguard[Safeguard] compression_safeguards.safeguards.abc.Safeguard --> compression_safeguards.safeguards.stencil.abc.StencilSafeguard click compression_safeguards.safeguards.stencil.abc.StencilSafeguard href "" "compression_safeguards.safeguards.stencil.abc.StencilSafeguard" click compression_safeguards.safeguards.abc.Safeguard href "" "compression_safeguards.safeguards.abc.Safeguard"

Stencil safeguard abstract base class.

Stencil safeguards describe properties that are computed in a neighbourhood around each element, i.e. whether or not an element satisfies the safeguard is coupled to its neighbouring elements.

Methods:

compute_check_neighbourhood_for_data_shape abstractmethod

compute_check_neighbourhood_for_data_shape(
    data_shape: tuple[int, ...],
) -> tuple[dict[BoundaryCondition, NeighbourhoodAxis], ...]

Compute the shape of the data neighbourhood for data of a given shape. Boundary conditions of the same kind are combined, but separate kinds are tracked separately.

An empty dict is returned along dimensions for which the stencil safeguard does not need to look at adjacent data points.

This method also checks that the data shape is compatible with this stencil safeguard.

Parameters:
  • data_shape (tuple[int, ...]) –

    The shape of the data.

Returns:

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 the approximation array upholds the property enforced by this safeguard.

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.

check_pointwise abstractmethod

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 which elements in the approximation array uphold the neighbourhood property enforced by this safeguard.

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.

compute_safe_intervals abstractmethod

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 intervals in which the safeguard's guarantees with respect to the data are upheld.

The returned union of intervals must not have any overlap between the intervals inside the union. The data must be contained in the union.

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:
  • intervals( IntervalUnion[T, int, int] ) –

    Union of intervals in which the safeguard's guarantees are upheld.

compute_footprint abstractmethod

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.

For stencil safeguards, the footprint usually extends beyond foot & where.

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 footprint at pointwise checks where the condition is True.

    Conceptually, where is applied to footprint at the end.

Returns:

compute_inverse_footprint abstractmethod

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.

For stencil safeguards, the inverse footprint usually extends beyond foot & where.

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.

    Conceptually, where is applied to foot at the start.

Returns: