Gravitational wave detection

From XuShuwenn/RedAct · View interactive version

Gravitational wave detection is an AI agent skill from the GitHub repository XuShuwenn/RedAct. Detect gravitational wave signals from binary black hole mergers using matched filtering with PyCBC.

How to use this skill

Skill file

Gravitational Wave Detection with Matched Filtering

When to Use

New Section

Environment / Tool Protocol

Input Data

Template Search

Approximants: "SEOBNRv4_opt", "IMRPhenomD", "TaylorT4"

Mass grid: mass1 and mass2 from 10 to 40 solar masses (integer steps)

Process

  1. Before touching data or writing code, restate the concrete task contract to yourself: required input file/channel, fixed approximants, full mass grid, exact output path/schema, and completion criteria. Do not commit to a workflow until these are explicit.

0a. Make that restatement operational before proceeding: enumerate the exact input path/channel, required approximants, full mass1=10..40, mass2=10..40 coverage, final CSV path/schema, and what counts as completion; choose the implementation path only after this is explicit.

0b. Treat the agent/runtime protocol as part of the contract too: if the environment requires exact tool-call syntax or a specific final completion token, follow that protocol exactly.

0c. Do not start with generic environment or process discovery. First ground yourself in the visible task artifacts and required deliverable.

0d. Before editing an existing script, reread the current file contents and patch real source text that actually exists in the file. Do not make blind replacements against invented labels or remembered blocks.

  1. Validate data loading first with a minimal script that reads /root/data/PyCBC_T2_2.gwf from H1:TEST-STRAIN successfully.
  2. Build one faithful serial baseline pipeline using PyCBC: condition detector data (whiten, bandpass), generate templates, and run matched filtering end-to-end on a tiny subset.
  1. Before the full sweep, benchmark a small representative subset (for example, one approximant and a few mass pairs) to estimate runtime and confirm progress/logging and CSV-writing behavior.

3aa. Defer process-management debugging until after this bounded trial exists. Do not spend early turns checking monitor/kill/process utilities before you have a working micro-run, an executable script, or a validated partial artifact.

3a. Do not start the full (approximant, mass1, mass2) sweep until one complete end-to-end trial has succeeded for at least one approximant and one mass pair, has produced a non-trivial interpretable SNR, and has emitted useful diagnostics.

3b. Turn that pilot into an explicit execution plan before launching the full search: estimate the rough full-grid runtime, decide whether to stay serial or split by approximant/batch, and define how intermediate best-per-approximant results will be checkpointed and merged into /root/detection_results.csv.

3c. If the estimate is too large for the remaining session budget, switch immediately to a resumable plan instead of launching the monolithic full sweep and later aborting it.

3c.i. Define that resumable plan explicitly before launching: choose the batch boundaries up front (for example by approximant or fixed mass ranges), decide the checkpoint file(s), and state exactly how completed batches will be merged so the entire required grid can finish without ad hoc reruns after each timeout.

3c.ii. Prefer resumable foreground batches first because they provide direct progress and are easier to verify than silent background jobs.

3c.iii. If a pilot or full run hits the environment timeout, do not respond with logging-only changes or a broad rewrite. Use the last completed stage/log line to localize the stall, reduce the execution unit to a bounded batch, checkpoint results, and define the merge step to /root/detection_results.csv.

3c.iii.a. After one or two unchanged progress checks, do not keep waiting or just rereading the same logs. If observed throughput implies the remaining required coverage will not finish in time, stop polling and change the plan.

3c.iii.b. Do not equate better observability with a runtime fix: extra logs, separate log files, or more frequent polling are diagnostic aids only unless they accompany a bounded execution plan that can actually finish.

3c.iv. Do not respond to repeated timeouts by manually shrinking and rerunning arbitrary subranges one at a time without an overall completion plan; convert immediately to a systematic partition with durable progress tracking.

3c.v. After the first full-run timeout or stall, do not relaunch a near-identical monolithic sweep. Immediately reduce the execution unit to the smallest meaningful foreground chunk, prove one chunk completes and writes a readable checkpoint/result artifact, then use that chunked pattern for the remaining coverage.

