cjfp-data / scripts /run-fisher-validation.sh
santicas's picture
Mirror cjfp-data validation artifacts
c7c67ef verified
Raw History Blame Contribute Delete
5.53 kB
#!/usr/bin/env bash
# Preflight or launch the source repository's maintained NumPy 2 Fisher campaign.
set -euo pipefail
DATA_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
SOURCE_ROOT="${COSMICFISHPIE_REPO_ROOT:-${DATA_ROOT}/../cosmicfishpie}"
action=""
args=()
usage() {
cat <<'EOF'
Usage: bash scripts/run-fisher-validation.sh --source PATH --check
bash scripts/run-fisher-validation.sh --source PATH --run [RUNNER OPTIONS]
--check checks imports, NumPy 2, checkout identity and all 25 current case inputs.
--run performs the same checks, records provenance, then launches fresh cases.
Runner options include --cases LIST, --all, --jobs N and --omp-threads N.
Default selection: all cases. Every run uses --force and a new directory under
validation/fisher/ so archived baseline results remain separate.
Install the selected source environment first with: uv sync --locked
COSMICFISHPIE_REPO_ROOT can replace --source. No Git or DVC publication is done.
EOF
}
while [[ $# -gt 0 ]]; do
case "$1" in
--source)
[[ $# -ge 2 ]] || { usage >&2; exit 2; }
SOURCE_ROOT="$2"; shift 2 ;;
--check|--run)
[[ -z "$action" ]] || { echo 'Choose one action.' >&2; exit 2; }
action="$1"; shift ;;
--help|-h) usage; exit 0 ;;
*) args+=("$1"); shift ;;
esac
done
[[ -n "$action" ]] || { usage >&2; exit 2; }
[[ "$action" != --check || ${#args[@]} -eq 0 ]] || {
echo '--check does not accept runner options.' >&2; exit 2;
}
SOURCE_ROOT="$(cd -- "$SOURCE_ROOT" && pwd)"
export SOURCE_ROOT DATA_ROOT
metadata="$(uv run --no-sync --project "$SOURCE_ROOT" python - <<'PY'
import importlib.metadata
import json
import os
from pathlib import Path
import platform
import subprocess
import sys
import camb # Verify that compiled backend extensions import successfully.
import classy
import cosmicfishpie
import numpy as np
import scipy
import yaml
source = Path(os.environ['SOURCE_ROOT']).resolve()
data = Path(os.environ['DATA_ROOT']).resolve()
package = Path(cosmicfishpie.__file__).resolve()
if not package.is_relative_to(source):
raise SystemExit(f'Wrong cosmicfishpie import: {package}; expected checkout {source}')
if not (2, 1) <= tuple(map(int, np.__version__.split('.')[:2])) < (2, 3):
raise SystemExit(f'Expected NumPy >=2.1,<2.3; got {np.__version__}')
def git(root, *args):
return subprocess.check_output(['git', '-C', str(root), *args], text=True).strip()
configs = sorted((source / 'scripts/validation/configs').glob('compare_run_config.env_*'))
if not configs:
raise SystemExit('No validation cases found in the selected source checkout')
def check_yaml(path, seen=None):
seen = set() if seen is None else seen
path = path.resolve()
if path in seen:
return
seen.add(path)
contents = yaml.safe_load(path.read_text()) or {}
if isinstance(contents, dict) and contents.get('precision_profile_file'):
check_yaml(path.parent / contents['precision_profile_file'], seen)
for config in configs:
values = subprocess.check_output([
'bash', '-eu', '-c',
'REPO_ROOT="$1"; source "$2"; printf "%s\\n" "$YAML_A" "$YAML_B" '
'"$COMMON_SPECS_JSON" "${SURVEY_NAME_PHOTO:-${SURVEY_NAME_SPECTRO:-}}"',
'preflight', str(source), str(config),
], text=True).splitlines()
for name in values[:3]:
if not Path(name).is_file():
raise SystemExit(f'{config.name}: missing input {name}')
for name in values[:2]:
check_yaml(Path(name))
json.loads(Path(values[2]).read_text())
survey = source / 'cosmicfishpie/configs/default_survey_specifications' / (values[3] + '.yaml')
if not survey.is_file():
raise SystemExit(f'{config.name}: missing survey {survey}')
check_yaml(survey)
payload = {
'source_root': str(source), 'source_commit': git(source, 'rev-parse', 'HEAD'),
'source_branch': git(source, 'rev-parse', '--abbrev-ref', 'HEAD'),
'source_status': git(source, 'status', '--porcelain'),
'data_commit': git(data, 'rev-parse', 'HEAD'),
'data_status': git(data, 'status', '--porcelain'),
'python': sys.version, 'platform': platform.platform(), 'package_path': str(package),
'versions': {name: importlib.metadata.version(name)
for name in ('numpy', 'scipy', 'camb', 'classy', 'symbolic-pofk')},
'thread_environment': {name: os.environ.get(name) for name in
('OMP_NUM_THREADS', 'OPENBLAS_NUM_THREADS', 'MKL_NUM_THREADS')},
'case_count': len(configs),
}
print(json.dumps(payload, indent=2))
PY
)"
printf '%s\n' "$metadata"
[[ "$action" == --run ]] || exit 0
revision="$(git -C "$SOURCE_ROOT" rev-parse --short HEAD)"
export CFP_DATA_REPO="$DATA_ROOT"
export CFP_VALIDATION_RESULTS_DIR="$DATA_ROOT/validation/fisher/numpy2_${revision}_$(date -u +%Y%m%d_%H%M%S)_$$"
mkdir -p "$CFP_VALIDATION_RESULTS_DIR"
printf '%s\n' "$metadata" > "$CFP_VALIDATION_RESULTS_DIR/campaign_environment.json"
printf '%q ' bash "$0" --source "$SOURCE_ROOT" --run "${args[@]}" > "$CFP_VALIDATION_RESULTS_DIR/launch_command.txt"
printf '\n' >> "$CFP_VALIDATION_RESULTS_DIR/launch_command.txt"
printf 'Fresh campaign: %s\n' "$CFP_VALIDATION_RESULTS_DIR"
# Keep the preflight environment unchanged when the source scripts invoke uv.
export UV_NO_SYNC=1
# A shell-level override must not redirect cases into an archived run.
unset OUTDIR
cd -- "$SOURCE_ROOT"
exec bash scripts/validation/run_parallel_validations.sh --force "${args[@]}"