Skip to content

cosmotron_mcp.systematics_tools

build_systematics_evidence

build_systematics_evidence(session_dir: str, jobspec: dict | None = None) -> dict

Deterministic systematics GATE: compute every applicable check, record verdict.

The gate analogue of build_review_evidence. Probe-aware from the manifest: spin-2 bins → c-term, PSF-leakage, B-mode nulls; all bins → template contamination (one check per ingested template). Computes any missing prerequisite itself (calls compute_cterm/compute_psf_leakage/ run_bmode_null_tests_from_session/compute_systematics_cls_from_session).

Writes results/systematics/systematics_gate.json ({checks, overall, config, evidence_text}) and registers a systematics_gate artefact. Idempotent — a re-run preserves an existing human override whose statistic is unchanged (a moved statistic voids it). Zero ingested templates on a non-full-sky session → a MISSING check → overall cannot PASS (unless template_contamination_max_frac is null). A full_sky / enabled:false session writes an overall-PASS DISABLED record.

The @systematics_checker agent calls this, relays the EVIDENCE block, and on a FAIL ends with one NEEDS_INPUT line — it NEVER calls override itself.

Parameters:

Name Type Description Default
session_dir str

Session directory.

required
jobspec dict | None

Optional {"backend": "slurm", "site": "<site>"} to run the WHOLE gate (including any catalogue-bound prerequisite it must compute) as one non-blocking remote job (async receipt; poll with check_job) — avoids computing cterm/psf on a multi-GB catalogue in-process on the stdio server. Omit for in-process.

None

Returns:

Type Description
dict

{checks, overall, config, evidence_text}, also written to

dict

results/systematics/systematics_gate.json.

Source code in cosmotron_mcp/server.py
@mcp.tool()
@sync_budget_guard
def build_systematics_evidence(session_dir: str, jobspec: dict | None = None) -> dict:
    """Deterministic systematics GATE: compute every applicable check, record verdict.

    The gate analogue of `build_review_evidence`. Probe-aware from the manifest:
    spin-2 bins → c-term, PSF-leakage, B-mode nulls; all bins → template
    contamination (one check per ingested template). Computes any missing
    prerequisite itself (calls compute_cterm/compute_psf_leakage/
    run_bmode_null_tests_from_session/compute_systematics_cls_from_session).

    Writes `results/systematics/systematics_gate.json` (`{checks, overall, config, evidence_text}`)
    and registers a `systematics_gate` artefact. Idempotent — a re-run preserves an
    existing human override whose statistic is unchanged (a moved statistic voids it).
    Zero ingested templates on a non-full-sky session → a MISSING check → overall
    cannot PASS (unless `template_contamination_max_frac` is null). A `full_sky` /
    `enabled:false` session writes an overall-PASS DISABLED record.

    The `@systematics_checker` agent calls this, relays the EVIDENCE block, and on a
    FAIL ends with one `NEEDS_INPUT` line — it NEVER calls override itself.

    Args:
        session_dir: Session directory.
        jobspec: Optional ``{"backend": "slurm", "site": "<site>"}`` to run
            the WHOLE gate (including any catalogue-bound prerequisite it must
            compute) as one non-blocking remote job (async receipt; poll with
            `check_job`) — avoids computing cterm/psf on a multi-GB catalogue
            in-process on the stdio server. Omit for in-process.

    Returns:
        ``{checks, overall, config, evidence_text}``, also written to
        ``results/systematics/systematics_gate.json``.
    """
    _require_human_gates(session_dir)
    from cosmotron_mcp.remote.dispatch import maybe_submit_async
    async_receipt = maybe_submit_async(
        "build_systematics_evidence", session_dir,
        {"session_dir": session_dir}, jobspec,
    )
    if async_receipt is not None:
        return async_receipt
    result = _build_systematics_evidence(session_dir)
    _log_tool_call(session_dir, "build_systematics_evidence", {})
    return _compact_result(result)