3c.vi. Once you decide to batch, declare the full batch ledger up front, including all required approximants and mass blocks, mark batches complete only after their checkpoint exists, and define the exact merge rule to /root/detection_results.csv before further launches.

3c.vii. If a run remains in startup or the first approximant after more than one check and no checkpoint/final CSV has appeared, stop passive polling and auxiliary monitor jobs. Change the computation plan to a smaller foreground chunk with flushed mid-loop progress and a durable artifact.

3c.viii. Before relying on process-control or monitoring commands in a restricted shell, verify they actually exist here. If commands such as ps, pgrep, or pkill are unavailable, use synchronous foreground chunks plus file/log/checkpoint inspection instead.

3d. If you write or edit a Python script, inspect the saved file and run a quick syntax/import smoke test before launching any expensive search.

3d.i. After writing a script, read back the exact saved file and confirm it is actual executable Python source, not prose, TODO text, placeholders, omitted sections, or malformed/truncated output.

3d.i.a. Treat any write/edit step as incomplete until you have inspected the saved file contents and verified it contains a full runnable program from imports through output writing.

3d.i.b. Reject the file immediately if it reads like a natural-language summary of intended steps rather than concrete Python syntax. Do not execute or patch further until a real program is present on disk.

3d.ii. Confirm the executed file still contains the intended control flow, required approximants, full mass-grid coverage, output path, and merge logic; do not trust patch operations alone without inspection.

3d.iii. Minimum pre-launch gate for any new or edited script: inspect the saved file, run python -m py_compile <script> or equivalent syntax/import validation, then execute one tiny foreground end-to-end case using that exact saved script path.

3d.iii.a. Make edits against exact source text read from the file, not descriptive placeholders such as previous block or update logging here.

3d.iii.b. After editing, reread the changed region and enough surrounding code to confirm the intended logic is present in the saved file before any expensive run.

3d.iii.c. On inspection, verify the file is real code end-to-end: no placeholder prose, no failed replacement markers, no omitted sections, and no accidental narrowing of required approximants or mass coverage before you trust it for a long run.

3d.iv. Do not background, parallelize, or batch-launch the search until that exact saved script has passed the bounded foreground validation.

3d.v. If inspection shows truncation, placeholder text, partial definitions, an unexpectedly short file, or missing imports/function bodies, stop and restore the last known-good script before making further changes.

3d.vi. When launching a long or background run, capture stdout/stderr to a concrete log file from the start and record the exact executed script path/command so you can verify later that the intended version is the one running.

3e. Instrument the pilot with explicit stage logs around waveform generation, PSD estimation, and matched filtering so a later stall can be localized quickly.

3e.a. On the first real run, inspect the emitted logs and confirm they show the intended pipeline stages in order (for example: frame load, conditioning, PSD, waveform generation, matched filtering, CSV/checkpoint write) before trusting downstream results.

3e.i. Make the pilot emit progress inside the search loop as well, such as current approximant, current (mass1, mass2), success/failure counts, and current best SNR.

3e.ii. Do not launch a long run that only logs at startup or once per approximant; require observable progress at template or small-batch granularity.

3e.iii. If a pilot or full run is slow or times out, diagnose the bottleneck first on a bounded case with stage timing so you know whether frame I/O, conditioning, PSD estimation, waveform generation, or matched filtering is dominant.

3e.iv. Before changing search structure, conditioning, or execution mode for performance reasons, capture at least one concrete timing or stage-localization signal from the current pipeline. Do not speculate about the bottleneck.

3e.v. Distinguish slow, silent, and failed: if a run is still alive and emitting plausible stage or loop progress, do not stop it just because it is slow. Either let that validated run continue, or pivot only after comparing observed throughput against the remaining budget.

3e.vi. After any timeout, follow this recovery loop before broader changes: inspect the last completed stage/log line, rerun one materially smaller bounded case that reproduces or localizes the slowdown, make one targeted change tied to that evidence, rerun the updated script or chunk immediately, and verify a completed checkpoint or /root/detection_results.csv artifact.

