Skip to content

Add direct unit tests for RadiativeRatesSolver class #3489

@adity1raut

Description

@adity1raut

Is your feature request related to a problem? Please describe.
The RadiativeRatesSolver class in tardis/plasma/equilibrium/rates/radiative_rates.py has no direct unit tests. A fixture radiative_rate_solver already exists in tardis/plasma/equilibrium/tests/conftest.py but no test file ever calls .solve() on it. Errors in this solver (wrong transition direction, missing spontaneous emission term A_ul, wrong output index structure) would silently corrupt all ion and level populations without any focused test catching them.

Describe the solution you'd like
Create a new test file tardis/plasma/equilibrium/tests/test_radiative_rates.py with focused unit tests for the class. Tests should cover:

  • Valid construction with a correct Einstein coefficients DataFrame
  • AssertionError raised when columns A_ul, B_ul, B_lu, or nu are missing
  • AssertionError raised when index names are wrong
  • AssertionError raised when level_number_lower >= level_number_upper
  • solve() output DataFrame has the correct 6-level MultiIndex
  • r_lu = B_lu × J_nu verified numerically
  • r_ul = B_ul × J_nu + A_ul with spontaneous emission term present
  • Full solve() output pinned against regression HDF5 data
  • Zero radiation field intensity (W=0) gives r_lu=0 and r_ul = A_ul

Regression data path should be modified locally so no PR to the regression data repository is needed.

Describe alternatives you've considered

  • Relying only on indirect full plasma regression tests — rejected because a failure anywhere in the plasma chain masks whether RadiativeRatesSolver is the cause.
  • Only testing construction validation — rejected because the most critical logic is inside solve() and must be verified against known physical values.

Additional context
The existing fixture in conftest.py (lines 64–66) already builds a RadiativeRatesSolver from Si Chianti atomic data — the test file just needs to use it. Bonus tests to mention in the PR: pass both DilutePlanckianRadiationField and PlanckianRadiationField as inputs to solve(), assert all output rates are non-negative, and verify that both up and down transitions appear for every spectral line.

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