Skip to content

[T-076] RiskMapper: p_fail slices for every parameter pair, region classification #135

Closed

Description

@CodewithJha

Task T-076 · Milestone M6 — Analysis + risk · Size S · Priority P0 · Epic #6

Implements FR-RSK-001 · FR-RSK-002 · FR-RSK-003 · PR-07

Branch feat/t-076-riskmapper-p-fail-slices-for — one task = one branch = one PR (doc 32 §6)

Summary

Implement risk/mapper.py per doc 05 §8 / doc 09 §5: p_fail = Φ(−μ/σ_tot), regions SAFE/UNCERTAIN/FAILURE from configurable thresholds, slice(x, y, anchor, resolution) on a grid with others at nominal or a mode medoid, all_pair_slices, classify.

Context / motivation

Produces the Risk Atlas — the operating-envelope map.

Scope

In scope

  • RiskSlice model incl. grid_u, physical axis values (log for illuminance), p_fail, mean, std, region.
  • .npz serialisation helper.
  • RiskThresholds settings model validated 0 < safe < failure < 1.

Implementation guidance

  • Module roboprobe/risk/mapper.py — interface exactly doc 05 §8: class RiskMapper: def __init__(self, gp: RobustnessGP, space: ScenarioSpace, thresholds: RiskThresholds); def slice(self, x_param: str, y_param: str, anchor: Mapping[str, Any], resolution: int = 50) -> RiskSlice; def all_pair_slices(self, anchor, resolution: int = 50) -> list[RiskSlice]; def classify(self, X_unit: NDArray) -> NDArray[np.int8].
  • p_fail = Φ(−μ/σ_tot) with σ_tot = sqrt(σ² + σ_noise²) (doc 09 §5.1); regions: SAFE if p_fail < thresholds.safe, FAILURE if > thresholds.failure, else UNCERTAIN.
  • Grid in unit space linspace(0,1,resolution); physical axes via denormalise (log axis flag for log-scaled params); remaining parameters fixed to anchor (nominal or a mode medoid), pins respected.
  • Batch prediction: build all pair grids in one tensor (15 pairs × 2 500 points for d = 6) and call gp.predict once (torch.no_grad()).
  • RiskSlice (frozen): x_param, y_param, x_values, y_values, log_x, log_y, p_fail, mean, std, region (int8 grid), anchor.
  • .npz serialisation helpers save_slices(path, slices) / load_slices(path) (used by T-075a and the API cache).
  • Standards: respect the layering contracts (doc 16 §2) and conventions in doc 34; no hard-coded tunables — thresholds/defaults come from typed settings (doc 27); no magic numbers (ruff PLR2004); public APIs typed (mypy strict) and documented.

Configuration keys

From the configuration reference (doc 27). Keys marked (new) must be added to the typed settings models and appear in the generated reference (T-003c).

  • risk.thresholds
  • risk.slice_resolution

Acceptance criteria

  • Grid shapes and log axes correct.
  • Classification thresholds honoured; pins respected.
  • 15 slices for d = 6 computed in < 1 s on CPU (benchmark).
  • classify output codes match doc 05 §8 (0/1/2).
  • npz round-trip equality test.
  • Tests listed below added and green in CI; coverage of new code meets the gate in doc 18 §3.
  • Docs, config reference and CHANGELOG Unreleased updated where behaviour, keys or interfaces changed.
  • Definition of Done (doc 32 §3) satisfied.

Tests required

  • tests/unit/risk/test_mapper.py.
  • Stub GP returning analytic μ/σ to test classification exactly.

Dependencies

Blocked by: #110 (T-055a)

Blocks: #136 (T-077)

Parallelization notes

Files / paths owned by this task — avoid editing other paths; shared files (pyproject.toml entry points, cli/main.py, api/routers/__init__.py, router.tsx, docker/compose.yaml, ci.yml) are append-only:

  • backend/src/roboprobe/risk/mapper.py

Parallel with analysis tasks.

Definition of Done

Per doc 32 §3 and AGENTS.md §5: lint, format, mypy strict and import-linter green; tests added and passing; docs updated; PR template completed with Closes #<this issue>; Conventional Commit messages referencing T-076 (doc 16 §6); commits authored only by the repository owner identity (AGENTS.md §4); CI green; reviewer checklist (doc 32 §5.1) satisfied.

References

Design docs: doc 05 §8 · doc 09 §5.1 · doc 09 §5.2 · doc 09 §5.3 · doc 02 §3.6

Requirements: FR-RSK-001 · FR-RSK-002 · FR-RSK-003 · PR-07 (traceability: doc 28)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:riskRisk maps and estimatesmilestone:M6M6 — Analysis + riskpriority:P0Critical path / blocks otherssize:S<= 1 daytaskChild task of a milestone epictype:featureNew functionality

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions