Terminations
Termination functions: does a transition land in a terminal state?
An Environment's termination_fn has the signature shared across this
module, navix.rewards and navix.events:
fn(prev_state: State, action: Array, state: State) -> Array
prev_stateis $s_t$ (before the action),actionis $a_t$,stateis $s_{t+1}$ (after). Most conditions only needstate; a few needprev_stateto detect a change this step (e.g. a door going closed -> open), because navix clears the per-step event record every step.- The return is a boolean scalar
bool[](True= terminate). Truncation atmax_stepsis added separately byEnvironment.termination, so a termination function only reports genuine absorbing states.
Most functions here are thin, correctly-typed wrappers around the
matching detector in navix.events (which holds the precise semantics);
compose ORs several into one, and DEFAULT_TERMINATION is the goal /
lava / ball-hit combination MiniGrid uses.
DEFAULT_TERMINATION = compose(on_goal_reached, on_lava_fall, on_ball_hit)
module-attribute
The termination_fn an Environment uses unless overridden: the
episode ends on reaching the goal, falling into lava, or being hit by a
moving ball (MiniGrid's default terminal conditions).
check_truncation(terminated, truncated)
Merges a termination flag and a truncation flag into a single
StepType value. Used by Environment.termination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
terminated
|
Array
|
|
required |
truncated
|
Array
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
|
Array
|
( |
|
Array
|
Termination wins over truncation. |
compose(*term_functions, operator=jnp.any)
Combines several termination functions into one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*term_functions
|
Callable
|
termination functions to combine,
each |
()
|
operator
|
Callable
|
reduces the stacked results to a scalar.
Default |
any
|
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
Callable
|
a single |
Callable
|
function. This is how |
|
Callable
|
combinations are built. |
on_any_target_pickup(prev_state, action, state)
Fetch's termination: any Key/Ball pickup this step ends the
episode, right or wrong (see rewards.on_target_fetched for which
one determines the reward).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_state
|
State
|
The previous state of the game. |
required |
action
|
Array
|
The action taken by the player. |
required |
state
|
State
|
The current state of the game. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
A boolean array. |
on_ball_hit(prev_state, action, state)
Check if the ball has hit something using the ball_hit event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_state
|
State
|
The previous state of the game. |
required |
action
|
Array
|
The action taken by the player. |
required |
state
|
State
|
The current state of the game. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
A boolean array indicating whether the ball has hit something. |
on_ball_pickup(prev_state, action, state)
Check if any ball was picked up this step, using the ball_pickup
event - for environments (e.g. DynamicObstacles) where Ball
represents a hazard to avoid touching, not an object to carry:
composing this alongside on_ball_hit makes picking one up end the
episode the same way walking into it already does, rather than
silently removing it from play now that Ball is Pickable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_state
|
State
|
The previous state of the game. |
required |
action
|
Array
|
The action taken by the player. |
required |
state
|
State
|
The current state of the game. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
A boolean array indicating whether any ball was picked up. |
on_box_pickup(prev_state, action, state)
Check if any box was picked up this step, using the box_pickup
event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_state
|
State
|
The previous state of the game. |
required |
action
|
Array
|
The action taken by the player. |
required |
state
|
State
|
The current state of the game. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
A boolean array indicating whether any box was picked up. |
on_door_done(prev_state, action, state)
Check if the action done has been called in front of a Door object with the correct colour.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_state
|
State
|
The previous state of the game. |
required |
action
|
Array
|
The action taken by the player. |
required |
state
|
State
|
The current state of the game. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
A boolean array indicating whether the action |
on_door_open(prev_state, action, state)
Check if any door was opened this step, using the door_opening
event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_state
|
State
|
The previous state of the game. |
required |
action
|
Array
|
The action taken by the player. |
required |
state
|
State
|
The current state of the game. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
A boolean array indicating whether any door was opened. |
on_goal_reached(prev_state, action, state)
Check if the goal has been reached using the goal_reached event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_state
|
State
|
The previous state of the game. |
required |
action
|
Array
|
The action taken by the player. |
required |
state
|
State
|
The current state of the game. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
A boolean array indicating whether the goal has been reached. |
on_lava_fall(prev_state, action, state)
Check if the lava has fallen using the lava_fall event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_state
|
State
|
The previous state of the game. |
required |
action
|
Array
|
The action taken by the player. |
required |
state
|
State
|
The current state of the game. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
A boolean array indicating whether the lava has fallen. |
on_memory_failure(prev_state, action, state)
Check if the player reached Memory's wrong (failure) position,
using the on_memory_failure event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_state
|
State
|
The previous state of the game. |
required |
action
|
Array
|
The action taken by the player. |
required |
state
|
State
|
The current state of the game. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
A boolean array indicating whether the wrong position was reached. |
on_memory_success(prev_state, action, state)
Check if the player reached Memory's target position, using
the on_memory_success event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_state
|
State
|
The previous state of the game. |
required |
action
|
Array
|
The action taken by the player. |
required |
state
|
State
|
The current state of the game. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
A boolean array indicating whether the target was reached. |
on_ordered_doors_resolved(prev_state, action, state)
RedBlueDoors' termination: ends the episode as soon as blue
opens, whether that was a success (red already open) or a failure
(blue opened first).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_state
|
State
|
The previous state of the game. |
required |
action
|
Array
|
The action taken by the player. |
required |
state
|
State
|
The current state of the game. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
A boolean array. |
on_put_near_drop_attempted(prev_state, action, state)
PutNear's termination on a genuine drop attempt (success or
failure - see rewards.on_put_near_success for which one this was).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_state
|
State
|
The previous state of the game. |
required |
action
|
Array
|
The action taken by the player. |
required |
state
|
State
|
The current state of the game. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
A boolean array. |
on_put_near_wrong_pickup(prev_state, action, state)
PutNear's failure-on-pickup termination: the wrong object was
picked up this step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_state
|
State
|
The previous state of the game. |
required |
action
|
Array
|
The action taken by the player. |
required |
state
|
State
|
The current state of the game. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
A boolean array. |
on_target_done(prev_state, action, state)
GoToObject's success termination: the done action was taken
while the player is orthogonally adjacent to the mission's target
object - facing it is not required (matches MiniGrid; see
events.on_target_done).
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
|
on_target_fetched(prev_state, action, state)
ObstructedMaze's termination: only picking up the specific
mission-target Key/Ball ends the episode - unlike Fetch's
on_any_target_pickup, a wrong pickup (the blocking Ball, say)
does not end it here, matching MiniGrid's actual ObstructedMazeEnv
(reward + termination only on picking up the target).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_state
|
State
|
The previous state of the game. |
required |
action
|
Array
|
The action taken by the player. |
required |
state
|
State
|
The current state of the game. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
A boolean array. |
on_wrong_toggle(prev_state, action, state)
GoToObject's failure termination: the toggle action was used
at all.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_state
|
State
|
The previous state of the game. |
required |
action
|
Array
|
The action taken by the player. |
required |
state
|
State
|
The current state of the game. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
A boolean array. |