Skip to content

Commit 834732b

Browse files
committed
data: Use single backticks in docstrings for code names
Match the single-backtick `name` convention rather than the double ``name`` form, across the distributed engine and the docstrings/comments this branch added to data.py, decomposition.py and test_data.py. Pre-existing double-backtick text elsewhere is left untouched.
1 parent eb5df51 commit 834732b

10 files changed

Lines changed: 109 additions & 109 deletions

File tree

devito/data/data.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ def _is_decomposed(self):
185185

186186
def _scattered_exchange(self, glb_idx):
187187
"""
188-
Return an ``Exchange`` when ``glb_idx`` advanced-indexes a
188+
Return an `Exchange` when `glb_idx` advanced-indexes a
189189
distributed axis (the "unbalanced"/scattered case, where the value is
190-
rank-local and ordered by ``glb_idx``), otherwise ``None`` so the caller
190+
rank-local and ordered by `glb_idx`), otherwise `None` so the caller
191191
falls back to the regular (basic-indexing) path.
192192
"""
193193
# Imported lazily: the redistribution engine depends on `devito.mpi`,
@@ -241,7 +241,7 @@ def swapaxes(self, axis1, axis2):
241241
"""
242242
Return a view of ``self`` with ``axis1`` and ``axis2`` swapped, with
243243
``_decomposition`` / ``_modulo`` swapped in the same way (see
244-
``transpose``).
244+
`transpose`).
245245
"""
246246
axis1 = axis1 % self.ndim
247247
axis2 = axis2 % self.ndim
@@ -257,7 +257,7 @@ def swapaxes(self, axis1, axis2):
257257
def T(self):
258258
"""
259259
The transposed array. Overridden so the C-level ``ndarray.T`` shortcut
260-
also permutes the per-axis metadata (see ``transpose``).
260+
also permutes the per-axis metadata (see `transpose`).
261261
"""
262262
return self.transpose()
263263

@@ -523,12 +523,12 @@ def _set_global_idx(self, val, idx, val_idx):
523523
def _gather(self, start=None, stop=None, step=1, rank=0):
524524
"""
525525
Gather (a slice of) the distributed data into a NumPy array on a single
526-
rank, returning ``None`` on the others. See the public ``data_gather``
526+
rank, returning `None` on the others. See the public `data_gather`
527527
method of `Function`.
528528
529529
Indexing is local (each rank already holds its induced result block);
530530
gathering is the explicit collect step -- every rank sends its block and
531-
the result indices it owns, and ``rank`` reassembles the global array.
531+
the result indices it owns, and `rank` reassembles the global array.
532532
"""
533533
if not isinstance(rank, int):
534534
raise TypeError('rank must be passed as an integer value.')

