pystencils.sympyextensions.random.Philox#
- class pystencils.sympyextensions.random.Philox(name, dtype, seed, offsets=(), periodicity=(), num_cells=())#
Implementation of the Philox counter-based RNG with W = 32 and N = 4.
See https://doi.org/10.1145/2063384.2063405.
This Philox RNG computes 128 random bits using a bijection
b_k, asb_k (n). Here,kis a subsequence key, andnis a 128-bit unsigned integer counter. The subsequence key of this implementation is given by theseedargument and an internal invocation key that is incremented by one at each call toget_random_vector.The counter
nis constructed by bitwise concatenation of a user-provided 32-bit external counter (passed toget_random_vector) and the up to three 32-bit spatial iteration indices of the kernel. The spatial indices may be shifted by user-defined offsets, set in theoffsetsparameter.- Parameters:
name (
str) – Name of this RNGdtype (
str|type|dtype|PsType) – Data type of the random numbers; must be eitherfloat32orfloat64seed (
Expr|int) – Expression or integer; the 32-bit unsigned integer seed for this RNGoffsets (
Sequence[Expr|int]) – Optionally, offsets that are added to the iteration space counters when computing the random valuesperiodicity (
Sequence[bool]) – Sequence of booleans indicating which spatial dimensions are periodic. For periodic dimensions, the spatial counter (after adding the offset) is wrapped using integer remainder with the correspondingnum_cellsentry, ensuring that cells on both sides of a periodic boundary receive the same random numbers.num_cells (
Sequence[Expr|int|None]) – Sequence of expressions or integers giving the number of cells (domain size) in each spatial dimension. Must be provided (non-None) for every dimension whereperiodicityisTrue.
- class PhiloxState(name, dtype, invocation_key, seed, offsets, periodicity, num_cells)#
- Parameters:
- next()#
Return the RNG state for the next invocation
- Return type:
- get_keys()#
Return the key tuple identifying the given RNG invocation’s number stream.
- Parameters:
invocation – Expression that is a call to this RNG’s generator function
- Return type:
Note
Must match the
keyarguments of the underlying RNG engine; seepystencils.backend.functions.PsRngEngineFunction.
- get_counters(invocation, rank)#
Return the symbolic counter tuple identifying the position in the RNG’s number stream of the given invocation.
- Parameters:
invocation – Expression that is a call to this RNG’s generator function
rank – Rank of the kernel’s iteration space
- Return type:
Note
Must match the
counterarguments of the underlying RNG engine; seepystencils.backend.functions.PsRngEngineFunction.