3e.vii. The first retry after a broad timeout must materially reduce execution scope and must complete a readable chunk artifact; added logging alone is not an adequate retry strategy.

3e.viii. Do not infer that a silent run is 'just buffering' from empty logs alone. First inspect the exact saved script, captured logs, exit/error output, or a bounded foreground rerun.

3f. Once one baseline path works, keep that implementation stable and scale it up; do not repeatedly rewrite core search logic unless a concrete observed failure requires a fix.

3f.i. After the first bounded end-to-end case succeeds, freeze the core scientific path: approximants, conditioning/filter settings, waveform domain choice, and matched-filter interface. Optimize execution structure around that baseline rather than changing analysis-defining parameters for speed.

3f.ii. If a bounded run or chunk is already producing valid checkpoints or steady template-count progress, treat that path as the production path. Do not stop it merely because it is slow; only pivot for a concrete blocker such as a reproducible exception, invalid output, or a runtime estimate that clearly prevents completion.

3g. After the pilot, record an observed throughput estimate such as templates/minute or seconds/template and use it to project full-grid wall time before any full launch.

3g.i. Base that estimate on completed template evaluations or a finished bounded batch, not on startup timing alone.

3g.ii. Convert that throughput into an explicit go/no-go check for the true required workload: 3 approximants x 31 x 31 = 2883 template evaluations. If the projected wall time is not comfortably within the remaining session budget, do not launch the full sweep unchanged.

3g.iii. Treat any claimed optimization as unproven until a bounded rerun shows improved observed throughput or a smaller required workload. Splitting by approximant, backgrounding, or multiprocessing does not by itself make the task more feasible.

3g.iv. After two interrupted, aborted, or timed-out attempts at the same broad search stage, treat the current plan as disproven and switch to a different bounded resumable structure rather than rerunning essentially the same command.

3h. Do not launch the full required sweep if that estimate is clearly incompatible with the remaining session budget; switch immediately to a resumable batch or per-approximant plan that still preserves the required search.

3i. When invoking shell or Python execution, use only concrete runnable commands or exact script paths. Do not send prose placeholders such as run a quick check or python script to ... to the shell.

3i.i. Every execution or monitoring step must be a literal command that could be pasted and run as-is: include the exact interpreter, script path, filenames, and any arguments. Do not use ellipses, descriptive stand-ins, or pseudo-commands.

3i.ii. If shell utilities are restricted or uncertain, use short concrete Python commands to inspect known file paths and print their contents/status; never substitute a descriptive phrase for an executable command.

3j. Keep one validated baseline pipeline authoritative. Prefer targeted fixes over full rewrites, and after any fix rerun the smallest case that exercises that exact change before broader scaling.

  1. Reuse conditioned strain data and PSD where possible instead of recomputing preprocessing inside the mass-grid loop.

4a. If you split work by approximant or batch, compute frame loading, conditioning, and PSD estimation once and reuse or persist those shared artifacts; do not repeat identical preprocessing in each worker unless you have confirmed it is negligible.

  1. Run the full required search over all listed approximants and the full integer mass grid, keeping one stable implementation path rather than repeatedly restarting with unvalidated changes.
  1. If runtime is high, use batching, checkpointing, or per-approximant execution that still preserves the required final search and supports a final merge.

6a. If you split execution by mass range or approximant, maintain an explicit completion checklist covering all 3 approximants and the full mass1=10..40, mass2=10..40 grid.

6b. If you write intermediate per-batch files, execute a final consolidation step that reads all completed batches, selects the highest-SNR result per approximant, and writes exactly /root/detection_results.csv with the required schema.

6c. Do not consider the task complete while results exist only in batch-specific files such as per-range or per-approximant CSVs.

6d. Do not treat partial console output, sparse logs, timeouts, or truncated captures as finished results; confirm completion from explicit artifacts, checkpoint contents, or exit evidence before proceeding.

6d.i. If stdout/stderr is truncated or ends mid-search, stop and inspect the underlying log, checkpoint, or final CSV before launching new runs or marking coverage complete.

