refactor(dqn): Plan 1 Task 4F — MAG_* magnitude sub-index named constants (Invariant 8)

Define MAG_QUARTER=0, MAG_HALF=1, MAG_FULL=2, NUM_MAGNITUDES=3 in
state_layout.cuh. Migrate the one unambiguous semantic comparison in
trade_physics.cuh (compute_target_position_4branch magnitude scaling).
Arithmetic operations on mag_idx (mag_idx±1, 2-mag_idx, mag_idx<2) are
runtime values, not semantic comparisons, and are not migrated.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jgrusewski
2026-04-24 11:30:03 +02:00
parent 2ecf36b94c
commit a7c4bc9a90
3 changed files with 12 additions and 2 deletions

View File

@@ -115,6 +115,15 @@
#define DIR_FLAT 3 // close all positions to zero
#define NUM_DIRECTIONS 4
// ────────────────────────────────────────────────────────────────────────────
// Magnitude action sub-indices (mag_idx in [0..NUM_MAGNITUDES)).
// Invariant 8: every magnitude value has a named constant.
// ────────────────────────────────────────────────────────────────────────────
#define MAG_QUARTER 0 // 0.25× max_position
#define MAG_HALF 1 // 0.50× max_position
#define MAG_FULL 2 // 1.00× max_position
#define NUM_MAGNITUDES 3
// ── Compile-time checks ──
static_assert(SL_PADDING_START + SL_PADDING_DIM == SL_STATE_DIM,
"State layout dimensions must sum to SL_STATE_DIM");

View File

@@ -70,7 +70,7 @@ __device__ __forceinline__ float compute_target_position_4branch(
* Returns NaN as safety net — any arithmetic with NaN propagates visibly. */
if (dir_idx == DIR_HOLD) return __int_as_float(0x7FC00000); /* NaN sentinel */
float direction = (dir_idx == DIR_SHORT) ? -1.0f : (dir_idx == DIR_LONG) ? 1.0f : 0.0f;
float magnitude = (mag_idx == 0) ? 0.25f : (mag_idx == 1) ? 0.5f : 1.0f;
float magnitude = (mag_idx == MAG_QUARTER) ? 0.25f : (mag_idx == MAG_HALF) ? 0.5f : 1.0f;
return direction * magnitude * max_position;
}

View File

@@ -122,4 +122,5 @@ From the trade_plan MLP output.
- Task 4B (plan_isv[0..6) constants): commit 741cb48d5
- Task 4C (plan_params[0..6) constants): commit 0ac83479e
- Task 4D (BRANCH_* constants): commit 11755632b
- Task 4E (DIR_* direction sub-indices): commit TBD
- Task 4E (DIR_* direction sub-indices): commit c64fde0be
- Task 4F (MAG_* magnitude sub-indices): commit TBD