mirror of
https://github.com/Richard-Sti/csiborgtools_public.git
synced 2025-05-14 06:31:11 +00:00
Attempt at absolute calibration and more (#146)
* Update nb * Update defaults * Add absolute calibration to fpath * Add basic absolute calibration * Switch to log density * Feed in r directly * Add more complex spacing option * Update script * Comment out abs calibration for now * Update script * Add MB profile * Add script * Update submit for all profiles * Update * Add option * Add iterator over sims * Update defaults on alpha * Update script * Parallelise script * Switch to feasible init * Switch to median init * Add vext option * Remove file if exists * Add optional sample_Vext * Add param * rm print * Add more iterator * Update script * Update nb * Update nb
This commit is contained in:
parent
32e36afdc3
commit
9c1aa26428
11 changed files with 568 additions and 160 deletions
|
@ -22,6 +22,19 @@ from argparse import ArgumentParser, ArgumentTypeError
|
|||
def none_or_int(value):
|
||||
if value.lower() == "none":
|
||||
return None
|
||||
|
||||
if "_" in value:
|
||||
args = value.split("_")
|
||||
if len(args) == 2:
|
||||
k0, kf = args
|
||||
dk = 1
|
||||
elif len(args) == 3:
|
||||
k0, kf, dk = args
|
||||
else:
|
||||
raise ArgumentTypeError(f"Invalid length of arguments: `{value}`.")
|
||||
|
||||
return [int(k) for k in range(int(k0), int(kf), int(dk))]
|
||||
|
||||
try:
|
||||
return int(value)
|
||||
except ValueError:
|
||||
|
@ -73,17 +86,17 @@ def print_variables(names, variables):
|
|||
print(flush=True)
|
||||
|
||||
|
||||
def get_models(get_model_kwargs, mag_selection, verbose=True):
|
||||
def get_models(ksim, get_model_kwargs, mag_selection, verbose=True):
|
||||
"""Load the data and create the NumPyro models."""
|
||||
paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)
|
||||
folder = "/mnt/extraspace/rstiskalek/catalogs/"
|
||||
|
||||
nsims = paths.get_ics(ARGS.simname)
|
||||
if ARGS.ksim is None:
|
||||
if ksim is None:
|
||||
nsim_iterator = [i for i in range(len(nsims))]
|
||||
else:
|
||||
nsim_iterator = [ARGS.ksim]
|
||||
nsims = [nsims[ARGS.ksim]]
|
||||
nsim_iterator = [ksim]
|
||||
nsims = [nsims[ksim]]
|
||||
|
||||
if verbose:
|
||||
print(f"{'Simulation:':<20} {ARGS.simname}")
|
||||
|
@ -114,7 +127,7 @@ def get_models(get_model_kwargs, mag_selection, verbose=True):
|
|||
models[i] = csiborgtools.flow.get_model(
|
||||
loader, mag_selection=mag_selection[i], **get_model_kwargs)
|
||||
|
||||
print(f"\n{'Num. radial steps':<20} {len(loader.rdist)}\n", flush=True)
|
||||
fprint(f"num. radial steps is {len(loader.rdist)}")
|
||||
return models
|
||||
|
||||
|
||||
|
@ -143,7 +156,7 @@ def run_model(model, nsteps, nburn, model_kwargs, out_folder,
|
|||
raise AttributeError("The models must have an attribute `ndata` "
|
||||
"indicating the number of data points.") from e
|
||||
|
||||
nuts_kernel = NUTS(model, init_strategy=init_to_median(num_samples=1000))
|
||||
nuts_kernel = NUTS(model, init_strategy=init_to_median(num_samples=10000))
|
||||
mcmc = MCMC(nuts_kernel, num_warmup=nburn, num_samples=nsteps)
|
||||
rng_key = jax.random.PRNGKey(42)
|
||||
|
||||
|
@ -283,11 +296,14 @@ if __name__ == "__main__":
|
|||
num_epochs = 50
|
||||
inference_method = "mike"
|
||||
mag_selection = None
|
||||
sample_alpha = True
|
||||
sample_alpha = False if "IndranilVoid_" in ARGS.simname else True
|
||||
sample_beta = None
|
||||
sample_Vext = None
|
||||
sample_Vmono = False
|
||||
sample_mag_dipole = False
|
||||
absolute_calibration = None
|
||||
calculate_harmonic = False if inference_method == "bayes" else True
|
||||
sample_h = True if absolute_calibration is not None else False
|
||||
|
||||
fname_kwargs = {"inference_method": inference_method,
|
||||
"smooth": ARGS.ksmooth,
|
||||
|
@ -297,8 +313,10 @@ if __name__ == "__main__":
|
|||
"mag_selection": mag_selection,
|
||||
"sample_alpha": sample_alpha,
|
||||
"sample_beta": sample_beta,
|
||||
"sample_Vext": sample_Vext,
|
||||
"sample_Vmono": sample_Vmono,
|
||||
"sample_mag_dipole": sample_mag_dipole,
|
||||
"absolute_calibration": absolute_calibration,
|
||||
}
|
||||
|
||||
main_params = {"nsteps": nsteps, "nburn": nburn,
|
||||
|
@ -310,6 +328,8 @@ if __name__ == "__main__":
|
|||
"num_epochs": num_epochs,
|
||||
"inference_method": inference_method,
|
||||
"sample_mag_dipole": sample_mag_dipole,
|
||||
"absolute_calibration": absolute_calibration,
|
||||
"sample_h": sample_h,
|
||||
}
|
||||
print_variables(main_params.keys(), main_params.values())
|
||||
|
||||
|
@ -335,8 +355,11 @@ if __name__ == "__main__":
|
|||
"Vmono_min": -1000, "Vmono_max": 1000,
|
||||
"beta_min": -10.0, "beta_max": 10.0,
|
||||
"sigma_v_min": 1.0, "sigma_v_max": 750.,
|
||||
"h_min": 0.01, "h_max": 5.0,
|
||||
"sample_Vext": True if sample_Vext is None else sample_Vext, # noqa
|
||||
"sample_Vmono": sample_Vmono,
|
||||
"sample_beta": sample_beta,
|
||||
"sample_h": sample_h,
|
||||
}
|
||||
print_variables(
|
||||
calibration_hyperparams.keys(), calibration_hyperparams.values())
|
||||
|
@ -353,17 +376,34 @@ if __name__ == "__main__":
|
|||
|
||||
###########################################################################
|
||||
|
||||
get_model_kwargs = {"zcmb_min": zcmb_min, "zcmb_max": zcmb_max}
|
||||
models = get_models(get_model_kwargs, mag_selection)
|
||||
model_kwargs = {
|
||||
"models": models,
|
||||
"field_calibration_hyperparams": calibration_hyperparams,
|
||||
"distmod_hyperparams_per_model": distmod_hyperparams_per_catalogue,
|
||||
"inference_method": inference_method,
|
||||
get_model_kwargs = {
|
||||
"zcmb_min": zcmb_min,
|
||||
"zcmb_max": zcmb_max,
|
||||
"absolute_calibration": absolute_calibration,
|
||||
"calibration_fpath": "/mnt/extraspace/rstiskalek/catalogs/PV/CF4/CF4_TF_calibration.hdf5", # noqa
|
||||
}
|
||||
|
||||
model = csiborgtools.flow.PV_validation_model
|
||||
# In case we want to run multiple simulations independently.
|
||||
if not isinstance(ARGS.ksim, list):
|
||||
ksim_iterator = [ARGS.ksim]
|
||||
else:
|
||||
ksim_iterator = ARGS.ksim
|
||||
|
||||
run_model(model, nsteps, nburn, model_kwargs, out_folder,
|
||||
calculate_harmonic, nchains_harmonic, num_epochs, kwargs_print,
|
||||
fname_kwargs)
|
||||
for i, ksim in enumerate(ksim_iterator):
|
||||
if len(ksim_iterator) > 1:
|
||||
print(f"{'Current simulation:':<20} {i + 1} ({ksim}) out of {len(ksim_iterator)}.") # noqa
|
||||
|
||||
fname_kwargs["nsim"] = ksim
|
||||
models = get_models(ksim, get_model_kwargs, mag_selection)
|
||||
model_kwargs = {
|
||||
"models": models,
|
||||
"field_calibration_hyperparams": calibration_hyperparams,
|
||||
"distmod_hyperparams_per_model": distmod_hyperparams_per_catalogue,
|
||||
"inference_method": inference_method,
|
||||
}
|
||||
|
||||
model = csiborgtools.flow.PV_validation_model
|
||||
|
||||
run_model(model, nsteps, nburn, model_kwargs, out_folder,
|
||||
calculate_harmonic, nchains_harmonic, num_epochs,
|
||||
kwargs_print, fname_kwargs)
|
||||
|
|
|
@ -37,42 +37,36 @@ else
|
|||
fi
|
||||
|
||||
|
||||
# for simname in "CLONES"; do
|
||||
# for simname in "csiborg2_main" "csiborg2X" ; do
|
||||
# for simname in "carrick2015" "lilow2024" "csiborg2_main" "csiborg2x" "cf4" "clones"; do
|
||||
for simname in "Carrick2015" "csiborg2_main"; do
|
||||
# for simname in "Carrick2015" "csiborg2X" "csiborg2_main"; do
|
||||
# for simname in "Carrick2015"; do
|
||||
# for catalogue in "LOSS" "Foundation" "2MTF" "SFI_gals" "CF4_TFR_i" "CF4_TFR_w1"; do
|
||||
for catalogue in "SFI_gals" "2MTF" "CF4_TFR_i"; do
|
||||
for simname in "IndranilVoid_exp" "IndranilVoid_gauss" "IndranilVoid_mb"; do
|
||||
# for catalogue in "2MTF" "SFI_gals" "CF4_TFR_i" "CF4_TFR_w1"; do
|
||||
# for catalogue in "CF4_TFR_i" "CF4_TFR_w1"; do
|
||||
# for catalogue in "2MTF" "SFI" "CF4_TFR_not2MTForSFI_i"; do
|
||||
# for catalogue in "2MTF" "SFI_gals" "CF4_TFR_i"; do
|
||||
# for catalogue in "CF4_TFR_w1"; do
|
||||
# for catalogue in "CF4_GroupAll"; do
|
||||
for ksmooth in 1 2 3 4; do
|
||||
for ksim in "none"; do
|
||||
for catalogue in "2MTF" "SFI_gals" "CF4_TFR_i" "CF4_TFR_w1"; do
|
||||
# for ksim in "none"; do
|
||||
# for ksim in 0; do
|
||||
# for ksim in $(seq 0 5 500); do
|
||||
for ksim in "0_100_5" "100_200_5" "200_300_5" "300_400_5" "400_500_5"; do
|
||||
# for ksim in {0..500}; do
|
||||
pythoncm="$env $file --catalogue $catalogue --simname $simname --ksim $ksim --ksmooth $ksmooth --ndevice $ndevice --device $device"
|
||||
for ksmooth in 0; do
|
||||
pythoncm="$env $file --catalogue $catalogue --simname $simname --ksim $ksim --ksmooth $ksmooth --ndevice $ndevice --device $device"
|
||||
|
||||
if [ "$on_login" == "1" ]; then
|
||||
echo $pythoncm
|
||||
eval $pythoncm
|
||||
else
|
||||
if [ "$device" == "gpu" ]; then
|
||||
cm="addqueue -q $queue -s -m $memory --gpus 1 --gputype $gputype $pythoncm"
|
||||
if [ "$on_login" == "1" ]; then
|
||||
echo $pythoncm
|
||||
eval $pythoncm
|
||||
else
|
||||
cm="addqueue -s -q $queue -n 1 -m $memory $pythoncm"
|
||||
if [ "$device" == "gpu" ]; then
|
||||
cm="addqueue -q $queue -s -m $memory --gpus 1 --gputype $gputype $pythoncm"
|
||||
else
|
||||
cm="addqueue -s -q $queue -n 1 -m $memory $pythoncm"
|
||||
fi
|
||||
echo "Submitting:"
|
||||
echo $cm
|
||||
eval $cm
|
||||
fi
|
||||
echo "Submitting:"
|
||||
echo $cm
|
||||
eval $cm
|
||||
fi
|
||||
|
||||
echo
|
||||
sleep 0.01
|
||||
echo
|
||||
sleep 0.001
|
||||
|
||||
done
|
||||
done
|
||||
done
|
||||
done
|
||||
done
|
Loading…
Add table
Add a link
Reference in a new issue