test_box_cartesian_utils¶
Classes¶
Tests for BoxCartesianDistribution. |
|
End-to-end tests for the Cartesian Box implementation. |
|
Tests for the Box environment with Cartesian semantics. |
|
Tests for BoxCartesianPBDistribution (backward policy). |
Module Contents¶
- class test_box_cartesian_utils.TestBoxCartesianDistribution¶
Tests for BoxCartesianDistribution.
- env()¶
- pf_estimator(env, pf_module)¶
- pf_module()¶
- test_batch_mixed_valid_invalid(env, pf_estimator)¶
In a batch, valid actions get finite log_prob and invalid get -inf.
- test_exit_from_s0_neg_inf(env, pf_estimator)¶
Exit from s0 is impossible and must get -inf.
- test_impossible_action_gets_neg_inf(env, pf_estimator, state, action, reason)¶
Out-of-support forward actions must get -inf log_prob.
- test_log_prob_exit_at_boundary(env, pf_estimator)¶
Exit at boundary should use learned Bernoulli log_prob (finite, <= 0).
Previously exit was forced to log_prob=0, making boundary exits invisible to the TB loss. Now the learned exit probability contributes so the policy gets gradient to prefer exiting at the reward ring vs. the hard boundary. Non-exit at boundary must remain -inf (impossible).
- test_log_prob_finite(env, pf_estimator)¶
Log probabilities should be finite for valid actions.
- test_non_exit_at_boundary_neg_inf(env, pf_estimator)¶
At the boundary, non-exit actions are impossible and must get -inf.
- test_sample_non_s0_in_range(env, pf_estimator)¶
From non-s0, sampled actions should be >= delta.
- test_sample_s0_in_range(env, pf_estimator)¶
From s0, sampled actions should be in [0, 1] (full space coverage).
- test_sample_shape(env, pf_estimator)¶
Sampled actions should have correct shape.
- test_valid_action_gets_finite_log_prob(env, pf_estimator, state, action)¶
In-support forward actions must get finite log_prob.
- class test_box_cartesian_utils.TestBoxCartesianEndToEnd¶
End-to-end tests for the Cartesian Box implementation.
- env()¶
- pb_estimator(env)¶
- pf_estimator(env)¶
- test_backward_trajectory_reaches_s0(env, pb_estimator)¶
A backward trajectory should reach s0.
- test_reward_function(env)¶
Reward function should return expected values.
- test_trajectory_stays_in_bounds(env, pf_estimator)¶
A trajectory should stay within [0, 1]^2.
- class test_box_cartesian_utils.TestBoxCartesianEnvironment¶
Tests for the Box environment with Cartesian semantics.
- env()¶
- test_backward_step_subtracts_action(env)¶
Backward step should subtract action from state.
- test_exit_action_valid_from_non_s0(env)¶
Exit actions should be valid for non-s0 states.
- test_exit_from_s0_invalid(env)¶
Exit from s0 should be invalid (must take at least one forward step).
- test_exit_from_s0_invalid_all_exits_batch(env)¶
A batch where all actions are exits from s0 should be invalid.
- test_exit_from_s0_invalid_mixed_batch(env)¶
A mixed batch with one exit-from-s0 should be invalid.
- test_exit_valid_mixed_batch_no_s0(env)¶
A mixed batch with exits only from non-s0 should be valid.
- test_forward_backward_roundtrip(env)¶
Forward then backward should return to original state.
- test_forward_step_adds_action(env)¶
Forward step should add action to state.
- test_is_action_valid_boundary(env)¶
Actions shouldn’t push state past boundary.
- test_is_action_valid_non_s0_forward(env)¶
From non-s0, forward actions should be >= delta.
- test_is_action_valid_s0_forward(env)¶
From s0, forward actions should be in [0, 1] (full space coverage).
- class test_box_cartesian_utils.TestBoxCartesianPBDistribution¶
Tests for BoxCartesianPBDistribution (backward policy).
- env()¶
- pb_estimator(env, pb_module)¶
- pb_module()¶
- test_log_prob_near_origin(env, pb_estimator)¶
Log prob for near-origin states going to s0 should be 0.
When near origin (any dimension <= delta), BTS is forced and log_prob = 0. For numerical robustness, any action from a near-origin state is treated as BTS since that’s the only valid action anyway.
- test_out_of_range_backward_action_gets_neg_inf(env, pb_estimator)¶
Non-BTS backward actions outside [delta, state] should get -inf log_prob.
- test_sample_mixed_dims_near_origin(env, pb_estimator)¶
States with mixed dims (some < delta, some >= delta) should handle correctly.
- test_sample_near_origin_to_s0(env, pb_estimator)¶
States near origin should go directly to s0.
- test_sample_non_origin_valid(env, pb_estimator)¶
Backward actions from non-origin should be valid.
- test_sample_shape(env, pb_estimator)¶
Sampled backward actions should have correct shape.
- test_valid_backward_action_gets_finite_log_prob(env, pb_estimator)¶
Valid backward actions should get finite log_prob.