Skip to content

Conversation

@mhliu0001
Copy link

@mhliu0001 mhliu0001 commented Jan 29, 2026

What is the problem / what does the code in this PR do

In simulation plugins (e.g., S2 simulations in fuse), operations like sampling electron drift time add variable delays to output timestamps. This causes output data to exceed input chunk boundaries, breaking strax's chunking assumptions. This PR adds TimeDelayPlugin, a base class that handles buffering and chunking for plugins with time-delayed output.

Can you briefly describe how it works?

TimeDelayPlugin buffers output data and releases it when safe:

  • Data with endtime <= input_chunk.end is output immediately
  • Data extending beyond the boundary is buffered until subsequent chunks arrive
  • Output is re-sorted by time (since variable delays may reorder data)
  • Chunk boundaries are constrained to ensure buffered data fits in subsequent chunks
  • Supports both single and multi-output plugins

Subclasses implement compute_with_delay(**kwargs) (returns delayed output arrays).

Can you give a minimal working example (or illustrate with a figure)?

import numpy as np
import strax
from strax.testutils import Records, run_id

class VariableDelayPlugin(strax.TimeDelayPlugin):
    """Plugin that adds random delays, simulating e.g. drift time."""
    depends_on = ("records",)
    provides = "delayed_records"
    data_kind = "delayed_records"
    dtype = strax.record_dtype()

    def compute_with_delay(self, records):
        result = records.copy()
        # Simulate variable drift time
        delays = np.random.randint(0, self.max_delay, size=len(result))
        result["time"] = result["time"] + delays
        return result

st = strax.Context(storage=[], register=[Records, VariableDelayPlugin])
result = st.get_array(run_id, "delayed_records")

Output times may exceed input chunk boundaries, and the plugin handles buffering and re-sorting automatically.

Checklist:

  • Docstrings included in TimeDelayPlugin class
  • Documentation updated: docs/source/advanced/plugin_dev.rst
  • Tests added: tests/test_time_delay_plugin.py (6 tests covering constant delay, variable delay, empty chunks, multi-output, chunk continuity, and straddling data)

@cfuselli cfuselli self-requested a review January 29, 2026 06:45
@coveralls
Copy link

Coverage Status

coverage: 89.197% (+0.3%) from 88.93%
when pulling b822b26 on mhliu0001:time_delay_plugin
into bdc4728 on AxFoundation:master.

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.

2 participants