devito/data/decomposition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ def index_decomposition(self, idx):
577577
Each subdomain keeps the result positions, in index order, of the global
578578
indices it owns. A strided or reversed slice therefore just relabels
579579
which rank owns which result index -- indexing never moves data across
580-
ranks. Unlike ``reshape`` (which adjusts subdomain *boundaries* and
580+
ranks. Unlike `reshape` (which adjusts subdomain *boundaries* and
581581
is used for halos), this follows exact NumPy slicing semantics.
582582
583583
Examples

devito/data/distributed/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
Indexing an MPI-distributed array is treated as a redistribution between layouts.
55
The engine is built as four pure layers plus a value object:
66
7-
* ``selection`` -- what an index expression means (serial NumPy semantics).
8-
* ``layout`` -- where a global coordinate physically lives.
9-
* ``plan`` -- the rank-to-rank routing, built without communication.
10-
* ``transport`` -- the sparse point-to-point exchange (NBX).
11-
* ``exchange`` -- ``Exchange(data, idx).get()/.put(value)``.
7+
* `selection` -- what an index expression means (serial NumPy semantics).
8+
* `layout` -- where a global coordinate physically lives.
9+
* `plan` -- the rank-to-rank routing, built without communication.
10+
* `transport` -- the sparse point-to-point exchange (NBX).
11+
* `exchange` -- `Exchange(data, idx).get()/.put(value)`.
1212
13-
Only ``Exchange`` is needed by ``Data``; the lower layers are independently
13+
Only `Exchange` is needed by `Data`; the lower layers are independently
1414
testable (in serial, or with toy buffers).
1515
"""
1616

devito/data/distributed/exchange.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""
22
Exchange: the value object tying a Selection and a Layout into a reusable plan.
33
4-
``Exchange(data, idx)`` builds the routing for one index expression without any
5-
communication. ``get`` pulls ``data[idx]`` and ``put`` assigns ``data[idx] =
6-
value``. Because the plan is communication-free to build and independent of the
4+
`Exchange(data, idx)` builds the routing for one index expression without any
5+
communication. `get` pulls `data[idx]` and `put` assigns `data[idx] =
6+
value`. Because the plan is communication-free to build and independent of the
77
data *values*, it can be cached and replayed across calls with the same index
88
(e.g. sparse injection every timestep), so the steady state is pure
9-
point-to-point with no re-planning. ``cached_exchange`` provides that cache;
10-
``Data`` uses it so ``data[idx] = value`` is automatically plan-cached.
9+
point-to-point with no re-planning. `cached_exchange` provides that cache;
10+
`Data` uses it so `data[idx] = value` is automatically plan-cached.
1111
"""
1212

1313
from functools import lru_cache
@@ -25,7 +25,7 @@
2525
class Exchange:
2626

2727
"""
28-
A reusable redistribution plan for ``data[idx]`` on distributed ``data``.
28+
A reusable redistribution plan for `data[idx]` on distributed `data`.
2929
3030
Parameters
3131
----------
@@ -49,22 +49,22 @@ def __init__(self, data, idx):
4949
self._plan = ExchangePlan.build(self._selection, self._layout)
5050

5151
def get(self):
52-
"""Return ``data[idx]`` as a NumPy array."""
52+
"""Return `data[idx]` as a NumPy array."""
5353
return self._plan.get(np.asarray(self._data))
5454

5555
def put(self, value):
56-
"""Assign ``data[idx] = value``."""
56+
"""Assign `data[idx] = value`."""
5757
self._plan.put(np.asarray(self._data), value)
5858

5959

6060
class _ExchangeKey:
6161

6262
"""
63-
Hashable, content-addressed key wrapping ``(data, idx)`` for plan caching.
63+
Hashable, content-addressed key wrapping `(data, idx)` for plan caching.
6464
6565
NumPy index arrays are unhashable, so the key digests their content (together
6666
with the decomposition and shape the plan depends on) and lets
67-
``functools.lru_cache`` own eviction. Content addressing means a freshly
67+
`functools.lru_cache` own eviction. Content addressing means a freshly
6868
built index array with the same values still hits, and an in-place mutation
6969
correctly misses.
7070
"""
@@ -89,7 +89,7 @@ def _build(key):
8989

9090

9191
def cached_exchange(data, idx):
92-
"""Return a (cached) ``Exchange`` for ``data[idx]``."""
92+
"""Return a (cached) `Exchange` for `data[idx]`."""
9393
return _build(_ExchangeKey(data, idx))
9494

9595

devito/data/distributed/layout.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""
22
Layout layer: where a global coordinate physically lives.
33
4-
A ``Layout`` wraps a distributor and a per-axis decomposition and answers,
4+
A `Layout` wraps a distributor and a per-axis decomposition and answers,
55
for any axis, "which rank owns global index g, and at what local offset". It is
6-
the single bridge between the layout-independent ``Selection`` and the
6+
the single bridge between the layout-independent `Selection` and the
77
physical MPI placement, and it is what makes replicated and distributed axes
88
look uniform to the planner. All maps are computed locally from replicated
99
metadata; no communication happens here.
@@ -29,7 +29,7 @@ class Layout:
2929
Provides the communicator, topology and rank/coord maps.
3030
decomposition : tuple
3131
One entry per array axis: a Decomposition for a distributed axis, or
32-
``None`` for a replicated axis.
32+
`None` for a replicated axis.
3333
global_shape : tuple of int
3434
The global array shape (full size on every axis).
3535
"""
@@ -61,12 +61,12 @@ def axis_maps(self, axis):
6161
Returns
6262
-------
6363
owner : ndarray
64-
``owner[g]`` is the topology sub-rank owning global index ``g`` along
65-
this axis (``-1`` if out of bounds).
64+
`owner[g]` is the topology sub-rank owning global index `g` along
65+
this axis (`-1` if out of bounds).
6666
local : ndarray
67-
``local[g]`` is the offset of ``g`` within its owner's subdomain.
67+
`local[g]` is the offset of `g` within its owner's subdomain.
6868
sizes : ndarray
69-
``sizes[i]`` is the number of indices owned by sub-rank ``i``.
69+
`sizes[i]` is the number of indices owned by sub-rank `i`.
7070
"""
7171
return self._axis_maps[axis]
7272

@@ -98,7 +98,7 @@ def topology_shape(self):
9898
def coord_to_rank(self):
9999
"""Map a topology coordinate tuple (over distributed axes) to a flat rank.
100100
101-
Grid distributors expose the inverse Cartesian map via ``all_coords``;
101+
Grid distributors expose the inverse Cartesian map via `all_coords`;
102102
single-axis distributors (e.g. sparse) lay ranks out linearly, so the
103103
sole sub-rank index is the flat rank.
104104
"""

devito/data/distributed/plan.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""
22
Plan layer: the rank-to-rank routing induced by a Selection on a Layout.
33
4-
``ExchangePlan`` is a value object built once (no communication) from a
5-
``Selection`` and a ``Layout``. It computes, for every routed element, its
4+
`ExchangePlan` is a value object built once (no communication) from a
5+
`Selection` and a `Layout`. It computes, for every routed element, its
66
owner rank and owner-local offset, and arranges the result/value array as
7-
``(npoints, payload)`` so packing and unpacking are single NumPy fancy-index
8-
operations. The same plan drives ``get`` (pull) and ``put`` (push).
7+
`(npoints, payload)` so packing and unpacking are single NumPy fancy-index
8+
operations. The same plan drives `get` (pull) and `put` (push).
99
1010
Every axis falls in one of four quadrants and is handled uniformly:
1111
@@ -35,14 +35,14 @@ class ExchangePlan:
3535
"""
3636
The rank-to-rank routing induced by a Selection on a Layout.
3737
38-
A plan is built once, without communication, and then drives both ``get``
39-
(pull ``data[idx]``) and ``put`` (assign ``data[idx] = value``). It maps
38+
A plan is built once, without communication, and then drives both `get`
39+
(pull `data[idx]`) and `put` (assign `data[idx] = value`). It maps
4040
every routed result element to its owner rank and owner-local offset, and
4141
splits the result axes into a "T" (transport) block over the distributed
4242
axes and a contiguous "payload" block over the replicated axes, so packing
4343
and unpacking are single NumPy fancy-index operations.
4444
45-
Use ``build`` to construct one; the constructor takes the already
45+
Use `build` to construct one; the constructor takes the already
4646
computed routing tables.
4747
4848
Parameters
@@ -52,15 +52,15 @@ class ExchangePlan:
5252
selection : Selection
5353
Normalized meaning of the index expression.
5454
perm : list of int
55-
Permutation taking the result axes to ``(T-dims..., payload-dims...)``.
55+
Permutation taking the result axes to `(T-dims..., payload-dims...)`.
5656
t_shape : tuple of int
5757
Shape of the transport block (the distributed result axes).
5858
payload_shape : tuple of int
5959
Shape of the payload block (the replicated result axes).
6060
owners : numpy.ndarray
61-
Owner rank of each T row (``-1`` when out of bounds).
61+
Owner rank of each T row (`-1` when out of bounds).
6262
peers : dict
63-
Maps a peer rank to ``(rows, dist_lin)``: the T rows it owns and their
63+
Maps a peer rank to `(rows, dist_lin)`: the T rows it owns and their
6464
owner-local linear offsets over the distributed axes.
6565
block_offsets : numpy.ndarray
6666
Offset of each payload element within the owner's replicated block.
@@ -91,7 +91,7 @@ def __init__(self, layout, selection, perm, t_shape, payload_shape, owners,
9191
@classmethod
9292
def build(cls, selection, layout):
9393
"""
94-
Plan the exchange for ``data[idx]``; the result serves both get and set.
94+
Plan the exchange for `data[idx]`; the result serves both get and set.
9595
9696
Parameters
9797
----------
@@ -159,7 +159,7 @@ def payload_size(self):
159159
def _raise_on_error(self, check_dup):
160160
"""Reach consensus on local errors and raise consistently on all ranks.
161161
162-
A single 1-bit ``Allreduce`` gates the (rare) error path so that every
162+
A single 1-bit `Allreduce` gates the (rare) error path so that every
163163
rank raises together, avoiding a deadlock where one rank raises while the
164164
others enter the exchange. This is log-depth, not an all-to-all.
165165
"""
@@ -187,7 +187,7 @@ def _owner_apply(self, moved, dist_lin, block_offsets):
187187

188188
def get(self, local):
189189
"""
190-
Return ``data[idx]`` as a NumPy array by pulling from the owner ranks.
190+
Return `data[idx]` as a NumPy array by pulling from the owner ranks.
191191
192192
Parameters
193193
----------
@@ -197,7 +197,7 @@ def get(self, local):
197197
Returns
198198
-------
199199
numpy.ndarray
200-
The indexed result, in ``selection.result_shape``.
200+
The indexed result, in `selection.result_shape`.
201201
"""
202202
self._raise_on_error(check_dup=False)
203203
comm, ps = self.comm, self.payload_size
@@ -228,14 +228,14 @@ def get(self, local):
228228

229229
def put(self, local, value):
230230
"""
231-
Assign ``data[idx] = value`` by pushing to the owner ranks.
231+
Assign `data[idx] = value` by pushing to the owner ranks.
232232
233233
Parameters
234234
----------
235235
local : numpy.ndarray
236236
The caller's rank-local array (written in place).
237237
value : array_like
238-
The value to assign, broadcast to ``selection.result_shape``.
238+
The value to assign, broadcast to `selection.result_shape`.
239239
"""
240240
self._raise_on_error(check_dup=True)
241241
rows_flat = self._value_to_rows(value, local.dtype)
@@ -314,11 +314,11 @@ def _resolve_owners(selection, layout, gcoords):
314314
Returns
315315
-------
316316
owners : numpy.ndarray
317-
Flat owner rank per T row (``-1`` if out of bounds).
317+
Flat owner rank per T row (`-1` if out of bounds).
318318
local : numpy.ndarray
319-
Per-axis owner-local offset per T row, shaped ``(naxes, nrows)``.
319+
Per-axis owner-local offset per T row, shaped `(naxes, nrows)`.
320320
sub : numpy.ndarray
321-
Per-axis owner sub-rank per T row, shaped ``(naxes, nrows)``.
321+
Per-axis owner sub-rank per T row, shaped `(naxes, nrows)`.
322322
"""
323323
axes = layout.distributed_axes
324324
nrows = len(next(iter(gcoords.values()))) if gcoords else 0
@@ -386,7 +386,7 @@ def _group_peers(layout, owners, dist_local, sub, gcoords):
386386
Returns
387387
-------
388388
peers : dict
389-
Maps a peer rank to ``(rows, dist_lin)``: the T rows it owns and their
389+
Maps a peer rank to `(rows, dist_lin)`: the T rows it owns and their
390390
owner-local linear offsets over the distributed axes.
391391
oob_error : str or None
392392
Set when any row addresses an out-of-bounds global index.
@@ -425,12 +425,12 @@ def _group_peers(layout, owners, dist_local, sub, gcoords):
425425
def nbx_push(comm, distributed_axes, repl_total, peers, block_offsets,
426426
payload_size, rows_flat, local):
427427
"""
428-
Route ``rows_flat`` to the owner ranks (NBX) and scatter each received
429-
payload into ``local`` at its owner-local position.
428+
Route `rows_flat` to the owner ranks (NBX) and scatter each received
429+
payload into `local` at its owner-local position.
430430
431-
This is the single push primitive behind both ``ExchangePlan.put``
432-
(advanced/replicated assignment, ``payload_size`` >= 1) and the structured
433-
redistribution layer (one value per point, ``payload_size`` == 1).
431+
This is the single push primitive behind both `ExchangePlan.put`
432+
(advanced/replicated assignment, `payload_size` >= 1) and the structured
433+
redistribution layer (one value per point, `payload_size` == 1).
434434
435435
Parameters
436436
----------
@@ -441,13 +441,13 @@ def nbx_push(comm, distributed_axes, repl_total, peers, block_offsets,
441441
repl_total : int
442442
Full replicated stride (1 when there is no replicated payload).
443443
peers : dict
444-
Maps a peer rank to ``(rows, dist_lin)`` (see ``_group_peers``).
444+
Maps a peer rank to `(rows, dist_lin)` (see `_group_peers`).
445445
block_offsets : numpy.ndarray
446446
Offset of each payload element within an owner's replicated block.
447447
payload_size : int
448448
Number of payload elements per point.
449449
rows_flat : numpy.ndarray
450-
Values to push, shaped ``(nrows, payload_size)`` in owner-grouped order.
450+
Values to push, shaped `(nrows, payload_size)` in owner-grouped order.
451451
local : numpy.ndarray
452452
The owner's rank-local array (written in place).
453453
"""
@@ -469,12 +469,12 @@ def nbx_push(comm, distributed_axes, repl_total, peers, block_offsets,
469469

470470

471471
def _encode(payload_size, block_offsets, dist_lin):
472-
"""Pack a request header as ``[payload_size, *block_offsets, *dist_lin]``."""
472+
"""Pack a request header as `[payload_size, *block_offsets, *dist_lin]`."""
473473
return np.concatenate(([payload_size], block_offsets, dist_lin)).astype(np.int64)
474474

475475

476476
def _decode(buf):
477-
"""Unpack a request header into ``(block_offsets, dist_lin)``."""
477+
"""Unpack a request header into `(block_offsets, dist_lin)`."""
478478
payload_size = int(buf[0])
479479
block_offsets = buf[1:1 + payload_size]
480480
dist_lin = buf[1 + payload_size:]

0 commit comments

Comments
 (0)