Skip to content

Add ThermoResult object and diffrax throw option#18

Closed
smsharma wants to merge 1 commit intomainfrom
feature/thermo-result-and-diffrax-throw
Closed

Add ThermoResult object and diffrax throw option#18
smsharma wants to merge 1 commit intomainfrom
feature/thermo-result-and-diffrax-throw

Conversation

@smsharma
Copy link
Collaborator

Summary

Implements two requested features:

1. ThermoResult object (closes #14)

  • BackgroundModel now returns a ThermoResult NamedTuple containing all thermo outputs plus T_start/T_end
  • AbundanceModel accepts ThermoResult directly with automatic temperature range detection
  • Maintains backward compatibility via tuple unpacking (use [:7] slice)

2. diffrax throw option (closes #17)

  • Add throw parameter to both BackgroundModel and AbundanceModel
  • Default is True (raises exceptions on solver failure)
  • Set to False for parameter scans where some combinations may fail
  • Passed through to all internal diffeqsolve calls

Usage examples

# New streamlined API
thermo_result = BackgroundModel()(0.)
abundances = AbundanceModel(nuclear_net)(thermo_result)
# T_start/T_end auto-detected from thermo_result

# Parameter scans with throw=False
thermo_model = BackgroundModel(throw=False)
abundance_model = AbundanceModel(nuclear_net, throw=False)
# Failures return partial results instead of raising

# Backward compatible usage
t, a, rho_g, rho_nu, rho_extra, P_extra, Neff = thermo_model(0.)[:7]
abundances = abundance_model(rho_g, rho_nu, rho_extra, P_extra, t_vec=t, a_vec=a)

Test plan

  • Existing tests pass (pytest pytest/test_abundances.py)
  • Tuple unpacking backward compatibility verified
  • Test ThermoResult acceptance by AbundanceModel
  • Test throw=False behavior

🤖 Generated with Claude Code

Implements two features:

1. ThermoResult object (closes #14):
   - BackgroundModel now returns a ThermoResult NamedTuple
   - Contains all thermo outputs plus T_start/T_end used for integration
   - AbundanceModel accepts ThermoResult directly with auto T_start/T_end detection
   - Maintains backward compatibility via tuple unpacking (use [:7] slice)

2. diffrax throw option (closes #17):
   - Add `throw` parameter to both BackgroundModel and AbundanceModel
   - Default is True (raises exceptions on solver failure)
   - Set to False for parameter scans where some combinations may fail
   - Passed through to all internal diffeqsolve calls

Usage examples:

  # New streamlined API
  thermo_result = BackgroundModel()(0.)
  abundances = AbundanceModel(nuclear_net)(thermo_result)

  # Parameter scans with throw=False
  thermo_model = BackgroundModel(throw=False)
  abundance_model = AbundanceModel(nuclear_net, throw=False)

  # Backward compatible
  t, a, rho_g, rho_nu, rho_extra, P_extra, Neff = thermo_model(0.)[:7]

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@smsharma smsharma requested a review from cgiovanetti January 23, 2026 20:57
@smsharma
Copy link
Collaborator Author

Splitting into separate PRs for #14 and #17

@smsharma smsharma closed this Jan 23, 2026
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.

Abundances T_start and T_end could track thermo by default No option to set diffrax throw

1 participant