mirror of
https://github.com/Richard-Sti/csiborgtools_public.git
synced 2025-05-21 01:51:11 +00:00
Add new ICs (#59)
* edit IC paths * Remove import * Edit path * Change naming * Add __main__ * Script to match everything * Edit docs * Remove test statement * Move import * Update nb
This commit is contained in:
parent
ab8199be2c
commit
b710b8e89c
18 changed files with 9536 additions and 134 deletions
79
scripts/match_all.py
Normal file
79
scripts/match_all.py
Normal file
|
@ -0,0 +1,79 @@
|
|||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the
|
||||
# Free Software Foundation; either version 3 of the License, or (at your
|
||||
# option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
# Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
"""
|
||||
Script to match all pairs of CSiBORG simulations. Mathches main haloes whose
|
||||
mass is above 1e12 solar masses.
|
||||
"""
|
||||
from argparse import ArgumentParser
|
||||
from datetime import datetime
|
||||
from distutils.util import strtobool
|
||||
from itertools import combinations
|
||||
from random import Random
|
||||
|
||||
from mpi4py import MPI
|
||||
|
||||
try:
|
||||
import csiborgtools
|
||||
except ModuleNotFoundError:
|
||||
import sys
|
||||
|
||||
sys.path.append("../")
|
||||
import csiborgtools
|
||||
|
||||
from taskmaster import master_process, worker_process
|
||||
|
||||
from match_singlematch import pair_match
|
||||
|
||||
# Argument parser
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument("--sigma", type=float, default=None)
|
||||
parser.add_argument("--smoothen", type=lambda x: bool(strtobool(x)),
|
||||
default=None)
|
||||
parser.add_argument("--verbose", type=lambda x: bool(strtobool(x)),
|
||||
default=False)
|
||||
args = parser.parse_args()
|
||||
|
||||
comm = MPI.COMM_WORLD
|
||||
rank = comm.Get_rank()
|
||||
nproc = comm.Get_size()
|
||||
|
||||
|
||||
def get_combs():
|
||||
"""
|
||||
Get the list of all pairs of simulations, then permute them with a known
|
||||
seed to minimise loading the same files simultaneously.
|
||||
"""
|
||||
paths = csiborgtools.read.CSiBORGPaths(**csiborgtools.paths_glamdring)
|
||||
ics = paths.get_ics()
|
||||
combs = list(combinations(ics, 2))
|
||||
Random(42).shuffle(combs)
|
||||
return combs
|
||||
|
||||
|
||||
def do_work(comb):
|
||||
nsim0, nsimx = comb
|
||||
pair_match(nsim0, nsimx, args.sigma, args.smoothen, args.verbose)
|
||||
|
||||
|
||||
if nproc > 1:
|
||||
if rank == 0:
|
||||
combs = get_combs()
|
||||
master_process(combs, comm, verbose=True)
|
||||
else:
|
||||
worker_process(do_work, comm, verbose=False)
|
||||
else:
|
||||
combs = get_combs()
|
||||
for comb in combs:
|
||||
print(f"{datetime.now()}: completing task `{comb}`.", flush=True)
|
||||
do_work(comb)
|
Loading…
Add table
Add a link
Reference in a new issue