2023-05-09 15:18:01 +00:00
|
|
|
# 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.
|
2023-07-31 14:13:21 +00:00
|
|
|
"""A script to match all IC pairs of a simulation."""
|
2023-08-18 18:20:47 +00:00
|
|
|
import warnings
|
2023-05-09 15:18:01 +00:00
|
|
|
from argparse import ArgumentParser
|
|
|
|
from distutils.util import strtobool
|
|
|
|
from itertools import combinations
|
|
|
|
from random import Random
|
|
|
|
|
|
|
|
from mpi4py import MPI
|
2023-06-18 10:42:21 +00:00
|
|
|
from taskmaster import work_delegation
|
|
|
|
|
2023-08-18 18:20:47 +00:00
|
|
|
import csiborgtools
|
2023-12-20 15:28:26 +00:00
|
|
|
from match_overlap_single import pair_match, pair_match_max
|
2023-05-09 15:18:01 +00:00
|
|
|
|
|
|
|
|
2023-07-31 14:13:21 +00:00
|
|
|
def get_combs(simname):
|
2023-05-09 15:18:01 +00:00
|
|
|
"""
|
2023-07-31 14:13:21 +00:00
|
|
|
Get the list of all pairs of IC indices and permute them with a fixed
|
|
|
|
seed.
|
2023-05-09 15:18:01 +00:00
|
|
|
"""
|
2023-05-13 16:37:34 +00:00
|
|
|
paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)
|
2023-07-31 14:13:21 +00:00
|
|
|
combs = list(combinations(paths.get_ics(simname), 2))
|
|
|
|
|
2023-05-09 15:18:01 +00:00
|
|
|
Random(42).shuffle(combs)
|
|
|
|
return combs
|
|
|
|
|
|
|
|
|
2023-08-18 18:20:47 +00:00
|
|
|
def main(comb, kind, simname, min_logmass, sigma, mult, verbose):
|
2023-06-18 10:42:21 +00:00
|
|
|
"""
|
|
|
|
Match a pair of simulations.
|
|
|
|
"""
|
2023-05-09 15:18:01 +00:00
|
|
|
nsim0, nsimx = comb
|
2023-08-18 18:20:47 +00:00
|
|
|
if kind == "overlap":
|
|
|
|
pair_match(nsim0, nsimx, simname, min_logmass, sigma, verbose)
|
|
|
|
elif args.kind == "max":
|
|
|
|
pair_match_max(nsim0, nsimx, simname, min_logmass, mult, verbose)
|
|
|
|
else:
|
|
|
|
raise ValueError(f"Unknown matching kind: `{kind}`.")
|
2023-05-09 15:18:01 +00:00
|
|
|
|
|
|
|
|
2023-06-18 10:42:21 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = ArgumentParser()
|
2023-08-18 18:20:47 +00:00
|
|
|
parser.add_argument("--kind", type=str, required=True,
|
|
|
|
choices=["overlap", "max"], help="Kind of matching.")
|
2023-08-08 10:46:56 +00:00
|
|
|
parser.add_argument("--simname", type=str, required=True,
|
2023-08-18 18:20:47 +00:00
|
|
|
help="Simulation name.",
|
2024-04-08 09:23:21 +00:00
|
|
|
choices=["csiborg1", "quijote", "csiborg2_main",
|
|
|
|
"csiborg2_random", "csiborg2_varysmall"])
|
2023-08-18 18:20:47 +00:00
|
|
|
parser.add_argument("--nsim0", type=int, default=None,
|
|
|
|
help="Reference IC for Max's matching method.")
|
2023-08-08 10:46:56 +00:00
|
|
|
parser.add_argument("--min_logmass", type=float, required=True,
|
|
|
|
help="Minimum log halo mass.")
|
2023-07-31 14:13:21 +00:00
|
|
|
parser.add_argument("--sigma", type=float, default=0,
|
|
|
|
help="Smoothing scale in number of grid cells.")
|
2023-08-18 18:20:47 +00:00
|
|
|
parser.add_argument("--mult", type=float, default=5,
|
|
|
|
help="Search radius multiplier for Max's method.")
|
2023-06-18 10:42:21 +00:00
|
|
|
parser.add_argument("--verbose", type=lambda x: bool(strtobool(x)),
|
2023-07-31 14:13:21 +00:00
|
|
|
default=False, help="Verbosity flag.")
|
2023-06-18 10:42:21 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2023-08-18 18:20:47 +00:00
|
|
|
if args.kind == "overlap":
|
|
|
|
combs = get_combs(args.simname)
|
|
|
|
else:
|
|
|
|
paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)
|
|
|
|
combs = [(args.nsim0, nsimx) for nsimx in paths.get_ics(args.simname)
|
|
|
|
if nsimx != args.nsim0]
|
2023-07-31 14:13:21 +00:00
|
|
|
|
|
|
|
def _main(comb):
|
2023-08-18 18:20:47 +00:00
|
|
|
with warnings.catch_warnings():
|
|
|
|
warnings.filterwarnings("ignore",
|
|
|
|
"invalid value encountered in cast",
|
|
|
|
RuntimeWarning)
|
|
|
|
main(comb, args.kind, args.simname, args.min_logmass, args.sigma,
|
|
|
|
args.mult, args.verbose)
|
2023-07-31 14:13:21 +00:00
|
|
|
|
|
|
|
work_delegation(_main, combs, MPI.COMM_WORLD)
|