fix: mass extraction NaN in Hydrotech Beam DOE — two bugs

Bug 1 — Journal (solve_simulation.py simple workflow):
  Expression lookup for p173 fails silently for derived/measurement
  expressions, so _temp_mass.txt was never written. Added MeasureManager
  fallback via extract_part_mass() (already used in assembly workflow).

Bug 2 — Extractor (extract_mass_from_expression.py):
  Journal writes 'p173=<value>' format but extractor tried float() on
  the whole content including 'p173='. Added key=value parsing.

Defense in depth — nx_interface.py:
  Added stdout parsing fallback: if _temp_mass.txt still missing, parse
  mass from journal output captured via solver.py stdout passthrough.

Files changed:
  - optimization_engine/nx/solve_simulation.py — MeasureManager fallback
  - optimization_engine/extractors/extract_mass_from_expression.py — key=value parse
  - optimization_engine/nx/solver.py — include stdout in result dict
  - projects/hydrotech-beam/studies/01_doe_landscape/nx_interface.py — stdout fallback

Tags: hydrotech-beam, mass-extraction
This commit is contained in:
2026-02-11 19:02:43 +00:00
parent 04f06766a0
commit 6f3325d86f
4 changed files with 70 additions and 16 deletions

View File

@@ -363,8 +363,34 @@ class AtomizerNXSolver:
op2_path = Path(op2_file)
# Step 3: Extract mass from journal temp file
# The journal writes _temp_mass.txt to working_dir (= model_dir).
# The extractor looks in prt_file.parent (= model_dir). These MUST match.
try:
mass_kg = self._extract_mass(prt_file, expression_name=EXPR_MASS)
except FileNotFoundError:
# Fallback: parse mass from journal stdout captured in solve_result
# The journal prints "[JOURNAL] Mass expression p173 = <value>" or
# "[JOURNAL] MeasureManager mass = <value>"
mass_kg = float("nan")
stdout = solve_result.get("stdout", "")
if stdout:
import re
# Match either extraction method's output
m = re.search(
r'\[JOURNAL\]\s+(?:Mass expression p173|MeasureManager mass)\s*=\s*([0-9.eE+-]+)',
stdout,
)
if m:
try:
mass_kg = float(m.group(1))
logger.info("Mass recovered from journal stdout: %.6f kg", mass_kg)
except ValueError:
pass
if mass_kg != mass_kg: # NaN check
logger.warning(
"Mass temp file not found in %s and no mass in journal stdout",
self.model_dir,
)
except Exception as e:
logger.warning("Mass extraction failed: %s", e)
mass_kg = float("nan")