6d.ii. Do not treat a partial New best ... line, startup banner, unreadable log, or cut-off progress snippet as evidence that the batch finished; retrieve the durable output and confirm the end-of-batch summary or written artifact.

6e. If a simple serial or batched baseline is showing real progress, prefer completing or resuming that path rather than replacing it with multiprocessing for speculative speedups.

6f. If a new execution mode shows only repeated startup or initialization lines without real progress on more than one check, stop using that mode and diagnose it on a tiny batch or revert to the last validated baseline.

6f.i. Treat repeated startup-only logs in multiprocessing/background mode as a hard warning of launch or worker-entrypoint failure. Check the exact executed script path, if __name__ == "__main__": protection where relevant, and whether workers emit per-batch progress before trusting that mode.

6f.ii. If two checks still show only initialization lines and no completed templates or chunks, revert to the last validated serial or simple batched implementation instead of redesigning again.

6g. If the same full-search approach times out twice or stalls twice at the same stage, stop relaunching that monolithic plan. Switch to a clearly bounded resumable strategy with checkpoints.

6h. Treat splitting, backgrounding, or multiprocessing honestly: they are not runtime fixes unless measured throughput or total completion time actually improves.

6i. Do not use parallelism as the first response to a timed-out brute-force sweep. First prove that one bounded serial chunk completes within budget and measure its throughput; only then consider parallel execution of the same validated chunk pattern.

6j. If a run is showing real template-level or batch-level progress and outputs remain plausible, prefer letting it finish or checkpoint naturally. Do not kill and restart it based only on liveness polling or impatience.

  1. Extract the strongest signal (highest SNR) per approximant.
  1. Write /root/detection_results.csv with the final best row for each approximant.
  2. Finish only after directly verifying the CSV exists, is non-empty, and contains the intended final rows.

9a. Treat /root/detection_results.csv as the completion artifact: explicitly list/read it after execution and verify plausible contents before declaring progress or success.

9b. Empty files, missing files, stale files from earlier attempts, logs, or background-job status are not evidence that the task is complete.

  1. If a script was written or patched for the search, actually execute it (or equivalent commands) and inspect its outputs; do not stop at code drafting or an unexecuted fix.

10a. After any bug fix or import-path change, rerun the updated script or the smallest affected pipeline stage immediately and inspect the new output or error before moving on.

10a.i. For import/API fixes specifically, rerun the exact saved script or a minimal executable probe that uses the corrected import path on the real frame file before doing anything else.

10b. Do not treat "edited the file" or "found the fix" as progress toward completion; a repair only counts after the updated code has been executed and validated.

10c. After any timeout-driven rewrite or bug fix, the very next step must be execution of the edited script on the smallest representative affected case and inspection of its output, traceback, or written artifact before any further redesign.

10d. Once one bounded execution path has produced a real matched-filter result for a required approximant, stop redesigning the workflow unless a new concrete blocker appears. Use that same validated path to complete the remaining approximants/batches, merge results, and finish the final CSV verification.

  1. Use an explicit completion checklist before finishing: data read succeeded, conditioning and matched filtering ran, the full required search completed, one strongest row was selected for each approximant, and /root/detection_results.csv was verified on disk.

11a. Keep a live coverage checklist during execution listing every required approximant and each planned batch/range; do not stop while any item remains incomplete.

11b. Do not treat "remaining ranges will be run later" as acceptable progress. Finish only after all planned batches have been executed, merged, and verified in the final CSV.

11c. Before any final response, compare the live coverage ledger against the required task contract and verify there are no unchecked approximants or mass blocks. Do not end on a statement like 'remaining ranges will be run later'; if anything is unfinished, continue executing or explicitly report the blocker.

11d. Finish with the required explicit completion signal only after the final CSV has been read back and verified; do not end on running/monitoring status alone.

Process

Preflight Checks

Output Format

CSV at /root/detection_results.csv.

Key Metrics

Tips

Tips

Failure Handling

Preflight Checks

Implementation Guardrails

Implementation Guardrails

Runtime-Safe Execution

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.