Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ndsl/initialization/allocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def _allocate(
extent=extent,
gt4py_backend=self._backend(),
allow_mismatch_float_precision=allow_mismatch_float_precision,
number_of_halo_points=self.sizer.n_halo,
)

def get_quantity_halo_spec(
Expand Down
2 changes: 2 additions & 0 deletions ndsl/quantity/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class QuantityMetadata:
"the start of the computational domain"
extent: tuple[int, ...]
"the shape of the computational domain"
n_halo: int
"Number of halo-points used in the horizontal"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "halo size" rather than "halo points"?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

dims: tuple[str, ...]
"names of each dimension"
units: str
Expand Down
43 changes: 29 additions & 14 deletions ndsl/quantity/quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,29 @@ def __init__(
extent: Sequence[int] | None = None,
gt4py_backend: str | None = None,
allow_mismatch_float_precision: bool = False,
number_of_halo_points: int = 0,
):
"""
Initialize a Quantity.
"""Initialize a Quantity.

Args:
data: ndarray-like object containing the underlying data
dims: dimension names for each axis
units: units of the quantity
origin: first point in data within the computational domain
extent: number of points along each axis within the computational domain
gt4py_backend: backend to use for gt4py storages, if not given this will
be derived from a Storage if given as the data argument, otherwise the
storage attribute is disabled and will raise an exception. Will raise
a TypeError if this is given with a gt4py storage type as data
"""
data (_type_): ndarray-like object containing the underlying data
dims (Sequence[str]): dimension names for each axis
units (str): units of the quantity
origin (Sequence[int] | None, optional): first point in data within the
computational domain. Defaults to None.
extent (Sequence[int] | None, optional): number of points along each axis
within the computational domain. Defaults to None.
gt4py_backend (str | None, optional): backend to use for gt4py storages,
if not given this will be derived from a Storage
if given as the data argument. Defaults to None.
allow_mismatch_float_precision (bool, optional): allow for precision that is
not the simulation-wide default configuration. Defaults to False.
number_of_halo_points (int, optional): Number of halo points used. Defaults to 0.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so sure about the name here because it's not really the number of halo points, right? If I put 3, there will be more then 3 halo points. Though not optimal either, I'd stick with what we already have (n_halo) to avoid confusion. Maybe we could do "halo size" instead?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, n_halo is just number of halo points, as per

n_halo: number of halo points

or
"""Number of horizontal halo points for produced arrays."""

or
and number of halo points.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then let's change all of them because they are equally wrong in that sense?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the lingo that is used to describe the halo size. This is not changeable

Copy link
Copy Markdown
Collaborator

@romanc romanc Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't our job here to dare new things and sometimes break with (old) conventions? Like, we tell atmospheric scientists that they can now write code in python(-ish) and that they can have variable names longer than 5 characters?

We even make use of the term "halo size" in our introduction examples when referring to the nhalo argument of the boilerplate functions.

"The `StencilFactory` object enables the sharing of stencil properties across multiple stencils as well as \"build and execute\" the stencil. To help ease the introduction, the [`boilerplate` module](./boilerplate.py) contains a function `get_one_tile_factory` that takes the domain size, halo size, and backend of interest and returns a `StencilFactory` object. For more details about the objects needed to create the `StencilFactory`, the reader can view the [`get_one_tile_factory`](./boilerplate.py#get_one_tile_factory) function."

"Next, we'll create a simple driver that defines the domain and halo size, specifies the backend (`dace:cpu` in order to use DaCe), and uses the boilerplate code to create a stencil and quantity factory objects. These objects help define the computational domain used for this particular example. After defining quantities (`in_field` and `out_field`) to hold the appropriate values and creating an object `local_sum` for our combined stencil/Python calculation, `local_sum` is called to perform the computation. In the output, we can see DaCe orchestrating the code. "


Raises:
ValueError: Data-type mismatch between configuration and input-data
TypeError: Typing of the data that does not fit
"""
if (
not allow_mismatch_float_precision
and is_float(data.dtype)
Expand Down Expand Up @@ -108,15 +115,14 @@ def __init__(
)
)
else:
if data is None:
raise TypeError("requires 'data' to be passed")
# We have no info about the gt4py_backend, so just assign it.
self._data = data

_validate_quantity_property_lengths(data.shape, dims, origin, extent)
self._metadata = QuantityMetadata(
origin=_ensure_int_tuple(origin, "origin"),
extent=_ensure_int_tuple(extent, "extent"),
n_halo=number_of_halo_points,
dims=tuple(dims),
units=units,
data_type=type(self._data),
Expand All @@ -135,6 +141,7 @@ def from_data_array(
origin: Sequence[int] | None = None,
extent: Sequence[int] | None = None,
gt4py_backend: str | None = None,
number_of_halo_points: int = 0,
) -> Quantity:
"""
Initialize a Quantity from an xarray.DataArray.
Expand All @@ -155,6 +162,7 @@ def from_data_array(
data_array.attrs["units"],
origin=origin,
extent=extent,
number_of_halo_points=number_of_halo_points,
gt4py_backend=gt4py_backend,
)

Expand All @@ -172,6 +180,13 @@ def to_netcdf(
)

def halo_spec(self, n_halo: int) -> QuantityHaloSpec:
# This is a preliminary check to see if this is ever triggered.
# If not, we can remove it down the line and change the call signature.
if n_halo != self._metadata.n_halo:
warnings.warn(
"Found inconsistency with number of halo points in Quantity:"
+ f"{n_halo} vs {self._metadata.n_halo}"
)
return QuantityHaloSpec(
n_halo,
self.data.strides,
Expand Down