Randomness¶
tinax.randomness owns typed scalar key validation, ordered deterministic coordinate derivation, and explicit continuation-key ownership. It never discovers process identity or stores mutable RNG state.
Concrete Python coordinates must be between 0 and 2**32 - 1. Dynamic coordinates inside JIT-compiled calls must be scalar unsigned JAX values of at most 32 bits, preventing silent fold_in collisions from signed or oversized values.
See the Deterministic Randomness guide for task-oriented usage.
import jax
from tinax.randomness import derive_process_step_key, split_key
key = derive_process_step_key(jax.random.key(0), process_index=0, step=10)
next_key, batch_keys = split_key(key, count=8)
derive_key
¶
Fold ordered integer coordinates into one typed scalar key without consuming global state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Array
|
Typed scalar JAX PRNG key to derive from. |
required |
*coordinates
|
int | Array
|
Integer coordinates folded in order via |
()
|
Returns:
| Type | Description |
|---|---|
Array
|
A new typed scalar JAX key derived from |
Array
|
input key is not consumed. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
derive_process_step_key
¶
derive_process_step_key(
key: Array,
*,
process_index: int | Array,
step: int | Array,
stream: int | Array = 0,
) -> Array
Derive one key using the stable process, step, then stream coordinate order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Array
|
Typed scalar JAX PRNG key to derive from. |
required |
process_index
|
int | Array
|
Coordinate identifying the process; folded in first. |
required |
step
|
int | Array
|
Coordinate identifying the step; folded in second. |
required |
stream
|
int | Array
|
Coordinate identifying the substream; folded in last. Defaults to 0. |
0
|
Returns:
| Type | Description |
|---|---|
Array
|
A new typed scalar JAX key derived in process, step, then stream order. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
split_key
¶
Return a continuation key and a leading-axis array of explicitly consumed operation keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Array
|
Typed scalar JAX PRNG key to split. |
required |
count
|
int
|
Number of operation keys to produce. Must be a non-negative integer. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
A |
Array
|
scalar key for further derivation; |
tuple[Array, Array]
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |