Add centered velocity-shear correction workflow #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Cosmology centered velocity-shear correction | |
| on: | |
| push: | |
| branches: | |
| - dark-sector-stability-architecture | |
| paths: | |
| - 'dark_sector_architecture/NATIVE_CENTERED_VELOCITY_SHEAR_CORRECTION_PREREG.md' | |
| - 'dark_sector_architecture/qualification/gevolution_velocity_operators.py' | |
| - 'dark_sector_architecture/qualification/run_centered_velocity_shear_correction.py' | |
| - '.github/workflows/cosmology-centered-velocity-shear-correction.yml' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| concurrency: | |
| group: cosmology-centered-velocity-shear-correction | |
| cancel-in-progress: true | |
| jobs: | |
| centered-velocity-shear-correction: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 35 | |
| env: | |
| GEVOLUTION_SHA: 0cca42e51a824002ae4fb602cbd79d671e8ffe60 | |
| LATFIELD2_SHA: 2d8c737ab6adc965a1d2718c209f5085af27b09c | |
| TEMPLATE_BLOB: d4de9a5400ef58f6a0181fbe61f18056b233a425 | |
| BOXSIZE: 64.0 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: dark-sector-stability-architecture | |
| fetch-depth: 0 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y build-essential openmpi-bin libopenmpi-dev libfftw3-dev libgsl-dev libhdf5-dev | |
| python -m pip install --upgrade pip | |
| python -m pip install numpy h5py | |
| - name: Verify frozen corrective preregistration | |
| run: | | |
| git log -1 --format=%H -- dark_sector_architecture/NATIVE_CENTERED_VELOCITY_SHEAR_CORRECTION_PREREG.md \ | |
| | tee centered_shear_prereg_commit.txt | |
| - name: Fetch pinned sources and canonical template | |
| run: | | |
| git clone https://github.com/gevolution-code/gevolution-1.3.git gevolution | |
| git -C gevolution checkout "$GEVOLUTION_SHA" | |
| git clone https://gitlab.uzh.ch/julian.adamek/LATfield2.git LATfield2 | |
| git -C LATfield2 checkout "$LATFIELD2_SHA" | |
| curl -L --fail --silent --show-error \ | |
| https://raw.githubusercontent.com/gevolution-code/gevolution-1.2/df8a930732aae1bafa32fd839ee70728bb10773a/sc1_crystal.dat \ | |
| -o gevolution/shear_template.dat | |
| test "$(git hash-object gevolution/shear_template.dat)" = "$TEMPLATE_BLOB" | |
| - name: Patch precise snapshot metadata only | |
| run: | | |
| python - <<'PY' | |
| from pathlib import Path | |
| path=Path('gevolution/main.cpp') | |
| text=path.read_text() | |
| marker=( | |
| '\t\t// snapshot output\n' | |
| '\t\tif (snapcount < sim.num_snapshot && ' | |
| '1. / a < sim.z_snapshot[snapcount] + 1.)\n' | |
| ) | |
| if marker not in text: | |
| raise SystemExit('snapshot marker missing') | |
| replacement=( | |
| '\t\t// snapshot output\n' | |
| '\t\tif (snapcount < sim.num_snapshot && ' | |
| '1. / a < sim.z_snapshot[snapcount] + 1.)\n' | |
| '\t\t{\n' | |
| '\t\t\tchar shear_meta[256];\n' | |
| '\t\t\tsprintf(shear_meta, ' | |
| '"SHEAR_CORRECTION_META index=%d cycle=%d a=%.17g z=%.17g ' | |
| 'tau_over_boxsize=%.17g", snapcount, cycle, a, (1./a)-1., tau);\n' | |
| '\t\t\tCOUT << shear_meta << endl;\n' | |
| '\t\t}\n' | |
| '\t\tif (snapcount < sim.num_snapshot && ' | |
| '1. / a < sim.z_snapshot[snapcount] + 1.)\n' | |
| ) | |
| path.write_text(text.replace(marker,replacement,1)) | |
| PY | |
| - name: Compile gevolution with velocity output | |
| working-directory: gevolution | |
| run: | | |
| make clean | |
| make -j2 \ | |
| INCLUDE="-I../LATfield2 -I/usr/include/hdf5/serial" \ | |
| LIB="-lfftw3 -lm -L/usr/lib/x86_64-linux-gnu/hdf5/serial -lhdf5 -lgsl -lgslcblas" \ | |
| DGEVOLUTION="-DPHINONLINEAR -DBENCHMARK -DVELOCITY" | |
| - name: Build frozen N32 N64 N128 settings | |
| run: | | |
| python - <<'PY' | |
| from pathlib import Path | |
| base=Path('dark_sector_architecture/qualification/gevolution_modal_pilot.ini').read_text() | |
| for n,tiling in ((32,8),(64,16),(128,32)): | |
| tag=f'n{n}' | |
| text=base | |
| replacements={ | |
| 'template file = pilot_template.dat':'template file = shear_template.dat', | |
| 'tiling factor = 2':f'tiling factor = {tiling}', | |
| 'Ngrid = 8':f'Ngrid = {n}', | |
| 'time step limit = 0.04':'time step limit = 0.0005', | |
| 'output path = ../pilot_output/':f'output path = ../centered_shear_{tag}_output/', | |
| 'generic file base = modalpilot':f'generic file base = centered_shear_{tag}', | |
| 'snapshot file base = modalpilot_snap':f'snapshot file base = centered_shear_{tag}_snap', | |
| 'snapshot outputs = phi, B, chi, hij, v':'snapshot outputs = v', | |
| 'Pk file base = modalpilot_pk':f'Pk file base = centered_shear_{tag}_pk', | |
| 'Pk outputs = phi, B, chi, hij':'Pk outputs = phi', | |
| } | |
| for old,new in replacements.items(): | |
| if old not in text: | |
| raise SystemExit(f'missing token {old}') | |
| text=text.replace(old,new,1) | |
| Path(f'gevolution/centered_shear_{tag}.ini').write_text(text) | |
| PY | |
| - name: Run N32 member | |
| run: | | |
| mkdir -p centered_shear_n32_output | |
| cd gevolution | |
| mpirun --oversubscribe -np 4 ./gevolution -n 2 -m 2 -s centered_shear_n32.ini | tee ../centered_shear_n32.log | |
| - name: Run N64 member | |
| run: | | |
| mkdir -p centered_shear_n64_output | |
| cd gevolution | |
| mpirun --oversubscribe -np 4 ./gevolution -n 2 -m 2 -s centered_shear_n64.ini | tee ../centered_shear_n64.log | |
| - name: Run N128 member | |
| run: | | |
| mkdir -p centered_shear_n128_output | |
| cd gevolution | |
| mpirun --oversubscribe -np 4 ./gevolution -n 2 -m 2 -s centered_shear_n128.ini | tee ../centered_shear_n128.log | |
| - name: Parse precise epochs and field paths | |
| run: | | |
| python - <<'PY' | |
| import json,re | |
| from pathlib import Path | |
| pattern=re.compile( | |
| r'SHEAR_CORRECTION_META index=([0-9]+) cycle=([0-9]+) ' | |
| r'a=([0-9eE+.-]+) z=([0-9eE+.-]+) tau_over_boxsize=([0-9eE+.-]+)' | |
| ) | |
| out=Path('dark_sector_architecture/qualification/results') | |
| out.mkdir(parents=True,exist_ok=True) | |
| for n in (32,64,128): | |
| tag=f'n{n}' | |
| matches=pattern.findall(Path(f'centered_shear_{tag}.log').read_text()) | |
| if len(matches) != 1: | |
| raise SystemExit(f'N{n}: expected one precise snapshot, got {matches}') | |
| index,cycle,a,z,tau=matches[0] | |
| files=list(Path(f'centered_shear_{tag}_output').glob('*_v.h5')) | |
| if len(files) != 1: | |
| raise SystemExit(f'N{n}: expected one velocity HDF5, got {files}') | |
| meta={ | |
| 'protocol':'P0-Q_CENTERED_VELOCITY_SHEAR_MEMBER', | |
| 'grid':n, | |
| 'actual_scale_factor':float(a), | |
| 'actual_redshift':float(z), | |
| 'tau_over_boxsize':float(tau), | |
| 'cycle':int(cycle), | |
| 'velocity_file':str(files[0]), | |
| 'seed':424242, | |
| 'time_step_limit':0.0005, | |
| 'gevolution_sha':'0cca42e51a824002ae4fb602cbd79d671e8ffe60', | |
| 'latfield2_sha':'2d8c737ab6adc965a1d2718c209f5085af27b09c', | |
| } | |
| (out/f'centered_velocity_shear_n{n}_metadata.json').write_text( | |
| json.dumps(meta,indent=2,sort_keys=True)+'\n' | |
| ) | |
| PY | |
| - name: Analyze corrected frozen shear ladder | |
| run: | | |
| v32="$(find centered_shear_n32_output -name '*_v.h5' | head -n1)" | |
| v64="$(find centered_shear_n64_output -name '*_v.h5' | head -n1)" | |
| v128="$(find centered_shear_n128_output -name '*_v.h5' | head -n1)" | |
| python dark_sector_architecture/qualification/run_centered_velocity_shear_correction.py \ | |
| --target-grid 32 --boxsize-mpc-over-h "$BOXSIZE" \ | |
| --member 32 "$v32" dark_sector_architecture/qualification/results/centered_velocity_shear_n32_metadata.json \ | |
| --member 64 "$v64" dark_sector_architecture/qualification/results/centered_velocity_shear_n64_metadata.json \ | |
| --member 128 "$v128" dark_sector_architecture/qualification/results/centered_velocity_shear_n128_metadata.json \ | |
| --output dark_sector_architecture/qualification/results/centered_velocity_shear_correction.json | |
| - name: Add frozen provenance | |
| run: | | |
| python - <<'PY' | |
| import json | |
| from pathlib import Path | |
| p=Path('dark_sector_architecture/qualification/results/centered_velocity_shear_correction.json') | |
| d=json.loads(p.read_text()) | |
| d['frozen_preregistration_commit']=Path('centered_shear_prereg_commit.txt').read_text().strip() | |
| d['workflow_head']='${{ github.sha }}' | |
| p.write_text(json.dumps(d,indent=2,sort_keys=True)+'\n') | |
| PY | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: cosmology-centered-velocity-shear-correction | |
| path: | | |
| centered_shear_prereg_commit.txt | |
| centered_shear_n32.log | |
| centered_shear_n64.log | |
| centered_shear_n128.log | |
| gevolution/centered_shear_n32.ini | |
| gevolution/centered_shear_n64.ini | |
| gevolution/centered_shear_n128.ini | |
| centered_shear_n32_output/*_v.h5 | |
| centered_shear_n64_output/*_v.h5 | |
| centered_shear_n128_output/*_v.h5 | |
| dark_sector_architecture/qualification/results/centered_velocity_shear_n32_metadata.json | |
| dark_sector_architecture/qualification/results/centered_velocity_shear_n64_metadata.json | |
| dark_sector_architecture/qualification/results/centered_velocity_shear_n128_metadata.json | |
| dark_sector_architecture/qualification/results/centered_velocity_shear_correction.json | |
| if-no-files-found: error | |
| - name: Persist corrected shear summaries | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add \ | |
| dark_sector_architecture/qualification/results/centered_velocity_shear_n32_metadata.json \ | |
| dark_sector_architecture/qualification/results/centered_velocity_shear_n64_metadata.json \ | |
| dark_sector_architecture/qualification/results/centered_velocity_shear_n128_metadata.json \ | |
| dark_sector_architecture/qualification/results/centered_velocity_shear_correction.json | |
| if git diff --cached --quiet; then exit 0; fi | |
| git commit -m "Persist corrected centered velocity-shear qualification" | |
| for attempt in 1 2 3 4 5; do | |
| git fetch origin dark-sector-stability-architecture | |
| git rebase origin/dark-sector-stability-architecture | |
| if git push origin HEAD:dark-sector-stability-architecture; then exit 0; fi | |
| sleep 2 | |
| done | |
| exit 1 |