Skip to content

Technical Debt: Remove demo-specific hardcoding from workflows #204

@KedoKudo

Description

@KedoKudo

Summary

Code audit revealed significant technical debt where demo-specific values were hardcoded into the workflow code. The code works for the Hafnium demo dataset but will silently produce wrong results for other datasets.

Audit Grade: D+

Critical Issues

1. Hardcoded Hafnium Isotopes/Abundances (lines 801-815)

elif primary_isotope.startswith("Hf-"):
    analysis_isotopes = ["Hf-174", "Hf-176", "Hf-177", "Hf-178", "Hf-179", "Hf-180"]
    abundances = [0.0016, 0.0526, 0.1860, 0.2728, 0.1362, 0.3508]

Impact: Analysis of natural U, W, Gd, or any multi-isotope element will use wrong isotopes/abundances.

2. Hardcoded Hafnium Mass Number (lines 876-880)

if primary_isotope.startswith("Hf"):
    mass_number = 178  # Weighted average for natural Hf

Impact: Other elements don't get weighted average mass calculation.

3. Hardcoded VENUS Resolution Path (lines 1067-1096)

default_venus_res = Path.home() / "SNS" / "VENUS" / "shared" / "instrument" / "resonance"

Impact: Non-VENUS facilities won't find resolution files.

4. No Natural Abundance Lookup System

IsotopeInfo.abundance field exists but is never populated from data files.
Impact: Forces developers to hardcode abundances.

5. Hardcoded ORNL Facility Default (line 720-722)

facility = Facility.ornl  # Always defaults to ORNL

Impact: LANL data processed with wrong facility assumptions.

6. Magic Number Defaults in inp_manager.py

DEFAULT_DENSITY = 9.000000  # What material is this?
DEFAULT_T0_VALUE = 0.86000000  # VENUS-specific?

Impact: Wrong physics if material properties not explicitly provided.

Required Fixes

Immediate (Before Production)

  • Remove Hf-specific hardcoding - use data-driven isotope lookup
  • Add natural abundance database/lookup
  • Fix facility detection from manifest
  • Remove or document magic number defaults
  • Fail loudly on missing critical parameters

Short-term

  • Add integration tests with non-Hf elements (U-235, W-nat)
  • Extract duplicated results parsing code (DRY)
  • Add input validation for isotopes parameter
  • Document full workflow limitations honestly

Architecture Changes

  • Create isotope resolution system (element → stable isotopes + abundances)
  • Create facility configuration system (facility/beamline → resolution files)
  • Add enrichment support via manifest field

Root Cause

Code was developed with Hafnium foil demo in mind, with "shortcuts" to make the demo work. These shortcuts were not generalized before being committed.

Files Affected

  • src/pleiades/workflows/resonance.py - Main offender
  • src/pleiades/sammy/io/inp_manager.py - Magic numbers
  • src/pleiades/nuclear/isotopes/manager.py - Missing abundance lookup
  • tests/unit/pleiades/workflows/test_resonance.py - Only tests happy path

Related Issues


🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions