Add SWIFT SPH (#147)

* Add new params

* Add manticore params

* Add SWIFT reader

* Update script

* Simplify

* Add comment

* Update H0 values for the void

* Update queue
This commit is contained in:
Richard Stiskalek 2024-09-19 14:34:22 +02:00 committed by GitHub
parent 1fc9ca9306
commit c2bc5a6398
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 104 additions and 28 deletions

View file

@ -107,6 +107,33 @@ def prepara_gadget2(snapshot_path, temporary_output_path):
return boxsize
def prepare_swift(snapshot_path, temporary_output_path):
"""
Read in SWIFT Manticore files from Stuart.
"""
# Get some basic information about the snapshots.
with File(snapshot_path, 'r') as src, File(temporary_output_path, 'w') as target: # noqa
h = src["Cosmology"].attrs["h"][0]
npart = src["Header"].attrs["NumPart_Total"][1]
# Convert to Msun / h
mpart = src["Header"].attrs["InitialMassTable"][1] * 1e10 * h
# Convert to Mpc / h
boxsize = src["Header"].attrs["BoxSize"][0] * h
print(f"{'Boxsize':<20}: {boxsize}")
print(f"{'Npart':<20}: {npart}")
print(f"{'Mpart':<20}: {mpart}")
dset = target.create_dataset("particles", (npart, 7), dtype=np.float32)
dset[:, :3] = src["DMParticles/Coordinates"][:] * h # Mpc / h
dset[:, 3:6] = src["DMParticles/Velocities"][:] # km/s
dset[:, 6] = np.ones(npart, dtype=np.float32) * mpart
return boxsize
def run_sph_filter(particles_path, output_path, boxsize, resolution,
SPH_executable):
"""
@ -171,7 +198,7 @@ def main(snapshot_path, output_path, resolution, scratch_space, SPH_executable,
[1] https://bitbucket.org/glavaux/cosmotool/src/master/sample/simple3DFilter.cpp # noqa
"""
# First get the temporary file path.
if snapshot_kind in ["gadget2", "gadget4"]:
if snapshot_kind in ["gadget2", "gadget4", "swift"]:
temporary_output_path = join(
scratch_space, generate_unique_id(snapshot_path))
elif snapshot_kind == "ramses":
@ -206,10 +233,12 @@ def main(snapshot_path, output_path, resolution, scratch_space, SPH_executable,
print(f"{now()}: preparing snapshot...", flush=True)
boxsize = prepara_gadget2(snapshot_path, temporary_output_path)
print(f"{now()}: wrote temporary data to {temporary_output_path}.")
elif snapshot_kind == "swift":
print(f"{now()}: preparing snapshot...", flush=True)
boxsize = prepare_swift(snapshot_path, temporary_output_path)
print(f"{now()}: wrote temporary data to {temporary_output_path}.")
else:
boxsize = 677.7 # Mpc/h
print(f"{now()}: CAREFUL, forcefully setting the boxsize to {boxsize} Mpc / h.", # noqa
flush=True)
raise RuntimeError(f"Snapshot kind `{snapshot_kind}` not implemented.")
# Run the SPH filter.
run_sph_filter(temporary_output_path, output_path, boxsize, resolution,
@ -237,7 +266,7 @@ if __name__ == "__main__":
parser.add_argument("--SPH_executable", type=str, required=True,
help="Path to the `simple3DFilter` executable.")
parser.add_argument("--snapshot_kind", type=str, required=True,
choices=["gadget4", "gadget2", "ramses"],
choices=["gadget4", "gadget2", "ramses", "swift"],
help="Kind of the simulation snapshot.")
args = parser.parse_args()

View file

@ -1,5 +1,5 @@
#!/bin/bash
nthreads=28
nthreads=12
memory=7
on_login=${1}
queue="berg"
@ -11,9 +11,10 @@ resolution=1024
SPH_executable="/mnt/users/rstiskalek/cosmotool/bld/sample/simple3DFilter"
scratch_space="/mnt/extraspace/rstiskalek/dump/"
snapshot_kind="gadget2"
snapshot_path="/mnt/extraspace/rstiskalek/CLONES/s8/cf2gvpecc1pt5elmo73_sig6distribsbvoldi_RZA3Derrv2_512_500_ss8_zinit60_000"
output_path="/mnt/extraspace/rstiskalek/CLONES/s8/cf2gvpecc1pt5elmo73_sig6distribsbvoldi_RZA3Derrv2_512_500_ss8_zinit60_000.hdf5"
# CLONES settings
# snapshot_kind="gadget2"
# snapshot_path="/mnt/extraspace/rstiskalek/CLONES/s8/cf2gvpecc1pt5elmo73_sig6distribsbvoldi_RZA3Derrv2_512_500_ss8_zinit60_000"
# output_path="/mnt/extraspace/rstiskalek/CLONES/s8/cf2gvpecc1pt5elmo73_sig6distribsbvoldi_RZA3Derrv2_512_500_ss8_zinit60_000.hdf5"
# Check if `on_login` is either 0 or 1
@ -26,14 +27,36 @@ fi
export OMP_NUM_THREADS={nthreads}
export OMP_NESTED=true
pythoncm="$env $file --snapshot_path $snapshot_path --output_path $output_path --resolution $resolution --scratch_space $scratch_space --SPH_executable $SPH_executable --snapshot_kind $snapshot_kind"
if [ $on_login -eq 1 ]; then
echo $pythoncm
$pythoncm
else
cm="addqueue -s -q $queue -n 1x$nthreads -m $memory $pythoncm"
echo "Submitting:"
echo $cm
echo
eval $cm
fi
# pythoncm="$env $file --snapshot_path $snapshot_path --output_path $output_path --resolution $resolution --scratch_space $scratch_space --SPH_executable $SPH_executable --snapshot_kind $snapshot_kind"
# if [ $on_login -eq 1 ]; then
# echo $pythoncm
# $pythoncm
# else
# cm="addqueue -s -q $queue -n 1x$nthreads -m $memory $pythoncm"
# echo "Submitting:"
# echo $cm
# echo
# eval $cm
# fi
# Manticore SWIFT submission loop
snapshot_kind="swift"
for k in {0..40}; do
snapshot_path="/mnt/extraspace/rstiskalek/MANTICORE/2MPP_N128_DES_V1/resimulations/R512/mcmc_$k/swift_monofonic/snap_0001/snap_0001.hdf5"
output_path="/mnt/extraspace/rstiskalek/MANTICORE/2MPP_N128_DES_V1/fields/R512/SPH_$k.hdf5"
pythoncm="$env $file --snapshot_path $snapshot_path --output_path $output_path --resolution $resolution --scratch_space $scratch_space --SPH_executable $SPH_executable --snapshot_kind $snapshot_kind"
if [ $on_login -eq 1 ]; then
echo $pythoncm
$pythoncm
else
cm="addqueue -s -q $queue -n 1x$nthreads -m $memory $pythoncm"
echo "Submitting:"
echo $cm
echo
eval $cm
fi
sleep 0.05
done