Skip to content

Commit bd01a8d

Browse files
Fix pickup_to_init big-endian I/O and NaN/Inf handling
- Read pickup as big-endian (>f8) matching MITgcm's useSingleCPUIO output - Write init files as big-endian (>f4) matching readBinaryPrec=32 - Replace NaN/Inf with zero after float64→float32 cast to prevent INI_THETA crash from overflow at land points - Add --start=N flag to repeat_year_chain.sh for resuming from a given run Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0fac7b6 commit bd01a8d

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

simulations/glorysv12-curvilinear/workflows/repeat_year_chain.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
2020
SIMULATION_DIR=$(dirname "$SCRIPT_DIR")
2121

2222
N_RUNS=50
23+
START_RUN=1
2324
EXPERIMENT="repeat-year-50"
2425
DRY_RUN=false
2526

26-
if [[ "${1:-}" == "--dry-run" ]]; then
27-
DRY_RUN=true
28-
echo "[DRY RUN] Will print sbatch commands without submitting."
29-
fi
27+
for arg in "$@"; do
28+
case "$arg" in
29+
--dry-run) DRY_RUN=true; echo "[DRY RUN] Will print sbatch commands without submitting." ;;
30+
--start=*) START_RUN="${arg#--start=}" ;;
31+
esac
32+
done
3033

3134
EXPERIMENT_DIR="${SIMULATION_DIR}/${EXPERIMENT}"
3235
mkdir -p "${EXPERIMENT_DIR}"
@@ -38,7 +41,7 @@ echo "======================================="
3841

3942
PREV_JOB_ID=""
4043

41-
for i in $(seq 1 $N_RUNS); do
44+
for i in $(seq $START_RUN $N_RUNS); do
4245
RUN_NUM=$(printf "%03d" $i)
4346
PREV_RUN_NUM=""
4447
if [[ $i -gt 1 ]]; then

spectre_utils/pickup_to_init.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def parse_pickup_meta(meta_path: Path) -> dict:
3535

3636
# Extract precision
3737
prec_match = re.search(r"dataprec\s*=\s*\[\s*'(\w+)'\s*\]", text)
38-
dtype = np.float64 if prec_match and "64" in prec_match.group(1) else np.float32
38+
dtype = np.dtype(">f8") if prec_match and "64" in prec_match.group(1) else np.dtype(">f4")
3939

4040
# Extract number of records
4141
nrec_match = re.search(r"nrecords\s*=\s*\[\s*(\d+)\s*\]", text)
@@ -123,7 +123,9 @@ def pickup_to_init(pickup_prefix: str, output_dir: str, nx: int, ny: int, nr: in
123123
init_path = out / init_name
124124
if init_path.is_symlink() or init_path.exists():
125125
init_path.unlink()
126-
data.astype(np.float32).tofile(init_path)
126+
data32 = data.astype(">f4")
127+
data32[~np.isfinite(data32)] = 0.0
128+
data32.tofile(init_path)
127129
size_mb = init_path.stat().st_size / 1e6
128130
print(f" Wrote {init_path} ({size_mb:.1f} MB)")
129131

0 commit comments

Comments
 (0)