Skip to content

Sum utu.spectrum.synthesize() in the precision of the emission measure - #18

Merged
roytsmart merged 1 commit into
mainfrom
fix/synthesize-dtype
Nov 12, 2026
Merged

roytsmart merged 1 commit into
mainfrom
fix/synthesize-dtype

Conversation

@roytsmart

Copy link
Copy Markdown
Contributor

utu.spectrum.synthesize() now sums the spectrum in the precision of the emission measure instead of always in double precision.

Why

The kernel was computed in double precision, and na.vecdot() multiplies it into the emission measure with np.matmul. A matrix product of a float64 kernel and a float32 emission measure first copies the whole emission measure to float64. For the 3.3 GB velocity-resolved DEM of a MURaM active region (VDEM_Quadrupolar_x_1380000_M6.6_B1.6), synthesizing one line in two velocity bins peaked at 10.1 GB of traced memory, close to the 16 GB of a GitHub runner.

What changed

  • Kernel: it is still computed in double precision. It is rounded to the precision of the emission measure, at least float32, just before the matrix product, so a float32 emission measure is no longer copied.
  • Result: it now has the precision of the emission measure too, so a float32 map gives a float32 spectrum. A float64 or integer emission measure gives float64, as before.
Full MURaM AR store, O V, 2 velocity bins v0.6.0 This PR
1 line, traced peak 10.09 GB 3.44 GB
24 lines, traced peak 10.48 GB 3.63 GB
Result float64, 16.8 MB float32, 8.4 MB

What remains is mostly the 3.32 GB cube itself. On that scene, the float32 result agrees with the float64 one to a worst relative error of 4.3e-7, on elements above 1e-6 of the maximum.

Tests

  • New:
    • test_synthesize_precision checks scalar and uncertain inputs, whole and in blocks. The result must be float32 and agree with float64 to rtol=1e-6.
    • test_synthesize_precision_empty checks the precision of the result when no lines are in the passband.
    • All 5 new cases fail without the fix.
  • Suite: 143 passed (-n 4). ruff and black are clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_017xqpht97bF4FWsACAA4wQa

The kernel is computed in double precision, and rounded to the precision of
the emission measure, at least single, before the matrix product. A product
of two precisions copied a single-precision emission measure whole into
double precision. For the 3.3 GB velocity-resolved DEM of a MURaM active
region, synthesizing one line in two bins of velocity peaked at 10.1 GB of
traced memory, and now peaks at 3.4 GB. The result is in the precision of
the emission measure too, which halves it for a single-precision map, and
agrees with the double-precision sum to a few parts in ten million.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xqpht97bF4FWsACAA4wQa
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 utu | 🛠️ Build #35850853 | 📁 Comparing 0c1f94d against latest (fdae758)

  🔍 Preview build  

2 files changed
± _autosummary/utu.spectrum.synthesize.html
± _modules/utu/spectrum/_synthesis.html

@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (fdae758) to head (0c1f94d).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #18   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           21        21           
  Lines         1514      1537   +23     
=========================================
+ Hits          1514      1537   +23     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@roytsmart
roytsmart merged commit 08f29ee into main Nov 12, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant