.PHONY: bench eval csd stats analysis tables numbers figures verify-ledger smoke \
        test build_bench clean

# Benchmark constructor: rebuilds every locked split from the WordNet/ConceptNet
# caches and re-checks the semantic invariants of each split.
bench:
	PYTHONPATH=src python scripts/build_bench.py

# Main evaluation: scores a trained checkpoint and writes per-item predictions
# with the raw model output for each item.
eval:
	bash scripts/07_eval_main.sh

# Evaluation with CSD parent fields (beam + prompt-visible cues + candidate logprobs).
# Example:
#   make eval-csd-parent CONFIG=configs/self_rewarding_strict.yaml OUT=outputs/self_rewarding_strict_eval.json
eval-csd-parent:
	PYTHONPATH=src python -m dion.evaluation.run_main_eval \
		--config "$(CONFIG)" --save_items --save_csd_parent --out "$(OUT)"

# Evaluation-time CSD: rebuild CSD items from a parent prediction file.
# Example:
#   make csd PARENT=outputs/predictions/self_rewarding_strict_items.jsonl \
#            OUT=outputs/predictions/self_rewarding_csd_items.jsonl
csd:
	PYTHONPATH=src python scripts/run_csd_intervention.py --parent "$(PARENT)" --out "$(OUT)"

# Statistics bundle: intervals, TOST decisions, AuditPass (incl. retention/PPL NI),
# equivalence-margin justification and the subset sensitivity views.
stats:
	PYTHONPATH=src python scripts/build_stats_bundle.py

# Checkpoint-level mediation and item-level specificity analysis.
analysis:
	PYTHONPATH=src python scripts/build_mediation_analysis.py

# Paper artifacts: every table, every in-text number, every diagnostic figure is
# rendered from the ledger, the statistics bundle and the audit sheets.
tables:
	PYTHONPATH=src python scripts/render_paper_tables.py

numbers:
	PYTHONPATH=src python scripts/render_paper_numbers.py

figures:
	PYTHONPATH=src python scripts/regen_diag_figures.py

# Fail-closed audit: gold is read only from the benchmark files, predictions are
# re-parsed from raw model output with the released parser, and every ledger row
# is recomputed. Exits non-zero on any drift.
verify-ledger:
	PYTHONPATH=src python ledger_validator.py

# CPU-only module smoke (no GPU required).
smoke:
	PYTHONPATH=src pytest tests/ -q

test: smoke

build_bench: bench

clean:
	rm -rf outputs/*_eval.json outputs/predictions outputs/stats outputs/figures outputs/tables

