Skip to content

Fix repeated line traversal bug in nonhomologous packet transport - #3802

Merged
jvshields merged 11 commits into
tardis-sn:masterfrom
connor-mcclellan:fix/repeated-line-traversal
Nov 10, 2026
Merged

jvshields merged 11 commits into
tardis-sn:masterfrom
connor-mcclellan:fix/repeated-line-traversal

Conversation

@connor-mcclellan

Copy link
Copy Markdown
Contributor

📝 Description

Type: 🪲 bugfix

Fixes a bug in the line search caused by floating point precision. When looking for resonances forward in the packet's trajectory, trace_packet (line 123) rebuilds an inclusive line range from comoving frequencies on every call, even when the packet has already traversed a line. The distance solver (line 319) rejects only roots within CLOSE_LINE_THRESHOLD × shell_width.

With a test nonhomologous shell of inner radius 1e14 cm, outer radius 2e14 cm, and edge velocities v_inner=1e8 cm/s, v_outer=1.8e-8 cm/s, the projected velocity along a test ray trajectory has no gradient reversal, so a resonance should be encountered at most once.

With a line already marked as traversed, trace_packet selects that line again 1.455078125 cm ahead of its current position since the distance threshold cutoff is 1 cm. A second call repeats the line event and estimator contribution.

📌 Resources

Andrew reproduced this bug with this ad-hoc test:

from tardis.transport.montecarlo.modes.nonhomologous.rad_packet_transport import (
    trace_packet as trace_nonhomologous,
)

from tardis.transport.montecarlo.packets.radiative_packet import (
    InteractionType,
    PacketStatus,
    RPacket,
)

def test_nonhomologous_trace_does_not_reresonate_in_homologous_flow(
    homologous_radial_1d_geometry: NumbaHomologousRadial1DGeometry,
    classic_opacity_state: OpacityStateNumba,
    line_estimators: EstimatorsLine,
) -> None:
    """A packet just emitted in a line cannot hit it again when v = r/t.

    In homologous flow the comoving frequency falls monotonically along every
    ray, so after emission the opaque line is behind the packet and the next
    event must be the shell boundary.
    """
    homologous = homologous_radial_1d_geometry
    geometry = NumbaRadial1DGeometry(
        homologous.r_inner,
        homologous.r_outer,
        homologous.v_inner,
        homologous.v_outer,
    )
    opacity_state = classic_opacity_state
    opacity_state.line_list_nu[:] = [4.0e14, 1.0e9]
    opacity_state.tau_sobolev[:] = 0.0
    opacity_state.tau_sobolev[0, :] = 100.0
    radius, mu = 7.5e14, 0.9
    doppler_factor = 1.0 - radius * mu / (
        C_SPEED_OF_LIGHT * homologous.time_explosion
    )
    # Packet state immediately after emission in line 0.
    packet = RPacket(
        radius, mu, opacity_state.line_list_nu[0] / doppler_factor, 1.0, 42, 0
    )
    packet.next_line_id = 1

    _, interaction_type, _ = trace_nonhomologous(
        packet, geometry, opacity_state, line_estimators, 0.0, False, False
    )

    assert interaction_type == InteractionType.BOUNDARY

🚦 Testing

How did you test these changes?

  • Testing pipeline
  • Other method (describe)
  • My changes can't be tested (explain why)

☑️ Checklist

  • I requested two reviewers for this pull request
  • I updated the documentation according to my changes
  • I built the documentation by applying the build_docs label

Note: If you are not allowed to perform any of these actions, ping (@) a contributor.

@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.62745% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.30%. Comparing base (db480c5) to head (2274429).

Files with missing lines Patch % Lines
...ecarlo/modes/nonhomologous/rad_packet_transport.py 71.87% 9 Missing ⚠️
...ntecarlo/modes/nonhomologous/packet_propagation.py 64.28% 5 Missing ⚠️
tardis/transport/geometry/calculate_distances.py 0.00% 1 Missing ⚠️
...ntecarlo/modes/nonhomologous/interaction_events.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3802      +/-   ##
==========================================
+ Coverage   70.94%   71.30%   +0.35%     
==========================================
  Files         207      207              
  Lines       15940    15969      +29     
==========================================
+ Hits        11309    11386      +77     
+ Misses       4631     4583      -48     

☔ 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.

@connor-mcclellan
connor-mcclellan marked this pull request as ready for review October 28, 2026 21:30
@tardis-bot

tardis-bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

The docs workflow has completed with these results:

  • Build: success

View the documentation preview.

Runs: build and test · publish

andrewfullard
andrewfullard previously approved these changes Nov 3, 2026

@andrewfullard andrewfullard left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the merge conflicts and add some better test docstrings and this is good to go.

@andrewfullard

Copy link
Copy Markdown
Contributor

Still need the merge conflict resolved

@jvshields
jvshields merged commit 6d6732c into tardis-sn:master Nov 10, 2026
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants