diff --git a/jz-submissions/README.md b/jz-submissions/README.md deleted file mode 100644 index 5e8c7e4f..00000000 --- a/jz-submissions/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# WF-PSF experiences - -Describe how to do the WF-PSF experiences. - diff --git a/jz-submissions/jobs-cli/1k_poly_v2_1cycle.sh b/jz-submissions/jobs-cli/1k_poly_v2_1cycle.sh deleted file mode 100644 index 9ac77e03..00000000 --- a/jz-submissions/jobs-cli/1k_poly_v2_1cycle.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=1k_poly_v2_1cycle # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=1k_poly_v2_1cycle%j.out # nom du fichier de sortie -#SBATCH --error=1k_poly_v2_1cycle%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/alternative_train_eval_script.py \ - --model poly \ - --id_name _chkp_1k_poly_v2_1cycle \ - --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy \ - --n_epochs_param 20 20 \ - --n_epochs_non_param 200 150 \ - --d_max_nonparam 5 \ - --saved_model_type checkpoint \ - --saved_cycle cycle1 \ - --total_cycles 1 \ diff --git a/jz-submissions/jobs-cli/1k_poly_v2_2cycle.sh b/jz-submissions/jobs-cli/1k_poly_v2_2cycle.sh deleted file mode 100644 index 5c02fb30..00000000 --- a/jz-submissions/jobs-cli/1k_poly_v2_2cycle.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=1k_poly_v2_2cycle # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=1k_poly_v2_2cycle%j.out # nom du fichier de sortie -#SBATCH --error=1k_poly_v2_2cycle%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/alternative_train_eval_script.py \ - --model poly \ - --id_name _chkp_1k_poly_v2_2cycle \ - --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy \ - --n_epochs_param 20 20 \ - --n_epochs_non_param 150 200 \ - --l_rate_param 0.01 0.001 \ - --l_rate_non_param 0.1 0.01 \ - --d_max_nonparam 5 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ diff --git a/jz-submissions/jobs-cli/1k_poly_v2_2cycle_no2param.sh b/jz-submissions/jobs-cli/1k_poly_v2_2cycle_no2param.sh deleted file mode 100644 index 1d9106bc..00000000 --- a/jz-submissions/jobs-cli/1k_poly_v2_2cycle_no2param.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=1k_poly_v2_2cycle_n2p # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=1k_poly_v2_2cycle_n2p%j.out # nom du fichier de sortie -#SBATCH --error=1k_poly_v2_2cycle_n2p%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/alternative_train_eval_script.py \ - --model poly \ - --id_name _chkp_1k_poly_v2_2cycle_no2param \ - --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy \ - --n_epochs_param 20 2 \ - --n_epochs_non_param 150 200 \ - --l_rate_param 0.01 0.001 \ - --l_rate_non_param 0.1 0.01 \ - --d_max_nonparam 5 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ diff --git a/jz-submissions/jobs-cli/1k_poly_var_l2_opd.sh b/jz-submissions/jobs-cli/1k_poly_var_l2_opd.sh deleted file mode 100644 index 6b841d1e..00000000 --- a/jz-submissions/jobs-cli/1k_poly_var_l2_opd.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=1k_poly_l2_opd # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=1k_poly_l2_opd%j.out # nom du fichier de sortie -#SBATCH --error=1k_poly_l2_opd%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -#SBATCH --array=0-3 -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--l2_param 1e-10" -opt[1]="--l2_param 5e-11" -opt[2]="--l2_param 1e-11" -opt[3]="--l2_param 5e-12" - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/l2_param_tr_ev.py \ - --model poly \ - --id_name 1k_poly_l2_opd \ - --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy \ - --n_epochs_param 20 20 \ - --n_epochs_non_param 150 150 \ - --l_rate_param 0.01 0.001 \ - --l_rate_non_param 0.1 0.01 \ - --d_max_nonparam 5 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_1k_poly_sample_w.sh b/jz-submissions/jobs-cli/full_1k_poly_sample_w.sh deleted file mode 100644 index 0104c55b..00000000 --- a/jz-submissions/jobs-cli/full_1k_poly_sample_w.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=poly_1k_sample_w # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=poly_1k_sample_w%j.out # nom du fichier de sortie -#SBATCH --error=poly_1k_sample_w%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _1k_sample_w_2c --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --l_rate_param 0.01 0.002 --l_rate_non_param 0.1 0.02" -opt[1]="--id_name _1k_sample_w_5c --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --l_rate_param 0.01 0.004 --l_rate_non_param 0.1 0.04" -opt[2]="--id_name _1k_sample_w_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --l_rate_param 0.01 0.008 --l_rate_non_param 0.1 0.08" -opt[3]="--id_name _1k_sample_w_2k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --l_rate_param 0.01 0.010 --l_rate_non_param 0.1 0.10" - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/train_eval_plot_script_click.py \ - --model poly \ - --d_max_nonparam 5 \ - --n_epochs_param 30 30 \ - --n_epochs_non_param 150 100 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 0. \ - --base_id_name _1k_sample_w_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/poly_1k_sample_w/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_1k_poly_sample_w_l2param_opd.sh b/jz-submissions/jobs-cli/full_1k_poly_sample_w_l2param_opd.sh deleted file mode 100644 index 3a4b6d75..00000000 --- a/jz-submissions/jobs-cli/full_1k_poly_sample_w_l2param_opd.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=poly_1k_sample_w_l2param_opd # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=poly_1k_sample_w_l2param_opd%j.out # nom du fichier de sortie -#SBATCH --error=poly_1k_sample_w_l2param_opd%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _1k_sample_w_l2param_opd_2c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --l_rate_param 0.01 0.002 --l_rate_non_param 0.1 0.02" -opt[1]="--id_name _1k_sample_w_l2param_opd_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --l_rate_param 0.01 0.004 --l_rate_non_param 0.1 0.04" -opt[2]="--id_name _1k_sample_w_l2param_opd_1k --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --l_rate_param 0.01 0.008 --l_rate_non_param 0.1 0.08" -opt[3]="--id_name _1k_sample_w_l2param_opd_2k --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --l_rate_param 0.01 0.010 --l_rate_non_param 0.1 0.10" - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/train_eval_plot_script_click.py \ - --model poly \ - --d_max_nonparam 5 \ - --n_epochs_param 30 30 \ - --n_epochs_non_param 150 100 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 5e-12 \ - --base_id_name _1k_sample_w_l2param_opd_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/poly_1k_sample_w_l2param_opd/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_5c_poly_sample_w.sh b/jz-submissions/jobs-cli/full_5c_poly_sample_w.sh deleted file mode 100644 index b7056016..00000000 --- a/jz-submissions/jobs-cli/full_5c_poly_sample_w.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=poly_5c_sample_w # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=poly_5c_sample_w%j.out # nom du fichier de sortie -#SBATCH --error=poly_5c_sample_w%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _5c_sample_w_2c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --l_rate_param 0.01 0.002 --l_rate_non_param 0.1 0.02" -opt[1]="--id_name _5c_sample_w_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --l_rate_param 0.01 0.004 --l_rate_non_param 0.1 0.04" -opt[2]="--id_name _5c_sample_w_1k --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --l_rate_param 0.01 0.008 --l_rate_non_param 0.1 0.08" -opt[3]="--id_name _5c_sample_w_2k --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --l_rate_param 0.01 0.010 --l_rate_non_param 0.1 0.10" - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/train_eval_plot_script_click.py \ - --model poly \ - --d_max_nonparam 5 \ - --n_epochs_param 30 30 \ - --n_epochs_non_param 200 150 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 0. \ - --base_id_name _5c_sample_w_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/poly_5c_sample_w/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_5c_poly_sample_w_l2param_opd.sh b/jz-submissions/jobs-cli/full_5c_poly_sample_w_l2param_opd.sh deleted file mode 100644 index 4353cb56..00000000 --- a/jz-submissions/jobs-cli/full_5c_poly_sample_w_l2param_opd.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=poly_5c_sample_w_l2param_opd # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=poly_5c_sample_w_l2param_opd%j.out # nom du fichier de sortie -#SBATCH --error=poly_5c_sample_w_l2param_opd%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _5c_sample_w_l2param_opd_2c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --l_rate_param 0.01 0.002 --l_rate_non_param 0.1 0.01" -opt[1]="--id_name _5c_sample_w_l2param_opd_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --l_rate_param 0.01 0.004 --l_rate_non_param 0.1 0.04" -opt[2]="--id_name _5c_sample_w_l2param_opd_1k --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --l_rate_param 0.01 0.008 --l_rate_non_param 0.1 0.08" -opt[3]="--id_name _5c_sample_w_l2param_opd_2k --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --l_rate_param 0.01 0.010 --l_rate_non_param 0.1 0.10" - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/train_eval_plot_script_click.py \ - --model poly \ - --d_max_nonparam 5 \ - --n_epochs_param 30 30 \ - --n_epochs_non_param 200 150 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 5e-12 \ - --base_id_name _5c_sample_w_l2param_opd_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/poly_5c_sample_w_l2param_opd/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_graph_sample_w.sh b/jz-submissions/jobs-cli/full_graph_sample_w.sh deleted file mode 100644 index 58188288..00000000 --- a/jz-submissions/jobs-cli/full_graph_sample_w.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=graph_sample_w # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=graph_sample_w_%j.out # nom du fichier de sortie -#SBATCH --error=graph_sample_w_%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A ynx@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _sample_w_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 300 300" -opt[1]="--id_name _sample_w_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 200 150" -opt[2]="--id_name _sample_w_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 150 100" -opt[3]="--id_name _sample_w_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 15 15 --n_epochs_non_param 100 50" - - -cd $WORK/repo/wf-psf/long-runs/ - -srun python -u ./train_eval_plot_script_click.py \ - --model graph \ - --n_zernikes 15 \ - --l_rate_param 0.01 0.004 \ - --l_rate_non_param 0.1 0.06 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 0. \ - --base_id_name _sample_w_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/graph_sample_w/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_graph_sample_w_tunned.sh b/jz-submissions/jobs-cli/full_graph_sample_w_tunned.sh deleted file mode 100644 index d2517838..00000000 --- a/jz-submissions/jobs-cli/full_graph_sample_w_tunned.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=graph_sample_w_tunned # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=graph_sample_w_tunned_%j.out # nom du fichier de sortie -#SBATCH --error=graph_sample_w_tunned_%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A ynx@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _sample_w_tunned_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 300 300" -opt[1]="--id_name _sample_w_tunned_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 200 150" -opt[2]="--id_name _sample_w_tunned_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 150 100" -opt[3]="--id_name _sample_w_tunned_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 15 15 --n_epochs_non_param 100 50" - - -cd $WORK/repo/wf-psf/long-runs/ - -srun python -u ./train_eval_plot_script_click.py \ - --model graph \ - --n_zernikes 15 \ - --graph_features 21 \ - --l_rate_param 0.01 0.004 \ - --l_rate_non_param 0.4 0.2 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 0. \ - --base_id_name _sample_w_tunned_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/graph_sample_w_tunned/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_mccd_sample_w.sh b/jz-submissions/jobs-cli/full_mccd_sample_w.sh deleted file mode 100644 index bd60eeed..00000000 --- a/jz-submissions/jobs-cli/full_mccd_sample_w.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=mccd_sample_w # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=mccd_sample_w%j.out # nom du fichier de sortie -#SBATCH --error=mccd_sample_w%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _sample_w_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 300 300" -opt[1]="--id_name _sample_w_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 200 150" -opt[2]="--id_name _sample_w_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 150 100" -opt[3]="--id_name _sample_w_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 15 15 --n_epochs_non_param 100 50" - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/train_eval_plot_script_click.py \ - --model mccd \ - --d_max_nonparam 3 \ - --l_rate_param 0.01 0.004 \ - --l_rate_non_param 0.1 0.06 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 0. \ - --base_id_name _sample_w_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/mccd_sample_w/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_mccd_sample_w_bis1.sh b/jz-submissions/jobs-cli/full_mccd_sample_w_bis1.sh deleted file mode 100644 index 894c7996..00000000 --- a/jz-submissions/jobs-cli/full_mccd_sample_w_bis1.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=mccd_sample_w_bis1_ # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=mccd_sample_w_bis1_%j.out # nom du fichier de sortie -#SBATCH --error=mccd_sample_w_bis1_%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A ynx@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _sample_w_bis1_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 300 300" -opt[1]="--id_name _sample_w_bis1_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 200 150" -opt[2]="--id_name _sample_w_bis1_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 150 100" -opt[3]="--id_name _sample_w_bis1_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 15 15 --n_epochs_non_param 100 50" - -cd $WORK/repo/wf-psf/long-runs/ - -srun python -u ./train_eval_plot_script_click.py \ - --model mccd \ - --d_max_nonparam 3 \ - --graph_features 10 \ - --l_rate_param 0.01 0.004 \ - --l_rate_non_param 0.1 0.06 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 0. \ - --base_id_name _sample_w_bis1_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/mccd_sample_w_bis1/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_mccd_sample_w_bis2.sh b/jz-submissions/jobs-cli/full_mccd_sample_w_bis2.sh deleted file mode 100644 index 5dece54c..00000000 --- a/jz-submissions/jobs-cli/full_mccd_sample_w_bis2.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=mccd_sample_w_bis2_ # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=mccd_sample_w_bis2_%j.out # nom du fichier de sortie -#SBATCH --error=mccd_sample_w_bis2_%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A ynx@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _sample_w_bis2_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 300 300" -opt[1]="--id_name _sample_w_bis2_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 200 150" -opt[2]="--id_name _sample_w_bis2_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 150 100" -opt[3]="--id_name _sample_w_bis2_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 15 15 --n_epochs_non_param 100 50" - -cd $WORK/repo/wf-psf/long-runs/ - -srun python -u ./train_eval_plot_script_click.py \ - --model mccd \ - --d_max_nonparam 3 \ - --graph_features 10 \ - --l_rate_param 0.01 0.004 \ - --l_rate_non_param 0.1 0.06 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 0. \ - --base_id_name _sample_w_bis2_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/mccd_sample_w_bis2/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_mccd_sample_w_l2param_opd.sh b/jz-submissions/jobs-cli/full_mccd_sample_w_l2param_opd.sh deleted file mode 100644 index c49dc1a3..00000000 --- a/jz-submissions/jobs-cli/full_mccd_sample_w_l2param_opd.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=mccd_sample_w_l2param_opd # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=mccd_sample_w_l2param_opd%j.out # nom du fichier de sortie -#SBATCH --error=mccd_sample_w_l2param_opd%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _sample_w_l2param_opd_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 300 300" -opt[1]="--id_name _sample_w_l2param_opd_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 200 150" -opt[2]="--id_name _sample_w_l2param_opd_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 150 100" -opt[3]="--id_name _sample_w_l2param_opd_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 15 15 --n_epochs_non_param 100 50" - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/train_eval_plot_script_click.py \ - --model mccd \ - --d_max_nonparam 3 \ - --l_rate_param 0.01 0.004 \ - --l_rate_non_param 0.1 0.06 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 5e-12 \ - --base_id_name _sample_w_l2param_opd_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/mccd_sample_w_l2param_opd/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_mccd_standard.sh b/jz-submissions/jobs-cli/full_mccd_standard.sh deleted file mode 100644 index 21ffaa8c..00000000 --- a/jz-submissions/jobs-cli/full_mccd_standard.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=mccd_standard # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=mccd_standard%j.out # nom du fichier de sortie -#SBATCH --error=mccd_standard%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _standard_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 300 300" -opt[1]="--id_name _standard_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 200 150" -opt[2]="--id_name _standard_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 150 100" -opt[3]="--id_name _standard_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 15 15 --n_epochs_non_param 100 50" - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/train_eval_plot_script_click.py \ - --model mccd \ - --d_max_nonparam 3 \ - --l_rate_param 0.01 0.004 \ - --l_rate_non_param 0.1 0.06 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights False \ - --l2_param 0. \ - --base_id_name _standard_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/mccd_standard/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_param_complete.sh b/jz-submissions/jobs-cli/full_param_complete.sh deleted file mode 100644 index 5820e0cd..00000000 --- a/jz-submissions/jobs-cli/full_param_complete.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=param_complete # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=param_complete%j.out # nom du fichier de sortie -#SBATCH --error=param_complete%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _complete_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 40 40 --l_rate_param 0.005 0.001" -opt[1]="--id_name _complete_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[2]="--id_name _complete_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[3]="--id_name _complete_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 20 20 --l_rate_param 0.005 0.001" - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/train_eval_plot_script_click.py \ - --model param \ - --n_zernikes 45 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights False \ - --l2_param 0. \ - --base_id_name _complete_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/param_complete/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_param_complete_sample_w.sh b/jz-submissions/jobs-cli/full_param_complete_sample_w.sh deleted file mode 100644 index 31fd0ee3..00000000 --- a/jz-submissions/jobs-cli/full_param_complete_sample_w.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=param_complete_sample_w # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=param_complete_sample_w%j.out # nom du fichier de sortie -#SBATCH --error=param_complete_sample_w%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A ynx@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _complete_sample_w_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 40 40 --l_rate_param 0.005 0.001" -opt[1]="--id_name _complete_sample_w_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[2]="--id_name _complete_sample_w_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[3]="--id_name _complete_sample_w_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 20 20 --l_rate_param 0.005 0.001" - - -cd $WORK/repo/wf-psf/long-runs/ - -srun python -u ./train_eval_plot_script_click.py \ - --model param \ - --n_zernikes 45 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 0. \ - --base_id_name _complete_sample_w_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/param_complete_sample_w/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_param_complete_v2.sh b/jz-submissions/jobs-cli/full_param_complete_v2.sh deleted file mode 100644 index 55f8db58..00000000 --- a/jz-submissions/jobs-cli/full_param_complete_v2.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=param_complete_v2 # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=param_complete_v2_%j.out # nom du fichier de sortie -#SBATCH --error=param_complete_v2_%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A ynx@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _complete_v2_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 40 40 --l_rate_param 0.005 0.001" -opt[1]="--id_name _complete_v2_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[2]="--id_name _complete_v2_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[3]="--id_name _complete_v2_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 20 20 --l_rate_param 0.005 0.001" - - -cd $WORK/repo/wf-psf/long-runs/ - -srun python -u ./train_eval_plot_script_click.py \ - --model param \ - --n_zernikes 45 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights False \ - --l2_param 0. \ - --base_id_name _complete_v2_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/param_complete_v2/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_param_complete_v3.sh b/jz-submissions/jobs-cli/full_param_complete_v3.sh deleted file mode 100644 index 7757fc87..00000000 --- a/jz-submissions/jobs-cli/full_param_complete_v3.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=param_complete_v3 # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=param_complete_v3_%j.out # nom du fichier de sortie -#SBATCH --error=param_complete_v3_%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A ynx@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _complete_v3_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 40 40 --l_rate_param 0.005 0.001" -opt[1]="--id_name _complete_v3_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[2]="--id_name _complete_v3_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[3]="--id_name _complete_v3_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 20 20 --l_rate_param 0.005 0.001" - - -cd $WORK/repo/wf-psf/long-runs/ - -srun python -u ./train_eval_plot_script_click.py \ - --model param \ - --n_zernikes 45 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights False \ - --l2_param 0. \ - --base_id_name _complete_v3_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/param_complete_v3/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_param_complete_v4.sh b/jz-submissions/jobs-cli/full_param_complete_v4.sh deleted file mode 100644 index 674d22ad..00000000 --- a/jz-submissions/jobs-cli/full_param_complete_v4.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=param_complete_v4 # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=param_complete_v4_%j.out # nom du fichier de sortie -#SBATCH --error=param_complete_v4_%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A ynx@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _complete_v4_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 40 40 --l_rate_param 0.005 0.001" -opt[1]="--id_name _complete_v4_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[2]="--id_name _complete_v4_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[3]="--id_name _complete_v4_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 20 20 --l_rate_param 0.005 0.001" - - -cd $WORK/repo/wf-psf/long-runs/ - -srun python -u ./train_eval_plot_script_click.py \ - --model param \ - --n_zernikes 45 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights False \ - --l2_param 0. \ - --base_id_name _complete_v4_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/param_complete_v4/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_param_incomplete.sh b/jz-submissions/jobs-cli/full_param_incomplete.sh deleted file mode 100644 index 9d790466..00000000 --- a/jz-submissions/jobs-cli/full_param_incomplete.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=param_incomplete # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=param_incomplete%j.out # nom du fichier de sortie -#SBATCH --error=param_incomplete%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _incomplete_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 40 40 --l_rate_param 0.005 0.001" -opt[1]="--id_name _incomplete_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[2]="--id_name _incomplete_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[3]="--id_name _incomplete_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 20 20 --l_rate_param 0.005 0.001" - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/train_eval_plot_script_click.py \ - --model param \ - --n_zernikes 15 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights False \ - --l2_param 0. \ - --base_id_name _incomplete_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/param_incomplete/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_param_incomplete_15_sample_w.sh b/jz-submissions/jobs-cli/full_param_incomplete_15_sample_w.sh deleted file mode 100644 index bcb71e73..00000000 --- a/jz-submissions/jobs-cli/full_param_incomplete_15_sample_w.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=param_incomplete_15_sample_w # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=param_incomplete_15_sample_w%j.out # nom du fichier de sortie -#SBATCH --error=param_incomplete_15_sample_w%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A ynx@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _incomplete_15_sample_w_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 40 40 --l_rate_param 0.005 0.001" -opt[1]="--id_name _incomplete_15_sample_w_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[2]="--id_name _incomplete_15_sample_w_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[3]="--id_name _incomplete_15_sample_w_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 20 20 --l_rate_param 0.005 0.001" - - -cd $WORK/repo/wf-psf/long-runs/ - -srun python -u ./train_eval_plot_script_click.py \ - --model param \ - --n_zernikes 15 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 0. \ - --base_id_name _incomplete_15_sample_w_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/param_incomplete_15_sample_w/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_param_incomplete_30.sh b/jz-submissions/jobs-cli/full_param_incomplete_30.sh deleted file mode 100644 index 39b4fdce..00000000 --- a/jz-submissions/jobs-cli/full_param_incomplete_30.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=param_incomplete_30 # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=param_incomplete_30%j.out # nom du fichier de sortie -#SBATCH --error=param_incomplete_30%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _incomplete_30_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 40 40 --l_rate_param 0.005 0.001" -opt[1]="--id_name _incomplete_30_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[2]="--id_name _incomplete_30_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[3]="--id_name _incomplete_30_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 20 20 --l_rate_param 0.005 0.001" - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/train_eval_plot_script_click.py \ - --model param \ - --n_zernikes 30 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights False \ - --l2_param 0. \ - --base_id_name _incomplete_30_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/param_incomplete_30/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_param_incomplete_40.sh b/jz-submissions/jobs-cli/full_param_incomplete_40.sh deleted file mode 100644 index 0514e0c7..00000000 --- a/jz-submissions/jobs-cli/full_param_incomplete_40.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=param_incomplete_40 # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=param_incomplete_40%j.out # nom du fichier de sortie -#SBATCH --error=param_incomplete_40%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A ynx@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _incomplete_40_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 40 40 --l_rate_param 0.005 0.001" -opt[1]="--id_name _incomplete_40_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[2]="--id_name _incomplete_40_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[3]="--id_name _incomplete_40_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 20 20 --l_rate_param 0.005 0.001" - - -cd $WORK/repo/wf-psf/long-runs/ - -srun python -u ./train_eval_plot_script_click.py \ - --model param \ - --n_zernikes 40 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights False \ - --l2_param 0. \ - --base_id_name _incomplete_40_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/param_incomplete_40/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_param_incomplete_40_sample_w.sh b/jz-submissions/jobs-cli/full_param_incomplete_40_sample_w.sh deleted file mode 100644 index f64c15b7..00000000 --- a/jz-submissions/jobs-cli/full_param_incomplete_40_sample_w.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=param_incomplete_40_sample_w # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=param_incomplete_40_sample_w%j.out # nom du fichier de sortie -#SBATCH --error=param_incomplete_40_sample_w%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A ynx@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _incomplete_40_sample_w_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 40 40 --l_rate_param 0.005 0.001" -opt[1]="--id_name _incomplete_40_sample_w_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[2]="--id_name _incomplete_40_sample_w_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[3]="--id_name _incomplete_40_sample_w_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 20 20 --l_rate_param 0.005 0.001" - - -cd $WORK/repo/wf-psf/long-runs/ - -srun python -u ./train_eval_plot_script_click.py \ - --model param \ - --n_zernikes 40 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 0. \ - --base_id_name _incomplete_40_sample_w_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/param_incomplete_40_sample_w/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_param_incomplete_40_sample_w_bis1.sh b/jz-submissions/jobs-cli/full_param_incomplete_40_sample_w_bis1.sh deleted file mode 100644 index 4608299e..00000000 --- a/jz-submissions/jobs-cli/full_param_incomplete_40_sample_w_bis1.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=param_incomplete_40_sample_w_bis1_ # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=param_incomplete_40_sample_w_bis1_%j.out # nom du fichier de sortie -#SBATCH --error=param_incomplete_40_sample_w_bis1_%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A ynx@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _incomplete_40_sample_w_bis1_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 40 40 --l_rate_param 0.005 0.001" -opt[1]="--id_name _incomplete_40_sample_w_bis1_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[2]="--id_name _incomplete_40_sample_w_bis1_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[3]="--id_name _incomplete_40_sample_w_bis1_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 20 20 --l_rate_param 0.005 0.001" - - -cd $WORK/repo/wf-psf/long-runs/ - -srun python -u ./train_eval_plot_script_click.py \ - --model param \ - --n_zernikes 40 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 0. \ - --base_id_name _incomplete_40_sample_w_bis1_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/param_incomplete_40_sample_w_bis1/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_param_incomplete_40_v2.sh b/jz-submissions/jobs-cli/full_param_incomplete_40_v2.sh deleted file mode 100644 index 6bb14047..00000000 --- a/jz-submissions/jobs-cli/full_param_incomplete_40_v2.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=param_incomplete_40_v2_ # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=param_incomplete_40_v2_%j.out # nom du fichier de sortie -#SBATCH --error=param_incomplete_40_v2_%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A ynx@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _incomplete_40_v2_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 40 40 --l_rate_param 0.005 0.001" -opt[1]="--id_name _incomplete_40_v2_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[2]="--id_name _incomplete_40_v2_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[3]="--id_name _incomplete_40_v2_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 20 20 --l_rate_param 0.005 0.001" - - -cd $WORK/repo/wf-psf/long-runs/ - -srun python -u ./train_eval_plot_script_click.py \ - --model param \ - --n_zernikes 40 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights False \ - --l2_param 0. \ - --base_id_name _incomplete_40_v2_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/param_incomplete_40_v2/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_param_incomplete_40_v3.sh b/jz-submissions/jobs-cli/full_param_incomplete_40_v3.sh deleted file mode 100644 index eb9e9236..00000000 --- a/jz-submissions/jobs-cli/full_param_incomplete_40_v3.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=param_incomplete_40_v3_ # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=param_incomplete_40_v3_%j.out # nom du fichier de sortie -#SBATCH --error=param_incomplete_40_v3_%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A ynx@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _incomplete_40_v3_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 40 40 --l_rate_param 0.005 0.001" -opt[1]="--id_name _incomplete_40_v3_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[2]="--id_name _incomplete_40_v3_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[3]="--id_name _incomplete_40_v3_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 20 20 --l_rate_param 0.005 0.001" - - -cd $WORK/repo/wf-psf/long-runs/ - -srun python -u ./train_eval_plot_script_click.py \ - --model param \ - --n_zernikes 40 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights False \ - --l2_param 0. \ - --base_id_name _incomplete_40_v3_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/param_incomplete_40_v3/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_param_overcomplete_55_v1.sh b/jz-submissions/jobs-cli/full_param_overcomplete_55_v1.sh deleted file mode 100644 index 726f8728..00000000 --- a/jz-submissions/jobs-cli/full_param_overcomplete_55_v1.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=param_overcomplete_55_v1 # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=param_overcomplete_55_v1_%j.out # nom du fichier de sortie -#SBATCH --error=param_overcomplete_55_v1_%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A ynx@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _overcomplete_55_v1_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 40 40 --l_rate_param 0.005 0.001" -opt[1]="--id_name _overcomplete_55_v1_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[2]="--id_name _overcomplete_55_v1_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[3]="--id_name _overcomplete_55_v1_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 20 20 --l_rate_param 0.005 0.001" - - -cd $WORK/repo/wf-psf/long-runs/ - -srun python -u ./train_eval_plot_script_click.py \ - --model param \ - --n_zernikes 55 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights False \ - --l2_param 0. \ - --base_id_name _overcomplete_55_v1_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/param_overcomplete_55_v1/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_param_overcomplete_55_v1_sample_w.sh b/jz-submissions/jobs-cli/full_param_overcomplete_55_v1_sample_w.sh deleted file mode 100644 index fcc5de37..00000000 --- a/jz-submissions/jobs-cli/full_param_overcomplete_55_v1_sample_w.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=param_overcomplete_55_v1_sample_w # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=param_overcomplete_55_v1_sample_w_%j.out # nom du fichier de sortie -#SBATCH --error=param_overcomplete_55_v1_sample_w_%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A ynx@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _overcomplete_55_v1_sample_w_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 40 40 --l_rate_param 0.005 0.001" -opt[1]="--id_name _overcomplete_55_v1_sample_w_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[2]="--id_name _overcomplete_55_v1_sample_w_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[3]="--id_name _overcomplete_55_v1_sample_w_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 20 20 --l_rate_param 0.005 0.001" - - -cd $WORK/repo/wf-psf/long-runs/ - -srun python -u ./train_eval_plot_script_click.py \ - --model param \ - --n_zernikes 55 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 0. \ - --base_id_name _overcomplete_55_v1_sample_w_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/param_overcomplete_55_v1_sample_w/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_param_sample_w_l2opd_incomplete.sh b/jz-submissions/jobs-cli/full_param_sample_w_l2opd_incomplete.sh deleted file mode 100644 index 35b2ef2a..00000000 --- a/jz-submissions/jobs-cli/full_param_sample_w_l2opd_incomplete.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=param_incomplete_sample_w_l2opd # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=param_incomplete_sample_w_l2opd%j.out # nom du fichier de sortie -#SBATCH --error=param_incomplete_sample_w_l2opd%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _incomplete_sample_w_l2opd_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 40 40 --l_rate_param 0.005 0.001" -opt[1]="--id_name _incomplete_sample_w_l2opd_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[2]="--id_name _incomplete_sample_w_l2opd_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[3]="--id_name _incomplete_sample_w_l2opd_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 20 20 --l_rate_param 0.005 0.001" - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/train_eval_plot_script_click.py \ - --model param \ - --n_zernikes 15 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 5e-12 \ - --base_id_name _incomplete_sample_w_l2opd_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/param_incomplete_sample_w_l2opd/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_poly_sample_w.sh b/jz-submissions/jobs-cli/full_poly_sample_w.sh deleted file mode 100644 index 2e9e809d..00000000 --- a/jz-submissions/jobs-cli/full_poly_sample_w.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=poly_sample_w # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=poly_sample_w%j.out # nom du fichier de sortie -#SBATCH --error=poly_sample_w%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _sample_w_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 300 300" -opt[1]="--id_name _sample_w_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 200 150" -opt[2]="--id_name _sample_w_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 150 100" -opt[3]="--id_name _sample_w_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 15 15 --n_epochs_non_param 100 50" - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/train_eval_plot_script_click.py \ - --model poly \ - --d_max_nonparam 5 \ - --l_rate_param 0.01 0.004 \ - --l_rate_non_param 0.1 0.06 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 0. \ - --base_id_name _sample_w_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/poly_sample_w/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_poly_sample_w_bis1.sh b/jz-submissions/jobs-cli/full_poly_sample_w_bis1.sh deleted file mode 100644 index 69734721..00000000 --- a/jz-submissions/jobs-cli/full_poly_sample_w_bis1.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=poly_sample_w_bis1_ # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=poly_sample_w_bis1_%j.out # nom du fichier de sortie -#SBATCH --error=poly_sample_w_bis1_%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A ynx@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _sample_w_bis1_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 300 300" -opt[1]="--id_name _sample_w_bis1_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 200 150" -opt[2]="--id_name _sample_w_bis1_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 150 100" -opt[3]="--id_name _sample_w_bis1_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 15 15 --n_epochs_non_param 100 50" - -cd $WORK/repo/wf-psf/long-runs/ - -srun python -u ./train_eval_plot_script_click.py \ - --model poly \ - --d_max_nonparam 5 \ - --l_rate_param 0.01 0.004 \ - --l_rate_non_param 0.1 0.06 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 0. \ - --base_id_name _sample_w_bis1_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/poly_sample_w_bis1/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_poly_sample_w_bis2.sh b/jz-submissions/jobs-cli/full_poly_sample_w_bis2.sh deleted file mode 100644 index a6e02eef..00000000 --- a/jz-submissions/jobs-cli/full_poly_sample_w_bis2.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=poly_sample_w_bis2_ # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=poly_sample_w_bis2_%j.out # nom du fichier de sortie -#SBATCH --error=poly_sample_w_bis2_%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A ynx@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _sample_w_bis2_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 300 300" -opt[1]="--id_name _sample_w_bis2_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 200 150" -opt[2]="--id_name _sample_w_bis2_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 150 100" -opt[3]="--id_name _sample_w_bis2_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 15 15 --n_epochs_non_param 100 50" - -cd $WORK/repo/wf-psf/long-runs/ - -srun python -u ./train_eval_plot_script_click.py \ - --model poly \ - --d_max_nonparam 5 \ - --l_rate_param 0.01 0.004 \ - --l_rate_non_param 0.1 0.06 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 0. \ - --base_id_name _sample_w_bis2_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/poly_sample_w_bis2/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ \ No newline at end of file diff --git a/jz-submissions/jobs-cli/full_poly_sample_w_l2param_opd.sh b/jz-submissions/jobs-cli/full_poly_sample_w_l2param_opd.sh deleted file mode 100644 index dfd78060..00000000 --- a/jz-submissions/jobs-cli/full_poly_sample_w_l2param_opd.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=poly_sample_w_l2param_opd # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=poly_sample_w_l2param_opd%j.out # nom du fichier de sortie -#SBATCH --error=poly_sample_w_l2param_opd%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _sample_w_l2param_opd_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 300 300" -opt[1]="--id_name _sample_w_l2param_opd_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 200 150" -opt[2]="--id_name _sample_w_l2param_opd_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 150 100" -opt[3]="--id_name _sample_w_l2param_opd_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 15 15 --n_epochs_non_param 100 50" - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/train_eval_plot_script_click.py \ - --model poly \ - --d_max_nonparam 5 \ - --l_rate_param 0.01 0.004 \ - --l_rate_non_param 0.1 0.06 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 5e-12 \ - --base_id_name _sample_w_l2param_opd_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/poly_sample_w_l2param_opd/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_poly_sample_w_l2param_opd_comparison.sh b/jz-submissions/jobs-cli/full_poly_sample_w_l2param_opd_comparison.sh deleted file mode 100644 index 8804ad08..00000000 --- a/jz-submissions/jobs-cli/full_poly_sample_w_l2param_opd_comparison.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=poly_sample_w_l2param_opd_comparison # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=poly_sample_w_l2param_opd_comparison%j.out # nom du fichier de sortie -#SBATCH --error=poly_sample_w_l2param_opd_comparison%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _sample_w_l2param_opd_comparison_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 300 300" -opt[1]="--id_name _sample_w_l2param_opd_comparison_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 250 250" -opt[2]="--id_name _sample_w_l2param_opd_comparison_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 150 150" -opt[3]="--id_name _sample_w_l2param_opd_comparison_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 15 15 --n_epochs_non_param 150 100" - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/train_eval_plot_script_click.py \ - --model poly \ - --d_max_nonparam 5 \ - --l_rate_param 0.01 0.001 \ - --l_rate_non_param 0.1 0.01 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 5e-12 \ - --base_id_name _sample_w_l2param_opd_comparison_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/poly_sample_w_l2param_opd_comparison/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_poly_standard.sh b/jz-submissions/jobs-cli/full_poly_standard.sh deleted file mode 100644 index 1e0e08b4..00000000 --- a/jz-submissions/jobs-cli/full_poly_standard.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=poly_standard # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=poly_standard%j.out # nom du fichier de sortie -#SBATCH --error=poly_standard%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _standard_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 300 300" -opt[1]="--id_name _standard_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 300 300" -opt[2]="--id_name _standard_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 200 150" -opt[3]="--id_name _standard_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 15 15 --n_epochs_non_param 150 100" - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/train_eval_plot_script_click.py \ - --model poly \ - --d_max_nonparam 5 \ - --l_rate_param 0.01 0.004 \ - --l_rate_non_param 0.1 0.04 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights False \ - --l2_param 0. \ - --base_id_name _standard_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/poly_standard/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/full_poly_standard_new_epochs.sh b/jz-submissions/jobs-cli/full_poly_standard_new_epochs.sh deleted file mode 100644 index 4186f79d..00000000 --- a/jz-submissions/jobs-cli/full_poly_standard_new_epochs.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=poly_standard_new_epochs # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=poly_standard_new_epochs%j.out # nom du fichier de sortie -#SBATCH --error=poly_standard_new_epochs%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the development queue, max 2h -##SBATCH --qos=qos_gpu-t3 # using the default queue, max 20h -##SBATCH --qos=qos_gpu-t4 # using the queue for long runs, max 100h -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _standard_new_epochs_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 300 300" -opt[1]="--id_name _standard_new_epochs_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 200 150" -opt[2]="--id_name _standard_new_epochs_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 150 100" -opt[3]="--id_name _standard_new_epochs_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 15 15 --n_epochs_non_param 100 50" - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/train_eval_plot_script_click.py \ - --model poly \ - --d_max_nonparam 5 \ - --l_rate_param 0.01 0.004 \ - --l_rate_non_param 0.1 0.06 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights False \ - --l2_param 0. \ - --base_id_name _standard_new_epochs_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/poly_standard_new_epochs/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/graph_lr_tunning.sh b/jz-submissions/jobs-cli/graph_lr_tunning.sh deleted file mode 100644 index 0bd6143b..00000000 --- a/jz-submissions/jobs-cli/graph_lr_tunning.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=graph_lr_tunning # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=graph_lr_tunning_%j.out # nom du fichier de sortie -#SBATCH --error=graph_lr_tunning_%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A ynx@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _lr_tunning_2c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --l_rate_non_param 0.5 0.25" -opt[1]="--id_name _lr_tunning_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --l_rate_non_param 1.0 0.50" -opt[2]="--id_name _lr_tunning_1k --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --l_rate_non_param 5.0 2.5" -opt[3]="--id_name _lr_tunning_2k --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --l_rate_non_param 10. 5.0" - - -cd $WORK/repo/wf-psf/long-runs/ - -srun python -u ./train_eval_plot_script_click.py \ - --model graph \ - --n_zernikes 15 \ - --l_rate_param 0.01 0.004 \ - --n_epochs_param 30 30 \ - --n_epochs_non_param 200 150 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 0. \ - --base_id_name _lr_tunning_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/graph_lr_tunning/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ \ No newline at end of file diff --git a/jz-submissions/jobs-cli/graph_lr_tunning_v2.sh b/jz-submissions/jobs-cli/graph_lr_tunning_v2.sh deleted file mode 100644 index 12bbd257..00000000 --- a/jz-submissions/jobs-cli/graph_lr_tunning_v2.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=graph_lr_tunning_v2_ # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=graph_lr_tunning_v2_%j.out # nom du fichier de sortie -#SBATCH --error=graph_lr_tunning_v2_%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A ynx@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _lr_tunning_v2_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --l_rate_non_param 0.2 0.10" -opt[1]="--id_name _lr_tunning_v2_5c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --l_rate_non_param 0.4 0.20" -opt[2]="--id_name _lr_tunning_v2_1k --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --l_rate_non_param 0.8 0.4" -opt[3]="--id_name _lr_tunning_v2_2k --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --l_rate_non_param 2.0 1.0" - - -cd $WORK/repo/wf-psf/long-runs/ - -srun python -u ./train_eval_plot_script_click.py \ - --model graph \ - --n_zernikes 15 \ - --graph_features 21 \ - --l_rate_param 0.01 0.004 \ - --n_epochs_param 30 30 \ - --n_epochs_non_param 200 150 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 0. \ - --base_id_name _lr_tunning_v2_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/graph_lr_tunning_v2/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/mccd_l2_opd_sample_w.sh b/jz-submissions/jobs-cli/mccd_l2_opd_sample_w.sh deleted file mode 100644 index a72a507c..00000000 --- a/jz-submissions/jobs-cli/mccd_l2_opd_sample_w.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=mccd_l2_sample_w # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=mccd_l2_sample_w%j.out # nom du fichier de sortie -#SBATCH --error=mccd_l2_sample_w%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _l2_opd_sample_w_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 300 300" -opt[1]="--id_name _l2_opd_sample_w_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 250 250" -opt[2]="--id_name _l2_opd_sample_w_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 150 150" -opt[3]="--id_name _l2_opd_sample_w_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 15 15 --n_epochs_non_param 150 100" - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/train_eval_plot_script_click.py \ - --model mccd \ - --d_max_nonparam 5 \ - --l_rate_param 0.01 0.001 \ - --l_rate_non_param 0.1 0.01 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 5e-12 \ - --base_id_name _l2_opd_sample_w_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/mccd_l2_opd_sample_w/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/param_l2_opd_full.sh b/jz-submissions/jobs-cli/param_l2_opd_full.sh deleted file mode 100644 index b2b8e29e..00000000 --- a/jz-submissions/jobs-cli/param_l2_opd_full.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=param_l2_opd_full # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=param_l2_opd_full%j.out # nom du fichier de sortie -#SBATCH --error=param_l2_opd_full%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name param_l2_opd_2c_ --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 40 40 --l_rate_param 0.005 0.001 " -opt[1]="--id_name param_l2_opd_5c_ --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001 " -opt[2]="--id_name param_l2_opd_1k_ --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001 " -opt[3]="--id_name param_l2_opd_2k_ --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 20 20 --l_rate_param 0.005 0.001 " - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/l2_param_tr_ev.py \ - --model param \ - --n_zernikes 45 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --l2_param 5e-12 \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/param_l2_opd_sample_w.sh b/jz-submissions/jobs-cli/param_l2_opd_sample_w.sh deleted file mode 100644 index 194c3e90..00000000 --- a/jz-submissions/jobs-cli/param_l2_opd_sample_w.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=param_l2_sample_w # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=param_l2_sample_w%j.out # nom du fichier de sortie -#SBATCH --error=param_l2_sample_w%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _l2_opd_sample_w_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 40 40 --l_rate_param 0.005 0.001" -opt[1]="--id_name _l2_opd_sample_w_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[2]="--id_name _l2_opd_sample_w_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 30 30 --l_rate_param 0.005 0.001" -opt[3]="--id_name _l2_opd_sample_w_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 20 20 --l_rate_param 0.005 0.001" - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/train_eval_plot_script_click.py \ - --model param \ - --n_zernikes 45 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 5e-12 \ - --base_id_name _l2_opd_sample_w_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/param_l2_opd_sample_w/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/poly_l2_opd_full.sh b/jz-submissions/jobs-cli/poly_l2_opd_full.sh deleted file mode 100644 index 2373b472..00000000 --- a/jz-submissions/jobs-cli/poly_l2_opd_full.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=poly_l2_opd_full # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=poly_l2_opd_full%j.out # nom du fichier de sortie -#SBATCH --error=poly_l2_opd_full%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-2 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name poly_l2_opd_2c_ --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 250 250 --l_rate_param 0.01 0.001 --l_rate_non_param 0.1 0.01" -opt[1]="--id_name poly_l2_opd_5c_ --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 100 120 --l_rate_param 0.01 0.01 --l_rate_non_param 0.1 0.1" -opt[2]="--id_name poly_l2_opd_2k_ --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 150 100 --l_rate_param 0.01 0.001 --l_rate_non_param 0.1 0.01" - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/l2_param_tr_ev.py \ - --model poly \ - --d_max_nonparam 5 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --l2_param 1e-11 \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/poly_l2_opd_sample_w.sh b/jz-submissions/jobs-cli/poly_l2_opd_sample_w.sh deleted file mode 100644 index 4324a6b5..00000000 --- a/jz-submissions/jobs-cli/poly_l2_opd_sample_w.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=poly_l2_sample_w # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=poly_l2_sample_w%j.out # nom du fichier de sortie -#SBATCH --error=poly_l2_sample_w%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _l2_opd_sample_w_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 300 300" -opt[1]="--id_name _l2_opd_sample_w_5c --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 250 250" -opt[2]="--id_name _l2_opd_sample_w_1k --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 150 150" -opt[3]="--id_name _l2_opd_sample_w_2k --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 15 15 --n_epochs_non_param 150 100" - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/train_eval_plot_script_click.py \ - --model poly \ - --d_max_nonparam 5 \ - --l_rate_param 0.01 0.001 \ - --l_rate_non_param 0.1 0.01 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 5e-12 \ - --base_id_name _l2_opd_sample_w_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/poly_l2_opd_sample_w/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/poly_lr_coherent_epochs.sh b/jz-submissions/jobs-cli/poly_lr_coherent_epochs.sh deleted file mode 100644 index c0d71f38..00000000 --- a/jz-submissions/jobs-cli/poly_lr_coherent_epochs.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=poly_lr_coherent_epochs # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=poly_lr_coherent_epochs%j.out # nom du fichier de sortie -#SBATCH --error=poly_lr_coherent_epochs%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - - -opt[0]="--id_name _2c_chkp_poly_lr_coherent_epochs --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 40 40 --n_epochs_non_param 500 500" -opt[1]="--id_name _5c_chkp_poly_lr_coherent_epochs --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 300 300" -opt[2]="--id_name _1k_chkp_poly_lr_coherent_epochs --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 150 150" -opt[3]="--id_name _2k_chkp_poly_lr_coherent_epochs --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 150 100" - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/alternative_train_eval_script.py \ - --model poly \ - --l_rate_param 0.01 0.001 \ - --l_rate_non_param 0.1 0.01 \ - --d_max_nonparam 5 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/poly_new_lr.sh b/jz-submissions/jobs-cli/poly_new_lr.sh deleted file mode 100644 index e46931f3..00000000 --- a/jz-submissions/jobs-cli/poly_new_lr.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=poly_new_lr # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=poly_new_lr%j.out # nom du fichier de sortie -#SBATCH --error=poly_new_lr%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _1k_chkp_poly_new_lr --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy" -opt[1]="--id_name _2c_chkp_poly_new_lr --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy" -opt[2]="--id_name _5c_chkp_poly_new_lr --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy" -opt[3]="--id_name _2k_chkp_poly_new_lr --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy" - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/alternative_train_eval_script.py \ - --model poly \ - --n_epochs_param 20 20 \ - --n_epochs_non_param 100 150 \ - --l_rate_param 0.01 0.001 \ - --l_rate_non_param 0.1 0.02 \ - --d_max_nonparam 5 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/poly_sample_weights.sh b/jz-submissions/jobs-cli/poly_sample_weights.sh deleted file mode 100644 index a262c762..00000000 --- a/jz-submissions/jobs-cli/poly_sample_weights.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=sample_weights_1k # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=sample_weights_1k%j.out # nom du fichier de sortie -#SBATCH --error=sample_weights_1k%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/alternative_train_eval_script.py \ - --model poly \ - --id_name _sample_weights_1k_ \ - --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy \ - --n_epochs_param 20 20 \ - --n_epochs_non_param 150 150 \ - --l_rate_param 0.01 0.001 \ - --l_rate_non_param 0.1 0.01 \ - --d_max_nonparam 5 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ diff --git a/jz-submissions/jobs-cli/poly_sample_weights_full.sh b/jz-submissions/jobs-cli/poly_sample_weights_full.sh deleted file mode 100644 index 5ca0120d..00000000 --- a/jz-submissions/jobs-cli/poly_sample_weights_full.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=sample_weights_full # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=sample_weights_full%j.out # nom du fichier de sortie -#SBATCH --error=sample_weights_full%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-2 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _sample_weights_2c_ --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 250 250 --l_rate_param 0.01 0.001 --l_rate_non_param 0.1 0.01" -opt[1]="--id_name _sample_weights_5c_ --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 100 120 --l_rate_param 0.01 0.01 --l_rate_non_param 0.1 0.1" -opt[2]="--id_name _sample_weights_2k_ --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 150 100 --l_rate_param 0.01 0.001 --l_rate_non_param 0.1 0.01" - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/alternative_train_eval_script.py \ - --model poly \ - --d_max_nonparam 5 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/poly_sample_weights_full_strategy1.sh b/jz-submissions/jobs-cli/poly_sample_weights_full_strategy1.sh deleted file mode 100644 index 13aedf54..00000000 --- a/jz-submissions/jobs-cli/poly_sample_weights_full_strategy1.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=sample_weights_full_strategy1 # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=sample_weights_full_strategy1%j.out # nom du fichier de sortie -#SBATCH --error=sample_weights_full_strategy1%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _sample_weights_strategy1_2c_ --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 300 300 --l_rate_param 0.01 0.001 --l_rate_non_param 0.1 0.01" -opt[1]="--id_name _sample_weights_strategy1_5c_ --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 250 250 --l_rate_param 0.01 0.001 --l_rate_non_param 0.1 0.01" -opt[2]="--id_name _sample_weights_strategy1_1k_ --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 150 150 --l_rate_param 0.01 0.001 --l_rate_non_param 0.1 0.01" -opt[3]="--id_name _sample_weights_strategy1_2k_ --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 15 15 --n_epochs_non_param 150 100 --l_rate_param 0.01 0.001 --l_rate_non_param 0.1 0.01" - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/alternative_train_eval_script.py \ - --model poly \ - --d_max_nonparam 5 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/poly_v2_original_lr_as_sample_w_strat1.sh b/jz-submissions/jobs-cli/poly_v2_original_lr_as_sample_w_strat1.sh deleted file mode 100644 index 7eb9de30..00000000 --- a/jz-submissions/jobs-cli/poly_v2_original_lr_as_sample_w_strat1.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=poly_v2_original_lr_as_sample_w_strat1 # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=poly_v2_original_lr_as_sample_w_strat1%j.out # nom du fichier de sortie -#SBATCH --error=poly_v2_original_lr_as_sample_w_strat1%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _poly_v2_original_lr_as_sample_w_strat1_2c_ --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy --n_epochs_param 30 30 --n_epochs_non_param 300 300 --l_rate_param 0.01 0.001 --l_rate_non_param 0.1 0.01" -opt[1]="--id_name _poly_v2_original_lr_as_sample_w_strat1_5c_ --train_dataset_file train_Euclid_res_500_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 250 250 --l_rate_param 0.01 0.001 --l_rate_non_param 0.1 0.01" -opt[2]="--id_name _poly_v2_original_lr_as_sample_w_strat1_1k_ --train_dataset_file train_Euclid_res_1000_TrainStars_id_001.npy --n_epochs_param 20 20 --n_epochs_non_param 150 150 --l_rate_param 0.01 0.001 --l_rate_non_param 0.1 0.01" -opt[3]="--id_name _poly_v2_original_lr_as_sample_w_strat1_2k_ --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy --n_epochs_param 15 15 --n_epochs_non_param 150 100 --l_rate_param 0.01 0.001 --l_rate_non_param 0.1 0.01" - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/alternative_train_eval_script.py \ - --model poly \ - --d_max_nonparam 5 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights False \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-cli/slurm-logs/slurm_output_logs.md b/jz-submissions/jobs-cli/slurm-logs/slurm_output_logs.md deleted file mode 100644 index c033fecc..00000000 --- a/jz-submissions/jobs-cli/slurm-logs/slurm_output_logs.md +++ /dev/null @@ -1,2 +0,0 @@ -slurm output logs - \ No newline at end of file diff --git a/jz-submissions/jobs-cli/test_sample_weights.sh b/jz-submissions/jobs-cli/test_sample_weights.sh deleted file mode 100644 index 0735b3aa..00000000 --- a/jz-submissions/jobs-cli/test_sample_weights.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=test_sample_weights # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=00:20:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=test_sample_weights%j.out # nom du fichier de sortie -#SBATCH --error=test_sample_weights%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -#SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/alternative_train_eval_script.py \ - --model poly \ - --id_name _test_sample_weights \ - --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy \ - --n_epochs_param 20 20 \ - --n_epochs_non_param 150 200 \ - --l_rate_param 0.01 0.001 \ - --l_rate_non_param 0.1 0.01 \ - --d_max_nonparam 5 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ diff --git a/jz-submissions/jobs-cli/testing_train_eval_plot.sh b/jz-submissions/jobs-cli/testing_train_eval_plot.sh deleted file mode 100644 index fadc2298..00000000 --- a/jz-submissions/jobs-cli/testing_train_eval_plot.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=testing_auto # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=02:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=testing_auto%j.out # nom du fichier de sortie -#SBATCH --error=testing_auto%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -#SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -opt[0]="--id_name _testing_auto_2c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy" -opt[1]="--id_name _testing_auto_5c --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy" -opt[2]="--id_name _testing_auto_1k --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy" -opt[3]="--id_name _testing_auto_2k --train_dataset_file train_Euclid_res_200_TrainStars_id_001.npy" - - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/train_eval_plot_script_click.py \ - --model param \ - --d_max_nonparam 5 \ - --n_epochs_param 2 2 \ - --n_epochs_non_param 2 2 \ - --l_rate_param 0.01 0.001 \ - --l_rate_non_param 0.1 0.01 \ - --saved_model_type checkpoint \ - --saved_cycle cycle2 \ - --total_cycles 2 \ - --use_sample_weights True \ - --l2_param 0.0 \ - --base_id_name _testing_auto_ \ - --suffix_id_name 2c --suffix_id_name 5c --suffix_id_name 1k --suffix_id_name 2k \ - --star_numbers 200 --star_numbers 500 --star_numbers 1000 --star_numbers 2000 \ - --plots_folder plots/testing_plot_folder/ \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ diff --git a/jz-submissions/jobs-test/generic_cli_train_eval.sh b/jz-submissions/jobs-test/generic_cli_train_eval.sh deleted file mode 100644 index e024a37f..00000000 --- a/jz-submissions/jobs-test/generic_cli_train_eval.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=2k_poly_tr_ev_click # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=2k_poly_tr_ev_click%j.out # nom du fichier de sortie -#SBATCH --error=2k_poly_tr_ev_click%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/alternative_train_eval_script.py \ - --model poly \ - --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy \ - --n_epochs_param 2 2 \ - --n_epochs_non_param 2 2 \ - --id_name _test-coherent_euclid_2000stars \ - --d_max_nonparam 5 \ diff --git a/jz-submissions/jobs-test/generic_cli_train_eval_v2.sh b/jz-submissions/jobs-test/generic_cli_train_eval_v2.sh deleted file mode 100644 index 8b90c10e..00000000 --- a/jz-submissions/jobs-test/generic_cli_train_eval_v2.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=2k_poly_tr_ev_click # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -##SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=00:05:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=2k_poly_tr_ev_click%j.out # nom du fichier de sortie -#SBATCH --error=2k_poly_tr_ev_click%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -#SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python -u ./../../long-runs/alternative_train_eval_script.py \ - --model poly \ - --train_dataset_file train_Euclid_res_2000_TrainStars_id_001.npy \ - --n_epochs_param 2 2 \ - --n_epochs_non_param 2 2 \ - --id_name _test-coherent_euclid_2000stars \ - --d_max_nonparam 5 \ diff --git a/jz-submissions/jobs/evaluation_mccd_1000.sh b/jz-submissions/jobs/evaluation_mccd_1000.sh deleted file mode 100644 index cb3e9080..00000000 --- a/jz-submissions/jobs/evaluation_mccd_1000.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=1k_mccd_eval # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=1k_mccd_eval%j.out # nom du fichier de sortie -#SBATCH --error=1k_mccd_eval%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/evaluation_mccd_1000.py diff --git a/jz-submissions/jobs/evaluation_mccd_200.sh b/jz-submissions/jobs/evaluation_mccd_200.sh deleted file mode 100644 index dd4671d6..00000000 --- a/jz-submissions/jobs/evaluation_mccd_200.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=2c_mccd_eval # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=2c_mccd_eval%j.out # nom du fichier de sortie -#SBATCH --error=2c_mccd_eval%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/evaluation_mccd_200.py diff --git a/jz-submissions/jobs/evaluation_mccd_2000.sh b/jz-submissions/jobs/evaluation_mccd_2000.sh deleted file mode 100644 index 7e860c55..00000000 --- a/jz-submissions/jobs/evaluation_mccd_2000.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=2k_mccd_eval # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=2k_mccd_eval%j.out # nom du fichier de sortie -#SBATCH --error=2k_mccd_eval%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/evaluation_mccd_2000.py diff --git a/jz-submissions/jobs/evaluation_mccd_500.sh b/jz-submissions/jobs/evaluation_mccd_500.sh deleted file mode 100644 index baac1033..00000000 --- a/jz-submissions/jobs/evaluation_mccd_500.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=5c_mccd_eval # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=5c_mccd_eval%j.out # nom du fichier de sortie -#SBATCH --error=5c_mccd_eval%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/evaluation_mccd_500.py diff --git a/jz-submissions/jobs/evaluation_param_1000.sh b/jz-submissions/jobs/evaluation_param_1000.sh deleted file mode 100644 index 6db65b17..00000000 --- a/jz-submissions/jobs/evaluation_param_1000.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=1k_param_eval # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=1k_param_eval%j.out # nom du fichier de sortie -#SBATCH --error=1k_param_eval%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/evaluation_param_1000.py diff --git a/jz-submissions/jobs/evaluation_param_200.sh b/jz-submissions/jobs/evaluation_param_200.sh deleted file mode 100644 index 3bcffaa5..00000000 --- a/jz-submissions/jobs/evaluation_param_200.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=2c_param_eval # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=2c_param_eval%j.out # nom du fichier de sortie -#SBATCH --error=2c_param_eval%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/evaluation_param_200.py diff --git a/jz-submissions/jobs/evaluation_param_2000.sh b/jz-submissions/jobs/evaluation_param_2000.sh deleted file mode 100644 index 6610d308..00000000 --- a/jz-submissions/jobs/evaluation_param_2000.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=2k_param_eval # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=2k_param_eval%j.out # nom du fichier de sortie -#SBATCH --error=2k_param_eval%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/evaluation_param_2000.py diff --git a/jz-submissions/jobs/evaluation_param_500.sh b/jz-submissions/jobs/evaluation_param_500.sh deleted file mode 100644 index d20be58a..00000000 --- a/jz-submissions/jobs/evaluation_param_500.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=5c_param_eval # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=5c_param_eval%j.out # nom du fichier de sortie -#SBATCH --error=5c_param_eval%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/evaluation_param_500.py diff --git a/jz-submissions/jobs/evaluation_poly_1000.sh b/jz-submissions/jobs/evaluation_poly_1000.sh deleted file mode 100644 index c95ece3a..00000000 --- a/jz-submissions/jobs/evaluation_poly_1000.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=1k_poly_v2_eval # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=1k_poly_v2_eval%j.out # nom du fichier de sortie -#SBATCH --error=1k_poly_v2_eval%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/evaluation_poly_1000.py diff --git a/jz-submissions/jobs/evaluation_poly_200.sh b/jz-submissions/jobs/evaluation_poly_200.sh deleted file mode 100644 index dc00c666..00000000 --- a/jz-submissions/jobs/evaluation_poly_200.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=2c_poly_v2_eval # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=2c_poly_v2_eval%j.out # nom du fichier de sortie -#SBATCH --error=2c_poly_v2_eval%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/evaluation_poly_200.py diff --git a/jz-submissions/jobs/evaluation_poly_2000.sh b/jz-submissions/jobs/evaluation_poly_2000.sh deleted file mode 100644 index 59652338..00000000 --- a/jz-submissions/jobs/evaluation_poly_2000.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=2k_poly_v2_eval # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=2k_poly_v2_eval%j.out # nom du fichier de sortie -#SBATCH --error=2k_poly_v2_eval%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/evaluation_poly_2000.py diff --git a/jz-submissions/jobs/evaluation_poly_500.sh b/jz-submissions/jobs/evaluation_poly_500.sh deleted file mode 100644 index c65e14a2..00000000 --- a/jz-submissions/jobs/evaluation_poly_500.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=5c_poly_v2_eval # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=5c_poly_v2_eval%j.out # nom du fichier de sortie -#SBATCH --error=5c_poly_v2_eval%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/evaluation_poly_500.py diff --git a/jz-submissions/jobs/train_eval_poly_200.sh b/jz-submissions/jobs/train_eval_poly_200.sh deleted file mode 100644 index c54895f9..00000000 --- a/jz-submissions/jobs/train_eval_poly_200.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=2c_poly_train_eval # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -##SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=2c_poly_train_eval%j.out # nom du fichier de sortie -#SBATCH --error=2c_poly_train_eval%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/train_eval_poly_200.py diff --git a/jz-submissions/jobs/train_eval_poly_200_click.sh b/jz-submissions/jobs/train_eval_poly_200_click.sh deleted file mode 100644 index a887318b..00000000 --- a/jz-submissions/jobs/train_eval_poly_200_click.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=2c_poly_tr_ev_click # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=2c_poly_tr_ev_click%j.out # nom du fichier de sortie -#SBATCH --error=2c_poly_tr_ev_click%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/train_eval_poly_200_click.py --n_epochs_param 2 2 --n_epochs_non_param 2 2 --id_name _test-coherent_euclid_200stars diff --git a/jz-submissions/jobs/training_mccd_1000.sh b/jz-submissions/jobs/training_mccd_1000.sh deleted file mode 100644 index 4abbc049..00000000 --- a/jz-submissions/jobs/training_mccd_1000.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=1k_mccd_train # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=1k_mccd_train%j.out # nom du fichier de sortie -#SBATCH --error=1k_mccd_train%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/training_mccd_1000.py diff --git a/jz-submissions/jobs/training_mccd_200.sh b/jz-submissions/jobs/training_mccd_200.sh deleted file mode 100644 index f3433172..00000000 --- a/jz-submissions/jobs/training_mccd_200.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=2c_mccd_train # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=2c_mccd_train%j.out # nom du fichier de sortie -#SBATCH --error=2c_mccd_train%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/training_mccd_200.py diff --git a/jz-submissions/jobs/training_mccd_2000.sh b/jz-submissions/jobs/training_mccd_2000.sh deleted file mode 100644 index a48c209a..00000000 --- a/jz-submissions/jobs/training_mccd_2000.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=2k_mccd_train # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=2k_mccd_train%j.out # nom du fichier de sortie -#SBATCH --error=2k_mccd_train%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/training_mccd_2000.py diff --git a/jz-submissions/jobs/training_mccd_500.sh b/jz-submissions/jobs/training_mccd_500.sh deleted file mode 100644 index ddbb7cc7..00000000 --- a/jz-submissions/jobs/training_mccd_500.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=5c_mccd_train # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=5c_mccd_train%j.out # nom du fichier de sortie -#SBATCH --error=5c_mccd_train%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/training_mccd_500.py diff --git a/jz-submissions/jobs/training_param_1000.sh b/jz-submissions/jobs/training_param_1000.sh deleted file mode 100644 index f4435bf0..00000000 --- a/jz-submissions/jobs/training_param_1000.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=1k_param_train # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=1k_param_train%j.out # nom du fichier de sortie -#SBATCH --error=1k_param_train%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/training_param_1000.py diff --git a/jz-submissions/jobs/training_param_200.sh b/jz-submissions/jobs/training_param_200.sh deleted file mode 100644 index cb4d71eb..00000000 --- a/jz-submissions/jobs/training_param_200.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=2c_param_train # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=2c_param_train%j.out # nom du fichier de sortie -#SBATCH --error=2c_param_train%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/training_param_200.py diff --git a/jz-submissions/jobs/training_param_2000.sh b/jz-submissions/jobs/training_param_2000.sh deleted file mode 100644 index e0ed3bf1..00000000 --- a/jz-submissions/jobs/training_param_2000.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=2k_param_train # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=2k_param_train%j.out # nom du fichier de sortie -#SBATCH --error=2k_param_train%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/training_param_2000.py diff --git a/jz-submissions/jobs/training_param_500.sh b/jz-submissions/jobs/training_param_500.sh deleted file mode 100644 index 132f3360..00000000 --- a/jz-submissions/jobs/training_param_500.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=5c_param_train # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=5c_param_train%j.out # nom du fichier de sortie -#SBATCH --error=5c_param_train%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/training_param_500.py diff --git a/jz-submissions/jobs/training_poly_1000.sh b/jz-submissions/jobs/training_poly_1000.sh deleted file mode 100644 index 1c65d04d..00000000 --- a/jz-submissions/jobs/training_poly_1000.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=1k_poly_v2_train # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=1k_poly_v2_train%j.out # nom du fichier de sortie -#SBATCH --error=1k_poly_v2_train%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/training_poly_1000.py diff --git a/jz-submissions/jobs/training_poly_200.sh b/jz-submissions/jobs/training_poly_200.sh deleted file mode 100644 index a4433cdd..00000000 --- a/jz-submissions/jobs/training_poly_200.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=2c_poly_v2_train # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-16g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=2c_poly_v2_train%j.out # nom du fichier de sortie -#SBATCH --error=2c_poly_v2_train%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/training_poly_200.py diff --git a/jz-submissions/jobs/training_poly_2000.sh b/jz-submissions/jobs/training_poly_2000.sh deleted file mode 100644 index 65483075..00000000 --- a/jz-submissions/jobs/training_poly_2000.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=2k_poly_v2_train # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=2k_poly_v2_train%j.out # nom du fichier de sortie -#SBATCH --error=2k_poly_v2_train%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/training_poly_2000.py diff --git a/jz-submissions/jobs/training_poly_500.sh b/jz-submissions/jobs/training_poly_500.sh deleted file mode 100644 index 4b339687..00000000 --- a/jz-submissions/jobs/training_poly_500.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=5c_poly_v2_train # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=5c_poly_v2_train%j.out # nom du fichier de sortie -#SBATCH --error=5c_poly_v2_train%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A xdy@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.4.1 - -# echo des commandes lancees -set -x - -cd $WORK/repo/wf-psf/jz-submissions/slurm-logs/ - -srun python ./../scripts/training_poly_500.py diff --git a/jz-submissions/scripts/evaluation_mccd_1000.py b/jz-submissions/scripts/evaluation_mccd_1000.py deleted file mode 100644 index 98fca698..00000000 --- a/jz-submissions/scripts/evaluation_mccd_1000.py +++ /dev/null @@ -1,374 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -## PSF modelling evaluation - -import sys -import numpy as np -import time -import matplotlib.pyplot as plt -import wf_psf as wf -import tensorflow as tf - - -## Start measuring elapsed time -starting_time = time.time() - - -## Define saving paths -model = 'mccd' -# model = 'poly' -# model = 'param' - -id_name = '-coherent_euclid_1000stars' -run_id_name = model + id_name - -# folder paths -log_save_file = '/gpfswork/rech/xdy/ulx23va/wf-outputs/log-files/' -model_folder = '/gpfswork/rech/xdy/ulx23va/wf-outputs/chkp/' - -weights_paths = model_folder + 'chkp_' + run_id_name + '_cycle2' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_1000_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Saving path -saving_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/metrics/' - - -## Model parameters -# Decimation factor for Zernike polynomials -n_zernikes = 15 -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 3 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - - -## Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '-metrics_output.log', 'w') -sys.stdout = log_file -print('Starting the log file.') - - -## Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - - -## Load datasets -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Prepare models -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Outputs (needed for the MCCD model) -outputs = tf_noisy_train_stars - - -## Create the model -## Select the model -if model == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=x_lims, - y_lims=y_lims, - d_max=d_max_nonparam, - graph_features=graph_features) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - graph_features=graph_features, - l1_rate=l1_rate, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - -## Load the model's weights -tf_semiparam_field.load_weights(weights_paths) - - -## Prepare ground truth model -n_zernikes_bis = 45 -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes_bis, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Initialize the model -GT_tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field( - zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes_bis, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -# For the Ground truth model -GT_tf_semiparam_field.tf_poly_Z_field.assign_coeff_matrix(train_C_poly) -_ = GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat.assign( - np.zeros_like(GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat)) - - -## Metric evaluation on the test dataset -print('\n***\nMetric evaluation on the test dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - tf_SEDs=test_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - lambda_list=lambda_list) - -mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_test_pos, - batch_size=batch_size) - -opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=test_SEDs, - tf_pos=tf_test_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics -test_metrics = {'poly_metric': poly_metric, - 'mono_metric': mono_metric, - 'opd_metric': opd_metric, - 'shape_results_dict': shape_results_dict - } - - -## Metric evaluation on the train dataset -print('\n***\nMetric evaluation on the train dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - tf_SEDs=train_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -train_poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - lambda_list=lambda_list) - -train_mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_train_pos, - batch_size=batch_size) - -train_opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -train_shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=train_SEDs, - tf_pos=tf_train_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics into dictionary -train_metrics = {'poly_metric': train_poly_metric, - 'mono_metric': train_mono_metric, - 'opd_metric': train_opd_metric, - 'shape_results_dict': train_shape_results_dict - } - - -## Save results -metrics = {'test_metrics': test_metrics, - 'train_metrics': train_metrics - } -output_path = saving_path + 'metrics-' + run_id_name -np.save(output_path, metrics, allow_pickle=True) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() - diff --git a/jz-submissions/scripts/evaluation_mccd_200.py b/jz-submissions/scripts/evaluation_mccd_200.py deleted file mode 100644 index 63ca4fa8..00000000 --- a/jz-submissions/scripts/evaluation_mccd_200.py +++ /dev/null @@ -1,374 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -## PSF modelling evaluation - -import sys -import numpy as np -import time -import matplotlib.pyplot as plt -import wf_psf as wf -import tensorflow as tf - - -## Start measuring elapsed time -starting_time = time.time() - - -## Define saving paths -model = 'mccd' -# model = 'poly' -# model = 'param' - -id_name = '-coherent_euclid_200stars' -run_id_name = model + id_name - -# folder paths -log_save_file = '/gpfswork/rech/xdy/ulx23va/wf-outputs/log-files/' -model_folder = '/gpfswork/rech/xdy/ulx23va/wf-outputs/chkp/' - -weights_paths = model_folder + 'chkp_' + run_id_name + '_cycle2' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_200_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Saving path -saving_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/metrics/' - - -## Model parameters -# Decimation factor for Zernike polynomials -n_zernikes = 15 -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 3 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - - -## Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '-metrics_output.log', 'w') -sys.stdout = log_file -print('Starting the log file.') - - -## Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - - -## Load datasets -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Prepare models -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Outputs (needed for the MCCD model) -outputs = tf_noisy_train_stars - - -## Create the model -## Select the model -if model == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=x_lims, - y_lims=y_lims, - d_max=d_max_nonparam, - graph_features=graph_features) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - graph_features=graph_features, - l1_rate=l1_rate, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - -## Load the model's weights -tf_semiparam_field.load_weights(weights_paths) - - -## Prepare ground truth model -n_zernikes_bis = 45 -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes_bis, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Initialize the model -GT_tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field( - zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes_bis, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -# For the Ground truth model -GT_tf_semiparam_field.tf_poly_Z_field.assign_coeff_matrix(train_C_poly) -_ = GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat.assign( - np.zeros_like(GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat)) - - -## Metric evaluation on the test dataset -print('\n***\nMetric evaluation on the test dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - tf_SEDs=test_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - lambda_list=lambda_list) - -mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_test_pos, - batch_size=batch_size) - -opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=test_SEDs, - tf_pos=tf_test_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics -test_metrics = {'poly_metric': poly_metric, - 'mono_metric': mono_metric, - 'opd_metric': opd_metric, - 'shape_results_dict': shape_results_dict - } - - -## Metric evaluation on the train dataset -print('\n***\nMetric evaluation on the train dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - tf_SEDs=train_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -train_poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - lambda_list=lambda_list) - -train_mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_train_pos, - batch_size=batch_size) - -train_opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -train_shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=train_SEDs, - tf_pos=tf_train_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics into dictionary -train_metrics = {'poly_metric': train_poly_metric, - 'mono_metric': train_mono_metric, - 'opd_metric': train_opd_metric, - 'shape_results_dict': train_shape_results_dict - } - - -## Save results -metrics = {'test_metrics': test_metrics, - 'train_metrics': train_metrics - } -output_path = saving_path + 'metrics-' + run_id_name -np.save(output_path, metrics, allow_pickle=True) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() - diff --git a/jz-submissions/scripts/evaluation_mccd_2000.py b/jz-submissions/scripts/evaluation_mccd_2000.py deleted file mode 100644 index 152603c4..00000000 --- a/jz-submissions/scripts/evaluation_mccd_2000.py +++ /dev/null @@ -1,374 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -## PSF modelling evaluation - -import sys -import numpy as np -import time -import matplotlib.pyplot as plt -import wf_psf as wf -import tensorflow as tf - - -## Start measuring elapsed time -starting_time = time.time() - - -## Define saving paths -model = 'mccd' -# model = 'poly' -# model = 'param' - -id_name = '-coherent_euclid_2000stars' -run_id_name = model + id_name - -# folder paths -log_save_file = '/gpfswork/rech/xdy/ulx23va/wf-outputs/log-files/' -model_folder = '/gpfswork/rech/xdy/ulx23va/wf-outputs/chkp/' - -weights_paths = model_folder + 'chkp_' + run_id_name + '_cycle2' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_2000_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Saving path -saving_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/metrics/' - - -## Model parameters -# Decimation factor for Zernike polynomials -n_zernikes = 15 -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 3 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - - -## Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '-metrics_output.log', 'w') -sys.stdout = log_file -print('Starting the log file.') - - -## Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - - -## Load datasets -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Prepare models -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Outputs (needed for the MCCD model) -outputs = tf_noisy_train_stars - - -## Create the model -## Select the model -if model == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=x_lims, - y_lims=y_lims, - d_max=d_max_nonparam, - graph_features=graph_features) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - graph_features=graph_features, - l1_rate=l1_rate, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - -## Load the model's weights -tf_semiparam_field.load_weights(weights_paths) - - -## Prepare ground truth model -n_zernikes_bis = 45 -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes_bis, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Initialize the model -GT_tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field( - zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes_bis, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -# For the Ground truth model -GT_tf_semiparam_field.tf_poly_Z_field.assign_coeff_matrix(train_C_poly) -_ = GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat.assign( - np.zeros_like(GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat)) - - -## Metric evaluation on the test dataset -print('\n***\nMetric evaluation on the test dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - tf_SEDs=test_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - lambda_list=lambda_list) - -mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_test_pos, - batch_size=batch_size) - -opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=test_SEDs, - tf_pos=tf_test_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics -test_metrics = {'poly_metric': poly_metric, - 'mono_metric': mono_metric, - 'opd_metric': opd_metric, - 'shape_results_dict': shape_results_dict - } - - -## Metric evaluation on the train dataset -print('\n***\nMetric evaluation on the train dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - tf_SEDs=train_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -train_poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - lambda_list=lambda_list) - -train_mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_train_pos, - batch_size=batch_size) - -train_opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -train_shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=train_SEDs, - tf_pos=tf_train_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics into dictionary -train_metrics = {'poly_metric': train_poly_metric, - 'mono_metric': train_mono_metric, - 'opd_metric': train_opd_metric, - 'shape_results_dict': train_shape_results_dict - } - - -## Save results -metrics = {'test_metrics': test_metrics, - 'train_metrics': train_metrics - } -output_path = saving_path + 'metrics-' + run_id_name -np.save(output_path, metrics, allow_pickle=True) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() - diff --git a/jz-submissions/scripts/evaluation_mccd_500.py b/jz-submissions/scripts/evaluation_mccd_500.py deleted file mode 100644 index d8f41b21..00000000 --- a/jz-submissions/scripts/evaluation_mccd_500.py +++ /dev/null @@ -1,374 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -## PSF modelling evaluation - -import sys -import numpy as np -import time -import matplotlib.pyplot as plt -import wf_psf as wf -import tensorflow as tf - - -## Start measuring elapsed time -starting_time = time.time() - - -## Define saving paths -model = 'mccd' -# model = 'poly' -# model = 'param' - -id_name = '-coherent_euclid_500stars' -run_id_name = model + id_name - -# folder paths -log_save_file = '/gpfswork/rech/xdy/ulx23va/wf-outputs/log-files/' -model_folder = '/gpfswork/rech/xdy/ulx23va/wf-outputs/chkp/' - -weights_paths = model_folder + 'chkp_' + run_id_name + '_cycle2' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_500_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Saving path -saving_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/metrics/' - - -## Model parameters -# Decimation factor for Zernike polynomials -n_zernikes = 15 -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 3 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - - -## Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '-metrics_output.log', 'w') -sys.stdout = log_file -print('Starting the log file.') - - -## Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - - -## Load datasets -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Prepare models -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Outputs (needed for the MCCD model) -outputs = tf_noisy_train_stars - - -## Create the model -## Select the model -if model == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=x_lims, - y_lims=y_lims, - d_max=d_max_nonparam, - graph_features=graph_features) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - graph_features=graph_features, - l1_rate=l1_rate, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - -## Load the model's weights -tf_semiparam_field.load_weights(weights_paths) - - -## Prepare ground truth model -n_zernikes_bis = 45 -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes_bis, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Initialize the model -GT_tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field( - zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes_bis, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -# For the Ground truth model -GT_tf_semiparam_field.tf_poly_Z_field.assign_coeff_matrix(train_C_poly) -_ = GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat.assign( - np.zeros_like(GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat)) - - -## Metric evaluation on the test dataset -print('\n***\nMetric evaluation on the test dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - tf_SEDs=test_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - lambda_list=lambda_list) - -mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_test_pos, - batch_size=batch_size) - -opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=test_SEDs, - tf_pos=tf_test_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics -test_metrics = {'poly_metric': poly_metric, - 'mono_metric': mono_metric, - 'opd_metric': opd_metric, - 'shape_results_dict': shape_results_dict - } - - -## Metric evaluation on the train dataset -print('\n***\nMetric evaluation on the train dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - tf_SEDs=train_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -train_poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - lambda_list=lambda_list) - -train_mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_train_pos, - batch_size=batch_size) - -train_opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -train_shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=train_SEDs, - tf_pos=tf_train_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics into dictionary -train_metrics = {'poly_metric': train_poly_metric, - 'mono_metric': train_mono_metric, - 'opd_metric': train_opd_metric, - 'shape_results_dict': train_shape_results_dict - } - - -## Save results -metrics = {'test_metrics': test_metrics, - 'train_metrics': train_metrics - } -output_path = saving_path + 'metrics-' + run_id_name -np.save(output_path, metrics, allow_pickle=True) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() - diff --git a/jz-submissions/scripts/evaluation_param_1000.py b/jz-submissions/scripts/evaluation_param_1000.py deleted file mode 100644 index 1f433c4c..00000000 --- a/jz-submissions/scripts/evaluation_param_1000.py +++ /dev/null @@ -1,375 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -## PSF modelling evaluation - -import sys -import numpy as np -import time -import matplotlib.pyplot as plt -import wf_psf as wf -import tensorflow as tf - - -## Start measuring elapsed time -starting_time = time.time() - - -## Define saving paths -# model = 'mccd' -# model = 'poly' -model = 'param' - -id_name = '-coherent_euclid_1000stars' -run_id_name = model + id_name - -# folder paths -log_save_file = '/gpfswork/rech/xdy/ulx23va/wf-outputs//log-files/' -model_folder = '/gpfswork/rech/xdy/ulx23va/wf-outputs/chkp/' - -weights_paths = model_folder + 'chkp_' + run_id_name + '_cycle2' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_1000_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Saving path -saving_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/metrics/' - - -## Model parameters -# Decimation factor for Zernike polynomials -n_zernikes = 45 -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 5 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - - -## Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '-metrics_output.log', 'w') -sys.stdout = log_file -print('Starting the log file.') - - -## Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - - -## Load datasets -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Prepare models -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Outputs (needed for the MCCD model) -outputs = tf_noisy_train_stars - - -## Create the model -## Select the model -if model == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=x_lims, - y_lims=y_lims, - d_max=d_max_nonparam, - graph_features=graph_features) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - graph_features=graph_features, - l1_rate=l1_rate, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - -## Load the model's weights -tf_semiparam_field.load_weights(weights_paths) - - -## Prepare ground truth model -n_zernikes_bis = 45 -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes_bis, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Initialize the model -GT_tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field( - zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes_bis, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -# For the Ground truth model -GT_tf_semiparam_field.tf_poly_Z_field.assign_coeff_matrix(train_C_poly) -_ = GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat.assign( - np.zeros_like(GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat)) - - -## Metric evaluation on the test dataset -print('\n***\nMetric evaluation on the test dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - tf_SEDs=test_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - lambda_list=lambda_list) - -mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_test_pos, - batch_size=batch_size) - -opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=test_SEDs, - tf_pos=tf_test_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics -test_metrics = {'poly_metric': poly_metric, - 'mono_metric': mono_metric, - 'opd_metric': opd_metric, - 'shape_results_dict': shape_results_dict - } - - -## Metric evaluation on the train dataset -print('\n***\nMetric evaluation on the train dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - tf_SEDs=train_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -train_poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - lambda_list=lambda_list) - -train_mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_train_pos, - batch_size=batch_size) - -train_opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -train_shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=train_SEDs, - tf_pos=tf_train_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics into dictionary -train_metrics = {'poly_metric': train_poly_metric, - 'mono_metric': train_mono_metric, - 'opd_metric': train_opd_metric, - 'shape_results_dict': train_shape_results_dict - } - - -## Save results -metrics = {'test_metrics': test_metrics, - 'train_metrics': train_metrics - } -output_path = saving_path + 'metrics-' + run_id_name -np.save(output_path, metrics, allow_pickle=True) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() - diff --git a/jz-submissions/scripts/evaluation_param_200.py b/jz-submissions/scripts/evaluation_param_200.py deleted file mode 100644 index 143150dc..00000000 --- a/jz-submissions/scripts/evaluation_param_200.py +++ /dev/null @@ -1,375 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -## PSF modelling evaluation - -import sys -import numpy as np -import time -import matplotlib.pyplot as plt -import wf_psf as wf -import tensorflow as tf - - -## Start measuring elapsed time -starting_time = time.time() - - -## Define saving paths -# model = 'mccd' -# model = 'poly' -model = 'param' - -id_name = '-coherent_euclid_200stars' -run_id_name = model + id_name - -# folder paths -log_save_file = '/gpfswork/rech/xdy/ulx23va/wf-outputs//log-files/' -model_folder = '/gpfswork/rech/xdy/ulx23va/wf-outputs/chkp/' - -weights_paths = model_folder + 'chkp_' + run_id_name + '_cycle2' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_200_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Saving path -saving_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/metrics/' - - -## Model parameters -# Decimation factor for Zernike polynomials -n_zernikes = 45 -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 5 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - - -## Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '-metrics_output.log', 'w') -sys.stdout = log_file -print('Starting the log file.') - - -## Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - - -## Load datasets -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Prepare models -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Outputs (needed for the MCCD model) -outputs = tf_noisy_train_stars - - -## Create the model -## Select the model -if model == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=x_lims, - y_lims=y_lims, - d_max=d_max_nonparam, - graph_features=graph_features) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - graph_features=graph_features, - l1_rate=l1_rate, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - -## Load the model's weights -tf_semiparam_field.load_weights(weights_paths) - - -## Prepare ground truth model -n_zernikes_bis = 45 -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes_bis, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Initialize the model -GT_tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field( - zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes_bis, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -# For the Ground truth model -GT_tf_semiparam_field.tf_poly_Z_field.assign_coeff_matrix(train_C_poly) -_ = GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat.assign( - np.zeros_like(GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat)) - - -## Metric evaluation on the test dataset -print('\n***\nMetric evaluation on the test dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - tf_SEDs=test_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - lambda_list=lambda_list) - -mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_test_pos, - batch_size=batch_size) - -opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=test_SEDs, - tf_pos=tf_test_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics -test_metrics = {'poly_metric': poly_metric, - 'mono_metric': mono_metric, - 'opd_metric': opd_metric, - 'shape_results_dict': shape_results_dict - } - - -## Metric evaluation on the train dataset -print('\n***\nMetric evaluation on the train dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - tf_SEDs=train_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -train_poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - lambda_list=lambda_list) - -train_mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_train_pos, - batch_size=batch_size) - -train_opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -train_shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=train_SEDs, - tf_pos=tf_train_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics into dictionary -train_metrics = {'poly_metric': train_poly_metric, - 'mono_metric': train_mono_metric, - 'opd_metric': train_opd_metric, - 'shape_results_dict': train_shape_results_dict - } - - -## Save results -metrics = {'test_metrics': test_metrics, - 'train_metrics': train_metrics - } -output_path = saving_path + 'metrics-' + run_id_name -np.save(output_path, metrics, allow_pickle=True) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() - diff --git a/jz-submissions/scripts/evaluation_param_2000.py b/jz-submissions/scripts/evaluation_param_2000.py deleted file mode 100644 index e4eef001..00000000 --- a/jz-submissions/scripts/evaluation_param_2000.py +++ /dev/null @@ -1,375 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -## PSF modelling evaluation - -import sys -import numpy as np -import time -import matplotlib.pyplot as plt -import wf_psf as wf -import tensorflow as tf - - -## Start measuring elapsed time -starting_time = time.time() - - -## Define saving paths -# model = 'mccd' -# model = 'poly' -model = 'param' - -id_name = '-coherent_euclid_2000stars' -run_id_name = model + id_name - -# folder paths -log_save_file = '/gpfswork/rech/xdy/ulx23va/wf-outputs//log-files/' -model_folder = '/gpfswork/rech/xdy/ulx23va/wf-outputs/chkp/' - -weights_paths = model_folder + 'chkp_' + run_id_name + '_cycle2' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_2000_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Saving path -saving_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/metrics/' - - -## Model parameters -# Decimation factor for Zernike polynomials -n_zernikes = 45 -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 5 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - - -## Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '-metrics_output.log', 'w') -sys.stdout = log_file -print('Starting the log file.') - - -## Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - - -## Load datasets -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Prepare models -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Outputs (needed for the MCCD model) -outputs = tf_noisy_train_stars - - -## Create the model -## Select the model -if model == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=x_lims, - y_lims=y_lims, - d_max=d_max_nonparam, - graph_features=graph_features) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - graph_features=graph_features, - l1_rate=l1_rate, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - -## Load the model's weights -tf_semiparam_field.load_weights(weights_paths) - - -## Prepare ground truth model -n_zernikes_bis = 45 -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes_bis, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Initialize the model -GT_tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field( - zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes_bis, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -# For the Ground truth model -GT_tf_semiparam_field.tf_poly_Z_field.assign_coeff_matrix(train_C_poly) -_ = GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat.assign( - np.zeros_like(GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat)) - - -## Metric evaluation on the test dataset -print('\n***\nMetric evaluation on the test dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - tf_SEDs=test_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - lambda_list=lambda_list) - -mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_test_pos, - batch_size=batch_size) - -opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=test_SEDs, - tf_pos=tf_test_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics -test_metrics = {'poly_metric': poly_metric, - 'mono_metric': mono_metric, - 'opd_metric': opd_metric, - 'shape_results_dict': shape_results_dict - } - - -## Metric evaluation on the train dataset -print('\n***\nMetric evaluation on the train dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - tf_SEDs=train_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -train_poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - lambda_list=lambda_list) - -train_mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_train_pos, - batch_size=batch_size) - -train_opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -train_shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=train_SEDs, - tf_pos=tf_train_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics into dictionary -train_metrics = {'poly_metric': train_poly_metric, - 'mono_metric': train_mono_metric, - 'opd_metric': train_opd_metric, - 'shape_results_dict': train_shape_results_dict - } - - -## Save results -metrics = {'test_metrics': test_metrics, - 'train_metrics': train_metrics - } -output_path = saving_path + 'metrics-' + run_id_name -np.save(output_path, metrics, allow_pickle=True) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() - diff --git a/jz-submissions/scripts/evaluation_param_500.py b/jz-submissions/scripts/evaluation_param_500.py deleted file mode 100644 index 6278c2c5..00000000 --- a/jz-submissions/scripts/evaluation_param_500.py +++ /dev/null @@ -1,375 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -## PSF modelling evaluation - -import sys -import numpy as np -import time -import matplotlib.pyplot as plt -import wf_psf as wf -import tensorflow as tf - - -## Start measuring elapsed time -starting_time = time.time() - - -## Define saving paths -# model = 'mccd' -# model = 'poly' -model = 'param' - -id_name = '-coherent_euclid_500stars' -run_id_name = model + id_name - -# folder paths -log_save_file = '/gpfswork/rech/xdy/ulx23va/wf-outputs//log-files/' -model_folder = '/gpfswork/rech/xdy/ulx23va/wf-outputs/chkp/' - -weights_paths = model_folder + 'chkp_' + run_id_name + '_cycle2' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_500_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Saving path -saving_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/metrics/' - - -## Model parameters -# Decimation factor for Zernike polynomials -n_zernikes = 45 -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 5 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - - -## Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '-metrics_output.log', 'w') -sys.stdout = log_file -print('Starting the log file.') - - -## Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - - -## Load datasets -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Prepare models -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Outputs (needed for the MCCD model) -outputs = tf_noisy_train_stars - - -## Create the model -## Select the model -if model == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=x_lims, - y_lims=y_lims, - d_max=d_max_nonparam, - graph_features=graph_features) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - graph_features=graph_features, - l1_rate=l1_rate, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - -## Load the model's weights -tf_semiparam_field.load_weights(weights_paths) - - -## Prepare ground truth model -n_zernikes_bis = 45 -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes_bis, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Initialize the model -GT_tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field( - zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes_bis, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -# For the Ground truth model -GT_tf_semiparam_field.tf_poly_Z_field.assign_coeff_matrix(train_C_poly) -_ = GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat.assign( - np.zeros_like(GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat)) - - -## Metric evaluation on the test dataset -print('\n***\nMetric evaluation on the test dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - tf_SEDs=test_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - lambda_list=lambda_list) - -mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_test_pos, - batch_size=batch_size) - -opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=test_SEDs, - tf_pos=tf_test_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics -test_metrics = {'poly_metric': poly_metric, - 'mono_metric': mono_metric, - 'opd_metric': opd_metric, - 'shape_results_dict': shape_results_dict - } - - -## Metric evaluation on the train dataset -print('\n***\nMetric evaluation on the train dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - tf_SEDs=train_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -train_poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - lambda_list=lambda_list) - -train_mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_train_pos, - batch_size=batch_size) - -train_opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -train_shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=train_SEDs, - tf_pos=tf_train_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics into dictionary -train_metrics = {'poly_metric': train_poly_metric, - 'mono_metric': train_mono_metric, - 'opd_metric': train_opd_metric, - 'shape_results_dict': train_shape_results_dict - } - - -## Save results -metrics = {'test_metrics': test_metrics, - 'train_metrics': train_metrics - } -output_path = saving_path + 'metrics-' + run_id_name -np.save(output_path, metrics, allow_pickle=True) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() - diff --git a/jz-submissions/scripts/evaluation_poly_1000.py b/jz-submissions/scripts/evaluation_poly_1000.py deleted file mode 100644 index 0bdb1bfb..00000000 --- a/jz-submissions/scripts/evaluation_poly_1000.py +++ /dev/null @@ -1,374 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -## PSF modelling evaluation - -import sys -import numpy as np -import time -import matplotlib.pyplot as plt -import wf_psf as wf -import tensorflow as tf - - -## Start measuring elapsed time -starting_time = time.time() - - -## Define saving paths -# model = 'mccd' -model = 'poly' -# model = 'param' - -id_name = '_v2-coherent_euclid_1000stars' -run_id_name = model + id_name - -# folder paths -log_save_file = '/gpfswork/rech/xdy/ulx23va/wf-outputs//log-files/' -model_folder = '/gpfswork/rech/xdy/ulx23va/wf-outputs/chkp/' - -weights_paths = model_folder + 'chkp_' + run_id_name + '_cycle2' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_1000_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Saving path -saving_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/metrics/' - - -## Model parameters -# Decimation factor for Zernike polynomials -n_zernikes = 15 -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 5 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - - -## Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '-metrics_output.log', 'w') -sys.stdout = log_file -print('Starting the log file.') - - -## Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - - -## Load datasets -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Prepare models -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Outputs (needed for the MCCD model) -outputs = tf_noisy_train_stars - - -## Create the model -## Select the model -if model == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=x_lims, - y_lims=y_lims, - d_max=d_max_nonparam, - graph_features=graph_features) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - graph_features=graph_features, - l1_rate=l1_rate, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - -## Load the model's weights -tf_semiparam_field.load_weights(weights_paths) - - -## Prepare ground truth model -n_zernikes_bis = 45 -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes_bis, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Initialize the model -GT_tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field( - zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes_bis, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -# For the Ground truth model -GT_tf_semiparam_field.tf_poly_Z_field.assign_coeff_matrix(train_C_poly) -_ = GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat.assign( - np.zeros_like(GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat)) - - -## Metric evaluation on the test dataset -print('\n***\nMetric evaluation on the test dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - tf_SEDs=test_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - lambda_list=lambda_list) - -mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_test_pos, - batch_size=batch_size) - -opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=test_SEDs, - tf_pos=tf_test_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics -test_metrics = {'poly_metric': poly_metric, - 'mono_metric': mono_metric, - 'opd_metric': opd_metric, - 'shape_results_dict': shape_results_dict - } - - -## Metric evaluation on the train dataset -print('\n***\nMetric evaluation on the train dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - tf_SEDs=train_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -train_poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - lambda_list=lambda_list) - -train_mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_train_pos, - batch_size=batch_size) - -train_opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -train_shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=train_SEDs, - tf_pos=tf_train_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics into dictionary -train_metrics = {'poly_metric': train_poly_metric, - 'mono_metric': train_mono_metric, - 'opd_metric': train_opd_metric, - 'shape_results_dict': train_shape_results_dict - } - - -## Save results -metrics = {'test_metrics': test_metrics, - 'train_metrics': train_metrics - } -output_path = saving_path + 'metrics-' + run_id_name -np.save(output_path, metrics, allow_pickle=True) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() - diff --git a/jz-submissions/scripts/evaluation_poly_200.py b/jz-submissions/scripts/evaluation_poly_200.py deleted file mode 100644 index ed41d113..00000000 --- a/jz-submissions/scripts/evaluation_poly_200.py +++ /dev/null @@ -1,374 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -## PSF modelling evaluation - -import sys -import numpy as np -import time -import matplotlib.pyplot as plt -import wf_psf as wf -import tensorflow as tf - - -## Start measuring elapsed time -starting_time = time.time() - - -## Define saving paths -# model = 'mccd' -model = 'poly' -# model = 'param' - -id_name = '_v2-coherent_euclid_200stars' -run_id_name = model + id_name - -# folder paths -log_save_file = '/gpfswork/rech/xdy/ulx23va/wf-outputs//log-files/' -model_folder = '/gpfswork/rech/xdy/ulx23va/wf-outputs/chkp/' - -weights_paths = model_folder + 'chkp_' + run_id_name + '_cycle2' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_200_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Saving path -saving_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/metrics/' - - -## Model parameters -# Decimation factor for Zernike polynomials -n_zernikes = 15 -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 5 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - - -## Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '-metrics_output.log', 'w') -sys.stdout = log_file -print('Starting the log file.') - - -## Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - - -## Load datasets -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Prepare models -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Outputs (needed for the MCCD model) -outputs = tf_noisy_train_stars - - -## Create the model -## Select the model -if model == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=x_lims, - y_lims=y_lims, - d_max=d_max_nonparam, - graph_features=graph_features) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - graph_features=graph_features, - l1_rate=l1_rate, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - -## Load the model's weights -tf_semiparam_field.load_weights(weights_paths) - - -## Prepare ground truth model -n_zernikes_bis = 45 -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes_bis, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Initialize the model -GT_tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field( - zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes_bis, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -# For the Ground truth model -GT_tf_semiparam_field.tf_poly_Z_field.assign_coeff_matrix(train_C_poly) -_ = GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat.assign( - np.zeros_like(GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat)) - - -## Metric evaluation on the test dataset -print('\n***\nMetric evaluation on the test dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - tf_SEDs=test_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - lambda_list=lambda_list) - -mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_test_pos, - batch_size=batch_size) - -opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=test_SEDs, - tf_pos=tf_test_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics -test_metrics = {'poly_metric': poly_metric, - 'mono_metric': mono_metric, - 'opd_metric': opd_metric, - 'shape_results_dict': shape_results_dict - } - - -## Metric evaluation on the train dataset -print('\n***\nMetric evaluation on the train dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - tf_SEDs=train_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -train_poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - lambda_list=lambda_list) - -train_mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_train_pos, - batch_size=batch_size) - -train_opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -train_shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=train_SEDs, - tf_pos=tf_train_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics into dictionary -train_metrics = {'poly_metric': train_poly_metric, - 'mono_metric': train_mono_metric, - 'opd_metric': train_opd_metric, - 'shape_results_dict': train_shape_results_dict - } - - -## Save results -metrics = {'test_metrics': test_metrics, - 'train_metrics': train_metrics - } -output_path = saving_path + 'metrics-' + run_id_name -np.save(output_path, metrics, allow_pickle=True) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() - diff --git a/jz-submissions/scripts/evaluation_poly_2000.py b/jz-submissions/scripts/evaluation_poly_2000.py deleted file mode 100644 index dc80272b..00000000 --- a/jz-submissions/scripts/evaluation_poly_2000.py +++ /dev/null @@ -1,374 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -## PSF modelling evaluation - -import sys -import numpy as np -import time -import matplotlib.pyplot as plt -import wf_psf as wf -import tensorflow as tf - - -## Start measuring elapsed time -starting_time = time.time() - - -## Define saving paths -# model = 'mccd' -model = 'poly' -# model = 'param' - -id_name = '_v2-coherent_euclid_2000stars' -run_id_name = model + id_name - -# folder paths -log_save_file = '/gpfswork/rech/xdy/ulx23va/wf-outputs//log-files/' -model_folder = '/gpfswork/rech/xdy/ulx23va/wf-outputs/chkp/' - -weights_paths = model_folder + 'chkp_' + run_id_name + '_cycle2' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_2000_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Saving path -saving_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/metrics/' - - -## Model parameters -# Decimation factor for Zernike polynomials -n_zernikes = 15 -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 5 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - - -## Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '-metrics_output.log', 'w') -sys.stdout = log_file -print('Starting the log file.') - - -## Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - - -## Load datasets -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Prepare models -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Outputs (needed for the MCCD model) -outputs = tf_noisy_train_stars - - -## Create the model -## Select the model -if model == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=x_lims, - y_lims=y_lims, - d_max=d_max_nonparam, - graph_features=graph_features) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - graph_features=graph_features, - l1_rate=l1_rate, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - -## Load the model's weights -tf_semiparam_field.load_weights(weights_paths) - - -## Prepare ground truth model -n_zernikes_bis = 45 -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes_bis, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Initialize the model -GT_tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field( - zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes_bis, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -# For the Ground truth model -GT_tf_semiparam_field.tf_poly_Z_field.assign_coeff_matrix(train_C_poly) -_ = GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat.assign( - np.zeros_like(GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat)) - - -## Metric evaluation on the test dataset -print('\n***\nMetric evaluation on the test dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - tf_SEDs=test_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - lambda_list=lambda_list) - -mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_test_pos, - batch_size=batch_size) - -opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=test_SEDs, - tf_pos=tf_test_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics -test_metrics = {'poly_metric': poly_metric, - 'mono_metric': mono_metric, - 'opd_metric': opd_metric, - 'shape_results_dict': shape_results_dict - } - - -## Metric evaluation on the train dataset -print('\n***\nMetric evaluation on the train dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - tf_SEDs=train_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -train_poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - lambda_list=lambda_list) - -train_mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_train_pos, - batch_size=batch_size) - -train_opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -train_shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=train_SEDs, - tf_pos=tf_train_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics into dictionary -train_metrics = {'poly_metric': train_poly_metric, - 'mono_metric': train_mono_metric, - 'opd_metric': train_opd_metric, - 'shape_results_dict': train_shape_results_dict - } - - -## Save results -metrics = {'test_metrics': test_metrics, - 'train_metrics': train_metrics - } -output_path = saving_path + 'metrics-' + run_id_name -np.save(output_path, metrics, allow_pickle=True) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() - diff --git a/jz-submissions/scripts/evaluation_poly_500.py b/jz-submissions/scripts/evaluation_poly_500.py deleted file mode 100644 index 0ae93881..00000000 --- a/jz-submissions/scripts/evaluation_poly_500.py +++ /dev/null @@ -1,374 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -## PSF modelling evaluation - -import sys -import numpy as np -import time -import matplotlib.pyplot as plt -import wf_psf as wf -import tensorflow as tf - - -## Start measuring elapsed time -starting_time = time.time() - - -## Define saving paths -# model = 'mccd' -model = 'poly' -# model = 'param' - -id_name = '_v2-coherent_euclid_500stars' -run_id_name = model + id_name - -# folder paths -log_save_file = '/gpfswork/rech/xdy/ulx23va/wf-outputs/log-files/' -model_folder = '/gpfswork/rech/xdy/ulx23va/wf-outputs/chkp/' - -weights_paths = model_folder + 'chkp_' + run_id_name + '_cycle2' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_500_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Saving path -saving_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/metrics/' - - -## Model parameters -# Decimation factor for Zernike polynomials -n_zernikes = 15 -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 5 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - - -## Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '-metrics_output.log', 'w') -sys.stdout = log_file -print('Starting the log file.') - - -## Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - - -## Load datasets -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Prepare models -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Outputs (needed for the MCCD model) -outputs = tf_noisy_train_stars - - -## Create the model -## Select the model -if model == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=x_lims, - y_lims=y_lims, - d_max=d_max_nonparam, - graph_features=graph_features) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - graph_features=graph_features, - l1_rate=l1_rate, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - -## Load the model's weights -tf_semiparam_field.load_weights(weights_paths) - - -## Prepare ground truth model -n_zernikes_bis = 45 -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes_bis, wfe_dim=pupil_diameter) -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -# Initialize the model -GT_tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field( - zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes_bis, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -# For the Ground truth model -GT_tf_semiparam_field.tf_poly_Z_field.assign_coeff_matrix(train_C_poly) -_ = GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat.assign( - np.zeros_like(GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat)) - - -## Metric evaluation on the test dataset -print('\n***\nMetric evaluation on the test dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - tf_SEDs=test_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - lambda_list=lambda_list) - -mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_test_pos, - batch_size=batch_size) - -opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=test_SEDs, - tf_pos=tf_test_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics -test_metrics = {'poly_metric': poly_metric, - 'mono_metric': mono_metric, - 'opd_metric': opd_metric, - 'shape_results_dict': shape_results_dict - } - - -## Metric evaluation on the train dataset -print('\n***\nMetric evaluation on the train dataset\n***\n') - -# Polychromatic star reconstructions -rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - tf_SEDs=train_SEDs, - n_bins_lda=n_bins_lda, - batch_size=batch_size) - -train_poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - -# Monochromatic star reconstructions -lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation -rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - lambda_list=lambda_list) - -train_mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - -# OPD metrics -rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_train_pos, - batch_size=batch_size) - -train_opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - -# Shape metrics -train_shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=train_SEDs, - tf_pos=tf_train_pos, - n_bins_lda=n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=batch_size) - -# Save metrics into dictionary -train_metrics = {'poly_metric': train_poly_metric, - 'mono_metric': train_mono_metric, - 'opd_metric': train_opd_metric, - 'shape_results_dict': train_shape_results_dict - } - - -## Save results -metrics = {'test_metrics': test_metrics, - 'train_metrics': train_metrics - } -output_path = saving_path + 'metrics-' + run_id_name -np.save(output_path, metrics, allow_pickle=True) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() - diff --git a/jz-submissions/scripts/train_eval_poly_200.py b/jz-submissions/scripts/train_eval_poly_200.py deleted file mode 100644 index 0718c73b..00000000 --- a/jz-submissions/scripts/train_eval_poly_200.py +++ /dev/null @@ -1,703 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -# PSF modelling and evaluation -from absl import app -from absl import flags - -import sys -import numpy as np -import time -import wf_psf as wf -import tensorflow as tf - -# import tensorflow as tf -import tensorflow_addons as tfa - - -## Training flags -# Model definition -flags.DEFINE_string("model", "poly", "Model type. Options are: 'mccd', 'poly, 'param'.") -flags.DEFINE_string("id_name", "_test-coherent_euclid_200stars", "Model saving id.") -# Saving paths -flags.DEFINE_string("base_path", "/gpfswork/rech/xdy/ulx23va/wf-outputs/", "Base path for saving files.") -flags.DEFINE_string("log_folder", "log-files/", "Folder name to save log files.") -flags.DEFINE_string("model_folder", "chkp/", "Folder name to save trained models.") -flags.DEFINE_string("optim_hist_folder", "optim-hist/", "Folder name to save optimisation history files.") -flags.DEFINE_string("chkp_save_path", "/gpfsscratch/rech/xdy/ulx23va/wf-outputs/chkp/", "Path to save model checkpoints during training.") -# Input dataset paths -flags.DEFINE_string("dataset_folder", "/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/", "Folder path of datasets.") -flags.DEFINE_string("train_dataset_file", "train_Euclid_res_200_TrainStars_id_001.npy", "Train dataset file name.") -flags.DEFINE_string("test_dataset_file", "test_Euclid_res_id_001.npy", "Test dataset file name.") -# Model parameters -flags.DEFINE_integer("n_zernikes", 15, "Zernike polynomial modes to use on the parametric part.") -flags.DEFINE_integer("pupil_diameter", 256, "Dimension of the OPD/Wavefront space.") -flags.DEFINE_integer("n_bins_lda", 20, "Number of wavelength bins to use to reconstruct polychromatic objects.") -flags.DEFINE_float("output_Q", 3., "Downsampling rate to match the specified telescope's sampling from the oversampling rate used in the model.") -flags.DEFINE_float("oversampling_rate", 3., "Oversampling rate used for the OPD/WFE PSF model.") -flags.DEFINE_integer("output_dim", 32, "Dimension of the pixel PSF postage stamp.") -flags.DEFINE_integer("d_max", 2, "Max polynomial degree of the parametric part.") -flags.DEFINE_integer("d_max_nonparam", 3, "Max polynomial degree of the non-parametric part.") -flags.DEFINE_list("x_lims", [0, 1e3], "Limits of the PSF field coordinates for the x axis.") -flags.DEFINE_list("y_lims", [0, 1e3], "Limits of the PSF field coordinates for the y axis.") -flags.DEFINE_integer("graph_features", 10, "Number of graph-constrained features of the non-parametric part.") -flags.DEFINE_float("l1_rate", 1e-8, "L1 regularisation parameter for the non-parametric part.") -# Training parameters -flags.DEFINE_integer("batch_size", 32, "Batch size used for the trainingin the stochastic gradient descend type of algorithm.") -flags.DEFINE_list("l_rate_param", [1e-2, 1e-2], "Learning rates for the parametric parts.") -flags.DEFINE_list("l_rate_non_param", [1e-1, 1e-1], "Learning rates for the non-parametric parts.") -flags.DEFINE_list("n_epochs_param", [2, 2], "Number of training epochs of the parametric parts.") -flags.DEFINE_list("n_epochs_non_param", [2, 2], "Number of training epochs of the non-parametric parts.") -flags.DEFINE_integer("total_cycles", 2, "Total amount of cycles to perform. For the moment the only available options are '1' or '2'.") - -## Evaluation flags -# Saving paths -flags.DEFINE_string("metric_base_path", "/gpfswork/rech/xdy/ulx23va/wf-outputs/metrics/", "Base path for saving metric files.") -flags.DEFINE_string("saved_model_type", "final", "Type of saved model to use for the evaluation. Can be 'final' or 'checkpoint'.") -flags.DEFINE_string("saved_cycle", "cycle2", "Saved cycle to use for the evaluation. Can be 'cycle1' or 'cycle2'.") -# Evaluation parameters -flags.DEFINE_integer("GT_n_zernikes", 45, "Zernike polynomial modes to use on the ground truth model parametric part.") -flags.DEFINE_integer("eval_batch_size", 16, "Batch size to use for the evaluation.") - -# Define flags -FLAGS = flags.FLAGS - - -def train_model(): - """ Train the model defined in the flags. """ - # Start measuring elapsed time - starting_time = time.time() - - # Define model run id - run_id_name = FLAGS.model + FLAGS.id_name - - # Define paths - log_save_file = FLAGS.base_path + FLAGS.log_folder - model_save_file= FLAGS.base_path + FLAGS.model_folder - optim_hist_file = FLAGS.base_path + FLAGS.optim_hist_folder - saving_optim_hist = dict() - - - # Save output prints to logfile - old_stdout = sys.stdout - log_file = open(log_save_file + run_id_name + '_output.log','w') - sys.stdout = log_file - print('Starting the log file.') - - # Print GPU and tensorflow info - device_name = tf.test.gpu_device_name() - print('Found GPU at: {}'.format(device_name)) - print('tf_version: ' + str(tf.__version__)) - - ## Prepare the inputs - # Generate Zernike maps - zernikes = wf.utils.zernike_generator(n_zernikes=FLAGS.n_zernikes, wfe_dim=FLAGS.pupil_diameter) - # Now as cubes - np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - np_zernike_cube[np.isnan(np_zernike_cube)] = 0 - tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - print('Zernike cube:') - print(tf_zernike_cube.shape) - - - ## Load the dictionaries - train_dataset = np.load(FLAGS.dataset_folder + FLAGS.train_dataset_file, allow_pickle=True)[()] - # train_stars = train_dataset['stars'] - # noisy_train_stars = train_dataset['noisy_stars'] - # train_pos = train_dataset['positions'] - train_SEDs = train_dataset['SEDs'] - # train_zernike_coef = train_dataset['zernike_coef'] - train_C_poly = train_dataset['C_poly'] - train_parameters = train_dataset['parameters'] - - test_dataset = np.load(FLAGS.dataset_folder + FLAGS.test_dataset_file, allow_pickle=True)[()] - # test_stars = test_dataset['stars'] - # test_pos = test_dataset['positions'] - test_SEDs = test_dataset['SEDs'] - # test_zernike_coef = test_dataset['zernike_coef'] - - # Convert to tensor - tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) - tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) - tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) - tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - - print('Dataset parameters:') - print(train_parameters) - - - ## Generate initializations - # Prepare np input - simPSF_np = wf.SimPSFToolkit(zernikes, max_order=FLAGS.n_zernikes, - pupil_diameter=FLAGS.pupil_diameter, output_dim=FLAGS.output_dim, - oversampling_rate=FLAGS.oversampling_rate, output_Q=FLAGS.output_Q) - simPSF_np.gen_random_Z_coeffs(max_order=FLAGS.n_zernikes) - z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) - simPSF_np.set_z_coeffs(z_coeffs) - simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - # Obscurations - obscurations = simPSF_np.generate_pupil_obscurations(N_pix=FLAGS.pupil_diameter, N_filter=2) - tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - # Initialize the SED data list - packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=FLAGS.n_bins_lda) - for _sed in train_SEDs] - - - # Prepare the inputs for the training - tf_packed_SED_data = tf.convert_to_tensor(packed_SED_data, dtype=tf.float32) - tf_packed_SED_data = tf.transpose(tf_packed_SED_data, perm=[0, 2, 1]) - - inputs = [tf_train_pos, tf_packed_SED_data] - - # Select the observed stars (noisy or noiseless) - outputs = tf_noisy_train_stars - # outputs = tf_train_stars - - - ## Prepare validation data inputs - val_SEDs = test_SEDs - tf_val_pos = tf_test_pos - tf_val_stars = tf_test_stars - - # Initialize the SED data list - val_packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=FLAGS.n_bins_lda) - for _sed in val_SEDs] - - # Prepare the inputs for the validation - tf_val_packed_SED_data = tf.convert_to_tensor(val_packed_SED_data, dtype=tf.float32) - tf_val_packed_SED_data = tf.transpose(tf_val_packed_SED_data, perm=[0, 2, 1]) - - # Prepare input validation tuple - val_x_inputs = [tf_val_pos, tf_val_packed_SED_data] - val_y_inputs = tf_val_stars - val_data = (val_x_inputs, val_y_inputs) - - - ## Select the model - if FLAGS.model == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=FLAGS.x_lims, - y_lims=FLAGS.y_lims, - d_max=FLAGS.d_max_nonparam, - graph_features=FLAGS.graph_features) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=FLAGS.batch_size, - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=FLAGS.output_Q, - d_max_nonparam=FLAGS.d_max_nonparam, - graph_features=FLAGS.graph_features, - l1_rate=FLAGS.l1_rate, - output_dim=FLAGS.output_dim, - n_zernikes=FLAGS.n_zernikes, - d_max=FLAGS.d_max, - x_lims=FLAGS.x_lims, - y_lims=FLAGS.y_lims) - - elif FLAGS.model == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=FLAGS.batch_size, - output_Q=FLAGS.output_Q, - d_max_nonparam=FLAGS.d_max_nonparam, - output_dim=FLAGS.output_dim, - n_zernikes=FLAGS.n_zernikes, - d_max=FLAGS.d_max, - x_lims=FLAGS.x_lims, - y_lims=FLAGS.y_lims) - - elif FLAGS.model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=FLAGS.batch_size, - output_Q=FLAGS.output_Q, - output_dim=FLAGS.output_dim, - n_zernikes=FLAGS.n_zernikes, - d_max=FLAGS.d_max, - x_lims=FLAGS.x_lims, - y_lims=FLAGS.y_lims) - - - # # Model Training - # Prepare the saving callback - # Prepare to save the model as a callback - filepath_chkp_callback = FLAGS.chkp_save_path + 'chkp_callback_' + run_id_name + '_cycle1' - model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - - # Prepare the optimisers - param_optim = tfa.optimizers.RectifiedAdam(lr=FLAGS.l_rate_param[0]) - non_param_optim = tfa.optimizers.RectifiedAdam(lr=FLAGS.l_rate_non_param[0]) - - print('Starting cycle 1..') - start_cycle1 = time.time() - - if FLAGS.model == 'param': - tf_semiparam_field, hist_param = wf.train_utils.param_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=FLAGS.batch_size, - l_rate=FLAGS.l_rate_param[0], - n_epochs=FLAGS.n_epochs_param[0], - param_optim=param_optim, - param_loss=None, - param_metrics=None, - param_callback=None, - general_callback=[model_chkp_callback], - verbose=2) - - else: - tf_semiparam_field, hist_param, hist_non_param = wf.train_utils.general_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=FLAGS.batch_size, - l_rate_param=FLAGS.l_rate_param[0], - l_rate_non_param=FLAGS.l_rate_non_param[0], - n_epochs_param=FLAGS.n_epochs_param[0], - n_epochs_non_param=FLAGS.n_epochs_non_param[0], - param_optim=param_optim, - non_param_optim=non_param_optim, - param_loss=None, non_param_loss=None, - param_metrics=None, non_param_metrics=None, - param_callback=None, non_param_callback=None, - general_callback=[model_chkp_callback], - first_run=True, - verbose=2) - - # Save weights - tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle1') - - end_cycle1 = time.time() - print('Cycle1 elapsed time: %f'%(end_cycle1-start_cycle1)) - - # Save optimisation history in the saving dict - saving_optim_hist['param_cycle1'] = hist_param.history - if FLAGS.model != 'param': - saving_optim_hist['nonparam_cycle1'] = hist_non_param.history - - if FLAGS.total_cycles >= 2: - # Prepare to save the model as a callback - filepath_chkp_callback = FLAGS.chkp_save_path + 'chkp_callback_' + run_id_name + '_cycle2' - model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - - # Prepare the optimisers - param_optim = tfa.optimizers.RectifiedAdam(lr=FLAGS.l_rate_param[1]) - non_param_optim = tfa.optimizers.RectifiedAdam(lr=FLAGS.l_rate_non_param[1]) - - print('Starting cycle 2..') - start_cycle2 = time.time() - - - # Compute the next cycle - if FLAGS.model == 'param': - tf_semiparam_field, hist_param_2 = wf.train_utils.param_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=FLAGS.batch_size, - l_rate=FLAGS.l_rate_param[1], - n_epochs=FLAGS.n_epochs_param[1], - param_optim=param_optim, - param_loss=None, - param_metrics=None, - param_callback=None, - general_callback=[model_chkp_callback], - verbose=2) - else: - # Compute the next cycle - tf_semiparam_field, hist_param_2, hist_non_param_2 = wf.train_utils.general_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=FLAGS.batch_size, - l_rate_param=FLAGS.l_rate_param[1], - l_rate_non_param=FLAGS.l_rate_non_param[1], - n_epochs_param=FLAGS.n_epochs_param[1], - n_epochs_non_param=FLAGS.n_epochs_non_param[1], - param_optim=param_optim, - non_param_optim=non_param_optim, - param_loss=None, non_param_loss=None, - param_metrics=None, non_param_metrics=None, - param_callback=None, non_param_callback=None, - general_callback=[model_chkp_callback], - first_run=False, - verbose=2) - - # Save the weights at the end of the second cycle - tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle2') - - end_cycle2 = time.time() - print('Cycle2 elapsed time: %f'%(end_cycle2 - start_cycle2)) - - # Save optimisation history in the saving dict - saving_optim_hist['param_cycle2'] = hist_param_2.history - if FLAGS.model != 'param': - saving_optim_hist['nonparam_cycle2'] = hist_non_param_2.history - - # Save optimisation history dictionary - np.save(optim_hist_file + 'optim_hist_' + run_id_name + '.npy', saving_optim_hist) - - ## Print final time - final_time = time.time() - print('\nTotal elapsed time: %f'%(final_time - starting_time)) - - ## Close log file - print('\n Good bye..') - sys.stdout = old_stdout - log_file.close() - - -def evaluate_model(): - """ Evaluate the trained model.""" - # Start measuring elapsed time - starting_time = time.time() - - # Define model run id - run_id_name = FLAGS.model + FLAGS.id_name - # Define paths - log_save_file = FLAGS.base_path + FLAGS.log_folder - - # Define saved model to use - if FLAGS.saved_model_type == 'checkpoint': - weights_paths = FLAGS.chkp_save_path + 'chkp_callback_' + run_id_name + '_' + FLAGS.saved_cycle - - elif FLAGS.saved_model_type == 'final': - model_save_file= FLAGS.base_path + FLAGS.model_folder - weights_paths = model_save_file + 'chkp_' + run_id_name + '_' + FLAGS.saved_cycle - - - ## Save output prints to logfile - old_stdout = sys.stdout - log_file = open(log_save_file + run_id_name + '-metrics_output.log', 'w') - sys.stdout = log_file - print('Starting the log file.') - - ## Check GPU and tensorflow version - device_name = tf.test.gpu_device_name() - print('Found GPU at: {}'.format(device_name)) - print('tf_version: ' + str(tf.__version__)) - - - ## Load datasets - train_dataset = np.load(FLAGS.dataset_folder + FLAGS.train_dataset_file, allow_pickle=True)[()] - # train_stars = train_dataset['stars'] - # noisy_train_stars = train_dataset['noisy_stars'] - # train_pos = train_dataset['positions'] - train_SEDs = train_dataset['SEDs'] - # train_zernike_coef = train_dataset['zernike_coef'] - train_C_poly = train_dataset['C_poly'] - train_parameters = train_dataset['parameters'] - - test_dataset = np.load(FLAGS.dataset_folder + FLAGS.test_dataset_file, allow_pickle=True)[()] - # test_stars = test_dataset['stars'] - # test_pos = test_dataset['positions'] - test_SEDs = test_dataset['SEDs'] - # test_zernike_coef = test_dataset['zernike_coef'] - - # Convert to tensor - tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) - tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - - print('Dataset parameters:') - print(train_parameters) - - - ## Prepare models - # Generate Zernike maps - zernikes = wf.utils.zernike_generator(n_zernikes=FLAGS.n_zernikes, wfe_dim=FLAGS.pupil_diameter) - # Now as cubes - np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - - for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - - np_zernike_cube[np.isnan(np_zernike_cube)] = 0 - tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - - # Prepare np input - simPSF_np = wf.SimPSFToolkit(zernikes, max_order=FLAGS.n_zernikes, - pupil_diameter=FLAGS.pupil_diameter, output_dim=FLAGS.output_dim, - oversampling_rate=FLAGS.oversampling_rate, output_Q=FLAGS.output_Q) - simPSF_np.gen_random_Z_coeffs(max_order=FLAGS.n_zernikes) - z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) - simPSF_np.set_z_coeffs(z_coeffs) - simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - - # Obscurations - obscurations = simPSF_np.generate_pupil_obscurations(N_pix=FLAGS.pupil_diameter, N_filter=2) - tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - - # Outputs (needed for the MCCD model) - outputs = tf_noisy_train_stars - - - ## Create the model - ## Select the model - if FLAGS.model == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=FLAGS.x_lims, - y_lims=FLAGS.y_lims, - d_max=FLAGS.d_max_nonparam, - graph_features=FLAGS.graph_features) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=FLAGS.batch_size, - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=FLAGS.output_Q, - d_max_nonparam=FLAGS.d_max_nonparam, - graph_features=FLAGS.graph_features, - l1_rate=FLAGS.l1_rate, - output_dim=FLAGS.output_dim, - n_zernikes=FLAGS.n_zernikes, - d_max=FLAGS.d_max, - x_lims=FLAGS.x_lims, - y_lims=FLAGS.y_lims) - - elif FLAGS.model == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=FLAGS.batch_size, - output_Q=FLAGS.output_Q, - d_max_nonparam=FLAGS.d_max_nonparam, - output_dim=FLAGS.output_dim, - n_zernikes=FLAGS.n_zernikes, - d_max=FLAGS.d_max, - x_lims=FLAGS.x_lims, - y_lims=FLAGS.y_lims) - - elif FLAGS.model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=FLAGS.batch_size, - output_Q=FLAGS.output_Q, - output_dim=FLAGS.output_dim, - n_zernikes=FLAGS.n_zernikes, - d_max=FLAGS.d_max, - x_lims=FLAGS.x_lims, - y_lims=FLAGS.y_lims) - - ## Load the model's weights - tf_semiparam_field.load_weights(weights_paths) - - ## Prepare ground truth model - # Generate Zernike maps - zernikes = wf.utils.zernike_generator(n_zernikes=FLAGS.GT_n_zernikes, wfe_dim=FLAGS.pupil_diameter) - # Now as cubes - np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - - np_zernike_cube[np.isnan(np_zernike_cube)] = 0 - tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - - # Initialize the model - GT_tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field( - zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=FLAGS.batch_size, - output_Q=FLAGS.output_Q, - d_max_nonparam=FLAGS.d_max_nonparam, - output_dim=FLAGS.output_dim, - n_zernikes=FLAGS.GT_n_zernikes, - d_max=FLAGS.d_max, - x_lims=FLAGS.x_lims, - y_lims=FLAGS.y_lims) - - # For the Ground truth model - GT_tf_semiparam_field.tf_poly_Z_field.assign_coeff_matrix(train_C_poly) - _ = GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat.assign( - np.zeros_like(GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat)) - - - ## Metric evaluation on the test dataset - print('\n***\nMetric evaluation on the test dataset\n***\n') - - # Polychromatic star reconstructions - rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - tf_SEDs=test_SEDs, - n_bins_lda=FLAGS.n_bins_lda, - batch_size=FLAGS.eval_batch_size) - - poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - - # Monochromatic star reconstructions - lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation - rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - lambda_list=lambda_list) - - mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - - # OPD metrics - rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_test_pos, - batch_size=FLAGS.eval_batch_size) - - opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - - # Shape metrics - shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=test_SEDs, - tf_pos=tf_test_pos, - n_bins_lda=FLAGS.n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=FLAGS.eval_batch_size) - - # Save metrics - test_metrics = {'poly_metric': poly_metric, - 'mono_metric': mono_metric, - 'opd_metric': opd_metric, - 'shape_results_dict': shape_results_dict - } - - - ## Metric evaluation on the train dataset - print('\n***\nMetric evaluation on the train dataset\n***\n') - - # Polychromatic star reconstructions - rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - tf_SEDs=train_SEDs, - n_bins_lda=FLAGS.n_bins_lda, - batch_size=FLAGS.eval_batch_size) - - train_poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - - # Monochromatic star reconstructions - lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation - rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - lambda_list=lambda_list) - - train_mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - - # OPD metrics - rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_train_pos, - batch_size=FLAGS.eval_batch_size) - - train_opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - - # Shape metrics - train_shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=train_SEDs, - tf_pos=tf_train_pos, - n_bins_lda=FLAGS.n_bins_lda, - output_Q=1, - output_dim=64, - batch_size=FLAGS.eval_batch_size) - - # Save metrics into dictionary - train_metrics = {'poly_metric': train_poly_metric, - 'mono_metric': train_mono_metric, - 'opd_metric': train_opd_metric, - 'shape_results_dict': train_shape_results_dict - } - - - ## Save results - metrics = {'test_metrics': test_metrics, - 'train_metrics': train_metrics - } - output_path = FLAGS.metric_base_path + 'metrics-' + run_id_name - np.save(output_path, metrics, allow_pickle=True) - - ## Print final time - final_time = time.time() - print('\nTotal elapsed time: %f'%(final_time - starting_time)) - - - ## Close log file - print('\n Good bye..') - sys.stdout = old_stdout - log_file.close() - - - -def main(_): - train_model() - evaluate_model() - -if __name__ == "__main__": - app.run(main) diff --git a/jz-submissions/scripts/train_eval_poly_200_click.py b/jz-submissions/scripts/train_eval_poly_200_click.py deleted file mode 100644 index 42667a91..00000000 --- a/jz-submissions/scripts/train_eval_poly_200_click.py +++ /dev/null @@ -1,843 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -# PSF modelling and evaluation - -# Import packages -import sys -import numpy as np -import time -import wf_psf as wf -import tensorflow as tf -import tensorflow_addons as tfa - -import click - -# from absl import app -# from absl import flags - -@click.command() - -@click.command() - -## Training options -# Model definition -@click.option( - "--model", - default="poly", - type=str, - help="Model type. Options are: 'mccd', 'poly, 'param'.") -@click.option( - "--id_name", - default="-coherent_euclid_200stars", - type=str, - help="Model saving id.") -# Saving paths -@click.option( - "--base_path", - default="/gpfswork/rech/xdy/ulx23va/wf-outputs/", - type=str, - help="Base path for saving files.") -@click.option( - "--log_folder", - default="log-files/", - type=str, - help="Folder name to save log files.") -@click.option( - "--model_folder", - default="chkp/", - type=str, - help="Folder name to save trained models.") -@click.option( - "--optim_hist_folder", - default="optim-hist/", - type=str, - help="Folder name to save optimisation history files.") -@click.option( - "--chkp_save_path", - default="/gpfsscratch/rech/xdy/ulx23va/wf-outputs/chkp/", - type=str, - help="Path to save model checkpoints during training.") -# Input dataset paths -@click.option( - "--dataset_folder", - default="/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/", - type=str, - help="Folder path of datasets.") -@click.option( - "--train_dataset_file", - default="train_Euclid_res_200_TrainStars_id_001.npy", - type=str, - help="Train dataset file name.") -@click.option( - "--test_dataset_file", - default="test_Euclid_res_id_001.npy", - type=str, - help="Test dataset file name.") -# Model parameters -@click.option( - "--n_zernikes", - default=15, - type=int, - help="Zernike polynomial modes to use on the parametric part.") -@click.option( - "--pupil_diameter", - default=256, - type=int, - help="Dimension of the OPD/Wavefront space.") -@click.option( - "--n_bins_lda", - default=20, - type=int, - help="Number of wavelength bins to use to reconstruct polychromatic objects.") -@click.option( - "--output_q", - default=3., - type=float, - help="Downsampling rate to match the specified telescope's sampling from the oversampling rate used in the model.") -@click.option( - "--oversampling_rate", - default=3., - type=float, - help="Oversampling rate used for the OPD/WFE PSF model.") -@click.option( - "--output_dim", - default=32, - type=int, - help="Dimension of the pixel PSF postage stamp.") -@click.option( - "--d_max", - default=2, - type=int, - help="Max polynomial degree of the parametric part.") -@click.option( - "--d_max_nonparam", - default=3, - type=int, - help="Max polynomial degree of the non-parametric part.") -@click.option( - "--x_lims", - nargs=2, - default=[0, 1e3], - type=float, - help="Limits of the PSF field coordinates for the x axis.") -@click.option( - "--y_lims", - nargs=2, - default=[0, 1e3], - type=float, - help="Limits of the PSF field coordinates for the y axis.") -@click.option( - "--graph_features", - default=10, - type=int, - help="Number of graph-constrained features of the non-parametric part.") -@click.option( - "--l1_rate", - default=1e-8, - type=float, - help="L1 regularisation parameter for the non-parametric part.") -# Training parameters -@click.option( - "--batch_size", - default=32, - type=int, - help="Batch size used for the trainingin the stochastic gradient descend type of algorithm.") -@click.option( - "--l_rate_param", - nargs=2, - default=[1e-2, 1e-2], - type=float, - help="Learning rates for the parametric parts.") -@click.option( - "--l_rate_non_param", - nargs=2, - default=[1e-1, 1e-1], - type=float, - help="Learning rates for the non-parametric parts.") -@click.option( - "--n_epochs_param", - nargs=2, - default=[20, 20], - type=int, - help="Number of training epochs of the parametric parts.") -@click.option( - "--n_epochs_non_param", - nargs=2, - default=[100, 120], - type=int, - help="Number of training epochs of the non-parametric parts.") -@click.option( - "--total_cycles", - default=2, - type=int, - help="Total amount of cycles to perform. For the moment the only available options are '1' or '2'.") -## Evaluation flags -# Saving paths -@click.option( - "--metric_base_path", - default="/gpfswork/rech/xdy/ulx23va/wf-outputs/metrics/", - type=str, - help="Base path for saving metric files.") -@click.option( - "--saved_model_type", - default="final", - type=str, - help="Type of saved model to use for the evaluation. Can be 'final' or 'checkpoint'.") -@click.option( - "--saved_cycle", - default="cycle2", - type=str, - help="Saved cycle to use for the evaluation. Can be 'cycle1' or 'cycle2'.") -# Evaluation parameters -@click.option( - "--gt_n_zernikes", - default=45, - type=int, - help="Zernike polynomial modes to use on the ground truth model parametric part.") -@click.option( - "--eval_batch_size", - default=16, - type=int, - help="Batch size to use for the evaluation.") - -def main(**args): - train_model(**args) - evaluate_model(**args) - - -def train_model(**args): - """ Train the model defined in the """ - # Start measuring elapsed time - starting_time = time.time() - - # Define model run id - run_id_name = args['model'] + args['id_name'] - - # Define paths - log_save_file = args['base_path'] + args['log_folder'] - model_save_file= args['base_path'] + args['model_folder'] - optim_hist_file = args['base_path'] + args['optim_hist_folder'] - saving_optim_hist = dict() - - - # Save output prints to logfile - old_stdout = sys.stdout - log_file = open(log_save_file + run_id_name + '_output.log','w') - sys.stdout = log_file - print('Starting the log file.') - - # Print GPU and tensorflow info - device_name = tf.test.gpu_device_name() - print('Found GPU at: {}'.format(device_name)) - print('tf_version: ' + str(tf.__version__)) - - ## Prepare the inputs - # Generate Zernike maps - zernikes = wf.utils.zernike_generator(n_zernikes=args['n_zernikes'], wfe_dim=args['pupil_diameter']) - # Now as cubes - np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - np_zernike_cube[np.isnan(np_zernike_cube)] = 0 - tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - print('Zernike cube:') - print(tf_zernike_cube.shape) - - - ## Load the dictionaries - train_dataset = np.load(args['dataset_folder'] + args['train_dataset_file'], allow_pickle=True)[()] - # train_stars = train_dataset['stars'] - # noisy_train_stars = train_dataset['noisy_stars'] - # train_pos = train_dataset['positions'] - train_SEDs = train_dataset['SEDs'] - # train_zernike_coef = train_dataset['zernike_coef'] - train_C_poly = train_dataset['C_poly'] - train_parameters = train_dataset['parameters'] - - test_dataset = np.load(args['dataset_folder'] + args['test_dataset_file'], allow_pickle=True)[()] - # test_stars = test_dataset['stars'] - # test_pos = test_dataset['positions'] - test_SEDs = test_dataset['SEDs'] - # test_zernike_coef = test_dataset['zernike_coef'] - - # Convert to tensor - tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) - tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) - tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) - tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - - print('Dataset parameters:') - print(train_parameters) - - - ## Generate initializations - # Prepare np input - simPSF_np = wf.SimPSFToolkit(zernikes, max_order=args['n_zernikes'], - pupil_diameter=args['pupil_diameter'], output_dim=args['output_dim'], - oversampling_rate=args['oversampling_rate'], output_Q=args['output_q']) - simPSF_np.gen_random_Z_coeffs(max_order=args['n_zernikes']) - z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) - simPSF_np.set_z_coeffs(z_coeffs) - simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - # Obscurations - obscurations = simPSF_np.generate_pupil_obscurations(N_pix=args['pupil_diameter'], N_filter=2) - tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - # Initialize the SED data list - packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=args['n_bins_lda']) - for _sed in train_SEDs] - - - # Prepare the inputs for the training - tf_packed_SED_data = tf.convert_to_tensor(packed_SED_data, dtype=tf.float32) - tf_packed_SED_data = tf.transpose(tf_packed_SED_data, perm=[0, 2, 1]) - - inputs = [tf_train_pos, tf_packed_SED_data] - - # Select the observed stars (noisy or noiseless) - outputs = tf_noisy_train_stars - # outputs = tf_train_stars - - - ## Prepare validation data inputs - val_SEDs = test_SEDs - tf_val_pos = tf_test_pos - tf_val_stars = tf_test_stars - - # Initialize the SED data list - val_packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=args['n_bins_lda']) - for _sed in val_SEDs] - - # Prepare the inputs for the validation - tf_val_packed_SED_data = tf.convert_to_tensor(val_packed_SED_data, dtype=tf.float32) - tf_val_packed_SED_data = tf.transpose(tf_val_packed_SED_data, perm=[0, 2, 1]) - - # Prepare input validation tuple - val_x_inputs = [tf_val_pos, tf_val_packed_SED_data] - val_y_inputs = tf_val_stars - val_data = (val_x_inputs, val_y_inputs) - - - ## Select the model - if args['model'] == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=args['x_lims'], - y_lims=args['y_lims'], - d_max=args['d_max_nonparam'], - graph_features=args['graph_features']) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=args['batch_size'], - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=args['output_q'], - d_max_nonparam=args['d_max_nonparam'], - graph_features=args['graph_features'], - l1_rate=args['l1_rate'], - output_dim=args['output_dim'], - n_zernikes=args['n_zernikes'], - d_max=args['d_max'], - x_lims=args['x_lims'], - y_lims=args['y_lims']) - - elif args['model'] == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=args['batch_size'], - output_Q=args['output_q'], - d_max_nonparam=args['d_max_nonparam'], - output_dim=args['output_dim'], - n_zernikes=args['n_zernikes'], - d_max=args['d_max'], - x_lims=args['x_lims'], - y_lims=args['y_lims']) - - elif args['model'] == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=args['batch_size'], - output_Q=args['output_q'], - output_dim=args['output_dim'], - n_zernikes=args['n_zernikes'], - d_max=args['d_max'], - x_lims=args['x_lims'], - y_lims=args['y_lims']) - - - # # Model Training - # Prepare the saving callback - # Prepare to save the model as a callback - filepath_chkp_callback = args['chkp_save_path'] + 'chkp_callback_' + run_id_name + '_cycle1' - model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - - # Prepare the optimisers - param_optim = tfa.optimizers.RectifiedAdam(lr=args['l_rate_param'][0]) - non_param_optim = tfa.optimizers.RectifiedAdam(lr=args['l_rate_non_param'][0]) - - print('Starting cycle 1..') - start_cycle1 = time.time() - - if args['model'] == 'param': - tf_semiparam_field, hist_param = wf.train_utils.param_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=args['batch_size'], - l_rate=args['l_rate_param'][0], - n_epochs=args['n_epochs_param'][0], - param_optim=param_optim, - param_loss=None, - param_metrics=None, - param_callback=None, - general_callback=[model_chkp_callback], - verbose=2) - - else: - tf_semiparam_field, hist_param, hist_non_param = wf.train_utils.general_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=args['batch_size'], - l_rate_param=args['l_rate_param'][0], - l_rate_non_param=args['l_rate_non_param'][0], - n_epochs_param=args['n_epochs_param'][0], - n_epochs_non_param=args['n_epochs_non_param'][0], - param_optim=param_optim, - non_param_optim=non_param_optim, - param_loss=None, non_param_loss=None, - param_metrics=None, non_param_metrics=None, - param_callback=None, non_param_callback=None, - general_callback=[model_chkp_callback], - first_run=True, - verbose=2) - - # Save weights - tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle1') - - end_cycle1 = time.time() - print('Cycle1 elapsed time: %f'%(end_cycle1-start_cycle1)) - - # Save optimisation history in the saving dict - saving_optim_hist['param_cycle1'] = hist_param.history - if args['model'] != 'param': - saving_optim_hist['nonparam_cycle1'] = hist_non_param.history - - if args['total_cycles'] >= 2: - # Prepare to save the model as a callback - filepath_chkp_callback = args['chkp_save_path'] + 'chkp_callback_' + run_id_name + '_cycle2' - model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - - # Prepare the optimisers - param_optim = tfa.optimizers.RectifiedAdam(lr=args['l_rate_param'][1]) - non_param_optim = tfa.optimizers.RectifiedAdam(lr=args['l_rate_non_param'][1]) - - print('Starting cycle 2..') - start_cycle2 = time.time() - - - # Compute the next cycle - if args['model'] == 'param': - tf_semiparam_field, hist_param_2 = wf.train_utils.param_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=args['batch_size'], - l_rate=args['l_rate_param'][1], - n_epochs=args['n_epochs_param'][1], - param_optim=param_optim, - param_loss=None, - param_metrics=None, - param_callback=None, - general_callback=[model_chkp_callback], - verbose=2) - else: - # Compute the next cycle - tf_semiparam_field, hist_param_2, hist_non_param_2 = wf.train_utils.general_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=args['batch_size'], - l_rate_param=args['l_rate_param'][1], - l_rate_non_param=args['l_rate_non_param'][1], - n_epochs_param=args['n_epochs_param'][1], - n_epochs_non_param=args['n_epochs_non_param'][1], - param_optim=param_optim, - non_param_optim=non_param_optim, - param_loss=None, non_param_loss=None, - param_metrics=None, non_param_metrics=None, - param_callback=None, non_param_callback=None, - general_callback=[model_chkp_callback], - first_run=False, - verbose=2) - - # Save the weights at the end of the second cycle - tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle2') - - end_cycle2 = time.time() - print('Cycle2 elapsed time: %f'%(end_cycle2 - start_cycle2)) - - # Save optimisation history in the saving dict - saving_optim_hist['param_cycle2'] = hist_param_2.history - if args['model'] != 'param': - saving_optim_hist['nonparam_cycle2'] = hist_non_param_2.history - - # Save optimisation history dictionary - np.save(optim_hist_file + 'optim_hist_' + run_id_name + '.npy', saving_optim_hist) - - ## Print final time - final_time = time.time() - print('\nTotal elapsed time: %f'%(final_time - starting_time)) - - ## Close log file - print('\n Good bye..') - sys.stdout = old_stdout - log_file.close() - - -def evaluate_model(**args): - """ Evaluate the trained model.""" - # Start measuring elapsed time - starting_time = time.time() - - # Define model run id - run_id_name = args['model'] + args['id_name'] - # Define paths - log_save_file = args['base_path'] + args['log_folder'] - - # Define saved model to use - if args['saved_model_type'] == 'checkpoint': - weights_paths = args['chkp_save_path'] + 'chkp_callback_' + run_id_name + '_' + args['saved_cycle'] - - elif args['saved_model_type'] == 'final': - model_save_file= args['base_path'] + args['model_folder'] - weights_paths = model_save_file + 'chkp_' + run_id_name + '_' + args['saved_cycle'] - - - ## Save output prints to logfile - old_stdout = sys.stdout - log_file = open(log_save_file + run_id_name + '-metrics_output.log', 'w') - sys.stdout = log_file - print('Starting the log file.') - - ## Check GPU and tensorflow version - device_name = tf.test.gpu_device_name() - print('Found GPU at: {}'.format(device_name)) - print('tf_version: ' + str(tf.__version__)) - - - ## Load datasets - train_dataset = np.load(args['dataset_folder'] + args['train_dataset_file'], allow_pickle=True)[()] - # train_stars = train_dataset['stars'] - # noisy_train_stars = train_dataset['noisy_stars'] - # train_pos = train_dataset['positions'] - train_SEDs = train_dataset['SEDs'] - # train_zernike_coef = train_dataset['zernike_coef'] - train_C_poly = train_dataset['C_poly'] - train_parameters = train_dataset['parameters'] - - test_dataset = np.load(args['dataset_folder'] + args['test_dataset_file'], allow_pickle=True)[()] - # test_stars = test_dataset['stars'] - # test_pos = test_dataset['positions'] - test_SEDs = test_dataset['SEDs'] - # test_zernike_coef = test_dataset['zernike_coef'] - - # Convert to tensor - tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) - tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - - print('Dataset parameters:') - print(train_parameters) - - - ## Prepare models - # Generate Zernike maps - zernikes = wf.utils.zernike_generator(n_zernikes=args['n_zernikes'], wfe_dim=args['pupil_diameter']) - # Now as cubes - np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - - for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - - np_zernike_cube[np.isnan(np_zernike_cube)] = 0 - tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - - # Prepare np input - simPSF_np = wf.SimPSFToolkit(zernikes, max_order=args['n_zernikes'], - pupil_diameter=args['pupil_diameter'], output_dim=args['output_dim'], - oversampling_rate=args['oversampling_rate'], output_Q=args['output_q']) - simPSF_np.gen_random_Z_coeffs(max_order=args['n_zernikes']) - z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) - simPSF_np.set_z_coeffs(z_coeffs) - simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - - # Obscurations - obscurations = simPSF_np.generate_pupil_obscurations(N_pix=args['pupil_diameter'], N_filter=2) - tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - - # Outputs (needed for the MCCD model) - outputs = tf_noisy_train_stars - - - ## Create the model - ## Select the model - if args['model'] == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=args['x_lims'], - y_lims=args['y_lims'], - d_max=args['d_max_nonparam'], - graph_features=args['graph_features']) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=args['batch_size'], - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=args['output_q'], - d_max_nonparam=args['d_max_nonparam'], - graph_features=args['graph_features'], - l1_rate=args['l1_rate'], - output_dim=args['output_dim'], - n_zernikes=args['n_zernikes'], - d_max=args['d_max'], - x_lims=args['x_lims'], - y_lims=args['y_lims']) - - elif args['model'] == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=args['batch_size'], - output_Q=args['output_q'], - d_max_nonparam=args['d_max_nonparam'], - output_dim=args['output_dim'], - n_zernikes=args['n_zernikes'], - d_max=args['d_max'], - x_lims=args['x_lims'], - y_lims=args['y_lims']) - - elif args['model'] == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=args['batch_size'], - output_Q=args['output_q'], - output_dim=args['output_dim'], - n_zernikes=args['n_zernikes'], - d_max=args['d_max'], - x_lims=args['x_lims'], - y_lims=args['y_lims']) - - ## Load the model's weights - tf_semiparam_field.load_weights(weights_paths) - - ## Prepare ground truth model - # Generate Zernike maps - zernikes = wf.utils.zernike_generator(n_zernikes=args['gt_n_zernikes'], wfe_dim=args['pupil_diameter']) - # Now as cubes - np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - - np_zernike_cube[np.isnan(np_zernike_cube)] = 0 - tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - - # Initialize the model - GT_tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field( - zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=args['batch_size'], - output_Q=args['output_q'], - d_max_nonparam=args['d_max_nonparam'], - output_dim=args['output_dim'], - n_zernikes=args['gt_n_zernikes'], - d_max=args['d_max'], - x_lims=args['x_lims'], - y_lims=args['y_lims']) - - # For the Ground truth model - GT_tf_semiparam_field.tf_poly_Z_field.assign_coeff_matrix(train_C_poly) - _ = GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat.assign( - np.zeros_like(GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat)) - - - ## Metric evaluation on the test dataset - print('\n***\nMetric evaluation on the test dataset\n***\n') - - # Polychromatic star reconstructions - rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - tf_SEDs=test_SEDs, - n_bins_lda=args['n_bins_lda'], - batch_size=args['eval_batch_size']) - - poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - - # Monochromatic star reconstructions - lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation - rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - lambda_list=lambda_list) - - mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - - # OPD metrics - rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_test_pos, - batch_size=args['eval_batch_size']) - - opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - - # Shape metrics - shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=test_SEDs, - tf_pos=tf_test_pos, - n_bins_lda=args['n_bins_lda'], - output_Q=1, - output_dim=64, - batch_size=args['eval_batch_size']) - - # Save metrics - test_metrics = {'poly_metric': poly_metric, - 'mono_metric': mono_metric, - 'opd_metric': opd_metric, - 'shape_results_dict': shape_results_dict - } - - - ## Metric evaluation on the train dataset - print('\n***\nMetric evaluation on the train dataset\n***\n') - - # Polychromatic star reconstructions - rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - tf_SEDs=train_SEDs, - n_bins_lda=args['n_bins_lda'], - batch_size=args['eval_batch_size']) - - train_poly_metric = {'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - - # Monochromatic star reconstructions - lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation - rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - lambda_list=lambda_list) - - train_mono_metric = {'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - - # OPD metrics - rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_train_pos, - batch_size=args['eval_batch_size']) - - train_opd_metric = { 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - - # Shape metrics - train_shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=train_SEDs, - tf_pos=tf_train_pos, - n_bins_lda=args['n_bins_lda'], - output_Q=1, - output_dim=64, - batch_size=args['eval_batch_size']) - - # Save metrics into dictionary - train_metrics = {'poly_metric': train_poly_metric, - 'mono_metric': train_mono_metric, - 'opd_metric': train_opd_metric, - 'shape_results_dict': train_shape_results_dict - } - - - ## Save results - metrics = {'test_metrics': test_metrics, - 'train_metrics': train_metrics - } - output_path = args['metric_base_path'] + 'metrics-' + run_id_name - np.save(output_path, metrics, allow_pickle=True) - - ## Print final time - final_time = time.time() - print('\nTotal elapsed time: %f'%(final_time - starting_time)) - - - ## Close log file - print('\n Good bye..') - sys.stdout = old_stdout - log_file.close() - - - -if __name__ == "__main__": - main() - diff --git a/jz-submissions/scripts/training_mccd_1000.py b/jz-submissions/scripts/training_mccd_1000.py deleted file mode 100644 index b3ccb7bf..00000000 --- a/jz-submissions/scripts/training_mccd_1000.py +++ /dev/null @@ -1,345 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -# # PSF modelling - - -#@title Import packages -import sys -import numpy as np -import time - -# Import wavefront code -import wf_psf as wf -import tensorflow as tf -import tensorflow_addons as tfa - -# Start measuring elapsed time -starting_time = time.time() - -# # Define saving paths -model = 'mccd' -# model = 'poly' -# model = 'param' - -id_name = '-coherent_euclid_1000stars' -run_id_name = model + id_name - -# Saving paths -base_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/' -log_save_file = base_path + 'log-files/' -model_save_file= base_path + 'chkp/' -optim_hist_file = base_path + 'optim-hist/' -saving_optim_hist = dict() - -chkp_save_file = '/gpfsscratch/rech/xdy/ulx23va/wf-outputs/chkp/' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_1000_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '_output.log','w') -sys.stdout = log_file -print('Starting the log file.') - -# Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - -# # Define new model - -# Decimation factor for Zernike polynomials -n_zernikes = 15 - -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 3 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - -# Learning rates and number of epochs -l_rate_param = [1e-2, 1e-2] -l_rate_non_param = [1e-1, 1e-1] - -n_epochs_param = [20, 20] -n_epochs_non_param = [100, 120] - - -## Prepare the inputs - -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) - -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -print('Zernike cube:') -print(tf_zernike_cube.shape) - - -## Load the dictionaries -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Generate initializations - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Initialize the SED data list -packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in train_SEDs] - - -# Prepare the inputs for the training -tf_packed_SED_data = tf.convert_to_tensor(packed_SED_data, dtype=tf.float32) -tf_packed_SED_data = tf.transpose(tf_packed_SED_data, perm=[0, 2, 1]) - -inputs = [tf_train_pos, tf_packed_SED_data] - -# Select the observed stars (noisy or noiseless) -outputs = tf_noisy_train_stars -# outputs = tf_train_stars - - -## Prepare validation data inputs - -# Let's take a subset of the testing data for the validation -# in order to test things faster -val_SEDs = test_SEDs # [0:50, :, :] -tf_val_pos = tf_test_pos # [0:50, :] -tf_val_stars = tf_test_stars # [0:50, :, :] - -# Initialize the SED data list -val_packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in val_SEDs] - -# Prepare the inputs for the validation -tf_val_packed_SED_data = tf.convert_to_tensor(val_packed_SED_data, dtype=tf.float32) -tf_val_packed_SED_data = tf.transpose(tf_val_packed_SED_data, perm=[0, 2, 1]) - -# Prepare input validation tuple -val_x_inputs = [tf_val_pos, tf_val_packed_SED_data] -val_y_inputs = tf_val_stars -val_data = (val_x_inputs, val_y_inputs) - - -## Select the model -if model == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=x_lims, - y_lims=y_lims, - d_max=d_max_nonparam, - graph_features=graph_features) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - graph_features=graph_features, - l1_rate=l1_rate, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - - - -# # Model Training - -# Prepare the saving callback -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle1' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[0]) -non_param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_non_param[0]) - -print('Starting cycle 1..') -start_cycle1 = time.time() - -tf_semiparam_field, hist_param, hist_non_param = wf.train_utils.general_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate_param=l_rate_param[0], - l_rate_non_param=l_rate_non_param[0], - n_epochs_param=n_epochs_param[0], - n_epochs_non_param=n_epochs_non_param[0], - param_optim=param_optim, - non_param_optim=non_param_optim, - param_loss=None, non_param_loss=None, - param_metrics=None, non_param_metrics=None, - param_callback=None, non_param_callback=None, - general_callback=[model_chkp_callback], - first_run=True, - verbose=2) - -# Save weights -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle1') - -end_cycle1 = time.time() -print('Cycle1 elapsed time: %f'%(end_cycle1-start_cycle1)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle1'] = hist_param.history -saving_optim_hist['nonparam_cycle1'] = hist_non_param.history - - - - -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle2' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[1]) -non_param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_non_param[1]) - -print('Starting cycle 2..') -start_cycle2 = time.time() - -# Compute the next cycle -tf_semiparam_field, hist_param_2, hist_non_param_2 = wf.train_utils.general_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate_param=l_rate_param[1], - l_rate_non_param=l_rate_non_param[1], - n_epochs_param=n_epochs_param[1], - n_epochs_non_param=n_epochs_non_param[1], - param_optim=param_optim, - non_param_optim=non_param_optim, - param_loss=None, non_param_loss=None, - param_metrics=None, non_param_metrics=None, - param_callback=None, non_param_callback=None, - general_callback=[model_chkp_callback], - first_run=False, - verbose=2) - -# Save the weights at the end of the second cycle -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle2') - -end_cycle2 = time.time() -print('Cycle2 elapsed time: %f'%(end_cycle2 - start_cycle2)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle2'] = hist_param_2.history -saving_optim_hist['nonparam_cycle2'] = hist_non_param_2.history - -# Save optimisation history dictionary -np.save(optim_hist_file + 'optim_hist_' + run_id_name + '.npy', saving_optim_hist) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() diff --git a/jz-submissions/scripts/training_mccd_200.py b/jz-submissions/scripts/training_mccd_200.py deleted file mode 100644 index b601c7ed..00000000 --- a/jz-submissions/scripts/training_mccd_200.py +++ /dev/null @@ -1,346 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -# # PSF modelling - - -#@title Import packages -import sys -import numpy as np -import time - -# Import wavefront code -import wf_psf as wf -import tensorflow as tf -import tensorflow_addons as tfa - -# Start measuring elapsed time -starting_time = time.time() - -# # Define saving paths -model = 'mccd' -# model = 'poly' -# model = 'param' - -id_name = '-coherent_euclid_200stars' -run_id_name = model + id_name - -# Saving paths -base_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/' -log_save_file = base_path + 'log-files/' -model_save_file= base_path + 'chkp/' -optim_hist_file = base_path + 'optim-hist/' -saving_optim_hist = dict() - -chkp_save_file = '/gpfsscratch/rech/xdy/ulx23va/wf-outputs/chkp/' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_200_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '_output.log','w') -sys.stdout = log_file -print('Starting the log file.') - -# Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - -# # Define new model - -# Decimation factor for Zernike polynomials -n_zernikes = 15 - -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 3 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - -# Learning rates and number of epochs -l_rate_param = [1e-2, 1e-2] -l_rate_non_param = [1e-1, 1e-1] - -n_epochs_param = [20, 20] -n_epochs_non_param = [100, 120] - - -## Prepare the inputs - -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) - -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 - -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -print('Zernike cube:') -print(tf_zernike_cube.shape) - - -## Load the dictionaries -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Generate initializations - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Initialize the SED data list -packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in train_SEDs] - - -# Prepare the inputs for the training -tf_packed_SED_data = tf.convert_to_tensor(packed_SED_data, dtype=tf.float32) -tf_packed_SED_data = tf.transpose(tf_packed_SED_data, perm=[0, 2, 1]) - -inputs = [tf_train_pos, tf_packed_SED_data] - -# Select the observed stars (noisy or noiseless) -outputs = tf_noisy_train_stars -# outputs = tf_train_stars - - -## Prepare validation data inputs - -# Let's take a subset of the testing data for the validation -# in order to test things faster -val_SEDs = test_SEDs # [0:50, :, :] -tf_val_pos = tf_test_pos # [0:50, :] -tf_val_stars = tf_test_stars # [0:50, :, :] - -# Initialize the SED data list -val_packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in val_SEDs] - -# Prepare the inputs for the validation -tf_val_packed_SED_data = tf.convert_to_tensor(val_packed_SED_data, dtype=tf.float32) -tf_val_packed_SED_data = tf.transpose(tf_val_packed_SED_data, perm=[0, 2, 1]) - -# Prepare input validation tuple -val_x_inputs = [tf_val_pos, tf_val_packed_SED_data] -val_y_inputs = tf_val_stars -val_data = (val_x_inputs, val_y_inputs) - - -## Select the model -if model == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=x_lims, - y_lims=y_lims, - d_max=d_max_nonparam, - graph_features=graph_features) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - graph_features=graph_features, - l1_rate=l1_rate, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - - - -# # Model Training - -# Prepare the saving callback -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle1' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[0]) -non_param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_non_param[0]) - -print('Starting cycle 1..') -start_cycle1 = time.time() - -tf_semiparam_field, hist_param, hist_non_param = wf.train_utils.general_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate_param=l_rate_param[0], - l_rate_non_param=l_rate_non_param[0], - n_epochs_param=n_epochs_param[0], - n_epochs_non_param=n_epochs_non_param[0], - param_optim=param_optim, - non_param_optim=non_param_optim, - param_loss=None, non_param_loss=None, - param_metrics=None, non_param_metrics=None, - param_callback=None, non_param_callback=None, - general_callback=[model_chkp_callback], - first_run=True, - verbose=2) - -# Save weights -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle1') - -end_cycle1 = time.time() -print('Cycle1 elapsed time: %f'%(end_cycle1-start_cycle1)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle1'] = hist_param.history -saving_optim_hist['nonparam_cycle1'] = hist_non_param.history - - - - -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle2' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[1]) -non_param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_non_param[1]) - -print('Starting cycle 2..') -start_cycle2 = time.time() - -# Compute the next cycle -tf_semiparam_field, hist_param_2, hist_non_param_2 = wf.train_utils.general_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate_param=l_rate_param[1], - l_rate_non_param=l_rate_non_param[1], - n_epochs_param=n_epochs_param[1], - n_epochs_non_param=n_epochs_non_param[1], - param_optim=param_optim, - non_param_optim=non_param_optim, - param_loss=None, non_param_loss=None, - param_metrics=None, non_param_metrics=None, - param_callback=None, non_param_callback=None, - general_callback=[model_chkp_callback], - first_run=False, - verbose=2) - -# Save the weights at the end of the second cycle -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle2') - -end_cycle2 = time.time() -print('Cycle2 elapsed time: %f'%(end_cycle2 - start_cycle2)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle2'] = hist_param_2.history -saving_optim_hist['nonparam_cycle2'] = hist_non_param_2.history - -# Save optimisation history dictionary -np.save(optim_hist_file + 'optim_hist_' + run_id_name + '.npy', saving_optim_hist) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() diff --git a/jz-submissions/scripts/training_mccd_2000.py b/jz-submissions/scripts/training_mccd_2000.py deleted file mode 100644 index affeb8ea..00000000 --- a/jz-submissions/scripts/training_mccd_2000.py +++ /dev/null @@ -1,345 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -# # PSF modelling - - -#@title Import packages -import sys -import numpy as np -import time - -# Import wavefront code -import wf_psf as wf -import tensorflow as tf -import tensorflow_addons as tfa - -# Start measuring elapsed time -starting_time = time.time() - -# # Define saving paths -model = 'mccd' -# model = 'poly' -# model = 'param' - -id_name = '-coherent_euclid_2000stars' -run_id_name = model + id_name - -# Saving paths -base_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/' -log_save_file = base_path + 'log-files/' -model_save_file= base_path + 'chkp/' -optim_hist_file = base_path + 'optim-hist/' -saving_optim_hist = dict() - -chkp_save_file = '/gpfsscratch/rech/xdy/ulx23va/wf-outputs/chkp/' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_2000_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '_output.log','w') -sys.stdout = log_file -print('Starting the log file.') - -# Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - -# # Define new model - -# Decimation factor for Zernike polynomials -n_zernikes = 15 - -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 3 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - -# Learning rates and number of epochs -l_rate_param = [1e-2, 1e-2] -l_rate_non_param = [1e-1, 1e-1] - -n_epochs_param = [20, 20] -n_epochs_non_param = [100, 120] - - -## Prepare the inputs - -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) - -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -print('Zernike cube:') -print(tf_zernike_cube.shape) - - -## Load the dictionaries -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Generate initializations - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Initialize the SED data list -packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in train_SEDs] - - -# Prepare the inputs for the training -tf_packed_SED_data = tf.convert_to_tensor(packed_SED_data, dtype=tf.float32) -tf_packed_SED_data = tf.transpose(tf_packed_SED_data, perm=[0, 2, 1]) - -inputs = [tf_train_pos, tf_packed_SED_data] - -# Select the observed stars (noisy or noiseless) -outputs = tf_noisy_train_stars -# outputs = tf_train_stars - - -## Prepare validation data inputs - -# Let's take a subset of the testing data for the validation -# in order to test things faster -val_SEDs = test_SEDs # [0:50, :, :] -tf_val_pos = tf_test_pos # [0:50, :] -tf_val_stars = tf_test_stars # [0:50, :, :] - -# Initialize the SED data list -val_packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in val_SEDs] - -# Prepare the inputs for the validation -tf_val_packed_SED_data = tf.convert_to_tensor(val_packed_SED_data, dtype=tf.float32) -tf_val_packed_SED_data = tf.transpose(tf_val_packed_SED_data, perm=[0, 2, 1]) - -# Prepare input validation tuple -val_x_inputs = [tf_val_pos, tf_val_packed_SED_data] -val_y_inputs = tf_val_stars -val_data = (val_x_inputs, val_y_inputs) - - -## Select the model -if model == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=x_lims, - y_lims=y_lims, - d_max=d_max_nonparam, - graph_features=graph_features) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - graph_features=graph_features, - l1_rate=l1_rate, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - - - -# # Model Training - -# Prepare the saving callback -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle1' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[0]) -non_param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_non_param[0]) - -print('Starting cycle 1..') -start_cycle1 = time.time() - -tf_semiparam_field, hist_param, hist_non_param = wf.train_utils.general_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate_param=l_rate_param[0], - l_rate_non_param=l_rate_non_param[0], - n_epochs_param=n_epochs_param[0], - n_epochs_non_param=n_epochs_non_param[0], - param_optim=param_optim, - non_param_optim=non_param_optim, - param_loss=None, non_param_loss=None, - param_metrics=None, non_param_metrics=None, - param_callback=None, non_param_callback=None, - general_callback=[model_chkp_callback], - first_run=True, - verbose=2) - -# Save weights -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle1') - -end_cycle1 = time.time() -print('Cycle1 elapsed time: %f'%(end_cycle1-start_cycle1)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle1'] = hist_param.history -saving_optim_hist['nonparam_cycle1'] = hist_non_param.history - - - - -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle2' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[1]) -non_param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_non_param[1]) - -print('Starting cycle 2..') -start_cycle2 = time.time() - -# Compute the next cycle -tf_semiparam_field, hist_param_2, hist_non_param_2 = wf.train_utils.general_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate_param=l_rate_param[1], - l_rate_non_param=l_rate_non_param[1], - n_epochs_param=n_epochs_param[1], - n_epochs_non_param=n_epochs_non_param[1], - param_optim=param_optim, - non_param_optim=non_param_optim, - param_loss=None, non_param_loss=None, - param_metrics=None, non_param_metrics=None, - param_callback=None, non_param_callback=None, - general_callback=[model_chkp_callback], - first_run=False, - verbose=2) - -# Save the weights at the end of the second cycle -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle2') - -end_cycle2 = time.time() -print('Cycle2 elapsed time: %f'%(end_cycle2 - start_cycle2)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle2'] = hist_param_2.history -saving_optim_hist['nonparam_cycle2'] = hist_non_param_2.history - -# Save optimisation history dictionary -np.save(optim_hist_file + 'optim_hist_' + run_id_name + '.npy', saving_optim_hist) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() diff --git a/jz-submissions/scripts/training_mccd_500.py b/jz-submissions/scripts/training_mccd_500.py deleted file mode 100644 index 7354a66e..00000000 --- a/jz-submissions/scripts/training_mccd_500.py +++ /dev/null @@ -1,345 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -# # PSF modelling - - -#@title Import packages -import sys -import numpy as np -import time - -# Import wavefront code -import wf_psf as wf -import tensorflow as tf -import tensorflow_addons as tfa - -# Start measuring elapsed time -starting_time = time.time() - -# # Define saving paths -model = 'mccd' -# model = 'poly' -# model = 'param' - -id_name = '-coherent_euclid_500stars' -run_id_name = model + id_name - -# Saving paths -base_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/' -log_save_file = base_path + 'log-files/' -model_save_file= base_path + 'chkp/' -optim_hist_file = base_path + 'optim-hist/' -saving_optim_hist = dict() - -chkp_save_file = '/gpfsscratch/rech/xdy/ulx23va/wf-outputs/chkp/' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_500_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '_output.log','w') -sys.stdout = log_file -print('Starting the log file.') - -# Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - -# # Define new model - -# Decimation factor for Zernike polynomials -n_zernikes = 15 - -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 3 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - -# Learning rates and number of epochs -l_rate_param = [1e-2, 1e-2] -l_rate_non_param = [1e-1, 1e-1] - -n_epochs_param = [20, 20] -n_epochs_non_param = [100, 120] - - -## Prepare the inputs - -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) - -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -print('Zernike cube:') -print(tf_zernike_cube.shape) - - -## Load the dictionaries -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Generate initializations - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Initialize the SED data list -packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in train_SEDs] - - -# Prepare the inputs for the training -tf_packed_SED_data = tf.convert_to_tensor(packed_SED_data, dtype=tf.float32) -tf_packed_SED_data = tf.transpose(tf_packed_SED_data, perm=[0, 2, 1]) - -inputs = [tf_train_pos, tf_packed_SED_data] - -# Select the observed stars (noisy or noiseless) -outputs = tf_noisy_train_stars -# outputs = tf_train_stars - - -## Prepare validation data inputs - -# Let's take a subset of the testing data for the validation -# in order to test things faster -val_SEDs = test_SEDs # [0:50, :, :] -tf_val_pos = tf_test_pos # [0:50, :] -tf_val_stars = tf_test_stars # [0:50, :, :] - -# Initialize the SED data list -val_packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in val_SEDs] - -# Prepare the inputs for the validation -tf_val_packed_SED_data = tf.convert_to_tensor(val_packed_SED_data, dtype=tf.float32) -tf_val_packed_SED_data = tf.transpose(tf_val_packed_SED_data, perm=[0, 2, 1]) - -# Prepare input validation tuple -val_x_inputs = [tf_val_pos, tf_val_packed_SED_data] -val_y_inputs = tf_val_stars -val_data = (val_x_inputs, val_y_inputs) - - -## Select the model -if model == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=x_lims, - y_lims=y_lims, - d_max=d_max_nonparam, - graph_features=graph_features) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - graph_features=graph_features, - l1_rate=l1_rate, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - - - -# # Model Training - -# Prepare the saving callback -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle1' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[0]) -non_param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_non_param[0]) - -print('Starting cycle 1..') -start_cycle1 = time.time() - -tf_semiparam_field, hist_param, hist_non_param = wf.train_utils.general_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate_param=l_rate_param[0], - l_rate_non_param=l_rate_non_param[0], - n_epochs_param=n_epochs_param[0], - n_epochs_non_param=n_epochs_non_param[0], - param_optim=param_optim, - non_param_optim=non_param_optim, - param_loss=None, non_param_loss=None, - param_metrics=None, non_param_metrics=None, - param_callback=None, non_param_callback=None, - general_callback=[model_chkp_callback], - first_run=True, - verbose=2) - -# Save weights -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle1') - -end_cycle1 = time.time() -print('Cycle1 elapsed time: %f'%(end_cycle1-start_cycle1)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle1'] = hist_param.history -saving_optim_hist['nonparam_cycle1'] = hist_non_param.history - - - - -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle2' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[1]) -non_param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_non_param[1]) - -print('Starting cycle 2..') -start_cycle2 = time.time() - -# Compute the next cycle -tf_semiparam_field, hist_param_2, hist_non_param_2 = wf.train_utils.general_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate_param=l_rate_param[1], - l_rate_non_param=l_rate_non_param[1], - n_epochs_param=n_epochs_param[1], - n_epochs_non_param=n_epochs_non_param[1], - param_optim=param_optim, - non_param_optim=non_param_optim, - param_loss=None, non_param_loss=None, - param_metrics=None, non_param_metrics=None, - param_callback=None, non_param_callback=None, - general_callback=[model_chkp_callback], - first_run=False, - verbose=2) - -# Save the weights at the end of the second cycle -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle2') - -end_cycle2 = time.time() -print('Cycle2 elapsed time: %f'%(end_cycle2 - start_cycle2)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle2'] = hist_param_2.history -saving_optim_hist['nonparam_cycle2'] = hist_non_param_2.history - -# Save optimisation history dictionary -np.save(optim_hist_file + 'optim_hist_' + run_id_name + '.npy', saving_optim_hist) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() diff --git a/jz-submissions/scripts/training_param_1000.py b/jz-submissions/scripts/training_param_1000.py deleted file mode 100644 index ff66daea..00000000 --- a/jz-submissions/scripts/training_param_1000.py +++ /dev/null @@ -1,302 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -# # PSF modelling - - -#@title Import packages -import sys -import numpy as np -import time - -# Import wavefront code -import wf_psf as wf -import tensorflow as tf -import tensorflow_addons as tfa - -# Start measuring elapsed time -starting_time = time.time() - -# # Define saving paths -# model = 'mccd' -# model = 'poly' -model = 'param' - -id_name = '-coherent_euclid_1000stars' -run_id_name = model + id_name - -# Saving paths -base_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/' -log_save_file = base_path + 'log-files/' -model_save_file= base_path + 'chkp/' -optim_hist_file = base_path + 'optim-hist/' -saving_optim_hist = dict() - -chkp_save_file = '/gpfsscratch/rech/xdy/ulx23va/wf-outputs/chkp/' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_1000_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '_output.log','w') -sys.stdout = log_file -print('Starting the log file.') - -# Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - -# # Define new model - -# Decimation factor for Zernike polynomials -n_zernikes = 45 - -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 3 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - -# Learning rates and number of epochs -l_rate_param = [1e-2, 1e-2] -n_epochs_param = [30, 40] - - -## Prepare the inputs - -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) - -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -print('Zernike cube:') -print(tf_zernike_cube.shape) - - -## Load the dictionaries -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Generate initializations - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Initialize the SED data list -packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in train_SEDs] - - -# Prepare the inputs for the training -tf_packed_SED_data = tf.convert_to_tensor(packed_SED_data, dtype=tf.float32) -tf_packed_SED_data = tf.transpose(tf_packed_SED_data, perm=[0, 2, 1]) - -inputs = [tf_train_pos, tf_packed_SED_data] - -# Select the observed stars (noisy or noiseless) -outputs = tf_noisy_train_stars -# outputs = tf_train_stars - - -## Prepare validation data inputs - -# Let's take a subset of the testing data for the validation -# in order to test things faster -val_SEDs = test_SEDs # [0:50, :, :] -tf_val_pos = tf_test_pos # [0:50, :] -tf_val_stars = tf_test_stars # [0:50, :, :] - -# Initialize the SED data list -val_packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in val_SEDs] - -# Prepare the inputs for the validation -tf_val_packed_SED_data = tf.convert_to_tensor(val_packed_SED_data, dtype=tf.float32) -tf_val_packed_SED_data = tf.transpose(tf_val_packed_SED_data, perm=[0, 2, 1]) - -# Prepare input validation tuple -val_x_inputs = [tf_val_pos, tf_val_packed_SED_data] -val_y_inputs = tf_val_stars -val_data = (val_x_inputs, val_y_inputs) - - -## Select the model -if model == 'mccd': - raise NotImplementedError - -elif model == 'poly': - # # Initialize the model - raise NotImplementedError - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - - - -# # Model Training - -# Prepare the saving callback -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle1' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[0]) - -print('Starting cycle 1..') -start_cycle1 = time.time() - -tf_semiparam_field, hist_param = wf.train_utils.param_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate=l_rate_param[0], - n_epochs=n_epochs_param[0], - param_optim=param_optim, - param_loss=None, - param_metrics=None, - param_callback=None, - general_callback=[model_chkp_callback], - verbose=2) - - - -# Save weights -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle1') - -end_cycle1 = time.time() -print('Cycle1 elapsed time: %f'%(end_cycle1-start_cycle1)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle1'] = hist_param.history - - - -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle2' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[1]) - - -print('Starting cycle 2..') -start_cycle2 = time.time() - -# Compute the next cycle -tf_semiparam_field, hist_param_2 = wf.train_utils.param_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate=l_rate_param[0], - n_epochs=n_epochs_param[0], - param_optim=param_optim, - param_loss=None, - param_metrics=None, - param_callback=None, - general_callback=[model_chkp_callback], - verbose=2) - - -# Save the weights at the end of the second cycle -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle2') - -end_cycle2 = time.time() -print('Cycle2 elapsed time: %f'%(end_cycle2 - start_cycle2)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle2'] = hist_param_2.history - -# Save optimisation history dictionary -np.save(optim_hist_file + 'optim_hist_' + run_id_name + '.npy', saving_optim_hist) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() diff --git a/jz-submissions/scripts/training_param_200.py b/jz-submissions/scripts/training_param_200.py deleted file mode 100644 index aa0c45e9..00000000 --- a/jz-submissions/scripts/training_param_200.py +++ /dev/null @@ -1,302 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -# # PSF modelling - - -#@title Import packages -import sys -import numpy as np -import time - -# Import wavefront code -import wf_psf as wf -import tensorflow as tf -import tensorflow_addons as tfa - -# Start measuring elapsed time -starting_time = time.time() - -# # Define saving paths -# model = 'mccd' -# model = 'poly' -model = 'param' - -id_name = '-coherent_euclid_200stars' -run_id_name = model + id_name - -# Saving paths -base_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/' -log_save_file = base_path + 'log-files/' -model_save_file= base_path + 'chkp/' -optim_hist_file = base_path + 'optim-hist/' -saving_optim_hist = dict() - -chkp_save_file = '/gpfsscratch/rech/xdy/ulx23va/wf-outputs/chkp/' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_200_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '_output.log','w') -sys.stdout = log_file -print('Starting the log file.') - -# Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - -# # Define new model - -# Decimation factor for Zernike polynomials -n_zernikes = 45 - -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 3 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - -# Learning rates and number of epochs -l_rate_param = [1e-2, 1e-2] -n_epochs_param = [30, 40] - - -## Prepare the inputs - -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) - -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -print('Zernike cube:') -print(tf_zernike_cube.shape) - - -## Load the dictionaries -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Generate initializations - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Initialize the SED data list -packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in train_SEDs] - - -# Prepare the inputs for the training -tf_packed_SED_data = tf.convert_to_tensor(packed_SED_data, dtype=tf.float32) -tf_packed_SED_data = tf.transpose(tf_packed_SED_data, perm=[0, 2, 1]) - -inputs = [tf_train_pos, tf_packed_SED_data] - -# Select the observed stars (noisy or noiseless) -outputs = tf_noisy_train_stars -# outputs = tf_train_stars - - -## Prepare validation data inputs - -# Let's take a subset of the testing data for the validation -# in order to test things faster -val_SEDs = test_SEDs # [0:50, :, :] -tf_val_pos = tf_test_pos # [0:50, :] -tf_val_stars = tf_test_stars # [0:50, :, :] - -# Initialize the SED data list -val_packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in val_SEDs] - -# Prepare the inputs for the validation -tf_val_packed_SED_data = tf.convert_to_tensor(val_packed_SED_data, dtype=tf.float32) -tf_val_packed_SED_data = tf.transpose(tf_val_packed_SED_data, perm=[0, 2, 1]) - -# Prepare input validation tuple -val_x_inputs = [tf_val_pos, tf_val_packed_SED_data] -val_y_inputs = tf_val_stars -val_data = (val_x_inputs, val_y_inputs) - - -## Select the model -if model == 'mccd': - raise NotImplementedError - -elif model == 'poly': - # # Initialize the model - raise NotImplementedError - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - - - -# # Model Training - -# Prepare the saving callback -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle1' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[0]) - -print('Starting cycle 1..') -start_cycle1 = time.time() - -tf_semiparam_field, hist_param = wf.train_utils.param_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate=l_rate_param[0], - n_epochs=n_epochs_param[0], - param_optim=param_optim, - param_loss=None, - param_metrics=None, - param_callback=None, - general_callback=[model_chkp_callback], - verbose=2) - - - -# Save weights -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle1') - -end_cycle1 = time.time() -print('Cycle1 elapsed time: %f'%(end_cycle1-start_cycle1)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle1'] = hist_param.history - - - -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle2' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[1]) - - -print('Starting cycle 2..') -start_cycle2 = time.time() - -# Compute the next cycle -tf_semiparam_field, hist_param_2 = wf.train_utils.param_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate=l_rate_param[0], - n_epochs=n_epochs_param[0], - param_optim=param_optim, - param_loss=None, - param_metrics=None, - param_callback=None, - general_callback=[model_chkp_callback], - verbose=2) - - -# Save the weights at the end of the second cycle -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle2') - -end_cycle2 = time.time() -print('Cycle2 elapsed time: %f'%(end_cycle2 - start_cycle2)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle2'] = hist_param_2.history - -# Save optimisation history dictionary -np.save(optim_hist_file + 'optim_hist_' + run_id_name + '.npy', saving_optim_hist) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() diff --git a/jz-submissions/scripts/training_param_2000.py b/jz-submissions/scripts/training_param_2000.py deleted file mode 100644 index ebbff6f9..00000000 --- a/jz-submissions/scripts/training_param_2000.py +++ /dev/null @@ -1,302 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -# # PSF modelling - - -#@title Import packages -import sys -import numpy as np -import time - -# Import wavefront code -import wf_psf as wf -import tensorflow as tf -import tensorflow_addons as tfa - -# Start measuring elapsed time -starting_time = time.time() - -# # Define saving paths -# model = 'mccd' -# model = 'poly' -model = 'param' - -id_name = '-coherent_euclid_2000stars' -run_id_name = model + id_name - -# Saving paths -base_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/' -log_save_file = base_path + 'log-files/' -model_save_file= base_path + 'chkp/' -optim_hist_file = base_path + 'optim-hist/' -saving_optim_hist = dict() - -chkp_save_file = '/gpfsscratch/rech/xdy/ulx23va/wf-outputs/chkp/' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_2000_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '_output.log','w') -sys.stdout = log_file -print('Starting the log file.') - -# Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - -# # Define new model - -# Decimation factor for Zernike polynomials -n_zernikes = 45 - -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 3 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - -# Learning rates and number of epochs -l_rate_param = [1e-2, 1e-2] -n_epochs_param = [30, 40] - - -## Prepare the inputs - -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) - -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -print('Zernike cube:') -print(tf_zernike_cube.shape) - - -## Load the dictionaries -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Generate initializations - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Initialize the SED data list -packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in train_SEDs] - - -# Prepare the inputs for the training -tf_packed_SED_data = tf.convert_to_tensor(packed_SED_data, dtype=tf.float32) -tf_packed_SED_data = tf.transpose(tf_packed_SED_data, perm=[0, 2, 1]) - -inputs = [tf_train_pos, tf_packed_SED_data] - -# Select the observed stars (noisy or noiseless) -outputs = tf_noisy_train_stars -# outputs = tf_train_stars - - -## Prepare validation data inputs - -# Let's take a subset of the testing data for the validation -# in order to test things faster -val_SEDs = test_SEDs # [0:50, :, :] -tf_val_pos = tf_test_pos # [0:50, :] -tf_val_stars = tf_test_stars # [0:50, :, :] - -# Initialize the SED data list -val_packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in val_SEDs] - -# Prepare the inputs for the validation -tf_val_packed_SED_data = tf.convert_to_tensor(val_packed_SED_data, dtype=tf.float32) -tf_val_packed_SED_data = tf.transpose(tf_val_packed_SED_data, perm=[0, 2, 1]) - -# Prepare input validation tuple -val_x_inputs = [tf_val_pos, tf_val_packed_SED_data] -val_y_inputs = tf_val_stars -val_data = (val_x_inputs, val_y_inputs) - - -## Select the model -if model == 'mccd': - raise NotImplementedError - -elif model == 'poly': - # # Initialize the model - raise NotImplementedError - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - - - -# # Model Training - -# Prepare the saving callback -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle1' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[0]) - -print('Starting cycle 1..') -start_cycle1 = time.time() - -tf_semiparam_field, hist_param = wf.train_utils.param_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate=l_rate_param[0], - n_epochs=n_epochs_param[0], - param_optim=param_optim, - param_loss=None, - param_metrics=None, - param_callback=None, - general_callback=[model_chkp_callback], - verbose=2) - - - -# Save weights -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle1') - -end_cycle1 = time.time() -print('Cycle1 elapsed time: %f'%(end_cycle1-start_cycle1)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle1'] = hist_param.history - - - -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle2' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[1]) - - -print('Starting cycle 2..') -start_cycle2 = time.time() - -# Compute the next cycle -tf_semiparam_field, hist_param_2 = wf.train_utils.param_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate=l_rate_param[0], - n_epochs=n_epochs_param[0], - param_optim=param_optim, - param_loss=None, - param_metrics=None, - param_callback=None, - general_callback=[model_chkp_callback], - verbose=2) - - -# Save the weights at the end of the second cycle -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle2') - -end_cycle2 = time.time() -print('Cycle2 elapsed time: %f'%(end_cycle2 - start_cycle2)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle2'] = hist_param_2.history - -# Save optimisation history dictionary -np.save(optim_hist_file + 'optim_hist_' + run_id_name + '.npy', saving_optim_hist) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() diff --git a/jz-submissions/scripts/training_param_500.py b/jz-submissions/scripts/training_param_500.py deleted file mode 100644 index 4d1835ad..00000000 --- a/jz-submissions/scripts/training_param_500.py +++ /dev/null @@ -1,302 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -# # PSF modelling - - -#@title Import packages -import sys -import numpy as np -import time - -# Import wavefront code -import wf_psf as wf -import tensorflow as tf -import tensorflow_addons as tfa - -# Start measuring elapsed time -starting_time = time.time() - -# # Define saving paths -# model = 'mccd' -# model = 'poly' -model = 'param' - -id_name = '-coherent_euclid_500stars' -run_id_name = model + id_name - -# Saving paths -base_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/' -log_save_file = base_path + 'log-files/' -model_save_file= base_path + 'chkp/' -optim_hist_file = base_path + 'optim-hist/' -saving_optim_hist = dict() - -chkp_save_file = '/gpfsscratch/rech/xdy/ulx23va/wf-outputs/chkp/' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_500_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '_output.log','w') -sys.stdout = log_file -print('Starting the log file.') - -# Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - -# # Define new model - -# Decimation factor for Zernike polynomials -n_zernikes = 45 - -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 3 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - -# Learning rates and number of epochs -l_rate_param = [1e-2, 1e-2] -n_epochs_param = [30, 40] - - -## Prepare the inputs - -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) - -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -print('Zernike cube:') -print(tf_zernike_cube.shape) - - -## Load the dictionaries -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Generate initializations - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Initialize the SED data list -packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in train_SEDs] - - -# Prepare the inputs for the training -tf_packed_SED_data = tf.convert_to_tensor(packed_SED_data, dtype=tf.float32) -tf_packed_SED_data = tf.transpose(tf_packed_SED_data, perm=[0, 2, 1]) - -inputs = [tf_train_pos, tf_packed_SED_data] - -# Select the observed stars (noisy or noiseless) -outputs = tf_noisy_train_stars -# outputs = tf_train_stars - - -## Prepare validation data inputs - -# Let's take a subset of the testing data for the validation -# in order to test things faster -val_SEDs = test_SEDs # [0:50, :, :] -tf_val_pos = tf_test_pos # [0:50, :] -tf_val_stars = tf_test_stars # [0:50, :, :] - -# Initialize the SED data list -val_packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in val_SEDs] - -# Prepare the inputs for the validation -tf_val_packed_SED_data = tf.convert_to_tensor(val_packed_SED_data, dtype=tf.float32) -tf_val_packed_SED_data = tf.transpose(tf_val_packed_SED_data, perm=[0, 2, 1]) - -# Prepare input validation tuple -val_x_inputs = [tf_val_pos, tf_val_packed_SED_data] -val_y_inputs = tf_val_stars -val_data = (val_x_inputs, val_y_inputs) - - -## Select the model -if model == 'mccd': - raise NotImplementedError - -elif model == 'poly': - # # Initialize the model - raise NotImplementedError - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - - - -# # Model Training - -# Prepare the saving callback -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle1' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[0]) - -print('Starting cycle 1..') -start_cycle1 = time.time() - -tf_semiparam_field, hist_param = wf.train_utils.param_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate=l_rate_param[0], - n_epochs=n_epochs_param[0], - param_optim=param_optim, - param_loss=None, - param_metrics=None, - param_callback=None, - general_callback=[model_chkp_callback], - verbose=2) - - - -# Save weights -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle1') - -end_cycle1 = time.time() -print('Cycle1 elapsed time: %f'%(end_cycle1-start_cycle1)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle1'] = hist_param.history - - - -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle2' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[1]) - - -print('Starting cycle 2..') -start_cycle2 = time.time() - -# Compute the next cycle -tf_semiparam_field, hist_param_2 = wf.train_utils.param_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate=l_rate_param[0], - n_epochs=n_epochs_param[0], - param_optim=param_optim, - param_loss=None, - param_metrics=None, - param_callback=None, - general_callback=[model_chkp_callback], - verbose=2) - - -# Save the weights at the end of the second cycle -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle2') - -end_cycle2 = time.time() -print('Cycle2 elapsed time: %f'%(end_cycle2 - start_cycle2)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle2'] = hist_param_2.history - -# Save optimisation history dictionary -np.save(optim_hist_file + 'optim_hist_' + run_id_name + '.npy', saving_optim_hist) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() diff --git a/jz-submissions/scripts/training_poly_1000.py b/jz-submissions/scripts/training_poly_1000.py deleted file mode 100644 index 600fddee..00000000 --- a/jz-submissions/scripts/training_poly_1000.py +++ /dev/null @@ -1,345 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -# # PSF modelling - - -#@title Import packages -import sys -import numpy as np -import time - -# Import wavefront code -import wf_psf as wf -import tensorflow as tf -import tensorflow_addons as tfa - -# Start measuring elapsed time -starting_time = time.time() - -# # Define saving paths -# model = 'mccd' -model = 'poly' -# model = 'param' - -id_name = '_v2-coherent_euclid_1000stars' -run_id_name = model + id_name - -# Saving paths -base_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/' -log_save_file = base_path + 'log-files/' -model_save_file= base_path + 'chkp/' -optim_hist_file = base_path + 'optim-hist/' -saving_optim_hist = dict() - -chkp_save_file = '/gpfsscratch/rech/xdy/ulx23va/wf-outputs/chkp/' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_1000_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '_output.log','w') -sys.stdout = log_file -print('Starting the log file.') - -# Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - -# # Define new model - -# Decimation factor for Zernike polynomials -n_zernikes = 15 - -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 5 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - -# Learning rates and number of epochs -l_rate_param = [1e-2, 1e-2] -l_rate_non_param = [1e-1, 1e-1] - -n_epochs_param = [20, 20] -n_epochs_non_param = [100, 120] - - -## Prepare the inputs - -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) - -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -print('Zernike cube:') -print(tf_zernike_cube.shape) - - -## Load the dictionaries -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Generate initializations - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Initialize the SED data list -packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in train_SEDs] - - -# Prepare the inputs for the training -tf_packed_SED_data = tf.convert_to_tensor(packed_SED_data, dtype=tf.float32) -tf_packed_SED_data = tf.transpose(tf_packed_SED_data, perm=[0, 2, 1]) - -inputs = [tf_train_pos, tf_packed_SED_data] - -# Select the observed stars (noisy or noiseless) -outputs = tf_noisy_train_stars -# outputs = tf_train_stars - - -## Prepare validation data inputs - -# Let's take a subset of the testing data for the validation -# in order to test things faster -val_SEDs = test_SEDs # [0:50, :, :] -tf_val_pos = tf_test_pos # [0:50, :] -tf_val_stars = tf_test_stars # [0:50, :, :] - -# Initialize the SED data list -val_packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in val_SEDs] - -# Prepare the inputs for the validation -tf_val_packed_SED_data = tf.convert_to_tensor(val_packed_SED_data, dtype=tf.float32) -tf_val_packed_SED_data = tf.transpose(tf_val_packed_SED_data, perm=[0, 2, 1]) - -# Prepare input validation tuple -val_x_inputs = [tf_val_pos, tf_val_packed_SED_data] -val_y_inputs = tf_val_stars -val_data = (val_x_inputs, val_y_inputs) - - -## Select the model -if model == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=x_lims, - y_lims=y_lims, - d_max=d_max_nonparam, - graph_features=graph_features) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - graph_features=graph_features, - l1_rate=l1_rate, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - - - -# # Model Training - -# Prepare the saving callback -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle1' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[0]) -non_param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_non_param[0]) - -print('Starting cycle 1..') -start_cycle1 = time.time() - -tf_semiparam_field, hist_param, hist_non_param = wf.train_utils.general_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate_param=l_rate_param[0], - l_rate_non_param=l_rate_non_param[0], - n_epochs_param=n_epochs_param[0], - n_epochs_non_param=n_epochs_non_param[0], - param_optim=param_optim, - non_param_optim=non_param_optim, - param_loss=None, non_param_loss=None, - param_metrics=None, non_param_metrics=None, - param_callback=None, non_param_callback=None, - general_callback=[model_chkp_callback], - first_run=True, - verbose=2) - -# Save weights -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle1') - -end_cycle1 = time.time() -print('Cycle1 elapsed time: %f'%(end_cycle1-start_cycle1)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle1'] = hist_param.history -saving_optim_hist['nonparam_cycle1'] = hist_non_param.history - - - - -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle2' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[1]) -non_param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_non_param[1]) - -print('Starting cycle 2..') -start_cycle2 = time.time() - -# Compute the next cycle -tf_semiparam_field, hist_param_2, hist_non_param_2 = wf.train_utils.general_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate_param=l_rate_param[1], - l_rate_non_param=l_rate_non_param[1], - n_epochs_param=n_epochs_param[1], - n_epochs_non_param=n_epochs_non_param[1], - param_optim=param_optim, - non_param_optim=non_param_optim, - param_loss=None, non_param_loss=None, - param_metrics=None, non_param_metrics=None, - param_callback=None, non_param_callback=None, - general_callback=[model_chkp_callback], - first_run=False, - verbose=2) - -# Save the weights at the end of the second cycle -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle2') - -end_cycle2 = time.time() -print('Cycle2 elapsed time: %f'%(end_cycle2 - start_cycle2)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle2'] = hist_param_2.history -saving_optim_hist['nonparam_cycle2'] = hist_non_param_2.history - -# Save optimisation history dictionary -np.save(optim_hist_file + 'optim_hist_' + run_id_name + '.npy', saving_optim_hist) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() diff --git a/jz-submissions/scripts/training_poly_200.py b/jz-submissions/scripts/training_poly_200.py deleted file mode 100644 index 38e1877e..00000000 --- a/jz-submissions/scripts/training_poly_200.py +++ /dev/null @@ -1,345 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -# # PSF modelling - - -#@title Import packages -import sys -import numpy as np -import time - -# Import wavefront code -import wf_psf as wf -import tensorflow as tf -import tensorflow_addons as tfa - -# Start measuring elapsed time -starting_time = time.time() - -# # Define saving paths -# model = 'mccd' -model = 'poly' -# model = 'param' - -id_name = '_test-coherent_euclid_200stars' -run_id_name = model + id_name - -# Saving paths -base_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/' -log_save_file = base_path + 'log-files/' -model_save_file= base_path + 'chkp/' -optim_hist_file = base_path + 'optim-hist/' -saving_optim_hist = dict() - -chkp_save_file = '/gpfsscratch/rech/xdy/ulx23va/wf-outputs/chkp/' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_200_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '_output.log','w') -sys.stdout = log_file -print('Starting the log file.') - -# Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - -# # Define new model - -# Decimation factor for Zernike polynomials -n_zernikes = 15 - -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 5 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - -# Learning rates and number of epochs -l_rate_param = [1e-2, 1e-2] -l_rate_non_param = [1e-1, 1e-1] - -n_epochs_param = [20, 20] -n_epochs_non_param = [100, 120] - - -## Prepare the inputs - -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) - -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -print('Zernike cube:') -print(tf_zernike_cube.shape) - - -## Load the dictionaries -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Generate initializations - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Initialize the SED data list -packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in train_SEDs] - - -# Prepare the inputs for the training -tf_packed_SED_data = tf.convert_to_tensor(packed_SED_data, dtype=tf.float32) -tf_packed_SED_data = tf.transpose(tf_packed_SED_data, perm=[0, 2, 1]) - -inputs = [tf_train_pos, tf_packed_SED_data] - -# Select the observed stars (noisy or noiseless) -outputs = tf_noisy_train_stars -# outputs = tf_train_stars - - -## Prepare validation data inputs - -# Let's take a subset of the testing data for the validation -# in order to test things faster -val_SEDs = test_SEDs # [0:50, :, :] -tf_val_pos = tf_test_pos # [0:50, :] -tf_val_stars = tf_test_stars # [0:50, :, :] - -# Initialize the SED data list -val_packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in val_SEDs] - -# Prepare the inputs for the validation -tf_val_packed_SED_data = tf.convert_to_tensor(val_packed_SED_data, dtype=tf.float32) -tf_val_packed_SED_data = tf.transpose(tf_val_packed_SED_data, perm=[0, 2, 1]) - -# Prepare input validation tuple -val_x_inputs = [tf_val_pos, tf_val_packed_SED_data] -val_y_inputs = tf_val_stars -val_data = (val_x_inputs, val_y_inputs) - - -## Select the model -if model == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=x_lims, - y_lims=y_lims, - d_max=d_max_nonparam, - graph_features=graph_features) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - graph_features=graph_features, - l1_rate=l1_rate, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - - - -# # Model Training - -# Prepare the saving callback -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle1' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[0]) -non_param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_non_param[0]) - -print('Starting cycle 1..') -start_cycle1 = time.time() - -tf_semiparam_field, hist_param, hist_non_param = wf.train_utils.general_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate_param=l_rate_param[0], - l_rate_non_param=l_rate_non_param[0], - n_epochs_param=n_epochs_param[0], - n_epochs_non_param=n_epochs_non_param[0], - param_optim=param_optim, - non_param_optim=non_param_optim, - param_loss=None, non_param_loss=None, - param_metrics=None, non_param_metrics=None, - param_callback=None, non_param_callback=None, - general_callback=[model_chkp_callback], - first_run=True, - verbose=2) - -# Save weights -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle1') - -end_cycle1 = time.time() -print('Cycle1 elapsed time: %f'%(end_cycle1-start_cycle1)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle1'] = hist_param.history -saving_optim_hist['nonparam_cycle1'] = hist_non_param.history - - - - -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle2' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[1]) -non_param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_non_param[1]) - -print('Starting cycle 2..') -start_cycle2 = time.time() - -# Compute the next cycle -tf_semiparam_field, hist_param_2, hist_non_param_2 = wf.train_utils.general_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate_param=l_rate_param[1], - l_rate_non_param=l_rate_non_param[1], - n_epochs_param=n_epochs_param[1], - n_epochs_non_param=n_epochs_non_param[1], - param_optim=param_optim, - non_param_optim=non_param_optim, - param_loss=None, non_param_loss=None, - param_metrics=None, non_param_metrics=None, - param_callback=None, non_param_callback=None, - general_callback=[model_chkp_callback], - first_run=False, - verbose=2) - -# Save the weights at the end of the second cycle -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle2') - -end_cycle2 = time.time() -print('Cycle2 elapsed time: %f'%(end_cycle2 - start_cycle2)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle2'] = hist_param_2.history -saving_optim_hist['nonparam_cycle2'] = hist_non_param_2.history - -# Save optimisation history dictionary -np.save(optim_hist_file + 'optim_hist_' + run_id_name + '.npy', saving_optim_hist) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() diff --git a/jz-submissions/scripts/training_poly_2000.py b/jz-submissions/scripts/training_poly_2000.py deleted file mode 100644 index 588dca42..00000000 --- a/jz-submissions/scripts/training_poly_2000.py +++ /dev/null @@ -1,345 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -# # PSF modelling - - -#@title Import packages -import sys -import numpy as np -import time - -# Import wavefront code -import wf_psf as wf -import tensorflow as tf -import tensorflow_addons as tfa - -# Start measuring elapsed time -starting_time = time.time() - -# # Define saving paths -# model = 'mccd' -model = 'poly' -# model = 'param' - -id_name = '_v2-coherent_euclid_2000stars' -run_id_name = model + id_name - -# Saving paths -base_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/' -log_save_file = base_path + 'log-files/' -model_save_file= base_path + 'chkp/' -optim_hist_file = base_path + 'optim-hist/' -saving_optim_hist = dict() - -chkp_save_file = '/gpfsscratch/rech/xdy/ulx23va/wf-outputs/chkp/' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_2000_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '_output.log','w') -sys.stdout = log_file -print('Starting the log file.') - -# Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - -# # Define new model - -# Decimation factor for Zernike polynomials -n_zernikes = 15 - -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 5 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - -# Learning rates and number of epochs -l_rate_param = [1e-2, 1e-2] -l_rate_non_param = [1e-1, 1e-1] - -n_epochs_param = [20, 20] -n_epochs_non_param = [100, 120] - - -## Prepare the inputs - -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) - -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -print('Zernike cube:') -print(tf_zernike_cube.shape) - - -## Load the dictionaries -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Generate initializations - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Initialize the SED data list -packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in train_SEDs] - - -# Prepare the inputs for the training -tf_packed_SED_data = tf.convert_to_tensor(packed_SED_data, dtype=tf.float32) -tf_packed_SED_data = tf.transpose(tf_packed_SED_data, perm=[0, 2, 1]) - -inputs = [tf_train_pos, tf_packed_SED_data] - -# Select the observed stars (noisy or noiseless) -outputs = tf_noisy_train_stars -# outputs = tf_train_stars - - -## Prepare validation data inputs - -# Let's take a subset of the testing data for the validation -# in order to test things faster -val_SEDs = test_SEDs # [0:50, :, :] -tf_val_pos = tf_test_pos # [0:50, :] -tf_val_stars = tf_test_stars # [0:50, :, :] - -# Initialize the SED data list -val_packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in val_SEDs] - -# Prepare the inputs for the validation -tf_val_packed_SED_data = tf.convert_to_tensor(val_packed_SED_data, dtype=tf.float32) -tf_val_packed_SED_data = tf.transpose(tf_val_packed_SED_data, perm=[0, 2, 1]) - -# Prepare input validation tuple -val_x_inputs = [tf_val_pos, tf_val_packed_SED_data] -val_y_inputs = tf_val_stars -val_data = (val_x_inputs, val_y_inputs) - - -## Select the model -if model == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=x_lims, - y_lims=y_lims, - d_max=d_max_nonparam, - graph_features=graph_features) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - graph_features=graph_features, - l1_rate=l1_rate, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - - - -# # Model Training - -# Prepare the saving callback -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle1' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[0]) -non_param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_non_param[0]) - -print('Starting cycle 1..') -start_cycle1 = time.time() - -tf_semiparam_field, hist_param, hist_non_param = wf.train_utils.general_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate_param=l_rate_param[0], - l_rate_non_param=l_rate_non_param[0], - n_epochs_param=n_epochs_param[0], - n_epochs_non_param=n_epochs_non_param[0], - param_optim=param_optim, - non_param_optim=non_param_optim, - param_loss=None, non_param_loss=None, - param_metrics=None, non_param_metrics=None, - param_callback=None, non_param_callback=None, - general_callback=[model_chkp_callback], - first_run=True, - verbose=2) - -# Save weights -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle1') - -end_cycle1 = time.time() -print('Cycle1 elapsed time: %f'%(end_cycle1-start_cycle1)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle1'] = hist_param.history -saving_optim_hist['nonparam_cycle1'] = hist_non_param.history - - - - -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle2' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[1]) -non_param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_non_param[1]) - -print('Starting cycle 2..') -start_cycle2 = time.time() - -# Compute the next cycle -tf_semiparam_field, hist_param_2, hist_non_param_2 = wf.train_utils.general_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate_param=l_rate_param[1], - l_rate_non_param=l_rate_non_param[1], - n_epochs_param=n_epochs_param[1], - n_epochs_non_param=n_epochs_non_param[1], - param_optim=param_optim, - non_param_optim=non_param_optim, - param_loss=None, non_param_loss=None, - param_metrics=None, non_param_metrics=None, - param_callback=None, non_param_callback=None, - general_callback=[model_chkp_callback], - first_run=False, - verbose=2) - -# Save the weights at the end of the second cycle -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle2') - -end_cycle2 = time.time() -print('Cycle2 elapsed time: %f'%(end_cycle2 - start_cycle2)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle2'] = hist_param_2.history -saving_optim_hist['nonparam_cycle2'] = hist_non_param_2.history - -# Save optimisation history dictionary -np.save(optim_hist_file + 'optim_hist_' + run_id_name + '.npy', saving_optim_hist) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() diff --git a/jz-submissions/scripts/training_poly_500.py b/jz-submissions/scripts/training_poly_500.py deleted file mode 100644 index 89539ed7..00000000 --- a/jz-submissions/scripts/training_poly_500.py +++ /dev/null @@ -1,345 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -# # PSF modelling - - -#@title Import packages -import sys -import numpy as np -import time - -# Import wavefront code -import wf_psf as wf -import tensorflow as tf -import tensorflow_addons as tfa - -# Start measuring elapsed time -starting_time = time.time() - -# # Define saving paths -# model = 'mccd' -model = 'poly' -# model = 'param' - -id_name = '_v2-coherent_euclid_500stars' -run_id_name = model + id_name - -# Saving paths -base_path = '/gpfswork/rech/xdy/ulx23va/wf-outputs/' -log_save_file = base_path + 'log-files/' -model_save_file= base_path + 'chkp/' -optim_hist_file = base_path + 'optim-hist/' -saving_optim_hist = dict() - -chkp_save_file = '/gpfsscratch/rech/xdy/ulx23va/wf-outputs/chkp/' - -# Input paths -dataset_path = '/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/' -train_path = 'train_Euclid_res_500_TrainStars_id_001.npy' -test_path = 'test_Euclid_res_id_001.npy' - - -# Save output prints to logfile -old_stdout = sys.stdout -log_file = open(log_save_file + run_id_name + '_output.log','w') -sys.stdout = log_file -print('Starting the log file.') - -# Check GPU -device_name = tf.test.gpu_device_name() -if device_name != '/device:GPU:0': - raise SystemError('GPU device not found') -print('Found GPU at: {}'.format(device_name)) -print('tf_version: ' + str(tf.__version__)) - -# # Define new model - -# Decimation factor for Zernike polynomials -n_zernikes = 15 - -# Some parameters -pupil_diameter = 256 -n_bins_lda = 20 - -output_Q = 3. -oversampling_rate = 3. - -batch_size = 16 -output_dim = 32 -d_max = 2 -d_max_nonparam = 5 # polynomial-constraint features -x_lims = [0, 1e3] -y_lims = [0, 1e3] -graph_features = 10 # Graph-constraint features -l1_rate = 1e-8 # L1 regularisation - -# Learning rates and number of epochs -l_rate_param = [1e-2, 1e-2] -l_rate_non_param = [1e-1, 1e-1] - -n_epochs_param = [20, 20] -n_epochs_non_param = [100, 120] - - -## Prepare the inputs - -# Generate Zernike maps -zernikes = wf.utils.zernike_generator(n_zernikes=n_zernikes, wfe_dim=pupil_diameter) - -# Now as cubes -np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - -for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - -np_zernike_cube[np.isnan(np_zernike_cube)] = 0 -tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - -print('Zernike cube:') -print(tf_zernike_cube.shape) - - -## Load the dictionaries -train_dataset = np.load(dataset_path + train_path, allow_pickle=True)[()] -# train_stars = train_dataset['stars'] -# noisy_train_stars = train_dataset['noisy_stars'] -# train_pos = train_dataset['positions'] -train_SEDs = train_dataset['SEDs'] -# train_zernike_coef = train_dataset['zernike_coef'] -train_C_poly = train_dataset['C_poly'] -train_parameters = train_dataset['parameters'] - - -test_dataset = np.load(dataset_path + test_path, allow_pickle=True)[()] -# test_stars = test_dataset['stars'] -# test_pos = test_dataset['positions'] -test_SEDs = test_dataset['SEDs'] -# test_zernike_coef = test_dataset['zernike_coef'] - -# Convert to tensor -tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) -tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) -tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - -tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) -tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - -print('Dataset parameters:') -print(train_parameters) - - -## Generate initializations - -# Prepare np input -simPSF_np = wf.SimPSFToolkit(zernikes, max_order=n_zernikes, - pupil_diameter=pupil_diameter, output_dim=output_dim, - oversampling_rate=oversampling_rate, output_Q=output_Q) -simPSF_np.gen_random_Z_coeffs(max_order=n_zernikes) -z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) -simPSF_np.set_z_coeffs(z_coeffs) -simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - -# Obscurations -obscurations = simPSF_np.generate_pupil_obscurations(N_pix=pupil_diameter, N_filter=2) -tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - -# Initialize the SED data list -packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in train_SEDs] - - -# Prepare the inputs for the training -tf_packed_SED_data = tf.convert_to_tensor(packed_SED_data, dtype=tf.float32) -tf_packed_SED_data = tf.transpose(tf_packed_SED_data, perm=[0, 2, 1]) - -inputs = [tf_train_pos, tf_packed_SED_data] - -# Select the observed stars (noisy or noiseless) -outputs = tf_noisy_train_stars -# outputs = tf_train_stars - - -## Prepare validation data inputs - -# Let's take a subset of the testing data for the validation -# in order to test things faster -val_SEDs = test_SEDs # [0:50, :, :] -tf_val_pos = tf_test_pos # [0:50, :] -tf_val_stars = tf_test_stars # [0:50, :, :] - -# Initialize the SED data list -val_packed_SED_data = [wf.utils.generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) - for _sed in val_SEDs] - -# Prepare the inputs for the validation -tf_val_packed_SED_data = tf.convert_to_tensor(val_packed_SED_data, dtype=tf.float32) -tf_val_packed_SED_data = tf.transpose(tf_val_packed_SED_data, perm=[0, 2, 1]) - -# Prepare input validation tuple -val_x_inputs = [tf_val_pos, tf_val_packed_SED_data] -val_y_inputs = tf_val_stars -val_data = (val_x_inputs, val_y_inputs) - - -## Select the model -if model == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2(obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=x_lims, - y_lims=y_lims, - d_max=d_max_nonparam, - graph_features=graph_features) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - graph_features=graph_features, - l1_rate=l1_rate, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_Q=output_Q, - d_max_nonparam=d_max_nonparam, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - -elif model == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model(zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=batch_size, - output_dim=output_dim, - n_zernikes=n_zernikes, - d_max=d_max, - x_lims=x_lims, - y_lims=y_lims) - - - - -# # Model Training - -# Prepare the saving callback -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle1' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[0]) -non_param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_non_param[0]) - -print('Starting cycle 1..') -start_cycle1 = time.time() - -tf_semiparam_field, hist_param, hist_non_param = wf.train_utils.general_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate_param=l_rate_param[0], - l_rate_non_param=l_rate_non_param[0], - n_epochs_param=n_epochs_param[0], - n_epochs_non_param=n_epochs_non_param[0], - param_optim=param_optim, - non_param_optim=non_param_optim, - param_loss=None, non_param_loss=None, - param_metrics=None, non_param_metrics=None, - param_callback=None, non_param_callback=None, - general_callback=[model_chkp_callback], - first_run=True, - verbose=2) - -# Save weights -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle1') - -end_cycle1 = time.time() -print('Cycle1 elapsed time: %f'%(end_cycle1-start_cycle1)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle1'] = hist_param.history -saving_optim_hist['nonparam_cycle1'] = hist_non_param.history - - - - -# Prepare to save the model as a callback -filepath_chkp_callback = chkp_save_file + 'chkp_callback_' + run_id_name + '_cycle2' -model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', verbose=1, save_best_only=True, - save_weights_only=False, mode='min', save_freq='epoch', - options=None) - -# Prepare the optimisers -param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_param[1]) -non_param_optim = tfa.optimizers.RectifiedAdam(lr=l_rate_non_param[1]) - -print('Starting cycle 2..') -start_cycle2 = time.time() - -# Compute the next cycle -tf_semiparam_field, hist_param_2, hist_non_param_2 = wf.train_utils.general_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=batch_size, - l_rate_param=l_rate_param[1], - l_rate_non_param=l_rate_non_param[1], - n_epochs_param=n_epochs_param[1], - n_epochs_non_param=n_epochs_non_param[1], - param_optim=param_optim, - non_param_optim=non_param_optim, - param_loss=None, non_param_loss=None, - param_metrics=None, non_param_metrics=None, - param_callback=None, non_param_callback=None, - general_callback=[model_chkp_callback], - first_run=False, - verbose=2) - -# Save the weights at the end of the second cycle -tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle2') - -end_cycle2 = time.time() -print('Cycle2 elapsed time: %f'%(end_cycle2 - start_cycle2)) - -# Save optimisation history in the saving dict -saving_optim_hist['param_cycle2'] = hist_param_2.history -saving_optim_hist['nonparam_cycle2'] = hist_non_param_2.history - -# Save optimisation history dictionary -np.save(optim_hist_file + 'optim_hist_' + run_id_name + '.npy', saving_optim_hist) - - -## Print final time -final_time = time.time() -print('\nTotal elapsed time: %f'%(final_time - starting_time)) - -## Close log file -print('\n Good bye..') -sys.stdout = old_stdout -log_file.close() diff --git a/jz-submissions/slurm-logs/slurm_output_logs.md b/jz-submissions/slurm-logs/slurm_output_logs.md deleted file mode 100644 index c033fecc..00000000 --- a/jz-submissions/slurm-logs/slurm_output_logs.md +++ /dev/null @@ -1,2 +0,0 @@ -slurm output logs - \ No newline at end of file diff --git a/long-runs/Input_data.md b/long-runs/Input_data.md deleted file mode 100644 index 27f6e27d..00000000 --- a/long-runs/Input_data.md +++ /dev/null @@ -1,80 +0,0 @@ -# Inputs of the WaveDiff model - -For the model to be trained a dataset is needed. The train and test datasets for the WaveDiff model are detailed below. - -## Input datasets -This model uses two datasets, one for optimising the model and another for testing the model. Both datasets are organised as python dictionaries. - -### Dataset keys - -``` -train_dataset.keys() --> ['stars', 'noisy_stars', 'super_res_stars', 'positions', 'SEDs', 'zernike_coef', 'C_poly', 'parameters'] - -test_dataset.keys() --> ['stars', 'super_res_stars', 'positions', 'SEDs', 'zernike_coef', 'C_poly', 'parameters'] -``` - -The contents of each entry are detailed below. - -## Composition of the datasets - -- Stars: it is a `numpy` ndarray containing the low resolution observations of each star. - - Shape: `(n_stars, output_dim, output_dim)`. -- Noisy stars: it is a `numpy` ndarray containing noisy version of the low resolution observations of each star. - - Shape: `(n_stars, output_dim, output_dim)`. -- Super resolved stars: it is a `numpy` ndarray containing the high resolution observations of each star. - - Shape: `(n_stars, super_out_res, super_out_res)`. -- Positions: it is a `numpy` ndarray containing the $(x,y)$ FOV position of each observation. - - Shape: `(n_stars, 2)`. - - Order: `pos[0]` $\rightarrow \, x$,   `pos[1]` $\rightarrow \, y$ -- SEDs: it is a `numpy` ndarray containing the SED asociated to each observed star. For each star, the SED is composed by a set of `n_bins` frequency values, a set of `n_bins` SED values and a set of `n_bins` bin weights proportional to the relative size of each bin with respect to the whole SED bandwidth. - - Shape: `(n_stars, n_bins, 3)`. - - Order: `SED[i,:,0]` $\rightarrow \, \lambda$,  `SED[i,:,1]` $\rightarrow \, \text{SED}(\lambda)$,  `SED[i,:,2]` $\rightarrow \, \frac{\Delta_{\text{bin}}}{B}$. -- Zernike_coef: it is a `numpy` ndarray containing the ground truth `n_zernike_gt` coefficients of each observed PSF wavefront error. - - Shape: `(n_stars, n_zernike_gt, 1)`. -- C_poly: it is a `numpy` ndarray containing the ground truth coefficients of the spatial variation polynomials asociated to each Zernike order. Each polynomial has a degree `d_max` and thus the number of coefficients is $n_{\text{max}} = (d_{\text{max}}+1)(d_{\text{max}}+2)/2$. - - Shape: `(n_zernikes_gt, n_max)`. -- Parameters: it is a python dictionary containing information about the data generation model parameters. - - Keys: `['d_max', 'max_order', 'x_lims', 'y_lims', 'grid_points', 'n_bins', 'max_wfe_rms', 'oversampling_rate', 'output_Q', 'output_dim', 'LP_filter_length', 'pupil_diameter', 'euclid_obsc', 'n_stars']`. - - -## Tensorflow inputs and outputs - -From each dataset, the inputs and outputs for the model will be generated. The inputs of the model, $X$, are the star positions and the SEDs. The outputs of the model, $Y$, are the noisy stars which will be constrasted with the model's predictions $\hat{Y}$ to compute the loss $\mathcal{L}(Y, \hat{Y})$. - -### Inputs -As mentioned before the input will contain two tensors, the first one containing the $(x,y)$ FOV positions and the second one containing the SED for each observation. - -``` -inputs = [tf_pos, tf_packed_SED_data] -``` - -- `tf_pos` is a tensor of shape `([n_stars,2])`. The order of the $(x,y)$ positions are the same as before. - -- `tf_packed_SED_data` is a tensor of shape `([n_stars,n_bins,3])`. For each observation $i$ this tensor contains three `n_bins`-point SED features. The first one contains each integer `feasible_N` needed for the upscaling of the wavefront error in order to compute the PSF at each `feasible_wv` (listed in the second position). Finaly in the third position the SED values are listed for each `feasible_wv`. - - Notes - - The second dimention of the packed SED data can change its lenght if SED interpolation is performed. The interpolated SED will then have the following number of samples: - - $n_{\text{bins\_interp}} = n_{\text{bins}} \times (\texttt{interp\_pts\_per\_bin} + 1) \; \pm \; 1$, - - if extrapolation is performed, a point is added to the SED, thus it corresponts to the $+1$ case. If exptrapolation is not performed the $-1$ case is considered. - - - The `feasible_N` asociated to each `feasible_wv` is calculated using the [`SimPSFToolkit.feasible_N()`](https://github.com/tobias-liaudat/wf-psf/blob/main/wf_psf/SimPSFToolkit.py#L636) method. - - The packed SED date is generated with the [generate_packed_elems()](https://github.com/tobias-liaudat/wf-psf/blob/main/wf_psf/utils.py#L44) method of the `wf_utils` class detailed in the `utils.py` file. - - The packed SED data must be converted to tensor to be an input of the model (a column permutation also takes place): - ``` - tf_packed_SED_data = tf.convert_to_tensor(packed_SED_data, dtype=tf.float32) - tf_packed_SED_data = tf.transpose(tf_packed_SED_data, perm=[0, 2, 1]) - ``` - -### Outputs -The output of the WaveDiff model contains the noisy low-resolution star observations. -``` -outputs = [tf_noisy_train_stars] -``` - -- `tf_noisy_train_stars` is a tensor of shape `([n_stars, output_dim, output_dim])` containing the noisy observation of each star. - - Notes - - The train stars must be converted to tensor in order to be used by the model. - ``` - tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) - ``` \ No newline at end of file diff --git a/long-runs/LR-PSF-field-gen-coherentFields.py b/long-runs/LR-PSF-field-gen-coherentFields.py deleted file mode 100644 index 1d0e078d..00000000 --- a/long-runs/LR-PSF-field-gen-coherentFields.py +++ /dev/null @@ -1,200 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -import numpy as np -import matplotlib.pyplot as plt -import wf_psf -from tqdm import tqdm - -r""" -This script is used to generate coherent datasets. - -With coherent we mean that each smaller dataset is a sub-ensemble -of the all the bigger datasets. -The number of training stars is determined by the list ``n_star_list`` -while the testing stars is fixed for all and is the number ``n_test_stars``. -""" - - -# Paths - -# SED folder path -SED_path = '/Users/tliaudat/Documents/PhD/codes/WF_PSF/notebooks/explore_SEDs/save_SEDs/' -# SED_path = '/local/home/tliaudat/data/' - -# Output saving path -output_folder = '/Users/tliaudat/Documents/PhD/codes/WF_PSF/github/wf-psf/data/coherent_euclid_dataset/' -# output_folder = '/local/home/tliaudat/psf-datasets/' - - -# Dataset ID -dataset_id = 1 -dataset_id_str = '%03d'%(dataset_id) - - -# This list must be in order from bigger to smaller -n_star_list = [2000, 1000, 500, 200] -n_test_stars = 400 # 20% of the max test stars - -# n_star_list = [50, 40, 30, 20] -# n_test_stars = 10 # 20% of the max test stars - - - -# Parameters -d_max = 2 -max_order = 45 -x_lims = [0, 1e3] -y_lims = [0, 1e3] -grid_points = [4, 4] -n_bins = 20 -verbose = True - -oversampling_rate = 3. -output_Q = 3. - -max_wfe_rms = 0.1 -output_dim = 32 -LP_filter_length = 2 -euclid_obsc = True -pupil_diameter = 256 - - - - -# Generate Zernike maps -zernikes = wf_psf.utils.zernike_generator(n_zernikes=max_order, wfe_dim=pupil_diameter) - -# Initialize PSF simulator -sim_PSF_toolkit = wf_psf.SimPSFToolkit( - zernikes, max_order=max_order, max_wfe_rms=max_wfe_rms, oversampling_rate=oversampling_rate, - output_Q=output_Q, output_dim=output_dim, pupil_diameter=pupil_diameter, euclid_obsc=euclid_obsc, - LP_filter_length=LP_filter_length) - -# Initialize PSF field -gen_poly_fieldPSF = wf_psf.GenPolyFieldPSF(sim_PSF_toolkit, d_max=d_max, - grid_points=grid_points, max_order=max_order, - x_lims=x_lims, y_lims=y_lims, n_bins=n_bins, - lim_max_wfe_rms=max_wfe_rms, verbose=verbose) - - - -# Load the SEDs -stellar_SEDs = np.load(SED_path + 'SEDs.npy', allow_pickle=True) -stellar_lambdas = np.load(SED_path + 'lambdas.npy', allow_pickle=True) - - - -# Total stars -n_stars = n_star_list[0] + n_test_stars -# Max train stars -tot_train_stars = n_star_list[0] - -# Generate all the stars and then go saving different subsets - - - -# Select random SEDs -SED_list = [] -for it in range(n_stars): - selected_id_SED = np.random.randint(low=0, high=13) - concat_SED_wv = np.concatenate((stellar_lambdas.reshape(-1,1), - stellar_SEDs[selected_id_SED,:].reshape(-1,1)), axis=1) - SED_list.append(concat_SED_wv) - - - -# First we choose the locations (randomly) -pos_np = np.random.rand(n_stars, 2) - -pos_np[:,0] = pos_np[:,0]*(x_lims[1] - x_lims[0]) + x_lims[0] -pos_np[:,1] = pos_np[:,1]*(y_lims[1] - y_lims[0]) + y_lims[0] - - - -# Generate all the polychromatic PSFs -poly_psf_list = [] -zernike_coef_list = [] - -for it in tqdm(range(n_stars)): - _psf, _zernike, _ = gen_poly_fieldPSF.get_poly_PSF(xv_flat=pos_np[it, 0], - yv_flat=pos_np[it, 1], - SED=SED_list[it]) - - poly_psf_list.append(_psf) - zernike_coef_list.append(_zernike) - - - -# Generate numpy arrays from the lists -poly_psf_np = np.array(poly_psf_list) -zernike_coef_np = np.array(zernike_coef_list) -SED_np = np.array(SED_list) - - -# Generate the noisy train stars - -# Copy the training stars -noisy_train_stars = np.copy(poly_psf_np[:tot_train_stars, :, :]) -# Generate a dataset with a SNR varying randomly from 10 to 120 -rand_SNR = (np.random.rand(noisy_train_stars.shape[0]) * 100) + 10 -# Add Gaussian noise to the observations -noisy_train_stars = np.stack([wf_psf.utils.add_noise(_im, desired_SNR=_SNR) - for _im, _SNR in zip(noisy_train_stars, rand_SNR)], axis=0) - - - -# Save only one test dataset - -# Build param dicitionary -dataset_params = {'d_max':d_max, 'max_order':max_order, 'x_lims':x_lims, 'y_lims':y_lims, - 'grid_points':grid_points, 'n_bins':n_bins, 'max_wfe_rms':max_wfe_rms, - 'oversampling_rate':oversampling_rate, 'output_Q':output_Q, - 'output_dim':output_dim, 'LP_filter_length':LP_filter_length, - 'pupil_diameter':pupil_diameter, 'euclid_obsc':euclid_obsc, - 'n_stars':n_test_stars} - -# Save dataset C coefficient matrix (reproductible dataset) -C_poly = gen_poly_fieldPSF.C_poly - -test_psf_dataset = {'stars' : poly_psf_np[tot_train_stars:, :, :], - 'positions' : pos_np[tot_train_stars:, :], - 'SEDs' : SED_np[tot_train_stars:, :, :], - 'zernike_coef' : zernike_coef_np[tot_train_stars:, :, :], - 'C_poly' : C_poly, - 'parameters': dataset_params} - -np.save(output_folder + 'test_Euclid_res_id_' + dataset_id_str + '.npy', - test_psf_dataset, allow_pickle=True) - - - -# Save the different train datasets - - -for it_glob in range(len(n_star_list)): - - n_train_stars = n_star_list[it_glob] - - # Build param dicitionary - dataset_params = {'d_max':d_max, 'max_order':max_order, 'x_lims':x_lims, 'y_lims':y_lims, - 'grid_points':grid_points, 'n_bins':n_bins, 'max_wfe_rms':max_wfe_rms, - 'oversampling_rate':oversampling_rate, 'output_Q':output_Q, - 'output_dim':output_dim, 'LP_filter_length':LP_filter_length, - 'pupil_diameter':pupil_diameter, 'euclid_obsc':euclid_obsc, - 'n_stars':n_train_stars} - - train_psf_dataset = {'stars' : poly_psf_np[:n_train_stars, :, :], - 'noisy_stars': noisy_train_stars[:n_train_stars, :, :], - 'positions' : pos_np[:n_train_stars, :], - 'SEDs' : SED_np[:n_train_stars, :, :], - 'zernike_coef' : zernike_coef_np[:n_train_stars, :, :], - 'C_poly' : C_poly, - 'parameters': dataset_params} - - - np.save(output_folder + 'train_Euclid_res_' + str(n_train_stars) + '_TrainStars_id_' + dataset_id_str + '.npy', - train_psf_dataset, allow_pickle=True) - - - \ No newline at end of file diff --git a/long-runs/LR-PSF-field-generation.py b/long-runs/LR-PSF-field-generation.py deleted file mode 100644 index ab75925c..00000000 --- a/long-runs/LR-PSF-field-generation.py +++ /dev/null @@ -1,214 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -# In[1]: - - -import wf_psf -from wf_psf import SimPSFToolkit -from wf_psf import GenPolyFieldPSF -import scipy.io as sio -import numpy as np -import matplotlib.pyplot as plt - -# get_ipython().run_line_magic('pylab', 'inline') - -import time -from tqdm import tqdm - - -# In[2]: - - -def add_noise(image, desired_SNR): - sigma_noise = np.sqrt((np.sum(image**2))/(desired_SNR * image.shape[0] * image.shape[1])) - noisy_image = image + np.random.standard_normal(image.shape) * sigma_noise - return noisy_image - - -# In[3]: - - -# Zcube_path = '/Users/tliaudat/Documents/PhD/codes/WF_PSF/data/PA-zernike-cubes/Zernike45.mat' -Zcube_path = '/local/home/tliaudat/data/Zernike45.mat' -Zcube = sio.loadmat(Zcube_path) - - -# In[4]: - - -# Parameters -d_max = 2 -max_order = 45 -x_lims = [0, 1e3] -y_lims = [0, 1e3] -grid_points = [4, 4] -n_bins = 20 -verbose = True - -oversampling_rate = 3. -output_Q = 3. - -max_wfe_rms=0.1 -output_dim=32 -LP_filter_length=2 -euclid_obsc = True -pupil_diameter = 256 - - -zernikes = [] -for it in range(45): - zernikes.append(wf_psf.utils.downsample_im(input_im=Zcube['Zpols'][0,it][5], output_dim=pupil_diameter)) - - -# Initialize PSF simulator -sim_PSF_toolkit = SimPSFToolkit.SimPSFToolkit( - zernikes, max_order=max_order, max_wfe_rms=max_wfe_rms, oversampling_rate=oversampling_rate, - output_Q=output_Q, output_dim=output_dim, pupil_diameter=pupil_diameter, euclid_obsc=euclid_obsc, - LP_filter_length=LP_filter_length) - -# Initialize PSF field -gen_poly_fieldPSF = GenPolyFieldPSF.GenPolyFieldPSF(sim_PSF_toolkit, d_max=d_max, - grid_points=grid_points, max_order=max_order, - x_lims=x_lims, y_lims=y_lims, n_bins=n_bins, - lim_max_wfe_rms=max_wfe_rms, verbose=verbose) - - -# Load the SEDs - -# SED_path = '/Users/tliaudat/Documents/PhD/codes/WF_PSF/notebooks/explore_SEDs/save_SEDs/' -SED_path = '/local/home/tliaudat/data/' - -stellar_SEDs = np.load(SED_path + 'SEDs.npy', allow_pickle=True) -stellar_lambdas = np.load(SED_path + 'lambdas.npy', allow_pickle=True) - - - - -n_star_list = [200, 500, 1000, 2000, 4000, 8000] -# n_star_list = [20, 40, 50] - -for it_glob in range(len(n_star_list)): - - n_stars = n_star_list[it_glob] - train_lim = int(n_stars*0.8) - - - # Build param dicitionary - dataset_params = {'d_max':d_max, 'max_order':max_order, 'x_lims':x_lims, 'y_lims':y_lims, - 'grid_points':grid_points, 'n_bins':n_bins, 'max_wfe_rms':max_wfe_rms, - 'oversampling_rate':oversampling_rate, 'output_Q':output_Q, - 'output_dim':output_dim, 'LP_filter_length':LP_filter_length, - 'pupil_diameter':pupil_diameter, 'euclid_obsc':euclid_obsc, - 'n_stars':n_stars, 'train_lim':train_lim} - - - - SED_list = [] - - # Select SEDs - for it in range(n_stars): - selected_id_SED = np.random.randint(low=0, high=13) - concat_SED_wv = np.concatenate((stellar_lambdas.reshape(-1,1), - stellar_SEDs[selected_id_SED,:].reshape(-1,1)), axis=1) - SED_list.append(concat_SED_wv) - - - - # In[7]: - - - # First we choose the locations (randomly) - pos_np = np.random.rand(n_stars,2) - - pos_np[:,0] = pos_np[:,0]*(x_lims[1] - x_lims[0]) + x_lims[0] - pos_np[:,1] = pos_np[:,1]*(y_lims[1] - y_lims[0]) + y_lims[0] - - - - - - # In[ ]: - - - # Generate the PSFs - poly_psf_list = [] - zernike_coef_list = [] - - for it in tqdm(range(n_stars)): - _psf, _zernike, _ = gen_poly_fieldPSF.get_poly_PSF(xv_flat=pos_np[it, 0], - yv_flat=pos_np[it, 1], - SED=SED_list[it]) - - poly_psf_list.append(_psf) - zernike_coef_list.append(_zernike) - - - # In[ ]: - - - # gen_poly_fieldPSF.show_WFE_RMS(save_img=True) - - - # In[ ]: - - - # Generate numpy arrays from the lists - poly_psf_np = np.array(poly_psf_list) - zernike_coef_np = np.array(zernike_coef_list) - SED_np = np.array(SED_list) - - - # In[ ]: - - - print(poly_psf_np.shape) - print(zernike_coef_np.shape) - print(SED_np.shape) - print(pos_np.shape) - - - - # Generate the noisy train stars - - # Copy the training stars - noisy_train_stars = np.copy(poly_psf_np[:train_lim, :, :]) - - # Generate a dataset with a SNR varying randomly from 10 to 80 - rand_SNR = (np.random.rand(noisy_train_stars.shape[0]) * 70) + 10 - - noisy_train_stars = np.stack([add_noise(_im, desired_SNR=_SNR) for _im, _SNR in zip(noisy_train_stars, rand_SNR)], axis=0) - - - - # In[ ]: - - - # Generate dictionary and save - - C_poly = gen_poly_fieldPSF.C_poly - - train_psf_dataset = {'stars' : poly_psf_np[:train_lim, :, :], - 'noisy_stars': noisy_train_stars, - 'positions' : pos_np[:train_lim, :], - 'SEDs' : SED_np[:train_lim, :, :], - 'zernike_coef' : zernike_coef_np[:train_lim, :, :], - 'C_poly' : C_poly, - 'parameters': dataset_params} - - test_psf_dataset = {'stars' : poly_psf_np[train_lim:, :, :], - 'positions' : pos_np[train_lim:, :], - 'SEDs' : SED_np[train_lim:, :, :], - 'zernike_coef' : zernike_coef_np[train_lim:, :, :], - 'C_poly' : C_poly, - 'parameters': dataset_params} - - - # In[ ]: - - - # output_folder = '/Users/tliaudat/Documents/PhD/codes/WF_PSF/notebooks/psf_field_datasets/Euclid_resolution/' - output_folder = '/local/home/tliaudat/psf-datasets/' - - np.save(output_folder + 'train_Euclid_res_' + str(n_stars) + '_stars_dim256.npy', train_psf_dataset, allow_pickle=True) - np.save(output_folder + 'test_Euclid_res_' + str(n_stars) + '_stars_dim256.npy', test_psf_dataset, allow_pickle=True) diff --git a/long-runs/README.md b/long-runs/README.md deleted file mode 100644 index 885e16b8..00000000 --- a/long-runs/README.md +++ /dev/null @@ -1,273 +0,0 @@ -# Use of the WaveDiff model - -The model should be installed as a python package as detailed in the main [README](https://github.com/tobias-liaudat/wf-psf) file. The `wf-psf` package includes functions to train, evaluate and plot the results of the model. In this file we detail how to make use of this functions. - -For more information on the input datasets see [Input_data.md](https://github.com/tobias-liaudat/wf-psf/blob/main/long-runs/Input_data.md). - -## Auxiliary functions - -The package has two main functions to perform test with the WaveDiff model. One function for running the model's optimisation process and one function for performing evaluation and saving the results. There is a third function that generates some plots when the evaluation is finished. This functions can be found in the [`script_utils.py`](https://github.com/tobias-liaudat/wf-psf/blob/main/wf_psf/script_utils.py) file. - -- `train_model(**args)` : trains the PSF model. -- `evaluate_model(**args)` : evaluate the trained PSF model. -- `plot_metrics(**args)`: Plot multiple models results. - -The arguments of these functions are detailed below. - -## Training script -For running the previous functions one can use the [`train_eval_plot_script_click.py`](https://github.com/tobias-liaudat/wf-psf/blob/main/long-runs/train_eval_plot_script_click.py) script. This script calls each of the above functions and serves as an interface to collect the `**args` options from command line arguments using the [`click`](https://click.palletsprojects.com/en/8.1.x/) package. - -To run the script one should input the desired parameters as command line arguments as in the following example: - -``` -./train_eval_plot_script_click.py \ - --train_opt True \ - --eval_opt True \ - --plot_opt True \ - --model poly \ - --id_name your_id \ - --suffix_id_name _1k_stars --suffix_id_name _2k_stars \ - --id_name your_id_1k_stars --id_name your_id_2k_stars \ - --star_numbers 1000 --stars_numbers 2000 \ - --base_path your/base/path/wf-outputs/ \ - ... - --pupil_diameter 256 \ - --n_epochs_param_multi_cycle "15 15" \ - --n_epochs_non_param_multi_cycle "100 50" \ - --l_rate_non_param_multi_cycle "0.1 0.06" \ - --l_rate_param_multi_cycle "0.01 0.004" \ - ... -``` - -The options that remain unset will take the default values defined in the [`train_eval_plot_script_click.py`](https://github.com/tobias-liaudat/wf-psf/blob/main/long-runs/train_eval_plot_script_click.py) script. - -# Running model on SLURM clusters -In the folder `./examples` a job scheduler example can be found. That script lets us run several experiments (model training and evaluation) in parallel on a computing cluster using SLURM directives. Each model can use different parameters, datasets or optimisation strategies. - -Note: -- The `--star_numbers` option is for the final plot's x-axis. It does not always represents the number of stars but it needs to be an integer. -- `--id_name` = `--base_id_name` + `--suffix_id_name` - -# Output folders - -For the auxiliary functions to work properly several folders must be created before running the experiments. The output file structure is shown below: - -``` -wf-outputs -├── chkp -| ├── model_1 -| ├── ... -| └── model_N -├── log-files -├── metrics -├── optim-hist -└── plots -``` - -One checkpoint folder is recommended for each model in a multi-model parallel training. This simplifies the organisation of multiple cycle model checkpoints. This folders should coincide with their corresponding script option. - -# Script options -Here we detail every option or argument used in the WaveDiff model auxiliary script. - -## Script options - -- `--train_opt`, default=`True`, type: `bool` - - Train the model. - -- `--eval_opt`, default=`True`, type: `bool` - - Evaluate the model. - -- `--plot_opt`, default=`True`, type: `bool` - - Plot the model results -## Training options -### Model definition - -- `--model`, default="poly", type: str - - Model type. Options are: 'mccd', 'graph', 'poly, 'param', 'poly_physical'. - -- `--id_name`, default="-coherent_euclid_200stars", type: str - - Model saving id. -### Saving paths - -- `--base_path`, default="/gpfswork/rech/ynx/ulx23va/wf-outputs/", type: str - - Base path for saving files. - -- `--log_folder`, default="log-files/", type: str - - Folder name to save log files. - -- `--model_folder`, default="chkp/", type: str - - Folder name to save trained models. - -- `--optim_hist_folder`, default="optim-hist/", type: str - - Folder name to save optimisation history files. - -- `--chkp_save_path`, default="/gpfsscratch/rech/ynx/ulx23va/wf-outputs/chkp/", type: str - - Path to save model checkpoints during training. - -- `--plots_folder`, default="plots/", type: str - - Folder name to save the generated plots. -### Input dataset paths - -- `--dataset_folder`, default="/gpfswork/rech/ynx/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/", type: str - - Folder path of datasets. - -- `--train_dataset_file`, default="train_Euclid_res_200_TrainStars_id_001.npy", type: str - - Train dataset file name. - -- `--test_dataset_file`, default="test_Euclid_res_id_001.npy", type: str - - Test dataset file name. -## Model parameters - -- `--n_zernikes`, default=15, type: int - - Zernike polynomial modes to use on the parametric part. - -- `--pupil_diameter`, default=256, type: int - - Dimension of the OPD/Wavefront space. - -- `--n_bins_lda`, default=20, type: int - - Number of wavelength bins to use to reconstruct polychromatic objects. - -- `--output_q`, default=3., type: float - - Downsampling rate to match the specified telescope's sampling from the oversampling rate used in the model. - -- `--oversampling_rate`, default=3., type: float - - Oversampling rate used for the OPD/WFE PSF model. - -- `--output_dim`, default=32, type: int - - Dimension of the pixel PSF postage stamp. - -- `--d_max`, default=2, type: int - - Max polynomial degree of the parametric part. - -- `--d_max_nonparam`, default=3, type: int - - Max polynomial degree of the non-parametric part. - -- `--x_lims` -nargs=2,, default=[0, 1e3], type: float - - Limits of the PSF field coordinates for the x axis. - -- `--y_lims` -nargs=2,, default=[0, 1e3], type: float - - Limits of the PSF field coordinates for the y axis. - -- `--graph_features`, default=10, type: int - - Number of graph-constrained features of the non-parametric part. - -- `--l1_rate`, default=`1e-8`, type: float - - L1 regularisation parameter for the non-parametric part. - -- `--use_sample_weights`, default=`False`, type: `bool` - - Boolean to define if we use sample weights based on the noise standard deviation estimation. - -- `--interpolation_type`, default="none", type: str - - The interpolation type for the physical poly model. Options are: 'none', 'all', 'top_K', 'independent_Zk'. -## Training parameters - -- `--batch_size`, default=32, type: int - - Batch size used for the training in the stochastic gradient descend type of algorithm. -### Old multicycle parameters for backwards compatibility. - -- `--l_rate_param`, default=None, type: float - - Learning rates for the parametric parts. - -- `--l_rate_non_param`, default=None, type: float - - Learning rates for the non-parametric parts. - -- `--n_epochs_param`, default=None, type: int - - Number of training epochs of the parametric parts. - -- `--n_epochs_non_param`, default=None, type: int - - Number of training epochs of the non-parametric parts. -### New multicycle parameters - -- `--l_rate_param_multi_cycle`, default="`1e-2` `1e-2`", type: str - - Learning rates for the parametric parts. It should be a string where numeric values are separated by spaces. - -- `--l_rate_non_param_multi_cycle`, default="`1e-1` `1e-1`", type: str - - Learning rates for the non-parametric parts. It should be a string where numeric values are separated by spaces. - -- `--n_epochs_param_multi_cycle`, default="20 20", type: str - - Number of training epochs of the parametric parts. It should be a string where numeric values are separated by spaces. - -- `--n_epochs_non_param_multi_cycle`, default="100 120", type: str - - Number of training epochs of the non-parametric parts. It should be a string where numeric values are separated by spaces. - -- `--save_all_cycles`, default=`False`, type: `bool` - - Make checkpoint at every cycle or just save the checkpoint at the end of the training. - -- `--total_cycles`, default=2, type: int - - Total amount of cycles to perform. For the moment the only available options are '1' or '2'. - -- `--cycle_def`, default="complete", type: str - - Train cycle definition. It can be: 'parametric', 'non-parametric', 'complete', 'only-non-parametric' and 'only-parametric'. -## Evaluation flags -### Saving paths - -- `--model_eval`, default="poly", type: str - - Model used as ground truth for the evaluation. Options are: 'poly', 'physical'. - -- `--metric_base_path`, default="/gpfswork/rech/ynx/ulx23va/wf-outputs/metrics/", type: str - - Base path for saving metric files. - -- `--saved_model_type`, default="final", type: str - - Type of saved model to use for the evaluation. Can be 'final' for a full model, 'checkpoint' for model weights or 'external' for a different model not saved under the same base_id as the current one.. - -- `--saved_cycle`, default="cycle2", type: str - - Saved cycle to use for the evaluation. Can be 'cycle1', 'cycle2', ..., 'cycleN'. -### Evaluation parameters - -- `--gt_n_zernikes`, default=45, type: int - - Zernike polynomial modes to use on the ground truth model parametric part. - -- `--eval_batch_size`, default=16, type: int - - Batch size to use for the evaluation. - -- `--n_bins_gt`, default=20, type: int, -help="Number of bins used for the ground truth model poly PSF generation." -) - -- `--opt_stars_rel_pix_rmse`, default=`False`, type: `bool` - - Option to get SR pixel PSF RMSE for each individual test star. -## Specific parameters - -- `--l2_param`, default=0., type: float - - Parameter for the l2 loss of the OPD. -## Plot parameters - -- `--base_id_name`, default="-coherent_euclid_", type: str - - Plot parameter. Base id_name before dataset suffix are added. - -- `--suffix_id_name`, default=["2c", "5c"], -multiple=`True`, type: str - - Plot parameter. Suffix needed to recreate the different id names. - -- `--star_numbers`, default=[200, 500], -multiple=`True`, type: int - - Plot parameter. Training star number of the different models evaluated. Needs to correspond with the `suffix_id_name`. -## WaveDiff new features -### Feature: SED interp - -- `--interp_pts_per_bin`, default=0, type: int - - Number of points per bin to add during the interpolation process. It can take values {0,1,2,3}, where 0 means no interpolation. - -- `--extrapolate`, default=`True`, type: `bool` - - Whether extrapolation is performed or not on the borders of the SED. - -- `--SED_interp_kind`, default="linear", type: str - - Type of interpolation for the SED. It can be "linear", "cubic", "quadratic", etc. Check [all available options](https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interp1d.html). - -- `--SED_sigma`, default=0, type: float - - Standard deviation of the multiplicative SED Gaussian noise. -### Feature: project parameters - -- `--project_dd_features`, default=`False`, type: `bool` - - Project NP DD features onto parametric model. - -- `--eval_only_param`, default=`False`, type: `bool` - - Use only the parametric model for evaluation. - -- `--reset_dd_features`, default=`False`, type: `bool` - - Reset to random initialisation the non-parametric model after projecting the DD features. - -- `--pretrained_model`, default=`None`, type: str - - Path to pretrained model checkpoint callback. \ No newline at end of file diff --git a/long-runs/alternative_train_eval_script.py b/long-runs/alternative_train_eval_script.py deleted file mode 100644 index 386525f0..00000000 --- a/long-runs/alternative_train_eval_script.py +++ /dev/null @@ -1,937 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -# PSF modelling and evaluation - -# Import packages -import sys -import numpy as np -import time -import wf_psf as wf -import tensorflow as tf -import tensorflow_addons as tfa - -import click - -# from absl import app -# from absl import flags - -@click.command() - -## Training options -# Model definition -@click.option( - "--model", - default="poly", - type=str, - help="Model type. Options are: 'mccd', 'poly, 'param'.") -@click.option( - "--id_name", - default="-coherent_euclid_200stars", - type=str, - help="Model saving id.") -# Saving paths -@click.option( - "--base_path", - default="/gpfswork/rech/xdy/ulx23va/wf-outputs/", - type=str, - help="Base path for saving files.") -@click.option( - "--log_folder", - default="log-files/", - type=str, - help="Folder name to save log files.") -@click.option( - "--model_folder", - default="chkp/", - type=str, - help="Folder name to save trained models.") -@click.option( - "--optim_hist_folder", - default="optim-hist/", - type=str, - help="Folder name to save optimisation history files.") -@click.option( - "--chkp_save_path", - default="/gpfsscratch/rech/xdy/ulx23va/wf-outputs/chkp/", - type=str, - help="Path to save model checkpoints during training.") -# Input dataset paths -@click.option( - "--dataset_folder", - default="/gpfswork/rech/xdy/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/", - type=str, - help="Folder path of datasets.") -@click.option( - "--train_dataset_file", - default="train_Euclid_res_200_TrainStars_id_001.npy", - type=str, - help="Train dataset file name.") -@click.option( - "--test_dataset_file", - default="test_Euclid_res_id_001.npy", - type=str, - help="Test dataset file name.") -# Model parameters -@click.option( - "--n_zernikes", - default=15, - type=int, - help="Zernike polynomial modes to use on the parametric part.") -@click.option( - "--pupil_diameter", - default=256, - type=int, - help="Dimension of the OPD/Wavefront space.") -@click.option( - "--n_bins_lda", - default=20, - type=int, - help="Number of wavelength bins to use to reconstruct polychromatic objects.") -@click.option( - "--output_q", - default=3., - type=float, - help="Downsampling rate to match the specified telescope's sampling from the oversampling rate used in the model.") -@click.option( - "--oversampling_rate", - default=3., - type=float, - help="Oversampling rate used for the OPD/WFE PSF model.") -@click.option( - "--output_dim", - default=32, - type=int, - help="Dimension of the pixel PSF postage stamp.") -@click.option( - "--d_max", - default=2, - type=int, - help="Max polynomial degree of the parametric part.") -@click.option( - "--d_max_nonparam", - default=3, - type=int, - help="Max polynomial degree of the non-parametric part.") -@click.option( - "--x_lims", - nargs=2, - default=[0, 1e3], - type=float, - help="Limits of the PSF field coordinates for the x axis.") -@click.option( - "--y_lims", - nargs=2, - default=[0, 1e3], - type=float, - help="Limits of the PSF field coordinates for the y axis.") -@click.option( - "--graph_features", - default=10, - type=int, - help="Number of graph-constrained features of the non-parametric part.") -@click.option( - "--l1_rate", - default=1e-8, - type=float, - help="L1 regularisation parameter for the non-parametric part.") -@click.option( - "--use_sample_weights", - default=False, - type=bool, - help="Boolean to define if we use sample weights based on the noise standard deviation estimation.") -# Training parameters -@click.option( - "--batch_size", - default=32, - type=int, - help="Batch size used for the trainingin the stochastic gradient descend type of algorithm.") -@click.option( - "--l_rate_param", - nargs=2, - default=[1e-2, 1e-2], - type=float, - help="Learning rates for the parametric parts.") -@click.option( - "--l_rate_non_param", - nargs=2, - default=[1e-1, 1e-1], - type=float, - help="Learning rates for the non-parametric parts.") -@click.option( - "--n_epochs_param", - nargs=2, - default=[20, 20], - type=int, - help="Number of training epochs of the parametric parts.") -@click.option( - "--n_epochs_non_param", - nargs=2, - default=[100, 120], - type=int, - help="Number of training epochs of the non-parametric parts.") -@click.option( - "--total_cycles", - default=2, - type=int, - help="Total amount of cycles to perform. For the moment the only available options are '1' or '2'.") -## Evaluation flags -# Saving paths -@click.option( - "--metric_base_path", - default="/gpfswork/rech/xdy/ulx23va/wf-outputs/metrics/", - type=str, - help="Base path for saving metric files.") -@click.option( - "--saved_model_type", - default="final", - type=str, - help="Type of saved model to use for the evaluation. Can be 'final' or 'checkpoint'.") -@click.option( - "--saved_cycle", - default="cycle2", - type=str, - help="Saved cycle to use for the evaluation. Can be 'cycle1' or 'cycle2'.") -# Evaluation parameters -@click.option( - "--gt_n_zernikes", - default=45, - type=int, - help="Zernike polynomial modes to use on the ground truth model parametric part.") -@click.option( - "--eval_batch_size", - default=16, - type=int, - help="Batch size to use for the evaluation.") - -## Specific parameters -@click.option( - "--l2_param", - default=0., - type=float, - help="Parameter for the l2 loss of the OPD.") - -def main(**args): - print(args) - train_model(**args) - evaluate_model(**args) - - -def train_model(**args): - """ Train the model defined in the """ - # Start measuring elapsed time - starting_time = time.time() - - # Define model run id - run_id_name = args['model'] + args['id_name'] - - # Define paths - log_save_file = args['base_path'] + args['log_folder'] - model_save_file= args['base_path'] + args['model_folder'] - optim_hist_file = args['base_path'] + args['optim_hist_folder'] - saving_optim_hist = dict() - - - # Save output prints to logfile - old_stdout = sys.stdout - log_file = open(log_save_file + run_id_name + '_output.log','w') - sys.stdout = log_file - print('Starting the log file.') - - # Print GPU and tensorflow info - device_name = tf.test.gpu_device_name() - print('Found GPU at: {}'.format(device_name)) - print('tf_version: ' + str(tf.__version__)) - - ## Prepare the inputs - # Generate Zernike maps - zernikes = wf.utils.zernike_generator(n_zernikes=args['n_zernikes'], wfe_dim=args['pupil_diameter']) - # Now as cubes - np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - np_zernike_cube[np.isnan(np_zernike_cube)] = 0 - tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - print('Zernike cube:') - print(tf_zernike_cube.shape) - - - ## Load the dictionaries - train_dataset = np.load(args['dataset_folder'] + args['train_dataset_file'], allow_pickle=True)[()] - # train_stars = train_dataset['stars'] - # noisy_train_stars = train_dataset['noisy_stars'] - # train_pos = train_dataset['positions'] - train_SEDs = train_dataset['SEDs'] - # train_zernike_coef = train_dataset['zernike_coef'] - # train_C_poly = train_dataset['C_poly'] - train_parameters = train_dataset['parameters'] - - test_dataset = np.load(args['dataset_folder'] + args['test_dataset_file'], allow_pickle=True)[()] - # test_stars = test_dataset['stars'] - # test_pos = test_dataset['positions'] - test_SEDs = test_dataset['SEDs'] - # test_zernike_coef = test_dataset['zernike_coef'] - - # Convert to tensor - tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) - # tf_train_stars = tf.convert_to_tensor(train_dataset['stars'], dtype=tf.float32) - tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - tf_test_stars = tf.convert_to_tensor(test_dataset['stars'], dtype=tf.float32) - tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - - print('Dataset parameters:') - print(train_parameters) - - - ## Generate initializations - # Prepare np input - simPSF_np = wf.SimPSFToolkit( - zernikes, - max_order=args['n_zernikes'], - pupil_diameter=args['pupil_diameter'], - output_dim=args['output_dim'], - oversampling_rate=args['oversampling_rate'], - output_Q=args['output_q'] - ) - simPSF_np.gen_random_Z_coeffs(max_order=args['n_zernikes']) - z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) - simPSF_np.set_z_coeffs(z_coeffs) - simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - # Obscurations - obscurations = simPSF_np.generate_pupil_obscurations(N_pix=args['pupil_diameter'], N_filter=2) - tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - # Initialize the SED data list - packed_SED_data = [ - wf.utils.generate_packed_elems( - _sed, - simPSF_np, - n_bins=args['n_bins_lda'] - ) - for _sed in train_SEDs - ] - - - # Prepare the inputs for the training - tf_packed_SED_data = tf.convert_to_tensor(packed_SED_data, dtype=tf.float32) - tf_packed_SED_data = tf.transpose(tf_packed_SED_data, perm=[0, 2, 1]) - - inputs = [tf_train_pos, tf_packed_SED_data] - - # Select the observed stars (noisy or noiseless) - outputs = tf_noisy_train_stars - # outputs = tf_train_stars - - - ## Prepare validation data inputs - val_SEDs = test_SEDs - tf_val_pos = tf_test_pos - tf_val_stars = tf_test_stars - - # Initialize the SED data list - val_packed_SED_data = [ - wf.utils.generate_packed_elems( - _sed, - simPSF_np, - n_bins=args['n_bins_lda'] - ) - for _sed in val_SEDs - ] - - # Prepare the inputs for the validation - tf_val_packed_SED_data = tf.convert_to_tensor(val_packed_SED_data, dtype=tf.float32) - tf_val_packed_SED_data = tf.transpose(tf_val_packed_SED_data, perm=[0, 2, 1]) - - # Prepare input validation tuple - val_x_inputs = [tf_val_pos, tf_val_packed_SED_data] - val_y_inputs = tf_val_stars - val_data = (val_x_inputs, val_y_inputs) - - - ## Select the model - if args['model'] == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2( - obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=args['x_lims'], - y_lims=args['y_lims'], - d_max=args['d_max_nonparam'], - graph_features=args['graph_features'] - ) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field( - zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=args['batch_size'], - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=args['output_q'], - d_max_nonparam=args['d_max_nonparam'], - graph_features=args['graph_features'], - l1_rate=args['l1_rate'], - output_dim=args['output_dim'], - n_zernikes=args['n_zernikes'], - d_max=args['d_max'], - x_lims=args['x_lims'], - y_lims=args['y_lims'] - ) - - elif args['model'] == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field( - zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=args['batch_size'], - output_Q=args['output_q'], - d_max_nonparam=args['d_max_nonparam'], - l2_param=args['l2_param'], - output_dim=args['output_dim'], - n_zernikes=args['n_zernikes'], - d_max=args['d_max'], - x_lims=args['x_lims'], - y_lims=args['y_lims'] - ) - - elif args['model'] == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model( - zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=args['batch_size'], - output_Q=args['output_q'], - l2_param=args['l2_param'], - output_dim=args['output_dim'], - n_zernikes=args['n_zernikes'], - d_max=args['d_max'], - x_lims=args['x_lims'], - y_lims=args['y_lims'] - ) - - - # # Model Training - # Prepare the saving callback - # Prepare to save the model as a callback - filepath_chkp_callback = args['chkp_save_path'] + 'chkp_callback_' + run_id_name + '_cycle1' - model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', - verbose=1, - save_best_only=True, - save_weights_only=False, - mode='min', - save_freq='epoch', - options=None - ) - - # Prepare the optimisers - param_optim = tfa.optimizers.RectifiedAdam(lr=args['l_rate_param'][0]) - non_param_optim = tfa.optimizers.RectifiedAdam(lr=args['l_rate_non_param'][0]) - - print('Starting cycle 1..') - start_cycle1 = time.time() - - if args['model'] == 'param': - tf_semiparam_field, hist_param = wf.train_utils.param_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=args['batch_size'], - l_rate=args['l_rate_param'][0], - n_epochs=args['n_epochs_param'][0], - param_optim=param_optim, - param_loss=None, - param_metrics=None, - param_callback=None, - general_callback=[model_chkp_callback], - use_sample_weights=args['use_sample_weights'], - verbose=2 - ) - - else: - tf_semiparam_field, hist_param, hist_non_param = wf.train_utils.general_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=args['batch_size'], - l_rate_param=args['l_rate_param'][0], - l_rate_non_param=args['l_rate_non_param'][0], - n_epochs_param=args['n_epochs_param'][0], - n_epochs_non_param=args['n_epochs_non_param'][0], - param_optim=param_optim, - non_param_optim=non_param_optim, - param_loss=None, - non_param_loss=None, - param_metrics=None, - non_param_metrics=None, - param_callback=None, - non_param_callback=None, - general_callback=[model_chkp_callback], - first_run=True, - use_sample_weights=args['use_sample_weights'], - verbose=2 - ) - - # Save weights - tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle1') - - end_cycle1 = time.time() - print('Cycle1 elapsed time: %f'%(end_cycle1-start_cycle1)) - - # Save optimisation history in the saving dict - saving_optim_hist['param_cycle1'] = hist_param.history - if args['model'] != 'param': - saving_optim_hist['nonparam_cycle1'] = hist_non_param.history - - if args['total_cycles'] >= 2: - # Prepare to save the model as a callback - filepath_chkp_callback = args['chkp_save_path'] + 'chkp_callback_' + run_id_name + '_cycle2' - model_chkp_callback = tf.keras.callbacks.ModelCheckpoint( - filepath_chkp_callback, - monitor='mean_squared_error', - verbose=1, - save_best_only=True, - save_weights_only=False, - mode='min', - save_freq='epoch', - options=None - ) - - # Prepare the optimisers - param_optim = tfa.optimizers.RectifiedAdam(lr=args['l_rate_param'][1]) - non_param_optim = tfa.optimizers.RectifiedAdam(lr=args['l_rate_non_param'][1]) - - print('Starting cycle 2..') - start_cycle2 = time.time() - - - # Compute the next cycle - if args['model'] == 'param': - tf_semiparam_field, hist_param_2 = wf.train_utils.param_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=args['batch_size'], - l_rate=args['l_rate_param'][1], - n_epochs=args['n_epochs_param'][1], - param_optim=param_optim, - param_loss=None, - param_metrics=None, - param_callback=None, - general_callback=[model_chkp_callback], - use_sample_weights=args['use_sample_weights'], - verbose=2 - ) - else: - # Compute the next cycle - tf_semiparam_field, hist_param_2, hist_non_param_2 = wf.train_utils.general_train_cycle( - tf_semiparam_field, - inputs=inputs, - outputs=outputs, - val_data=val_data, - batch_size=args['batch_size'], - l_rate_param=args['l_rate_param'][1], - l_rate_non_param=args['l_rate_non_param'][1], - n_epochs_param=args['n_epochs_param'][1], - n_epochs_non_param=args['n_epochs_non_param'][1], - param_optim=param_optim, - non_param_optim=non_param_optim, - param_loss=None, - non_param_loss=None, - param_metrics=None, - non_param_metrics=None, - param_callback=None, - non_param_callback=None, - general_callback=[model_chkp_callback], - first_run=False, - use_sample_weights=args['use_sample_weights'], - verbose=2 - ) - - # Save the weights at the end of the second cycle - tf_semiparam_field.save_weights(model_save_file + 'chkp_' + run_id_name + '_cycle2') - - end_cycle2 = time.time() - print('Cycle2 elapsed time: %f'%(end_cycle2 - start_cycle2)) - - # Save optimisation history in the saving dict - saving_optim_hist['param_cycle2'] = hist_param_2.history - if args['model'] != 'param': - saving_optim_hist['nonparam_cycle2'] = hist_non_param_2.history - - # Save optimisation history dictionary - np.save(optim_hist_file + 'optim_hist_' + run_id_name + '.npy', saving_optim_hist) - - ## Print final time - final_time = time.time() - print('\nTotal elapsed time: %f'%(final_time - starting_time)) - - ## Close log file - print('\n Good bye..') - sys.stdout = old_stdout - log_file.close() - - -def evaluate_model(**args): - """ Evaluate the trained model.""" - # Start measuring elapsed time - starting_time = time.time() - - # Define model run id - run_id_name = args['model'] + args['id_name'] - # Define paths - log_save_file = args['base_path'] + args['log_folder'] - - # Define saved model to use - if args['saved_model_type'] == 'checkpoint': - weights_paths = args['chkp_save_path'] + 'chkp_callback_' + run_id_name + '_' + args['saved_cycle'] - - elif args['saved_model_type'] == 'final': - model_save_file= args['base_path'] + args['model_folder'] - weights_paths = model_save_file + 'chkp_' + run_id_name + '_' + args['saved_cycle'] - - - ## Save output prints to logfile - old_stdout = sys.stdout - log_file = open(log_save_file + run_id_name + '-metrics_output.log', 'w') - sys.stdout = log_file - print('Starting the log file.') - - ## Check GPU and tensorflow version - device_name = tf.test.gpu_device_name() - print('Found GPU at: {}'.format(device_name)) - print('tf_version: ' + str(tf.__version__)) - - - ## Load datasets - train_dataset = np.load(args['dataset_folder'] + args['train_dataset_file'], allow_pickle=True)[()] - # train_stars = train_dataset['stars'] - # noisy_train_stars = train_dataset['noisy_stars'] - # train_pos = train_dataset['positions'] - train_SEDs = train_dataset['SEDs'] - # train_zernike_coef = train_dataset['zernike_coef'] - train_C_poly = train_dataset['C_poly'] - train_parameters = train_dataset['parameters'] - - test_dataset = np.load(args['dataset_folder'] + args['test_dataset_file'], allow_pickle=True)[()] - # test_stars = test_dataset['stars'] - # test_pos = test_dataset['positions'] - test_SEDs = test_dataset['SEDs'] - # test_zernike_coef = test_dataset['zernike_coef'] - - # Convert to tensor - tf_noisy_train_stars = tf.convert_to_tensor(train_dataset['noisy_stars'], dtype=tf.float32) - tf_train_pos = tf.convert_to_tensor(train_dataset['positions'], dtype=tf.float32) - tf_test_pos = tf.convert_to_tensor(test_dataset['positions'], dtype=tf.float32) - - print('Dataset parameters:') - print(train_parameters) - - - ## Prepare models - # Generate Zernike maps - zernikes = wf.utils.zernike_generator(n_zernikes=args['n_zernikes'], wfe_dim=args['pupil_diameter']) - # Now as cubes - np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - - for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - - np_zernike_cube[np.isnan(np_zernike_cube)] = 0 - tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - - # Prepare np input - simPSF_np = wf.SimPSFToolkit( - zernikes, - max_order=args['n_zernikes'], - pupil_diameter=args['pupil_diameter'], - output_dim=args['output_dim'], - oversampling_rate=args['oversampling_rate'], - output_Q=args['output_q'] - ) - simPSF_np.gen_random_Z_coeffs(max_order=args['n_zernikes']) - z_coeffs = simPSF_np.normalize_zernikes(simPSF_np.get_z_coeffs(), simPSF_np.max_wfe_rms) - simPSF_np.set_z_coeffs(z_coeffs) - simPSF_np.generate_mono_PSF(lambda_obs=0.7, regen_sample=False) - - # Obscurations - obscurations = simPSF_np.generate_pupil_obscurations(N_pix=args['pupil_diameter'], N_filter=2) - tf_obscurations = tf.convert_to_tensor(obscurations, dtype=tf.complex64) - - # Outputs (needed for the MCCD model) - outputs = tf_noisy_train_stars - - - ## Create the model - ## Select the model - if args['model'] == 'mccd': - poly_dic, graph_dic = wf.tf_mccd_psf_field.build_mccd_spatial_dic_v2( - obs_stars=outputs.numpy(), - obs_pos=tf_train_pos.numpy(), - x_lims=args['x_lims'], - y_lims=args['y_lims'], - d_max=args['d_max_nonparam'], - graph_features=args['graph_features'] - ) - - spatial_dic = [poly_dic, graph_dic] - - # Initialize the model - tf_semiparam_field = wf.tf_mccd_psf_field.TF_SP_MCCD_field( - zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=args['batch_size'], - obs_pos=tf_train_pos, - spatial_dic=spatial_dic, - output_Q=args['output_q'], - d_max_nonparam=args['d_max_nonparam'], - graph_features=args['graph_features'], - l1_rate=args['l1_rate'], - output_dim=args['output_dim'], - n_zernikes=args['n_zernikes'], - d_max=args['d_max'], - x_lims=args['x_lims'], - y_lims=args['y_lims'] - ) - - elif args['model'] == 'poly': - # # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field( - zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=args['batch_size'], - output_Q=args['output_q'], - d_max_nonparam=args['d_max_nonparam'], - l2_param=args['l2_param'], - output_dim=args['output_dim'], - n_zernikes=args['n_zernikes'], - d_max=args['d_max'], - x_lims=args['x_lims'], - y_lims=args['y_lims'] - ) - - elif args['model'] == 'param': - # Initialize the model - tf_semiparam_field = wf.tf_psf_field.TF_PSF_field_model( - zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=args['batch_size'], - output_Q=args['output_q'], - l2_param=args['l2_param'], - output_dim=args['output_dim'], - n_zernikes=args['n_zernikes'], - d_max=args['d_max'], - x_lims=args['x_lims'], - y_lims=args['y_lims'] - ) - - ## Load the model's weights - tf_semiparam_field.load_weights(weights_paths) - - ## Prepare ground truth model - # Generate Zernike maps - zernikes = wf.utils.zernike_generator(n_zernikes=args['gt_n_zernikes'], wfe_dim=args['pupil_diameter']) - # Now as cubes - np_zernike_cube = np.zeros((len(zernikes), zernikes[0].shape[0], zernikes[0].shape[1])) - for it in range(len(zernikes)): - np_zernike_cube[it,:,:] = zernikes[it] - - np_zernike_cube[np.isnan(np_zernike_cube)] = 0 - tf_zernike_cube = tf.convert_to_tensor(np_zernike_cube, dtype=tf.float32) - - # Initialize the model - GT_tf_semiparam_field = wf.tf_psf_field.TF_SemiParam_field( - zernike_maps=tf_zernike_cube, - obscurations=tf_obscurations, - batch_size=args['batch_size'], - output_Q=args['output_q'], - d_max_nonparam=args['d_max_nonparam'], - output_dim=args['output_dim'], - n_zernikes=args['gt_n_zernikes'], - d_max=args['d_max'], - x_lims=args['x_lims'], - y_lims=args['y_lims'] - ) - - # For the Ground truth model - GT_tf_semiparam_field.tf_poly_Z_field.assign_coeff_matrix(train_C_poly) - _ = GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat.assign( - np.zeros_like(GT_tf_semiparam_field.tf_np_poly_opd.alpha_mat) - ) - - - ## Metric evaluation on the test dataset - print('\n***\nMetric evaluation on the test dataset\n***\n') - - # Polychromatic star reconstructions - rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - tf_SEDs=test_SEDs, - n_bins_lda=args['n_bins_lda'], - batch_size=args['eval_batch_size'] - ) - - poly_metric = { - 'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - - # Monochromatic star reconstructions - lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation - rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_test_pos, - lambda_list=lambda_list - ) - - mono_metric = { - 'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - - # OPD metrics - rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_test_pos, - batch_size=args['eval_batch_size'] - ) - - opd_metric = { - 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - - # Shape metrics - shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=test_SEDs, - tf_pos=tf_test_pos, - n_bins_lda=args['n_bins_lda'], - output_Q=1, - output_dim=64, - batch_size=args['eval_batch_size'] - ) - - # Save metrics - test_metrics = { - 'poly_metric': poly_metric, - 'mono_metric': mono_metric, - 'opd_metric': opd_metric, - 'shape_results_dict': shape_results_dict - } - - - ## Metric evaluation on the train dataset - print('\n***\nMetric evaluation on the train dataset\n***\n') - - # Polychromatic star reconstructions - rmse, rel_rmse, std_rmse, std_rel_rmse = wf.metrics.compute_poly_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - tf_SEDs=train_SEDs, - n_bins_lda=args['n_bins_lda'], - batch_size=args['eval_batch_size'] - ) - - train_poly_metric = { - 'rmse': rmse, - 'rel_rmse': rel_rmse, - 'std_rmse': std_rmse, - 'std_rel_rmse': std_rel_rmse - } - - # Monochromatic star reconstructions - lambda_list = np.arange(0.55, 0.9, 0.01) # 10nm separation - rmse_lda, rel_rmse_lda, std_rmse_lda, std_rel_rmse_lda = wf.metrics.compute_mono_metric( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - tf_pos=tf_train_pos, - lambda_list=lambda_list - ) - - train_mono_metric = { - 'rmse_lda': rmse_lda, - 'rel_rmse_lda': rel_rmse_lda, - 'std_rmse_lda': std_rmse_lda, - 'std_rel_rmse_lda': std_rel_rmse_lda - } - - # OPD metrics - rmse_opd, rel_rmse_opd, rmse_std_opd, rel_rmse_std_opd = wf.metrics.compute_opd_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - pos=tf_train_pos, - batch_size=args['eval_batch_size'] - ) - - train_opd_metric = { - 'rmse_opd': rmse_opd, - 'rel_rmse_opd': rel_rmse_opd, - 'rmse_std_opd': rmse_std_opd, - 'rel_rmse_std_opd': rel_rmse_std_opd - } - - # Shape metrics - train_shape_results_dict = wf.metrics.compute_shape_metrics( - tf_semiparam_field=tf_semiparam_field, - GT_tf_semiparam_field=GT_tf_semiparam_field, - simPSF_np=simPSF_np, - SEDs=train_SEDs, - tf_pos=tf_train_pos, - n_bins_lda=args['n_bins_lda'], - output_Q=1, - output_dim=64, - batch_size=args['eval_batch_size'] - ) - - # Save metrics into dictionary - train_metrics = { - 'poly_metric': train_poly_metric, - 'mono_metric': train_mono_metric, - 'opd_metric': train_opd_metric, - 'shape_results_dict': train_shape_results_dict - } - - - ## Save results - metrics = { - 'test_metrics': test_metrics, - 'train_metrics': train_metrics - } - output_path = args['metric_base_path'] + 'metrics-' + run_id_name - np.save(output_path, metrics, allow_pickle=True) - - ## Print final time - final_time = time.time() - print('\nTotal elapsed time: %f'%(final_time - starting_time)) - - - ## Close log file - print('\n Good bye..') - sys.stdout = old_stdout - log_file.close() - - -if __name__ == "__main__": - main() diff --git a/long-runs/examples/job_parallel_training_example.sh b/long-runs/examples/job_parallel_training_example.sh deleted file mode 100644 index 7c364850..00000000 --- a/long-runs/examples/job_parallel_training_example.sh +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=5_cycles_256 # nom du job -##SBATCH --partition=gpu_p2 # de-commente pour la partition gpu_p2 -#SBATCH --ntasks=1 # nombre total de tache MPI (= nombre total de GPU) -#SBATCH --ntasks-per-node=1 # nombre de tache MPI par noeud (= nombre de GPU par noeud) -#SBATCH --gres=gpu:1 # nombre de GPU par n?~Sud (max 8 avec gpu_p2) -#SBATCH --cpus-per-task=10 # nombre de coeurs CPU par tache (un quart du noeud ici) -#SBATCH -C v100-32g -# /!\ Attention, "multithread" fait reference a l'hyperthreading dans la terminologie Slurm -#SBATCH --hint=nomultithread # hyperthreading desactive -#SBATCH --time=20:00:00 # temps d'execution maximum demande (HH:MM:SS) -#SBATCH --output=5_cycles_256%j.out # nom du fichier de sortie -#SBATCH --error=5_cycles_256%j.err # nom du fichier d'erreur (ici commun avec la sortie) -#SBATCH -A ynx@gpu # specify the project -##SBATCH --qos=qos_gpu-dev # using the dev queue, as this is only for profiling -#SBATCH --array=0-3 - -# nettoyage des modules charges en interactif et herites par defaut -module purge - -# chargement des modules -module load tensorflow-gpu/py3/2.7.0 - -# echo des commandes lancees -set -x - -# n_bins ---> number of points per SED (n_bins + 1) -opt[0]="--id_name _5_cycles_256_proj_d2_45z --project_dd_features True --d_max 2 --n_zernikes 45" -opt[1]="--id_name _5_cycles_256_no_proj_d2_45z --project_dd_features False --d_max 2 --n_zernikes 45" -opt[2]="--id_name _5_cycles_256_proj_d5_45z --project_dd_features True --d_max 5 --n_zernikes 45" -opt[3]="--id_name _5_cycles_256_proj_d2_60z --project_dd_features True --d_max 2 --n_zernikes 60" - - -cd $WORK/repos/wf-SEDs/HD_projected_optimisation/scripts/ - -srun python -u ./train_project_click_multi_cycle.py \ - --train_opt True \ - --eval_opt True \ - --plot_opt True \ - --model poly \ - --base_path /gpfswork/rech/ynx/uds36vp/repos/wf-SEDs/HD_projected_optimisation/wf-outputs/ \ - --log_folder log-files/ \ - --model_folder chkp/8_bins/ \ - --optim_hist_folder optim-hist/ \ - --chkp_save_path /gpfswork/rech/ynx/uds36vp/repos/wf-SEDs/HD_projected_optimisation/wf-outputs/chkp/8_bins/ \ - --plots_folder plots/ \ - --dataset_folder /gpfswork/rech/ynx/uds36vp/datasets/interp_SEDs/ \ - --train_dataset_file train_Euclid_res_2000_TrainStars_id_009_8_bins_sigma_0.npy \ - --test_dataset_file test_Euclid_res_id_009_8_bins.npy \ - --pupil_diameter 256 \ - --n_bins_lda 8 \ - --output_ 3. \ - --oversampling_rate 3. \ - --output_dim 32 \ - --d_max_nonparam 5 \ - --use_sample_weights True \ - --interpolation_type none \ - --l_rate_param_multi_cycle "0.01 0.0085 0.007 0.0055 0.004" \ - --l_rate_non_param_multi_cycle "0.1 0.09 0.08 0.07 0.06" \ - --n_epochs_param_multi_cycle "10 5 5 5 15" \ - --n_epochs_non_param_multi_cycle "25 25 25 25 50" \ - --save_all_cycles True \ - --total_cycles 5 \ - --cycle_def complete \ - --model_eval poly \ - --metric_base_path /gpfswork/rech/ynx/uds36vp/repos/wf-SEDs/HD_projected_optimisation/wf-outputs/metrics/ \ - --saved_model_type checkpoint \ - --saved_cycle cycle5 \ - --eval_batch_size 16 \ - --n_bins_gt 8 \ - --opt_stars_rel_pix_rmse True \ - --l2_param 0. \ - --base_id_name _5_cycles_256_ \ - --suffix_id_name proj_d2_45z --suffix_id_name no_proj_d2_45z --suffix_id_name proj_d5_45z --suffix_id_name proj_d2_60z \ - --star_numbers 1 --star_numbers 2 --star_numbers 3 --star_numbers 4 \ - ${opt[$SLURM_ARRAY_TASK_ID]} \ - -## --star_numbers is for the final plot's x-axis. It does not always represents the number of stars. -## --id_name = --base_id_name + --suffix_id_name \ No newline at end of file diff --git a/long-runs/train_eval_plot_script_click.py b/long-runs/train_eval_plot_script_click.py deleted file mode 100644 index 20e98422..00000000 --- a/long-runs/train_eval_plot_script_click.py +++ /dev/null @@ -1,376 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -# PSF modelling and evaluation - -import wf_psf as wf -import click -from wf_psf.utils.io import make_wfpsf_file_struct - -# from absl import app -# from absl import flags - - -@click.command() -# Script options -@click.option("--train_opt", default=True, type=bool, help="Train the model.") -@click.option("--eval_opt", default=True, type=bool, help="Evaluate the model.") -@click.option("--plot_opt", default=True, type=bool, help="Plot the model results") -# Training options -# Model definition -@click.option( - "--model", - default="poly", - type=str, - help="Model type. Options are: 'mccd', 'graph', 'poly, 'param', 'poly_physical'." -) -@click.option( - "--id_name", - default="-coherent_euclid_200stars", - type=str, - help="Model saving id." -) -# Saving paths -@click.option( - "--base_path", - default="/gpfswork/rech/ynx/ulx23va/wf-outputs/", - type=str, - help="Base path for saving files." -) -@click.option( - "--log_folder", - default="log-files/", - type=str, - help="Folder name to save log files." -) -@click.option( - "--model_folder", - default="chkp/", - type=str, - help="Folder name to save trained models." -) -@click.option( - "--optim_hist_folder", - default="optim-hist/", - type=str, - help="Folder name to save optimisation history files." -) -@click.option( - "--chkp_save_path", - default="/gpfsscratch/rech/ynx/ulx23va/wf-outputs/chkp/", - type=str, - help="Path to save model checkpoints during training." -) -@click.option( - "--plots_folder", - default="plots/", - type=str, - help="Folder name to save the generated plots." -) -# Input dataset paths -@click.option( - "--dataset_folder", - default="/gpfswork/rech/ynx/ulx23va/repo/wf-psf/data/coherent_euclid_dataset/", - type=str, - help="Folder path of datasets." -) -@click.option( - "--train_dataset_file", - default="train_Euclid_res_200_TrainStars_id_001.npy", - type=str, - help="Train dataset file name." -) -@click.option( - "--test_dataset_file", - default="test_Euclid_res_id_001.npy", - type=str, - help="Test dataset file name." -) -# Model parameters -@click.option( - "--n_zernikes", - default=15, - type=int, - help="Zernike polynomial modes to use on the parametric part." -) -@click.option( - "--pupil_diameter", - default=256, - type=int, - help="Dimension of the OPD/Wavefront space." -) -@click.option( - "--n_bins_lda", - default=20, - type=int, - help="Number of wavelength bins to use to reconstruct polychromatic objects." -) -@click.option( - "--output_q", - default=3., - type=float, - help="Downsampling rate to match the specified telescope's sampling from the oversampling rate used in the model." -) -@click.option( - "--oversampling_rate", - default=3., - type=float, - help="Oversampling rate used for the OPD/WFE PSF model." -) -@click.option( - "--output_dim", - default=32, - type=int, - help="Dimension of the pixel PSF postage stamp." -) -@click.option( - "--d_max", - default=2, - type=int, - help="Max polynomial degree of the parametric part." -) -@click.option( - "--d_max_nonparam", - default=3, - type=int, - help="Max polynomial degree of the non-parametric part." -) -@click.option( - "--x_lims", - nargs=2, - default=[0, 1e3], - type=float, - help="Limits of the PSF field coordinates for the x axis." -) -@click.option( - "--y_lims", - nargs=2, - default=[0, 1e3], - type=float, - help="Limits of the PSF field coordinates for the y axis." -) -@click.option( - "--graph_features", - default=10, - type=int, - help="Number of graph-constrained features of the non-parametric part." -) -@click.option( - "--l1_rate", - default=1e-8, - type=float, - help="L1 regularisation parameter for the non-parametric part." -) -@click.option( - "--use_sample_weights", - default=False, - type=bool, - help="Boolean to define if we use sample weights based on the noise standard deviation estimation." -) -@click.option( - "--interpolation_type", - default="none", - type=str, - help="The interpolation type for the physical poly model. Options are: 'none', 'all', 'top_K', 'independent_Zk'." -) -# Training parameters -@click.option( - "--batch_size", - default=32, - type=int, - help="Batch size used for the trainingin the stochastic gradient descend type of algorithm." -) -# Old multicycle parameters for backwards compatibility. -@click.option( - "--l_rate_param", - nargs=2, - default=None, - type=float, - help="Learning rates for the parametric parts." -) -@click.option( - "--l_rate_non_param", - nargs=2, - default=None, - type=float, - help="Learning rates for the non-parametric parts." -) -@click.option( - "--n_epochs_param", - nargs=2, - default=None, - type=int, - help="Number of training epochs of the parametric parts." -) -@click.option( - "--n_epochs_non_param", - nargs=2, - default=None, - type=int, - help="Number of training epochs of the non-parametric parts." -) -# New multicycle parameters -@click.option( - "--l_rate_param_multi_cycle", - default="1e-2 1e-2", - type=str, - help="Learning rates for the parametric parts. It should be a strign where numeric values are separated by spaces." -) -@click.option( - "--l_rate_non_param_multi_cycle", - default="1e-1 1e-1", - type=str, - help="Learning rates for the non-parametric parts. It should be a strign where numeric values are separated by spaces." -) -@click.option( - "--n_epochs_param_multi_cycle", - default="20 20", - type=str, - help="Number of training epochs of the parametric parts. It should be a strign where numeric values are separated by spaces." -) -@click.option( - "--n_epochs_non_param_multi_cycle", - default="100 120", - type=str, - help="Number of training epochs of the non-parametric parts. It should be a strign where numeric values are separated by spaces." -) -@click.option( - "--save_all_cycles", - default=False, - type=bool, - help="Make checkpoint at every cycle or just save the checkpoint at the end of the training." -) -@click.option( - "--total_cycles", - default=2, - type=int, - help="Total amount of cycles to perform. For the moment the only available options are '1' or '2'." -) -@click.option( - "--cycle_def", - default="complete", - type=str, - help="Train cycle definition. It can be: 'parametric', 'non-parametric', 'complete', 'only-non-parametric' and 'only-parametric'." -) -# Evaluation flags -# Saving paths -@click.option( - "--model_eval", - default="poly", - type=str, - help="Model used as ground truth for the evaluation. Options are: 'poly', 'physical'." -) -@click.option( - "--metric_base_path", - default="/gpfswork/rech/ynx/ulx23va/wf-outputs/metrics/", - type=str, - help="Base path for saving metric files." -) -@click.option( - "--saved_model_type", - default="final", - type=str, - help="Type of saved model to use for the evaluation. Can be 'final' or 'checkpoint'." -) -@click.option( - "--saved_cycle", - default="cycle2", - type=str, - help="Saved cycle to use for the evaluation. Can be 'cycle1' or 'cycle2'." -) -# Evaluation parameters -@click.option( - "--gt_n_zernikes", - default=45, - type=int, - help="Zernike polynomial modes to use on the ground truth model parametric part." -) -@click.option( - "--eval_batch_size", - default=16, - type=int, - help="Batch size to use for the evaluation." -) -@click.option( - "--n_bins_gt", - default=20, - type=int, - help="Number of bins used for the ground truth model poly PSF generation." -) -@click.option( - "--opt_stars_rel_pix_rmse", - default=False, - type=bool, - help="Save RMS error for each super resolved PSF in the test dataset in addition to the mean across the FOV." -) -# Specific parameters -@click.option( - "--l2_param", - default=0., - type=float, - help="Parameter for the l2 loss of the OPD." -) -# Plot parameters -@click.option( - "--base_id_name", - default="-coherent_euclid_", - type=str, - help="Plot parameter. Base id_name before dataset suffix are added." -) -@click.option( - "--suffix_id_name", - default=["2c", "5c"], - multiple=True, - type=str, - help="Plot parameter. Suffix needed to recreate the different id names." -) -@click.option( - "--star_numbers", - default=[200, 500], - multiple=True, - type=int, - help="Plot parameter. Training star number of the different models evaluated. Needs to correspond with the `suffix_id_name`." -) -# Feature: SED interp -@click.option( - "--interp_pts_per_bin", - default=0, - type=int, - help="Number of points per bin to add during the interpolation process. It can take values {0,1,2,3}, where 0 means no interpolation." -) -@click.option( - "--extrapolate", - default=True, - type=bool, - help="Whether extrapolation is performed or not on the borders of the SED." -) -@click.option( - "--SED_interp_kind", - default="linear", - type=str, - help="Type of interpolation for the SED." -) -# Feature: project parameters -@click.option( - "--project_dd_features", - default=False, - type=bool, - help="Project NP DD features onto parametric model." -) -def main(**args): - print(args) - make_wfpsf_file_struct() - if args['train_opt']: - print('Training...') - wf.script_utils.train_model(**args) - if args['eval_opt']: - print('Evaluation...') - wf.script_utils.evaluate_model(**args) - if args['plot_opt']: - print('Plotting...') - wf.script_utils.plot_metrics(**args) - wf.script_utils.plot_optimisation_metrics(**args) - - -if __name__ == "__main__": - main() diff --git a/long-runs/train_eval_plot_script_click_multi_cycle.py b/long-runs/train_eval_plot_script_click_multi_cycle.py deleted file mode 100644 index 4ca2cb52..00000000 --- a/long-runs/train_eval_plot_script_click_multi_cycle.py +++ /dev/null @@ -1,426 +0,0 @@ -#!/usr/bin/env python3 -# coding: utf-8 - -# PSF modelling and evaluation -""" -This script is a second version of the script 'train_eval_plot_script_click.py' in the same folder. - -This script allows for a multi-cycle optimisation where the number of cycles can be greater than 2. - -For backwards compatibility the old click parameters concerning multiple cycles are preserved. - -""" -import wf_psf as wf -import click - -# from absl import app -# from absl import flags - - -@click.command() -## Script options -@click.option("--train_opt", default=True, type=bool, help="Train the model.") -@click.option("--eval_opt", default=True, type=bool, help="Evaluate the model.") -@click.option("--plot_opt", default=True, type=bool, help="Plot the model results") -## Training options -# Model definition -@click.option( - "--model", - default="poly", - type=str, - help="Model type. Options are: 'mccd', 'graph', 'poly, 'param', 'poly_physical'." -) -@click.option( - "--id_name", - default="-coherent_euclid_2000stars", - type=str, - help="Model saving id." -) -# Saving paths -@click.option( - "--base_path", - default="/home/ecentofanti/wf-SEDs/WFE_sampling_test/wf-outputs/", - type=str, - help="Base path for saving files." -) -@click.option( - "--log_folder", - default="log-files/", - type=str, - help="Folder name to save log files." -) -@click.option( - "--model_folder", - default="chkp/", - type=str, - help="Folder name to save trained models." -) -@click.option( - "--optim_hist_folder", - default="optim-hist/", - type=str, - help="Folder name to save optimisation history files." -) -@click.option( - "--chkp_save_path", - default="/home/ecentofanti/wf-SEDs/WFE_sampling_test/wf-outputs/chkp/", - type=str, - help="Path to save model checkpoints during training." -) -@click.option( - "--plots_folder", - default="plots/", - type=str, - help="Folder name to save the generated plots." -) -# Input dataset paths -@click.option( - "--dataset_folder", - default="/n05data/ecentofanti/WFE_sampling_test/multires_dataset/", - type=str, - help="Folder path of datasets." -) -@click.option( - "--train_dataset_file", - default="train_Euclid_res_2000_TrainStars_id_004_wfeRes_256.npy", - type=str, - help="Train dataset file name." -) -@click.option( - "--test_dataset_file", - default="test_Euclid_res_id_004_wfeRes_256.npy", - type=str, - help="Test dataset file name." -) -# Model parameters -@click.option( - "--n_zernikes", - default=15, - type=int, - help="Zernike polynomial modes to use on the parametric part." -) -@click.option( - "--pupil_diameter", - default=256, - type=int, - help="Dimension of the OPD/Wavefront space." -) -@click.option( - "--n_bins_lda", - default=20, - type=int, - help="Number of wavelength bins to use to reconstruct polychromatic objects." -) -@click.option( - "--output_q", - default=3., - type=float, - help="Downsampling rate to match the specified telescope's sampling from the oversampling rate used in the model." -) -@click.option( - "--oversampling_rate", - default=3., - type=float, - help="Oversampling rate used for the OPD/WFE PSF model." -) -@click.option( - "--output_dim", - default=32, - type=int, - help="Dimension of the pixel PSF postage stamp." -) -@click.option( - "--d_max", - default=2, - type=int, - help="Max polynomial degree of the parametric part." -) -@click.option( - "--d_max_nonparam", - default=3, - type=int, - help="Max polynomial degree of the non-parametric part." -) -@click.option( - "--x_lims", - nargs=2, - default=[0, 1e3], - type=float, - help="Limits of the PSF field coordinates for the x axis." -) -@click.option( - "--y_lims", - nargs=2, - default=[0, 1e3], - type=float, - help="Limits of the PSF field coordinates for the y axis." -) -@click.option( - "--graph_features", - default=10, - type=int, - help="Number of graph-constrained features of the non-parametric part." -) -@click.option( - "--l1_rate", - default=1e-8, - type=float, - help="L1 regularisation parameter for the non-parametric part." -) -@click.option( - "--use_sample_weights", - default=False, - type=bool, - help="Boolean to define if we use sample weights based on the noise standard deviation estimation." -) -@click.option( - "--interpolation_type", - default="none", - type=str, - help="The interpolation type for the physical poly model. Options are: 'none', 'all', 'top_K', 'independent_Zk'." -) -# Training parameters -@click.option( - "--batch_size", - default=32, - type=int, - help="Batch size used for the trainingin the stochastic gradient descend type of algorithm." -) -# Old multicycle parameters for backwards compatibility. -@click.option( - "--l_rate_param", - nargs=2, - default=None, - type=float, - help="Learning rates for the parametric parts." -) -@click.option( - "--l_rate_non_param", - nargs=2, - default=None, - type=float, - help="Learning rates for the non-parametric parts." -) -@click.option( - "--n_epochs_param", - nargs=2, - default=None, - type=int, - help="Number of training epochs of the parametric parts." -) -@click.option( - "--n_epochs_non_param", - nargs=2, - default=None, - type=int, - help="Number of training epochs of the non-parametric parts." -) -# New multicycle parameters -@click.option( - "--l_rate_param_multi_cycle", - default="1e-2 1e-2", - type=str, - help="Learning rates for the parametric parts. It should be a string where numeric values are separated by spaces." -) -@click.option( - "--l_rate_non_param_multi_cycle", - default="1e-1 1e-1", - type=str, - help="Learning rates for the non-parametric parts. It should be a string where numeric values are separated by spaces." -) -@click.option( - "--n_epochs_param_multi_cycle", - default="20 20", - type=str, - help="Number of training epochs of the parametric parts. It should be a string where integer values are separated by spaces." -) -@click.option( - "--n_epochs_non_param_multi_cycle", - default="100 120", - type=str, - help="Number of training epochs of the non-parametric parts. It should be a string where integer values are separated by spaces." -) -@click.option( - "--save_all_cycles", - default=False, - type=bool, - help="Make checkpoint at every cycle or just save the checkpoint at the end of the training." -) -@click.option( - "--total_cycles", - default=2, - type=int, - help="Total amount of cycles to perform." -) -@click.option( - "--cycle_def", - default="complete", - type=str, - help="Train cycle definition. It can be: 'parametric', 'non-parametric', 'complete', 'only-non-parametric' and 'only-parametric'." -) -## Evaluation flags -# Saving paths -@click.option( - "--model_eval", - default="poly", - type=str, - help="Model used as ground truth for the evaluation. Options are: 'poly', 'physical'." -) -@click.option( - "--metric_base_path", - default="/home/ecentofanti/wf-SEDs/WFE_sampling_test/wf-outputs/metrics/", - type=str, - help="Base path for saving metric files." -) -@click.option( - "--saved_model_type", - default="final", - type=str, - help="Type of saved model to use for the evaluation. Can be 'final' for a full model, 'checkpoint' for model weights or 'external' for a different model not saved under the same base_id as the current one." -) -@click.option( - "--saved_cycle", - default="cycle2", - type=str, - help="Saved cycle to use for the evaluation. Can be 'cycle1' or 'cycle2'." -) -# Evaluation parameters -@click.option( - "--gt_n_zernikes", - default=45, - type=int, - help="Zernike polynomial modes to use on the ground truth model parametric part." -) -@click.option( - "--eval_batch_size", - default=16, - type=int, - help="Batch size to use for the evaluation." -) -@click.option( - "--n_bins_gt", - default=20, - type=int, - help="Number of bins used for the ground truth model poly PSF generation." -) -@click.option( - "--opt_stars_rel_pix_rmse", - default=False, - type=bool, - help="Save RMS error for each super resolved PSF in the test dataset in addition to the mean across the FOV." -) -@click.option( - "--eval_mono_metric_rmse", - default=True, - type=bool, - help="Evaluate the monchromatic RMSE metric." -) -@click.option( - "--eval_opd_metric_rmse", - default=True, - type=bool, - help="Evaluate the OPD RMSE metric." -) -@click.option( - "--eval_train_shape_sr_metric_rmse", - default=True, - type=bool, - help="Evaluate the super-resolution and the shape RMSE metrics for the train dataset." -) -## Specific parameters -@click.option( - "--l2_param", - default=0., - type=float, - help="Parameter for the l2 loss of the OPD." -) -## Plot parameters -@click.option( - "--base_id_name", - default="-multires_euclid_", - type=str, - help="Plot parameter. Base id_name before dataset suffix are added." -) -@click.option( - "--suffix_id_name", - default=["2c", "5c"], - multiple=True, - type=str, - help="Plot parameter. Suffix needed to recreate the different id names." -) -@click.option( - "--star_numbers", - default=[200, 500], - multiple=True, - type=int, - help="Plot parameter. Training star number of the different models evaluated. Needs to correspond with the `suffix_id_name`." -) -# Feature: SED interp -@click.option( - "--interp_pts_per_bin", - default=0, - type=int, - help="Number of points per bin to add during the interpolation process. It can take values {0,1,2,3}, where 0 means no interpolation." -) -@click.option( - "--extrapolate", - default=True, - type=bool, - help="Whether extrapolation is performed or not on the borders of the SED." -) -@click.option( - "--sed_interp_kind", - default="linear", - type=str, - help="Type of interpolation for the SED." -) -@click.option( - "--sed_sigma", - default=0, - type=float, - help="Standard deviation of the multiplicative SED Gaussian noise." -) -# Feature: project parameters -@click.option( - "--project_dd_features", - default=False, - type=bool, - help="Project NP DD features onto parametric model." -) -@click.option( - "--eval_only_param", - default=False, - type=bool, - help="Use only the parametric model for evaluation." -) -@click.option( - "--reset_dd_features", - default=False, - type=bool, - help="Reset to random initialisation the non-parametric model after projecting." -) -@click.option( - "--pretrained_model", - default=None, - type=str, - help="Path to pretrained model checkpoint callback." -) - - -def main(**args): - args = wf.utils.load_multi_cycle_params_click(args) - print(args) - if args['train_opt']: - print('Training...') - wf.script_utils.train_model(**args) - if args['eval_opt']: - print('Evaluation...') - wf.script_utils.evaluate_model(**args) - if args['plot_opt']: - print('Plotting...') - wf.script_utils.plot_metrics(**args) - wf.script_utils.plot_optimisation_metrics(**args) - - -if __name__ == "__main__": - main() diff --git a/src/wf_psf/metrics/method_comp_utils.py b/src/wf_psf/metrics/method_comp_utils.py deleted file mode 100644 index e0276146..00000000 --- a/src/wf_psf/metrics/method_comp_utils.py +++ /dev/null @@ -1,253 +0,0 @@ -import os -import numpy as np -from astropy.io import fits -import galsim as gs -import warnings - -try: - import mccd -except: - warnings.warn( - "Warning! Problem importing MCCD package." - "Check out that MCCD dependencies are correctly installed." - ) - - -def interpsfex(dotpsfpath, pos): - """Use PSFEx generated model to perform spatial PSF interpolation. - Parameters - ---------- - dotpsfpath : string - Path to .psf file (PSFEx output). - pos : np.ndaray - Positions where the PSF model should be evaluated. - Returns - ------- - PSFs : np.ndarray - Each row is the PSF imagette at the corresponding asked position. - """ - - if not os.path.exists(dotpsfpath): - return None - - # read PSF model and extract basis and polynomial degree and scale position - PSF_model = fits.open(dotpsfpath)[1] - - PSF_basis = np.array(PSF_model.data)[0][0] - try: - deg = PSF_model.header["POLDEG1"] - except KeyError: - # constant PSF model - return PSF_basis[0, :, :] - - # scale coordinates - x_interp, x_scale = (PSF_model.header["POLZERO1"], PSF_model.header["POLSCAL1"]) - y_interp, y_scale = (PSF_model.header["POLZERO2"], PSF_model.header["POLSCAL2"]) - xs, ys = (pos[:, 0] - x_interp) / x_scale, (pos[:, 1] - y_interp) / y_scale - - # compute polynomial coefficients - coeffs = np.array([[x**i for i in range(deg + 1)] for x in xs]) - cross_coeffs = np.array( - [ - np.concatenate( - [ - [(x**j) * (y**i) for j in range(deg - i + 1)] - for i in range(1, deg + 1) - ] - ) - for x, y in zip(xs, ys) - ] - ) - coeffs = np.hstack((coeffs, cross_coeffs)) - - # compute interpolated PSF - PSFs = np.array( - [ - np.sum( - [coeff * atom for coeff, atom in zip(coeffs_posi, PSF_basis)], axis=0 - ) - for coeffs_posi in coeffs - ] - ) - - return PSFs - - -def match_psfs(interp_psfs, test_stars, psf_size=1.25): - """Match PSF model to stars - in flux, shift and pixel sampling - for validation tests. - Returns both the matched PSFs' stamps. - - Parameters - ---------- - interp_psfs: np.ndarray - PSFs stamps to be matched. - test_stars: np.ndarray - Star stamps to be used for comparison with the PSF model. - psf_size: float - PSF size in sigma format. - """ - - sigmas = np.ones((test_stars.shape[0],)) * psf_size - - cents = [ - mccd.utils.CentroidEstimator(test_stars[it, :, :], sig=sigmas[it]) - for it in range(test_stars.shape[0]) - ] - # Calculate shifts - test_shifts = np.array([ce.return_shifts() for ce in cents]) - - # Estimate shift kernels - lanc_rad = np.ceil(3.0 * np.max(sigmas)).astype(int) - shift_kernels, _ = mccd.utils.shift_ker_stack( - test_shifts, upfact=1, lanc_rad=lanc_rad - ) - - # Degrade PSFs - interp_psfs = np.array( - [ - mccd.utils.degradation_op(interp_psfs[j, :, :], shift_kernels[:, :, j], D=1) - for j in range(test_stars.shape[0]) - ] - ) - - # Optimised fulx matching - norm_factor = np.array( - [ - np.sum(_star * _psf) / np.sum(_psf * _psf) - for _star, _psf in zip(test_stars, interp_psfs) - ] - ).reshape(-1, 1, 1) - interp_psfs *= norm_factor - - return interp_psfs - - -def crop_at_center(img, output_size): - """ " Crop image to a desired output size.""" - x = img.shape[0] - y = img.shape[1] - startx = x // 2 - (output_size[0] // 2) - starty = y // 2 - (output_size[1] // 2) - return img[startx : startx + output_size[0], starty : starty + output_size[1]] - - -def calc_shapes(matched_psfs, test_stars): - # Measure shapes of the reconstructions - pred_moments = [ - gs.hsm.FindAdaptiveMom(gs.Image(_pred), strict=False) for _pred in matched_psfs - ] - - # Measure shapes of the reconstructions - GT_pred_moments = [ - gs.hsm.FindAdaptiveMom(gs.Image(_pred), strict=False) for _pred in test_stars - ] - - pred_e1_HSM, pred_e2_HSM, pred_R2_HSM = [], [], [] - GT_pred_e1_HSM, GT_pred_e2_HSM, GT_pred_R2_HSM = [], [], [] - - for it in range(len(test_stars)): - # Only save shape if both measurements do not raise errors - if ( - pred_moments[it].moments_status == 0 - and GT_pred_moments[it].moments_status == 0 - ): - pred_e1_HSM.append(pred_moments[it].observed_shape.g1) - pred_e2_HSM.append(pred_moments[it].observed_shape.g2) - pred_R2_HSM.append(2 * (pred_moments[it].moments_sigma ** 2)) - - GT_pred_e1_HSM.append(GT_pred_moments[it].observed_shape.g1) - GT_pred_e2_HSM.append(GT_pred_moments[it].observed_shape.g2) - GT_pred_R2_HSM.append(2 * (GT_pred_moments[it].moments_sigma ** 2)) - - logger.info( - "Total number of stars: %d\t Number of shape measurements problems %d." - % (len(test_stars), len(test_stars) - len(pred_e1_HSM)) - ) - pred_e1_HSM = np.array(pred_e1_HSM) - pred_e2_HSM = np.array(pred_e2_HSM) - pred_R2_HSM = np.array(pred_R2_HSM) - - GT_pred_e1_HSM = np.array(GT_pred_e1_HSM) - GT_pred_e2_HSM = np.array(GT_pred_e2_HSM) - GT_pred_R2_HSM = np.array(GT_pred_R2_HSM) - - return (pred_e1_HSM, pred_e2_HSM, pred_R2_HSM), ( - GT_pred_e1_HSM, - GT_pred_e2_HSM, - GT_pred_R2_HSM, - ) - - -def shape_pix_metrics(exp_psfs, exp_stars): - # Calculate residuals - residuals = np.sqrt(np.mean((exp_psfs - exp_stars) ** 2, axis=(1, 2))) - GT_star_mean = np.sqrt(np.mean((exp_stars) ** 2, axis=(1, 2))) - - # RMSE calculations - rmse = np.mean(residuals) - rel_rmse = 100.0 * np.mean(residuals / GT_star_mean) - - # STD calculations - pix_rmse_std = np.std(residuals) - rel_pix_rmse_std = 100.0 * np.std(residuals / GT_star_mean) - - ## Shape error - # Calculate shapes - psf_shapes, star_shapes = calc_shapes(exp_psfs, exp_stars) - # Extract results - pred_e1_HSM, pred_e2_HSM, pred_R2_HSM = psf_shapes[0], psf_shapes[1], psf_shapes[2] - GT_pred_e1_HSM, GT_pred_e2_HSM, GT_pred_R2_HSM = ( - star_shapes[0], - star_shapes[1], - star_shapes[2], - ) - - # e1 - e1_res = GT_pred_e1_HSM - pred_e1_HSM - e1_res_rel = (GT_pred_e1_HSM - pred_e1_HSM) / GT_pred_e1_HSM - - rmse_e1 = np.sqrt(np.mean(e1_res**2)) - rel_rmse_e1 = 100.0 * np.sqrt(np.mean(e1_res_rel**2)) - std_rmse_e1 = np.std(e1_res) - std_rel_rmse_e1 = 100.0 * np.std(e1_res_rel) - - # e2 - e2_res = GT_pred_e2_HSM - pred_e2_HSM - e2_res_rel = (GT_pred_e2_HSM - pred_e2_HSM) / GT_pred_e2_HSM - - rmse_e2 = np.sqrt(np.mean(e2_res**2)) - rel_rmse_e2 = 100.0 * np.sqrt(np.mean(e2_res_rel**2)) - std_rmse_e2 = np.std(e2_res) - std_rel_rmse_e2 = 100.0 * np.std(e2_res_rel) - - # R2 - R2_res = GT_pred_R2_HSM - pred_R2_HSM - - rmse_R2_meanR2 = np.sqrt(np.mean(R2_res**2)) / np.mean(GT_pred_R2_HSM) - std_rmse_R2_meanR2 = np.std(R2_res / GT_pred_R2_HSM) - - # Save the metrics - metrics_dict = { - "pix_rmse": rmse, - "pix_rel_rmse": rel_rmse, - "pix_rmse_std": pix_rmse_std, - "rel_pix_rmse_std": rel_pix_rmse_std, - "pred_e1_HSM": pred_e1_HSM, - "pred_e2_HSM": pred_e2_HSM, - "pred_R2_HSM": pred_R2_HSM, - "GT_pred_e1_HSM": GT_pred_e1_HSM, - "GT_ped_e2_HSM": GT_pred_e2_HSM, - "GT_pred_R2_HSM": GT_pred_R2_HSM, - "rmse_e1": rmse_e1, - "std_rmse_e1": std_rmse_e1, - "rel_rmse_e1": rel_rmse_e1, - "std_rel_rmse_e1": std_rel_rmse_e1, - "rmse_e2": rmse_e2, - "std_rmse_e2": std_rmse_e2, - "rel_rmse_e2": rel_rmse_e2, - "std_rel_rmse_e2": std_rel_rmse_e2, - "rmse_R2_meanR2": rmse_R2_meanR2, - "std_rmse_R2_meanR2": std_rmse_R2_meanR2, - } - - return metrics_dict diff --git a/src/wf_psf/psf_models/GenFieldPSF.py b/src/wf_psf/psf_models/GenFieldPSF.py deleted file mode 100644 index 9dbe6a83..00000000 --- a/src/wf_psf/psf_models/GenFieldPSF.py +++ /dev/null @@ -1,233 +0,0 @@ -import numpy as np -import scipy as sp -import scipy.interpolate as sinterp -import scipy.io as sio -import matplotlib.pyplot as plt -import matplotlib as mpl -from matplotlib.colors import ListedColormap, LinearSegmentedColormap -from mpl_toolkits.axes_grid1 import make_axes_locatable -import logging - -logger = logging.getLogger(__name__) - - -class GenFieldPSF(object): - def __init__( - self, - sim_psf_toolkit, - max_order=45, - xlim=1e3, - ylim=1e3, - n_bins=35, - lim_max_wfe_rms=None, - verbose=0, - ): - # Input attributes - self.sim_psf_toolkit = sim_psf_toolkit - self.max_order = max_order - self.xlim = xlim - self.ylim = ylim - self.n_bins = n_bins - self.verbose = verbose - if lim_max_wfe_rms is None: - self.lim_max_wfe_rms = sim_psf_toolkit.max_wfe_rms - - # Class attributes - self.z_coeffs = [] - self.new_z_coef = None - - def gen_z_coeffs(self, random_gen=False): - if len(self.z_coeffs) == 0: - # x-variable - if random_gen: - rand_seed = None - else: - rand_seed = 1 - # Generate Z coeffs and normalize them - # Normalize coefficients - self.sim_psf_toolkit.gen_random_Z_coeffs( - max_order=self.max_order, rand_seed=rand_seed - ) - z_coef_1 = self.sim_psf_toolkit.normalize_zernikes( - self.sim_psf_toolkit.get_z_coeffs(), self.lim_max_wfe_rms - ) - self.z_coeffs.append(np.array(z_coef_1)) - - # y-variable - if random_gen: - rand_seed = None - else: - rand_seed = 4 - self.sim_psf_toolkit.gen_random_Z_coeffs( - max_order=self.max_order, rand_seed=rand_seed - ) - z_coef_4 = self.sim_psf_toolkit.normalize_zernikes( - self.sim_psf_toolkit.get_z_coeffs(), self.lim_max_wfe_rms - ) - self.z_coeffs.append(np.array(z_coef_4)) - - # global-variable - if random_gen: - rand_seed = None - else: - rand_seed = 5 - self.sim_psf_toolkit.gen_random_Z_coeffs( - max_order=self.max_order, rand_seed=rand_seed - ) - z_coef_5 = self.sim_psf_toolkit.normalize_zernikes( - self.sim_psf_toolkit.get_z_coeffs(), self.lim_max_wfe_rms - ) - self.z_coeffs.append(np.array(z_coef_5) / 5) - - # Normalize PSF field - self.normalize_field() - - def normalize_field(self): - """Normalize the zernike coefficients for extreme positions. - - At this moment I only check the extreme positions. - This should check the WFE_RMS throughout all the field. - - """ - max_wfe_corner_1 = self.compute_wfe_rms(x=0, y=0) - max_wfe_corner_2 = self.compute_wfe_rms(x=self.xlim, y=self.ylim) - max_wfe_corner_3 = self.compute_wfe_rms(x=0, y=self.ylim) - max_wfe_corner_4 = self.compute_wfe_rms(x=self.xlim, y=0) - - max_wfe_rms = np.max( - [max_wfe_corner_1, max_wfe_corner_2, max_wfe_corner_3, max_wfe_corner_4] - ) - - if max_wfe_rms > self.lim_max_wfe_rms: - if self.verbose: - logger.info( - "WFE_RMS %.4f [um] is exceeding from max value: %.4f [um]. Normalizing." - % (max_wfe_rms, self.lim_max_wfe_rms) - ) - - wfe_rms_ratio = self.lim_max_wfe_rms / max_wfe_rms - for it in range(len(self.z_coeffs)): - self.z_coeffs[it] = self.z_coeffs[it] * wfe_rms_ratio - - def erase_z_coeffs(self): - self.z_coeffs = [] - - def zernike_coeff_map(self, x, y): - """Calculate Zernikes for a specific position - - Normalize (x,y) inputs - (x,y) need to be in [0,self.xlim] x [0,self.ylim] - (x_norm,y_norm) need to be in [-1, +1] x [-1, +1] - """ - if x >= self.xlim and x <= 0: - logger.info( - "WARNING! x value: %f is not between the limits [0, %f]" - % (x, self.xlim) - ) - if y >= self.ylim and y <= 0: - logger.info( - "WARNING! y value: %f is not between the limits [0, %f]" - % (y, self.ylim) - ) - - x_norm = (x - self.xlim / 2) / (self.xlim / 2) - y_norm = (y - self.ylim / 2) / (self.ylim / 2) - - self.new_z_coef = ( - self.z_coeffs[0] * x_norm + self.z_coeffs[1] * y_norm + self.z_coeffs[2] - ) - - dif_wfe_rms = self.sim_psf_toolkit.check_wfe_rms(z_coeffs=self.new_z_coef) - - if dif_wfe_rms < 0: - logger.info( - "WARNING: Position (%d,%d) posses an WFE_RMS of %f.\n" - % (x, y, self.sim_psf_toolkit.max_wfe_rms - dif_wfe_rms) - ) - logger.info( - "It exceeds the maximum allowed error (max WFE_RMS=%.4f [um])" - % (self.sim_psf_toolkit.max_wfe_rms) - ) - - if self.verbose > 0: - logger.info("Info for position: (%d, %d)" % (x, y)) - logger.info( - "WFE_RMS: %.4f [um]" % (self.sim_psf_toolkit.max_wfe_rms - dif_wfe_rms) - ) - logger.info("MAX_WFE_RMS: %.4f [um]" % (self.sim_psf_toolkit.max_wfe_rms)) - - def compute_wfe_rms(self, x, y): - """Compute the WFE RMS for a specific field position.""" - x_norm = (x - self.xlim / 2) / (self.xlim / 2) - y_norm = (y - self.ylim / 2) / (self.ylim / 2) - - self.new_z_coef = ( - self.z_coeffs[0] * x_norm + self.z_coeffs[1] * y_norm + self.z_coeffs[2] - ) - - dif_wfe_rms = self.sim_psf_toolkit.check_wfe_rms(z_coeffs=self.new_z_coef) - - return self.sim_psf_toolkit.max_wfe_rms - dif_wfe_rms - - def get_zernike_coeff_map(self): - if self.new_z_coef is not None: - return self.new_z_coef - else: - logger.info("Coeff map has not been calculated yet.") - - def get_mono_PSF(self, x, y, lambda_obs=0.725): - # Calculate the specific field's zernike coeffs - self.zernike_coeff_map(x, y) - # Set the Z coefficients to the PSF toolkit generator - self.sim_psf_toolkit.set_z_coeffs(self.get_zernike_coeff_map()) - # Generate the monochromatic psf - self.sim_psf_toolkit.generate_mono_PSF( - lambda_obs=lambda_obs, regen_sample=False - ) - # Return the generated PSF - - return self.sim_psf_toolkit.get_psf() - - def inspect_opd_map(self, cmap="viridis", save_img=False): - """Plot the last saved OPD map.""" - self.sim_psf_toolkit.plot_opd_phase(cmap, save_img) - - def inspect_field_wfe_rms(self, mesh_bins=20, save_img=False): - """Plot a chart of WFE_RMS as a function of position throughout the field.""" - x_coord = np.linspace(0, self.xlim, mesh_bins) - y_coord = np.linspace(0, self.ylim, mesh_bins) - - x_mesh, y_mesh = np.meshgrid(x_coord, y_coord) - - wfe_rms_field = np.array( - [ - self.compute_wfe_rms(_x, _y) - for _x, _y in zip(x_mesh.flatten(), y_mesh.flatten()) - ] - ) - - wfe_rms_field_mesh = wfe_rms_field.reshape((mesh_bins, mesh_bins)) - - # Plot the field - fig = plt.figure(figsize=(8, 8)) - ax1 = fig.add_subplot(111) - im1 = ax1.imshow(wfe_rms_field_mesh, interpolation="None") - divider = make_axes_locatable(ax1) - cax = divider.append_axes("right", size="5%", pad=0.05) - fig.colorbar(im1, cax=cax, orientation="vertical") - ax1.set_title("PSF field WFE RMS [um]") - ax1.set_xlabel("x axis") - ax1.set_ylabel("y axis") - - if save_img: - plt.savefig("./WFE_field_meshdim_%d.pdf" % mesh_bins, bbox_inches="tight") - - plt.show() - - def get_poly_PSF(self, x, y, SED): - # Calculate the specific field's zernike coeffs - self.zernike_coeff_map(x, y) - # Set the Z coefficients to the PSF toolkit generator - self.sim_psf_toolkit.set_z_coeffs(self.get_zernike_coeff_map()) - - return self.sim_psf_toolkit.generate_poly_PSF(SED, n_bins=self.n_bins) diff --git a/src/wf_psf/psf_models/GenPolyFieldPSF.py b/src/wf_psf/psf_models/GenPolyFieldPSF.py deleted file mode 100644 index e04c7064..00000000 --- a/src/wf_psf/psf_models/GenPolyFieldPSF.py +++ /dev/null @@ -1,261 +0,0 @@ -import numpy as np -import matplotlib.pyplot as plt -import matplotlib as mpl -from matplotlib.colors import ListedColormap, LinearSegmentedColormap -from mpl_toolkits.axes_grid1 import make_axes_locatable - - -class GenPolyFieldPSF(object): - """Generate PSF field with polynomial variations of Zernike coefficients.""" - - def __init__( - self, - sim_psf_toolkit, - d_max=2, - grid_points=[4, 4], - max_order=45, - x_lims=[0, 1e3], - y_lims=[0, 1e3], - n_bins=35, - lim_max_wfe_rms=None, - auto_init=True, - verbose=False, - ): - # Input attributes - self.sim_psf_toolkit = sim_psf_toolkit - self.max_order = max_order - self.d_max = d_max - self.x_lims = x_lims - self.y_lims = y_lims - self.grid_points = grid_points - self.n_bins = n_bins - self.verbose = verbose - if lim_max_wfe_rms is None: - self.lim_max_wfe_rms = sim_psf_toolkit.max_wfe_rms - else: - self.lim_max_wfe_rms = lim_max_wfe_rms - - self.auto_init = auto_init - - # Class attributes - self.C_poly = None - self.WFE_RMS = None - - # Build coefficient polynomial matric - if self.auto_init: - self.build_poly_coefficients() - - def scale_positions(self, xv_flat, yv_flat): - # Scale positions to the square [-1,1] x [-1,1] - scaled_x = (xv_flat - self.x_lims[0]) / (self.x_lims[1] - self.x_lims[0]) - scaled_x = (scaled_x - 0.5) * 2 - scaled_y = (yv_flat - self.y_lims[0]) / (self.y_lims[1] - self.y_lims[0]) - scaled_y = (scaled_y - 0.5) * 2 - - return scaled_x, scaled_y - - def poly_mat_gen(self, xv_flat, yv_flat): - """Generate polynomial matrix of positions. - - Parameters - ---------- - xv_flat: np.ndarray (dim,) - x positions. - yv_flat: np.ndarray (dim,) - y positions. - """ - n_mono = (self.d_max + 1) * (self.d_max + 2) // 2 - if np.isscalar(xv_flat): - Pi = np.zeros((n_mono, 1)) - else: - Pi = np.zeros((n_mono, xv_flat.shape[0])) - - # Scale positions to the square [-1,1] x [-1,1] - scaled_x, scaled_y = self.scale_positions(xv_flat, yv_flat) - - for d in range(self.d_max + 1): - row_idx = d * (d + 1) // 2 - for p in range(d + 1): - Pi[row_idx + p, :] = scaled_x ** (d - p) * scaled_y**p - - return Pi - - def zernike_poly_gen(self, xv_flat, yv_flat): - """Generate zernike values from positions. - - Parameters - ---------- - xv_flat: np.ndarray (dim,) - x positions. - yv_flat: np.ndarray (dim,) - y positions. - """ - # Generate the polynomial matrix - Pi_samples = self.poly_mat_gen(xv_flat, yv_flat) - - return self.C_poly @ Pi_samples - - def set_C_poly(self, C_poly): - """Set the polynomial coefficients. - - Parameters - ---------- - C_poly: np.ndarray - Polynomial coefficients. - """ - self.C_poly = C_poly - - def set_WFE_RMS(self, WFE_RMS): - """Set the WFE RMS map. - - Parameters - ---------- - WFE_RMS: np.ndarray - WFE_RMS map of the C_poly values. - """ - self.WFE_RMS = WFE_RMS - - def build_poly_coefficients(self): - """Build a polynomial coefficient matrix.""" - ## Choose the anchor points on a regular grid - x = np.linspace( - self.x_lims[0], self.x_lims[1], num=self.grid_points[0], endpoint=True - ) - y = np.linspace( - self.y_lims[0], self.y_lims[1], num=self.grid_points[1], endpoint=True - ) - # Build mesh - xv_grid, yv_grid = np.meshgrid(x, y) - - ## Random position shift - # It is done as a random shift defined in a - # square centred in each grid position so that there is - # no overlaping between the squares. - xv_rand = np.random.rand(self.grid_points[0], self.grid_points[1]) - yv_rand = np.random.rand(self.grid_points[0], self.grid_points[1]) - # Calculate the shift length - x_step = (self.x_lims[1] - self.x_lims[0]) / self.grid_points[0] - y_step = (self.y_lims[1] - self.y_lims[0]) / self.grid_points[1] - # Center and scale shifts - xv_rand = (xv_rand - 0.5) * x_step - yv_rand = (yv_rand - 0.5) * y_step - # Add the shift to the grid values - xv = xv_grid + xv_rand - yv = yv_grid + yv_rand - # Flatten - xv_flat = xv.flatten() - yv_flat = yv.flatten() - # Check the limits - xv_flat[xv_flat > self.x_lims[1]] = self.x_lims[1] - xv_flat[xv_flat < self.x_lims[0]] = self.x_lims[0] - yv_flat[yv_flat > self.y_lims[1]] = self.y_lims[1] - yv_flat[yv_flat < self.y_lims[0]] = self.y_lims[0] - - ## Select a random vector of size `max_order` for each position - # When concatenated into the Z matrix we have: - Z = np.random.randn(self.max_order, len(xv_flat)) - # Normalize so that each position has the lim_max_wfe_rms - norm_weights = np.sqrt(np.sum(Z**2, axis=1)) - Z /= norm_weights.reshape((-1, 1)) / self.lim_max_wfe_rms - - ## Generate position polynomial matrix - Pi = self.poly_mat_gen(xv_flat, yv_flat) - - ## Estimate by least-squares the C matrix - self.C_poly = Z @ np.linalg.pinv(Pi) - # Re-estimate the Z matrix with the estimated C - Z_hat = self.C_poly @ Pi - - ## Sampling the space - # Choose the anchor points on a regular grid - x = np.linspace(self.x_lims[0], self.x_lims[1], num=100, endpoint=True) - y = np.linspace(self.y_lims[0], self.y_lims[1], num=100, endpoint=True) - xv_grid, yv_grid = np.meshgrid(x, y) - # Recalculate the Zernike coefficients with the new C_poly matrix - Z_est = self.zernike_poly_gen(xv_grid.flatten(), yv_grid.flatten()) - - ## We need to renormalize and check that the WFE RMS has a max value near the expected one - # Calculate the WFE_RMS on the new grid - calc_wfe = np.sqrt(np.sum(Z_est**2, axis=0)) - # Due to the polynomnial behaviour we will set the mean WFE_RMS over the field of view to be 80% of - # the maximum allowed WFE_RMS per position. - scale_factor = (0.8 * self.lim_max_wfe_rms) / np.mean(calc_wfe) - self.C_poly *= scale_factor - - # Recalculate the Z coefficients - scaled_Z_est = self.zernike_poly_gen(xv_grid.flatten(), yv_grid.flatten()) - # Calculate and save the WFE_RMS map of the C_poly values. - self.WFE_RMS = np.sqrt(np.sum(scaled_Z_est**2, axis=0)).reshape(xv_grid.shape) - - def show_WFE_RMS(self, save_img=False, save_name="WFE_field_meshdim"): - """Plot the WFE RMS map.""" - fig = plt.figure(figsize=(8, 8)) - ax1 = fig.add_subplot(111) - im1 = ax1.imshow(self.WFE_RMS, interpolation="None") - divider = make_axes_locatable(ax1) - cax = divider.append_axes("right", size="5%", pad=0.05) - fig.colorbar(im1, cax=cax, orientation="vertical") - ax1.set_title("PSF field WFE RMS [um]") - ax1.set_xlabel("x axis") - ax1.set_ylabel("y axis") - if save_img: - plt.savefig("./" + save_name + ".pdf", bbox_inches="tight") - plt.show() - - def calc_zernike(self, xv_flat, yv_flat): - """Calculate Zernikes for a specific position. - - Normalize (x,y) inputs - (x,y) need to be in [self.x_lims[0],self.x_lims[1]] x [self.y_lims[0],self.y_lims[1]] - (x_norm,y_norm) need to be in [-1, +1] x [-1, +1] - """ - # Check limits - x_check = np.sum(xv_flat >= self.x_lims[1] * 1.1) + np.sum( - xv_flat <= self.x_lims[0] * 1.1 - ) - y_check = np.sum(yv_flat >= self.y_lims[1] * 1.1) + np.sum( - yv_flat <= self.y_lims[0] * 1.1 - ) - - if self.verbose and x_check > 0: - print( - "WARNING! x value is outside the limits [%f, %f]" - % (self.x_lims[0], self.x_lims[1]) - ) - print(xv_flat) - print(x_check) - if self.verbose and y_check > 0: - print( - "WARNING! y value is outside the limits [%f, %f]" - % (self.y_lims[0], self.y_lims[1]) - ) - print(yv_flat) - print(y_check) - - # Return Zernikes - # The position scaling is done inside zernike_poly_gen - return self.zernike_poly_gen(xv_flat, yv_flat) - - def get_mono_PSF(self, xv_flat, yv_flat, lambda_obs=0.725): - """Calculate monochromatic PSF at a specific position and wavelength.""" - # Calculate the specific field's zernike coeffs - zernikes = self.calc_zernike(xv_flat, yv_flat) - # Set the Z coefficients to the PSF toolkit generator - self.sim_psf_toolkit.set_z_coeffs(zernikes) - # Generate the monochromatic psf - self.sim_psf_toolkit.generate_mono_PSF( - lambda_obs=lambda_obs, regen_sample=False - ) - # Return the generated PSF - return self.sim_psf_toolkit.get_psf() - - def get_poly_PSF(self, xv_flat, yv_flat, SED): - """Calculate polychromatic PSF for a specific position and SED.""" - # Calculate the specific field's zernike coeffs - zernikes = self.calc_zernike(xv_flat, yv_flat) - # Set the Z coefficients to the PSF toolkit generator - self.sim_psf_toolkit.set_z_coeffs(zernikes) - poly_psf = self.sim_psf_toolkit.generate_poly_PSF(SED, n_bins=self.n_bins) - opd = self.sim_psf_toolkit.opd - - return poly_psf, zernikes, opd diff --git a/src/wf_psf/psf_models/tf_alt_psf_models.py b/src/wf_psf/psf_models/tf_alt_psf_models.py deleted file mode 100644 index 9d13fc0e..00000000 --- a/src/wf_psf/psf_models/tf_alt_psf_models.py +++ /dev/null @@ -1,442 +0,0 @@ -import numpy as np -import tensorflow as tf -from wf_psf.psf_models.tf_layers import ( - TF_poly_Z_field, - TF_zernike_OPD, - TF_batch_poly_PSF, -) -from wf_psf.psf_models.tf_layers import TF_NP_poly_OPD, TF_batch_mono_PSF - - -class TF_SemiParam_field_l2_OPD(tf.keras.Model): - """PSF field forward model! - - Semi parametric model based on the Zernike polynomial basis. The - - Parameters - ---------- - zernike_maps: Tensor(n_batch, opd_dim, opd_dim) - Zernike polynomial maps. - obscurations: Tensor(opd_dim, opd_dim) - Predefined obscurations of the phase. - batch_size: int - Batch sizet - output_Q: float - Oversampling used. This should match the oversampling Q used to generate - the diffraction zero padding that is found in the input `packed_SEDs`. - We call this other Q the `input_Q`. - In that case, we replicate the original sampling of the model used to - calculate the input `packed_SEDs`. - The final oversampling of the generated PSFs with respect to the - original instrument sampling depend on the division `input_Q/output_Q`. - It is not recommended to use `output_Q < 1`. - Although it works with float values it is better to use integer values. - d_max_nonparam: int - Maximum degree of the polynomial for the non-parametric variations. - l2_param: float - Parameter going with the l2 loss on the opd. - output_dim: int - Output dimension of the PSF stamps. - n_zernikes: int - Order of the Zernike polynomial for the parametric model. - d_max: int - Maximum degree of the polynomial for the Zernike coefficient variations. - x_lims: [float, float] - Limits for the x coordinate of the PSF field. - y_lims: [float, float] - Limits for the x coordinate of the PSF field. - coeff_mat: Tensor or None - Initialization of the coefficient matrix defining the parametric psf - field model. - - """ - - def __init__( - self, - zernike_maps, - obscurations, - batch_size, - output_Q, - d_max_nonparam=3, - l2_param=1e-11, - output_dim=64, - n_zernikes=45, - d_max=2, - x_lims=[0, 1e3], - y_lims=[0, 1e3], - coeff_mat=None, - name="TF_SemiParam_field_l2_OPD", - ): - super(TF_SemiParam_field_l2_OPD, self).__init__() - - # Inputs: oversampling used - self.output_Q = output_Q - - # Inputs: TF_poly_Z_field - self.n_zernikes = n_zernikes - self.d_max = d_max - self.x_lims = x_lims - self.y_lims = y_lims - - # Inputs: TF_NP_poly_OPD - self.d_max_nonparam = d_max_nonparam - self.opd_dim = tf.shape(zernike_maps)[1].numpy() - - # Inputs: TF_zernike_OPD - # They are not stored as they are memory-heavy - # zernike_maps =[] - - # Inputs: TF_batch_poly_PSF - self.batch_size = batch_size - self.obscurations = obscurations - self.output_dim = output_dim - - # Inputs: Loss - self.l2_param = l2_param - - # Initialize the first layer - self.tf_poly_Z_field = TF_poly_Z_field( - x_lims=self.x_lims, - y_lims=self.y_lims, - n_zernikes=self.n_zernikes, - d_max=self.d_max, - ) - - # Initialize the zernike to OPD layer - self.tf_zernike_OPD = TF_zernike_OPD(zernike_maps=zernike_maps) - - # Initialize the non-parametric layer - self.tf_np_poly_opd = TF_NP_poly_OPD( - x_lims=self.x_lims, - y_lims=self.y_lims, - d_max=self.d_max_nonparam, - opd_dim=self.opd_dim, - ) - - # Initialize the batch opd to batch polychromatic PSF layer - self.tf_batch_poly_PSF = TF_batch_poly_PSF( - obscurations=self.obscurations, - output_Q=self.output_Q, - output_dim=self.output_dim, - ) - - # Initialize the model parameters with non-default value - if coeff_mat is not None: - self.assign_coeff_matrix(coeff_mat) - - def get_coeff_matrix(self): - """Get coefficient matrix.""" - return self.tf_poly_Z_field.get_coeff_matrix() - - def assign_coeff_matrix(self, coeff_mat): - """Assign coefficient matrix.""" - self.tf_poly_Z_field.assign_coeff_matrix(coeff_mat) - - def set_zero_nonparam(self): - """Set to zero the non-parametric part.""" - self.tf_np_poly_opd.set_alpha_zero() - - def set_nonzero_nonparam(self): - """Set to non-zero the non-parametric part.""" - self.tf_np_poly_opd.set_alpha_identity() - - def set_trainable_layers(self, param_bool=True, nonparam_bool=True): - """Set the layers to be trainable or not.""" - self.tf_np_poly_opd.trainable = nonparam_bool - self.tf_poly_Z_field.trainable = param_bool - - def set_output_Q(self, output_Q, output_dim=None): - """Set the value of the output_Q parameter. - Useful for generating/predicting PSFs at a different sampling wrt the - observation sampling. - """ - self.output_Q = output_Q - if output_dim is not None: - self.output_dim = output_dim - - # Reinitialize the PSF batch poly generator - self.tf_batch_poly_PSF = TF_batch_poly_PSF( - obscurations=self.obscurations, - output_Q=self.output_Q, - output_dim=self.output_dim, - ) - - def predict_mono_psfs(self, input_positions, lambda_obs, phase_N): - """Predict a set of monochromatic PSF at desired positions. - - input_positions: Tensor(batch_dim x 2) - - lambda_obs: float - Observed wavelength in um. - - phase_N: int - Required wavefront dimension. Should be calculated with as: - ``simPSF_np = wf.SimPSFToolkit(...)`` - ``phase_N = simPSF_np.feasible_N(lambda_obs)`` - """ - - # Initialise the monochromatic PSF batch calculator - tf_batch_mono_psf = TF_batch_mono_PSF( - obscurations=self.obscurations, - output_Q=self.output_Q, - output_dim=self.output_dim, - ) - # Set the lambda_obs and the phase_N parameters - tf_batch_mono_psf.set_lambda_phaseN(phase_N, lambda_obs) - - # Calculate parametric part - zernike_coeffs = self.tf_poly_Z_field(input_positions) - param_opd_maps = self.tf_zernike_OPD(zernike_coeffs) - # Calculate the non parametric part - nonparam_opd_maps = self.tf_np_poly_opd(input_positions) - # Add the estimations - opd_maps = tf.math.add(param_opd_maps, nonparam_opd_maps) - - # Compute the monochromatic PSFs - mono_psf_batch = tf_batch_mono_psf(opd_maps) - - return mono_psf_batch - - def predict_opd(self, input_positions): - """Predict the OPD at some positions. - - Parameters - ---------- - input_positions: Tensor(batch_dim x 2) - Positions to predict the OPD. - - Returns - ------- - opd_maps : Tensor [batch x opd_dim x opd_dim] - OPD at requested positions. - - """ - # Calculate parametric part - zernike_coeffs = self.tf_poly_Z_field(input_positions) - param_opd_maps = self.tf_zernike_OPD(zernike_coeffs) - # Calculate the non parametric part - nonparam_opd_maps = self.tf_np_poly_opd(input_positions) - # Add the estimations - opd_maps = tf.math.add(param_opd_maps, nonparam_opd_maps) - - return opd_maps - - def call(self, inputs): - """Define the PSF field forward model. - - [1] From positions to Zernike coefficients - [2] From Zernike coefficients to OPD maps - [3] From OPD maps and SED info to polychromatic PSFs - - OPD: Optical Path Differences - """ - # Unpack inputs - input_positions = inputs[0] - packed_SEDs = inputs[1] - - # Forward model - # Calculate parametric part - zernike_coeffs = self.tf_poly_Z_field(input_positions) - param_opd_maps = self.tf_zernike_OPD(zernike_coeffs) - # Calculate the non parametric part - nonparam_opd_maps = self.tf_np_poly_opd(input_positions) - # Add the estimations - opd_maps = tf.math.add(param_opd_maps, nonparam_opd_maps) - - # Add l2 loss on the OPD - self.add_loss(self.l2_param * tf.math.reduce_sum(tf.math.square(opd_maps))) - - # Compute the polychromatic PSFs - poly_psfs = self.tf_batch_poly_PSF([opd_maps, packed_SEDs]) - - return poly_psfs - - -class TF_PSF_field_model_l2_OPD(tf.keras.Model): - """Parametric PSF field model! - - Fully parametric model based on the Zernike polynomial basis. - - Parameters - ---------- - zernike_maps: Tensor(n_batch, opd_dim, opd_dim) - Zernike polynomial maps. - obscurations: Tensor(opd_dim, opd_dim) - Predefined obscurations of the phase. - batch_size: int - Batch size - l2_param: float - Parameter going with the l2 loss on the opd. - output_dim: int - Output dimension of the PSF stamps. - n_zernikes: int - Order of the Zernike polynomial for the parametric model. - d_max: int - Maximum degree of the polynomial for the Zernike coefficient variations. - x_lims: [float, float] - Limits for the x coordinate of the PSF field. - y_lims: [float, float] - Limits for the x coordinate of the PSF field. - coeff_mat: Tensor or None - Initialization of the coefficient matrix defining the parametric psf - field model. - - """ - - def __init__( - self, - zernike_maps, - obscurations, - batch_size, - output_Q, - l2_param=1e-11, - output_dim=64, - n_zernikes=45, - d_max=2, - x_lims=[0, 1e3], - y_lims=[0, 1e3], - coeff_mat=None, - name="TF_PSF_field_model_l2_OPD", - ): - super(TF_PSF_field_model_l2_OPD, self).__init__() - - self.output_Q = output_Q - - # Inputs: TF_poly_Z_field - self.n_zernikes = n_zernikes - self.d_max = d_max - self.x_lims = x_lims - self.y_lims = y_lims - - # Inputs: TF_zernike_OPD - # They are not stored as they are memory-heavy - # zernike_maps =[] - - # Inputs: TF_batch_poly_PSF - self.batch_size = batch_size - self.obscurations = obscurations - self.output_dim = output_dim - - # Inputs: Loss - self.l2_param = l2_param - - # Initialize the first layer - self.tf_poly_Z_field = TF_poly_Z_field( - x_lims=self.x_lims, - y_lims=self.y_lims, - n_zernikes=self.n_zernikes, - d_max=self.d_max, - ) - - # Initialize the zernike to OPD layer - self.tf_zernike_OPD = TF_zernike_OPD(zernike_maps=zernike_maps) - - # Initialize the batch opd to batch polychromatic PSF layer - self.tf_batch_poly_PSF = TF_batch_poly_PSF( - obscurations=self.obscurations, - output_Q=self.output_Q, - output_dim=self.output_dim, - ) - - # Initialize the model parameters with non-default value - if coeff_mat is not None: - self.assign_coeff_matrix(coeff_mat) - - def get_coeff_matrix(self): - """Get coefficient matrix.""" - return self.tf_poly_Z_field.get_coeff_matrix() - - def assign_coeff_matrix(self, coeff_mat): - """Assign coefficient matrix.""" - self.tf_poly_Z_field.assign_coeff_matrix(coeff_mat) - - def set_output_Q(self, output_Q, output_dim=None): - """Set the value of the output_Q parameter. - Useful for generating/predicting PSFs at a different sampling wrt the - observation sampling. - """ - self.output_Q = output_Q - if output_dim is not None: - self.output_dim = output_dim - # Reinitialize the PSF batch poly generator - self.tf_batch_poly_PSF = TF_batch_poly_PSF( - obscurations=self.obscurations, - output_Q=self.output_Q, - output_dim=self.output_dim, - ) - - def predict_mono_psfs(self, input_positions, lambda_obs, phase_N): - """Predict a set of monochromatic PSF at desired positions. - - input_positions: Tensor(batch_dim x 2) - - lambda_obs: float - Observed wavelength in um. - - phase_N: int - Required wavefront dimension. Should be calculated with as: - ``simPSF_np = wf.SimPSFToolkit(...)`` - ``phase_N = simPSF_np.feasible_N(lambda_obs)`` - """ - - # Initialise the monochromatic PSF batch calculator - tf_batch_mono_psf = TF_batch_mono_PSF( - obscurations=self.obscurations, - output_Q=self.output_Q, - output_dim=self.output_dim, - ) - # Set the lambda_obs and the phase_N parameters - tf_batch_mono_psf.set_lambda_phaseN(phase_N, lambda_obs) - - # Continue the OPD maps - zernike_coeffs = self.tf_poly_Z_field(input_positions) - opd_maps = self.tf_zernike_OPD(zernike_coeffs) - - # Compute the monochromatic PSFs - mono_psf_batch = tf_batch_mono_psf(opd_maps) - - return mono_psf_batch - - def predict_opd(self, input_positions): - """Predict the OPD at some positions. - - Parameters - ---------- - input_positions: Tensor(batch_dim x 2) - Positions to predict the OPD. - - Returns - ------- - opd_maps : Tensor [batch x opd_dim x opd_dim] - OPD at requested positions. - - """ - # Continue the OPD maps - zernike_coeffs = self.tf_poly_Z_field(input_positions) - opd_maps = self.tf_zernike_OPD(zernike_coeffs) - - return opd_maps - - def call(self, inputs): - """Define the PSF field forward model. - - [1] From positions to Zernike coefficients - [2] From Zernike coefficients to OPD maps - [3] From OPD maps and SED info to polychromatic PSFs - - OPD: Optical Path Differences - """ - # Unpack inputs - input_positions = inputs[0] - packed_SEDs = inputs[1] - - # Continue the forward model - zernike_coeffs = self.tf_poly_Z_field(input_positions) - opd_maps = self.tf_zernike_OPD(zernike_coeffs) - - # Add l2 loss on the OPD - self.add_loss(self.l2_param * tf.math.reduce_sum(tf.math.square(opd_maps))) - - poly_psfs = self.tf_batch_poly_PSF([opd_maps, packed_SEDs]) - - return poly_psfs diff --git a/src/wf_psf/psf_models/tf_mccd_psf_field.py b/src/wf_psf/psf_models/tf_mccd_psf_field.py deleted file mode 100644 index ca965ed1..00000000 --- a/src/wf_psf/psf_models/tf_mccd_psf_field.py +++ /dev/null @@ -1,707 +0,0 @@ -import numpy as np -import tensorflow as tf -from tensorflow.python.keras.engine import data_adapter -from wf_psf.psf_models.tf_layers import ( - TF_poly_Z_field, - TF_zernike_OPD, - TF_batch_poly_PSF, -) -from wf_psf.psf_models.tf_layers import TF_NP_MCCD_OPD_v2, TF_NP_GRAPH_OPD -from wf_psf.psf_models.tf_layers import TF_batch_mono_PSF -from wf_psf.utils.graph_utils import GraphBuilder -from wf_psf.utils.utils import calc_poly_position_mat - - -class TF_SP_MCCD_field(tf.keras.Model): - r"""Semi-parametric MCCD PSF field model! - - Semi parametric model based on the hybrid-MCCD matrix factorization scheme. - - The forward model is different for the training procedure and for the - inference procedure. This makes things more complicated and requires several - custom functions. - - The prediction step is the forward model for the inference while the - ``call(inputs, trainable=True)`` is the forward model for the training - procedure. When calling ``call(inputs, trainable=False)`` we are falling - back to the predict function for the inference forward model. This is needed - in order to handle the calculation of validation metrics on the validation - dataset. - - - Parameters - ---------- - zernike_maps: Tensor(n_batch, opd_dim, opd_dim) - Zernike polynomial maps. - obscurations: Tensor(opd_dim, opd_dim) - Predefined obscurations of the phase. - batch_size: int - Batch size - obs_pos: Tensor(n_stars, 2) - The positions of all the stars - spatial_dic: - TODO ... - output_Q: int - Downsampling rate to match the specified telescope's sampling. The value - of `output_Q` should be equal to `oversampling_rate` in order to have - the right pixel sampling corresponding to the telescope characteristics - `pix_sampling`, `tel_diameter`, `tel_focal_length`. The final - oversampling obtained is `oversampling_rate/output_Q`. - Default is `1`, so the output psf will be super-resolved by a factor of - `oversampling_rate`. - l2_param: float - Parameter going with the l2 loss on the opd. If it is `0.` the loss - is not added. Default is `0.`. - d_max_nonparam: int - Maximum degree of the polynomial for the non-parametric variations. - output_dim: int - Output dimension of the PSF stamps. - n_zernikes: int - Order of the Zernike polynomial for the parametric model. - d_max: int - Maximum degree of the polynomial for the Zernike coefficient variations. - x_lims: [float, float] - Limits for the x coordinate of the PSF field. - y_lims: [float, float] - Limits for the x coordinate of the PSF field. - coeff_mat: Tensor or None - Initialization of the coefficient matrix defining the parametric psf - field model. - - """ - - def __init__( - self, - zernike_maps, - obscurations, - batch_size, - obs_pos, - spatial_dic, - output_Q, - l2_param=0.0, - d_max_nonparam=3, - graph_features=6, - l1_rate=1e-3, - output_dim=64, - n_zernikes=45, - d_max=2, - x_lims=[0, 1e3], - y_lims=[0, 1e3], - coeff_mat=None, - name="TF_SP_MCCD_field", - ): - super(TF_SP_MCCD_field, self).__init__() - - # Inputs: oversampling used - self.output_Q = output_Q - - # Inputs: TF_poly_Z_field - self.n_zernikes = n_zernikes - self.d_max = d_max - self.x_lims = x_lims - self.y_lims = y_lims - - # Inputs: TF_NP_MCCD_OPD - self.d_max_nonparam = d_max_nonparam - self.opd_dim = tf.shape(zernike_maps)[1].numpy() - self.graph_features = graph_features - self.l1_rate = l1_rate - - # Inputs: TF_zernike_OPD - # They are not stored as they are memory-heavy - # zernike_maps =[] - - # Inputs: TF_batch_poly_PSF - self.batch_size = batch_size - self.obscurations = obscurations - self.output_dim = output_dim - - # Inputs: Loss - self.l2_param = l2_param - - # Initialize the first layer - self.tf_poly_Z_field = TF_poly_Z_field( - x_lims=self.x_lims, - y_lims=self.y_lims, - n_zernikes=self.n_zernikes, - d_max=self.d_max, - ) - - # Initialize the zernike to OPD layer - self.tf_zernike_OPD = TF_zernike_OPD(zernike_maps=zernike_maps) - - # Initialize the non-parametric layer - self.tf_NP_mccd_OPD = TF_NP_MCCD_OPD_v2( - obs_pos=obs_pos, - spatial_dic=spatial_dic, - x_lims=self.x_lims, - y_lims=self.y_lims, - d_max=self.d_max_nonparam, - graph_features=self.graph_features, - l1_rate=self.l1_rate, - opd_dim=self.opd_dim, - ) - - # Initialize the batch opd to batch polychromatic PSF layer - self.tf_batch_poly_PSF = TF_batch_poly_PSF( - obscurations=self.obscurations, - output_Q=self.output_Q, - output_dim=self.output_dim, - ) - - # Initialize the model parameters with non-default value - if coeff_mat is not None: - self.assign_coeff_matrix(coeff_mat) - - def set_zero_nonparam(self): - r"""Set to zero the non-parametric part.""" - self.tf_NP_mccd_OPD.set_alpha_zero() - - def set_output_Q(self, output_Q, output_dim=None): - r"""Set the value of the output_Q parameter. - Useful for generating/predicting PSFs at a different sampling wrt the - observation sampling. - """ - self.output_Q = output_Q - if output_dim is not None: - self.output_dim = output_dim - # Reinitialize the PSF batch poly generator - self.tf_batch_poly_PSF = TF_batch_poly_PSF( - obscurations=self.obscurations, - output_Q=self.output_Q, - output_dim=self.output_dim, - ) - - def set_l1_rate(self, new_l1_rate): - r"""Set l1 rate the non-parametric part.""" - self.l1_rate = new_l1_rate - self.tf_NP_mccd_OPD.l1_rate = new_l1_rate - - def set_nonzero_nonparam(self): - r"""Set to non-zero the non-parametric part.""" - self.tf_NP_mccd_OPD.set_alpha_identity() - - def set_trainable_layers(self, param_bool=True, nonparam_bool=True): - r"""Set the layers to be trainable or not.""" - self.tf_NP_mccd_OPD.trainable = nonparam_bool - self.tf_poly_Z_field.trainable = param_bool - - def get_coeff_matrix(self): - """Get coefficient matrix.""" - return self.tf_poly_Z_field.get_coeff_matrix() - - def assign_coeff_matrix(self, coeff_mat): - r"""Assign coefficient matrix.""" - self.tf_poly_Z_field.assign_coeff_matrix(coeff_mat) - - def predict_step(self, data, evaluate_step=False): - r"""Custom predict (inference) step. - - It is needed as the non-parametric MCCD part requires a special - interpolation (different from training). - - """ - if evaluate_step: - input_data = data - else: - # Format input data - data = data_adapter.expand_1d(data) - input_data, _, _ = data_adapter.unpack_x_y_sample_weight(data) - - # Unpack inputs - input_positions = input_data[0] - packed_SEDs = input_data[1] - - # Calculate parametric part - zernike_coeffs = self.tf_poly_Z_field(input_positions) - param_opd_maps = self.tf_zernike_OPD(zernike_coeffs) - - # Calculate the non parametric part - nonparam_opd_maps = self.tf_NP_mccd_OPD.predict(input_positions) - - # Add the estimations - opd_maps = tf.math.add(param_opd_maps, nonparam_opd_maps) - # Compute the polychromatic PSFs - poly_psfs = self.tf_batch_poly_PSF([opd_maps, packed_SEDs]) - - return poly_psfs - - def predict_mono_psfs(self, input_positions, lambda_obs, phase_N): - r"""Predict a set of monochromatic PSF at desired positions. - - Parameters - ---------- - input_positions: Tensor(batch x 2) - Positions to predict the monochromatic PSFs. - lambda_obs: float - Observed wavelength in um. - phase_N: int - Required wavefront dimension. Should be calculated with as: - ``simPSF_np = wf.SimPSFToolkit(...)`` - ``phase_N = simPSF_np.feasible_N(lambda_obs)`` - - Returns - ------- - mono_psf_batch: Tensor [batch x output_dim x output_dim] - Batch of monochromatic PSFs at requested positions and - wavelength. - """ - # Initialise the monochromatic PSF batch calculator - tf_batch_mono_psf = TF_batch_mono_PSF( - obscurations=self.obscurations, - output_Q=self.output_Q, - output_dim=self.output_dim, - ) - # Set the lambda_obs and the phase_N parameters - tf_batch_mono_psf.set_lambda_phaseN(phase_N, lambda_obs) - - # Calculate parametric part - zernike_coeffs = self.tf_poly_Z_field(input_positions) - param_opd_maps = self.tf_zernike_OPD(zernike_coeffs) - - # Calculate the non parametric part - nonparam_opd_maps = self.tf_NP_mccd_OPD.predict(input_positions) - - # Add the estimations - opd_maps = tf.math.add(param_opd_maps, nonparam_opd_maps) - - # Compute the monochromatic PSFs - mono_psf_batch = tf_batch_mono_psf(opd_maps) - - return mono_psf_batch - - def predict_opd(self, input_positions): - r"""Predict the OPD at some positions. - - Parameters - ---------- - input_positions: Tensor(batch_dim x 2) - Positions to predict the OPD. - - Returns - ------- - opd_maps : Tensor [batch x opd_dim x opd_dim] - OPD at requested positions. - - """ - # Calculate parametric part - zernike_coeffs = self.tf_poly_Z_field(input_positions) - param_opd_maps = self.tf_zernike_OPD(zernike_coeffs) - - # Calculate the non parametric part - nonparam_opd_maps = self.tf_NP_mccd_OPD.predict(input_positions) - - # Add the estimations - opd_maps = tf.math.add(param_opd_maps, nonparam_opd_maps) - - return opd_maps - - def call(self, inputs, training=True): - r"""Define the PSF field forward model. - - [1] From positions to Zernike coefficients - [2] From Zernike coefficients to OPD maps - [3] From OPD maps and SED info to polychromatic PSFs - - OPD: Optical Path Differences - """ - # Unpack inputs - input_positions = inputs[0] - packed_SEDs = inputs[1] - - # Forward model - # For the training - if training: - # Calculate parametric part - zernike_coeffs = self.tf_poly_Z_field(input_positions) - param_opd_maps = self.tf_zernike_OPD(zernike_coeffs) - # Calculate the non parametric part - nonparam_opd_maps = self.tf_NP_mccd_OPD(input_positions) - # Add l2 loss on the parmetric OPD - self.add_loss( - self.l2_param * tf.math.reduce_sum(tf.math.square(nonparam_opd_maps)) - ) - # Add the estimations - opd_maps = tf.math.add(param_opd_maps, nonparam_opd_maps) - # Compute the polychromatic PSFs - poly_psfs = self.tf_batch_poly_PSF([opd_maps, packed_SEDs]) - - # For the inference - # This is absolutely needed to compute the metrics on the - # validation data. - else: - # Compute predictions - poly_psfs = self.predict_step(inputs, evaluate_step=True) - - return poly_psfs - - -def build_mccd_spatial_dic( - obs_stars, obs_pos, x_lims, y_lims, d_max=2, graph_features=6, verbose=0 -): - """Build the spatial-constraint dictionary. - - Based on the hybrid approach from the MCCD model. - """ - # The obs_data needs to be in RCA format (with the batch dim at the end) - - # Graph parameters - graph_kwargs = { - "obs_data": obs_stars.swapaxes(0, 1).swapaxes(1, 2), - "obs_pos": obs_pos, - "obs_weights": np.ones_like(obs_stars), - "n_comp": graph_features, - "n_eigenvects": 5, - "n_iter": 3, - "ea_gridsize": 10, - "distances": None, - "auto_run": True, - "verbose": verbose, - } - - # Compute graph-spatial constraint matrix - VT = GraphBuilder(**graph_kwargs).VT - - # Compute polynomial-spatial constaint matrix - tf_Pi = calc_poly_position_mat( - pos=obs_pos, x_lims=x_lims, y_lims=y_lims, d_max=d_max - ) - - # Need to translate to have the batch dimension first - spatial_dic = np.concatenate((tf_Pi.numpy(), VT), axis=0).T - - # Return the tf spatial dictionary - return tf.convert_to_tensor(spatial_dic, dtype=tf.float32) - - -def build_mccd_spatial_dic_v2( - obs_stars, obs_pos, x_lims, y_lims, d_max=2, graph_features=6, verbose=0 -): - """Build the spatial-constraint dictionaries. - - Based on the hybrid approach from the MCCD model. - Returns the polynomial dict and the graph dict. - """ - # The obs_data needs to be in RCA format (with the batch dim at the end) - - # Graph parameters - graph_kwargs = { - "obs_data": obs_stars.swapaxes(0, 1).swapaxes(1, 2), - "obs_pos": obs_pos, - "obs_weights": np.ones_like(obs_stars), - "n_comp": graph_features, - "n_eigenvects": 5, - "n_iter": 3, - "ea_gridsize": 10, - "distances": None, - "auto_run": True, - "verbose": verbose, - } - - # Compute graph-spatial constraint matrix - VT = GraphBuilder(**graph_kwargs).VT - - # Compute polynomial-spatial constaint matrix - tf_Pi = calc_poly_position_mat( - pos=obs_pos, x_lims=x_lims, y_lims=y_lims, d_max=d_max - ) - - # Return the poly dictionary and the graph dictionary - return tf.transpose(tf_Pi, perm=[1, 0]), tf.convert_to_tensor( - VT.T, dtype=tf.float32 - ) - - -class TF_SP_graph_field(tf.keras.Model): - # ids=("graph",) - r"""Semi-parametric graph-constraint-only PSF field model! - - Semi parametric model based on the graph-constraint-only matrix factorization scheme. - - Parameters - ---------- - zernike_maps: Tensor(n_batch, opd_dim, opd_dim) - Zernike polynomial maps. - obscurations: Tensor(opd_dim, opd_dim) - Predefined obscurations of the phase. - batch_size: int - Batch size - d_max_nonparam: int - Maximum degree of the polynomial for the non-parametric variations. - output_dim: int - Output dimension of the PSF stamps. - n_zernikes: int - Order of the Zernike polynomial for the parametric model. - d_max: int - Maximum degree of the polynomial for the Zernike coefficient variations. - x_lims: [float, float] - Limits for the x coordinate of the PSF field. - y_lims: [float, float] - Limits for the x coordinate of the PSF field. - coeff_mat: Tensor or None - Initialization of the coefficient matrix defining the parametric psf - field model. - - """ - - def __init__( - self, - zernike_maps, - obscurations, - batch_size, - obs_pos, - spatial_dic, - output_Q, - l2_param=0.0, - graph_features=6, - l1_rate=1e-3, - output_dim=64, - n_zernikes=45, - d_max=2, - x_lims=[0, 1e3], - y_lims=[0, 1e3], - coeff_mat=None, - name="TF_SP_graph_field", - ): - super(TF_SP_graph_field, self).__init__() - - # Inputs: oversampling used - self.output_Q = output_Q - - # Inputs: TF_poly_Z_field - self.n_zernikes = n_zernikes - self.d_max = d_max - self.x_lims = x_lims - self.y_lims = y_lims - - # Inputs: TF_NP_GRAPH_OPD - self.opd_dim = tf.shape(zernike_maps)[1].numpy() - self.graph_features = graph_features - self.l1_rate = l1_rate - - # Inputs: TF_zernike_OPD - # They are not stored as they are memory-heavy - # zernike_maps =[] - - # Inputs: TF_batch_poly_PSF - self.batch_size = batch_size - self.obscurations = obscurations - self.output_dim = output_dim - - # Inputs: Loss - self.l2_param = l2_param - - # Initialize the first layer - self.tf_poly_Z_field = TF_poly_Z_field( - x_lims=self.x_lims, - y_lims=self.y_lims, - n_zernikes=self.n_zernikes, - d_max=self.d_max, - ) - - # Initialize the zernike to OPD layer - self.tf_zernike_OPD = TF_zernike_OPD(zernike_maps=zernike_maps) - - # Initialize the non-parametric layer - self.tf_NP_graph_OPD = TF_NP_GRAPH_OPD( - obs_pos=obs_pos, - spatial_dic=spatial_dic, - x_lims=self.x_lims, - y_lims=self.y_lims, - graph_features=self.graph_features, - l1_rate=self.l1_rate, - opd_dim=self.opd_dim, - ) - - # Initialize the batch opd to batch polychromatic PSF layer - self.tf_batch_poly_PSF = TF_batch_poly_PSF( - obscurations=self.obscurations, - output_Q=self.output_Q, - output_dim=self.output_dim, - ) - - # Initialize the model parameters with non-default value - if coeff_mat is not None: - self.assign_coeff_matrix(coeff_mat) - - def set_zero_nonparam(self): - """Set to zero the non-parametric part.""" - self.tf_NP_graph_OPD.set_alpha_zero() - - def set_output_Q(self, output_Q, output_dim=None): - r"""Set the value of the output_Q parameter. - Useful for generating/predicting PSFs at a different sampling wrt the - observation sampling. - """ - self.output_Q = output_Q - if output_dim is not None: - self.output_dim = output_dim - # Reinitialize the PSF batch poly generator - self.tf_batch_poly_PSF = TF_batch_poly_PSF( - obscurations=self.obscurations, - output_Q=self.output_Q, - output_dim=self.output_dim, - ) - - def set_l1_rate(self, new_l1_rate): - """Set l1 rate the non-parametric part.""" - self.l1_rate = new_l1_rate - self.tf_NP_graph_OPD.l1_rate = new_l1_rate - - def set_nonzero_nonparam(self): - """Set to non-zero the non-parametric part.""" - self.tf_NP_graph_OPD.set_alpha_identity() - - def set_trainable_layers(self, param_bool=True, nonparam_bool=True): - """Set the layers to be trainable or not.""" - self.tf_NP_graph_OPD.trainable = nonparam_bool - self.tf_poly_Z_field.trainable = param_bool - - def get_coeff_matrix(self): - """Get coefficient matrix.""" - return self.tf_poly_Z_field.get_coeff_matrix() - - def assign_coeff_matrix(self, coeff_mat): - """Assign coefficient matrix.""" - self.tf_poly_Z_field.assign_coeff_matrix(coeff_mat) - - def predict_step(self, data, evaluate_step=False): - """Custom predict (inference) step. - - It is needed as the non-parametric MCCD part requires a special - interpolation (different from training). - - """ - if evaluate_step: - input_data = data - else: - # Format input data - data = data_adapter.expand_1d(data) - input_data, _, _ = data_adapter.unpack_x_y_sample_weight(data) - - # Unpack inputs - input_positions = input_data[0] - packed_SEDs = input_data[1] - - # Calculate parametric part - zernike_coeffs = self.tf_poly_Z_field(input_positions) - param_opd_maps = self.tf_zernike_OPD(zernike_coeffs) - - # Calculate the non parametric part - nonparam_opd_maps = self.tf_NP_graph_OPD.predict(input_positions) - - # Add the estimations - opd_maps = tf.math.add(param_opd_maps, nonparam_opd_maps) - # Compute the polychromatic PSFs - poly_psfs = self.tf_batch_poly_PSF([opd_maps, packed_SEDs]) - - return poly_psfs - - def predict_mono_psfs(self, input_positions, lambda_obs, phase_N): - r"""Predict a set of monochromatic PSF at desired positions. - - Parameters - ---------- - input_positions: Tensor(batch x 2) - Positions to predict the monochromatic PSFs. - lambda_obs: float - Observed wavelength in um. - phase_N: int - Required wavefront dimension. Should be calculated with as: - ``simPSF_np = wf.SimPSFToolkit(...)`` - ``phase_N = simPSF_np.feasible_N(lambda_obs)`` - - Returns - ------- - mono_psf_batch: Tensor [batch x output_dim x output_dim] - Batch of monochromatic PSFs at requested positions and - wavelength. - """ - # Initialise the monochromatic PSF batch calculator - tf_batch_mono_psf = TF_batch_mono_PSF( - obscurations=self.obscurations, - output_Q=self.output_Q, - output_dim=self.output_dim, - ) - # Set the lambda_obs and the phase_N parameters - tf_batch_mono_psf.set_lambda_phaseN(phase_N, lambda_obs) - - # Calculate parametric part - zernike_coeffs = self.tf_poly_Z_field(input_positions) - param_opd_maps = self.tf_zernike_OPD(zernike_coeffs) - - # Calculate the non parametric part - nonparam_opd_maps = self.tf_NP_graph_OPD.predict(input_positions) - - # Add the estimations - opd_maps = tf.math.add(param_opd_maps, nonparam_opd_maps) - - # Compute the monochromatic PSFs - mono_psf_batch = tf_batch_mono_psf(opd_maps) - - return mono_psf_batch - - def predict_opd(self, input_positions): - """Predict the OPD at some positions. - - Parameters - ---------- - input_positions: Tensor(batch_dim x 2) - Positions to predict the OPD. - - Returns - ------- - opd_maps : Tensor [batch x opd_dim x opd_dim] - OPD at requested positions. - - """ - # Calculate parametric part - zernike_coeffs = self.tf_poly_Z_field(input_positions) - param_opd_maps = self.tf_zernike_OPD(zernike_coeffs) - - # Calculate the non parametric part - nonparam_opd_maps = self.tf_NP_graph_OPD.predict(input_positions) - - # Add the estimations - opd_maps = tf.math.add(param_opd_maps, nonparam_opd_maps) - - return opd_maps - - def call(self, inputs, training=True): - r"""Define the PSF field forward model. - - [1] From positions to Zernike coefficients - [2] From Zernike coefficients to OPD maps - [3] From OPD maps and SED info to polychromatic PSFs - - OPD: Optical Path Differences - """ - # Unpack inputs - input_positions = inputs[0] - packed_SEDs = inputs[1] - - # Forward model - # For the training - if training: - # Calculate parametric part - zernike_coeffs = self.tf_poly_Z_field(input_positions) - param_opd_maps = self.tf_zernike_OPD(zernike_coeffs) - # Calculate the non parametric part - nonparam_opd_maps = self.tf_NP_graph_OPD(input_positions) - # Add l2 loss on the parmetric OPD - self.add_loss( - self.l2_param * tf.math.reduce_sum(tf.math.square(nonparam_opd_maps)) - ) - # Add the estimations - opd_maps = tf.math.add(param_opd_maps, nonparam_opd_maps) - # Compute the polychromatic PSFs - poly_psfs = self.tf_batch_poly_PSF([opd_maps, packed_SEDs]) - - # For the inference - # This is absolutely needed to compute the metrics on the - # validation data. - else: - # Compute predictions - poly_psfs = self.predict_step(inputs, evaluate_step=True) - - return poly_psfs diff --git a/src/wf_psf/tests/data/config/configs.yaml b/src/wf_psf/tests/data/config/configs.yaml deleted file mode 100644 index 96b92819..00000000 --- a/src/wf_psf/tests/data/config/configs.yaml +++ /dev/null @@ -1,4 +0,0 @@ ---- - training_conf_200: training_config_200.yaml - training_conf_500: training_config_500.yaml - training_conf_1000: training_config_1000.yaml \ No newline at end of file diff --git a/src/wf_psf/tests/data/config/configs_1000.yaml b/src/wf_psf/tests/data/config/configs_1000.yaml deleted file mode 100644 index 091f7365..00000000 --- a/src/wf_psf/tests/data/config/configs_1000.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- - training_config: training_config_1000.yaml - diff --git a/src/wf_psf/tests/data/config/configs_empty.yaml b/src/wf_psf/tests/data/config/configs_empty.yaml deleted file mode 100644 index 03984042..00000000 --- a/src/wf_psf/tests/data/config/configs_empty.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -metrics_conf: metrics_config_empty.yaml - diff --git a/src/wf_psf/tests/data/config/configs_scanner_error.yaml b/src/wf_psf/tests/data/config/configs_scanner_error.yaml deleted file mode 100644 index 7c2f2e04..00000000 --- a/src/wf_psf/tests/data/config/configs_scanner_error.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -metrics_conf:metrics_config_scanner_error.yml - test1: t 1-1 diff --git a/src/wf_psf/tests/data/config/configs_typo.yaml b/src/wf_psf/tests/data/config/configs_typo.yaml deleted file mode 100644 index 1713c699..00000000 --- a/src/wf_psf/tests/data/config/configs_typo.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -metrics_conf: metrics_config_typo.yaml - diff --git a/src/wf_psf/tests/data/config/data_config.yaml b/src/wf_psf/tests/data/config/data_config.yaml deleted file mode 100644 index 115abf0e..00000000 --- a/src/wf_psf/tests/data/config/data_config.yaml +++ /dev/null @@ -1,44 +0,0 @@ -# Training and test datasets for training and/or metrics evaluation -data: - training: - # Specify directory path to data; Default setting is /path/to/repo/data - data_dir: data/coherent_euclid_dataset/ - file: train_Euclid_res_200_TrainStars_id_001.npy - # if training dataset file does not exist, generate a new one by setting values below - stars: null - positions: null - SEDS: null - zernike_coef: null - C_poly: null - params: # - d_max: 2 - max_order: 45 - x_lims: [0, 1000.0] - y_lims: [0, 1000.0] - grid_points: [4, 4] - n_bins: 20 - max_wfe_rms: 0.1 - oversampling_rate: 3.0 - output_Q: 3.0 - output_dim: 32 - LP_filter_length: 2 - pupil_diameter: 256 - euclid_obsc: true - n_stars: 200 - test: - data_dir: data/coherent_euclid_dataset/ - file: test_Euclid_res_id_001.npy - # If test dataset file not provided produce a new one - stars: null - noisy_stars: null - positions: null - SEDS: null - zernike_coef: null - C_poly: null - parameters: - d_max: 2 - max_order: 45 - x_lims: [0, 1000.0] - y_lims: [0, 1000.0] - grid_points: [4,4] - max_wfe_rms: 0.1 \ No newline at end of file diff --git a/src/wf_psf/tests/data/config/metrics_config-bug.yaml b/src/wf_psf/tests/data/config/metrics_config-bug.yaml deleted file mode 100644 index 4c3a04db..00000000 --- a/src/wf_psf/tests/data/config/metrics_config-bug.yaml +++ /dev/null @@ -1,124 +0,0 @@ -metrics: - # Specify the type of model weights to load by entering "psf_model" to load weights of final psf model or "checkpoint" to load weights from a checkpoint callback. - model_save_path: psf_model - # Choose the training cycle for which to evaluate the psf_model. Can be: 1, 2, ... - saved_training_cycle: 3 - # Fill model_params if computing metrics_only on a pre-trained model else leave blank if training model first - # Specify path to Trained Model - Optional if model is pre-trained - trained_model_path: /gpfswork/rech/ynx/uuu68hq/wf-outputs/wf-outputs-202309212345/ - # Name of Trained Model Config file - Optional if model is pre-trained - trained_model_config: config/training_config_200.yaml - # Name of Plotting Config file - Enter file to run plot metrics else if empty run metrics evaluation only - plotting_config: - #Evaluate the monchromatic RMSE metric. - eval_mono_metric_rmse: False - #Evaluate the OPD RMSE metric. - eval_opd_metric_rmse: True - #Evaluate the super-resolution and the shape RMSE metrics for the train dataset. - eval_train_shape_sr_metric_rmse: True - ground_truth_model: - model_params: - #Model used as ground truth for the evaluation. Options are: 'poly', 'physical'. - model_name: poly - - # Evaluation parameters - #Number of bins used for the ground truth model poly PSF generation - n_bins_lda: 20 - - #Downsampling rate to match the oversampled model to the specified telescope's sampling. - output_Q: 3 - - #Oversampling rate used for the OPD/WFE PSF model. - oversampling_rate: 3 - - #Dimension of the pixel PSF postage stamp - output_dim: 32 - - #Dimension of the OPD/Wavefront space." - pupil_diameter: 256 - - #Boolean to define if we use sample weights based on the noise standard deviation estimation - use_sample_weights: True - - #Interpolation type for the physical poly model. Options are: 'none', 'all', 'top_K', 'independent_Zk'." - interpolation_type: None - - # SED intepolation points per bin - sed_interp_pts_per_bin: 0 - - # SED extrapolate - sed_extrapolate: True - - # SED interpolate kind - sed_interp_kind: linear - - # Standard deviation of the multiplicative SED Gaussian noise. - sed_sigma: 0 - - #Limits of the PSF field coordinates for the x axis. - x_lims: [0.0, 1.0e+3] - - #Limits of the PSF field coordinates for the y axis. - y_lims: [0.0, 1.0e+3] - - # Hyperparameters for Parametric model - param_hparams: - # Random seed for Tensor Flow Initialization - random_seed: 3877572 - - # Parameter for the l2 loss function for the Optical path differences (OPD)/WFE - l2_param: 0. - - #Zernike polynomial modes to use on the parametric part. - n_zernikes: 45 - - #Max polynomial degree of the parametric part. chg to max_deg_param - d_max: 2 - - #Flag to save optimisation history for parametric model - save_optim_history_param: true - - # Hyperparameters for non-parametric model - nonparam_hparams: - #Max polynomial degree of the non-parametric part. chg to max_deg_nonparam - d_max_nonparam: 5 - - # Number of graph features - num_graph_features: 10 - - #L1 regularisation parameter for the non-parametric part." - l1_rate: 1.0e-8 - - #Flag to enable Projected learning for DD_features to be used with `poly` or `semiparametric` model. - project_dd_features: False - - #Flag to reset DD_features to be used with `poly` or `semiparametric` model - reset_dd_features: False - - #Flag to save optimisation history for non-parametric model - save_optim_history_nonparam: true - - metrics_hparams: - # Batch size to use for the evaluation. - batch_size: 16 - - #Save RMS error for each super resolved PSF in the test dataset in addition to the mean across the FOV." - #Flag to get Super-Resolution pixel PSF RMSE for each individual test star. - #If `True`, the relative pixel RMSE of each star is added to ther saving dictionary. - opt_stars_rel_pix_rmse: False - - ## Specific parameters - # Parameter for the l2 loss of the OPD. - l2_param: 0. - - ## Define the resolution at which you'd like to measure the shape of the PSFs - #Downsampling rate from the high-resolution pixel modelling space. - # Recommended value: 1 - output_Q: 1 - - #Dimension of the pixel PSF postage stamp; it should be big enough so that most of the signal is contained inside the postage stamp. - # It also depends on the Q values used. - # Recommended value: 64 or higher - output_dim: 64 - - diff --git a/src/wf_psf/tests/data/config/metrics_config-main_random.yaml b/src/wf_psf/tests/data/config/metrics_config-main_random.yaml deleted file mode 100644 index 12c8578f..00000000 --- a/src/wf_psf/tests/data/config/metrics_config-main_random.yaml +++ /dev/null @@ -1,126 +0,0 @@ -metrics: - # Set flag to evaluate model weights; if False, then final updated model will be evaluated - use_callback: False - # Choose the training cycle for the evaluation. Can be: 1, 2, ... - saved_training_cycle: 2 - # Provide path to saved model checkpoints. - chkp_save_path: chkp - # Fill model_params if computing metrics_only on a pre-trained model else leave blank if training model first - # Specify path to Trained Model - Optional if model is pre-trained - trained_model_path: /gpfswork/rech/ynx/uuu68hq/wf-outputs/wf-outputs-random-seed-4 - # Name of Trained Model Config file - Optional if model is pre-trained - trained_model_config: config/training_config.yaml - # Name of Plotting Config file - Enter file to run plot metrics else if empty run metrics evaluation only - plotting_config: - #Evaluate the monchromatic RMSE metric. - eval_mono_metric_rmse: False - #Evaluate the OPD RMSE metric. - eval_opd_metric_rmse: True - #Evaluate the super-resolution and the shape RMSE metrics for the train dataset. - eval_train_shape_sr_metric_rmse: True - ground_truth_model: - model_params: - #Model used as ground truth for the evaluation. Options are: 'poly', 'physical'. - model_name: poly - - # Evaluation parameters - #Number of bins used for the ground truth model poly PSF generation - n_bins_lda: 20 - - #Downsampling rate to match the oversampled model to the specified telescope's sampling. - output_Q: 3 - - #Oversampling rate used for the OPD/WFE PSF model. - oversampling_rate: 3 - - #Dimension of the pixel PSF postage stamp - output_dim: 32 - - #Dimension of the OPD/Wavefront space." - pupil_diameter: 256 - - #Boolean to define if we use sample weights based on the noise standard deviation estimation - use_sample_weights: True - - #Interpolation type for the physical poly model. Options are: 'none', 'all', 'top_K', 'independent_Zk'." - interpolation_type: None - - # SED intepolation points per bin - sed_interp_pts_per_bin: 0 - - # SED extrapolate - sed_extrapolate: True - - # SED interpolate kind - sed_interp_kind: linear - - # Standard deviation of the multiplicative SED Gaussian noise. - sed_sigma: 0 - - #Limits of the PSF field coordinates for the x axis. - x_lims: [0.0, 1.0e+3] - - #Limits of the PSF field coordinates for the y axis. - y_lims: [0.0, 1.0e+3] - - # Hyperparameters for Parametric model - param_hparams: - # Random seed for Tensor Flow Initialization - random_seed: 3877572 - - # Parameter for the l2 loss function for the Optical path differences (OPD)/WFE - l2_param: 0. - - #Zernike polynomial modes to use on the parametric part. - n_zernikes: 45 - - #Max polynomial degree of the parametric part. chg to max_deg_param - d_max: 2 - - #Flag to save optimisation history for parametric model - save_optim_history_param: true - - # Hyperparameters for non-parametric model - nonparam_hparams: - #Max polynomial degree of the non-parametric part. chg to max_deg_nonparam - d_max_nonparam: 5 - - # Number of graph features - num_graph_features: 10 - - #L1 regularisation parameter for the non-parametric part." - l1_rate: 1.0e-8 - - #Flag to enable Projected learning for DD_features to be used with `poly` or `semiparametric` model. - project_dd_features: False - - #Flag to reset DD_features to be used with `poly` or `semiparametric` model - reset_dd_features: False - - #Flag to save optimisation history for non-parametric model - save_optim_history_nonparam: true - - metrics_hparams: - # Batch size to use for the evaluation. - batch_size: 16 - - #Save RMS error for each super resolved PSF in the test dataset in addition to the mean across the FOV." - #Flag to get Super-Resolution pixel PSF RMSE for each individual test star. - #If `True`, the relative pixel RMSE of each star is added to ther saving dictionary. - opt_stars_rel_pix_rmse: False - - ## Specific parameters - # Parameter for the l2 loss of the OPD. - l2_param: 0. - - ## Define the resolution at which you'd like to measure the shape of the PSFs - #Downsampling rate from the high-resolution pixel modelling space. - # Recommended value: 1 - output_Q: 1 - - #Dimension of the pixel PSF postage stamp; it should be big enough so that most of the signal is contained inside the postage stamp. - # It also depends on the Q values used. - # Recommended value: 64 or higher - output_dim: 64 - - diff --git a/src/wf_psf/tests/data/config/metrics_config.yaml b/src/wf_psf/tests/data/config/metrics_config.yaml deleted file mode 100644 index cb2750c9..00000000 --- a/src/wf_psf/tests/data/config/metrics_config.yaml +++ /dev/null @@ -1,124 +0,0 @@ -metrics: - # Specify the type of model weights to load by entering "psf_model" to load weights of final psf model or "checkpoint" to load weights from a checkpoint callback. - model_save_path: psf_model - # Choose the training cycle for which to evaluate the psf_model. Can be: 1, 2, ... - saved_training_cycle: 2 - # Fill model_params if computing metrics_only on a pre-trained model else leave blank if training model first - # Specify path to Trained Model - Optional if model is pre-trained - trained_model_path: - # Name of Trained Model Config file - Optional if model is pre-trained - trained_model_config: - # Name of Plotting Config file - Enter file to run plot metrics else if empty run metrics evaluation only - plotting_config: - #Evaluate the monchromatic RMSE metric. - eval_mono_metric_rmse: Flase - #Evaluate the OPD RMSE metric. - eval_opd_metric_rmse: True - #Evaluate the super-resolution and the shape RMSE metrics for the train dataset. - eval_train_shape_sr_metric_rmse: True - ground_truth_model: - model_params: - #Model used as ground truth for the evaluation. Options are: 'poly', 'physical'. - model_name: poly - - # Evaluation parameters - #Number of bins used for the ground truth model poly PSF generation - n_bins_lda: 20 - - #Downsampling rate to match the oversampled model to the specified telescope's sampling. - output_Q: 3 - - #Oversampling rate used for the OPD/WFE PSF model. - oversampling_rate: 3 - - #Dimension of the pixel PSF postage stamp - output_dim: 32 - - #Dimension of the OPD/Wavefront space." - pupil_diameter: 256 - - #Boolean to define if we use sample weights based on the noise standard deviation estimation - use_sample_weights: True - - #Interpolation type for the physical poly model. Options are: 'none', 'all', 'top_K', 'independent_Zk'." - interpolation_type: None - - # SED intepolation points per bin - sed_interp_pts_per_bin: 0 - - # SED extrapolate - sed_extrapolate: True - - # SED interpolate kind - sed_interp_kind: linear - - # Standard deviation of the multiplicative SED Gaussian noise. - sed_sigma: 0 - - #Limits of the PSF field coordinates for the x axis. - x_lims: [0.0, 1.0e+3] - - #Limits of the PSF field coordinates for the y axis. - y_lims: [0.0, 1.0e+3] - - # Hyperparameters for Parametric model - param_hparams: - # Random seed for Tensor Flow Initialization - random_seed: 3877572 - - # Parameter for the l2 loss function for the Optical path differences (OPD)/WFE - l2_param: 0. - - #Zernike polynomial modes to use on the parametric part. - n_zernikes: 45 - - #Max polynomial degree of the parametric part. chg to max_deg_param - d_max: 2 - - #Flag to save optimisation history for parametric model - save_optim_history_param: true - - # Hyperparameters for non-parametric model - nonparam_hparams: - #Max polynomial degree of the non-parametric part. chg to max_deg_nonparam - d_max_nonparam: 5 - - # Number of graph features - num_graph_features: 10 - - #L1 regularisation parameter for the non-parametric part." - l1_rate: 1.0e-8 - - #Flag to enable Projected learning for DD_features to be used with `poly` or `semiparametric` model. - project_dd_features: False - - #Flag to reset DD_features to be used with `poly` or `semiparametric` model - reset_dd_features: False - - #Flag to save optimisation history for non-parametric model - save_optim_history_nonparam: true - - metrics_hparams: - # Batch size to use for the evaluation. - batch_size: 16 - - #Save RMS error for each super resolved PSF in the test dataset in addition to the mean across the FOV." - #Flag to get Super-Resolution pixel PSF RMSE for each individual test star. - #If `True`, the relative pixel RMSE of each star is added to ther saving dictionary. - opt_stars_rel_pix_rmse: False - - ## Specific parameters - # Parameter for the l2 loss of the OPD. - l2_param: 0. - - ## Define the resolution at which you'd like to measure the shape of the PSFs - #Downsampling rate from the high-resolution pixel modelling space. - # Recommended value: 1 - output_Q: 1 - - #Dimension of the pixel PSF postage stamp; it should be big enough so that most of the signal is contained inside the postage stamp. - # It also depends on the Q values used. - # Recommended value: 64 or higher - output_dim: 64 - - diff --git a/src/wf_psf/tests/data/config/metrics_config_1.yaml b/src/wf_psf/tests/data/config/metrics_config_1.yaml deleted file mode 100644 index 04b194ac..00000000 --- a/src/wf_psf/tests/data/config/metrics_config_1.yaml +++ /dev/null @@ -1,124 +0,0 @@ -metrics: - # Set flag to evaluate model weights; if False, then final updated model will be evaluated - use_callback: True - # Choose the training cycle for the evaluation. Can be: 1, 2, ... - saved_training_cycle: 2 - # Provide path to saved model checkpoints. - chkp_save_path: checkpoint - # Fill model_params if computing metrics_only on a pre-trained model - # Path to Trained Model - trained_model_path: /gpfswork/rech/ynx/uuu68hq/wf-outputs/Archive/wf-outputs-202307041437/ - # trained_model_path: /Users/jenniferpollack/Projects/wf-outputs/wf-outputs-202306011821/ - # Name of Trained Model Config file - trained_model_config: config/training_config.yaml - # Name of Plotting Config file - Enter file to run plot metrics else if empty run metrics evaluation only - plotting_config: plotting_config.yaml - #Evaluate the monchromatic RMSE metric. - eval_mono_metric_rmse: False - #Evaluate the OPD RMSE metric. - eval_opd_metric_rmse: True - #Evaluate the super-resolution and the shape RMSE metrics for the train dataset. - eval_train_shape_sr_metric_rmse: True - ground_truth_model: - model_params: - #Model used as ground truth for the evaluation. Options are: 'poly', 'physical'. - model_name: poly - - # Evaluation parameters - #Number of bins used for the ground truth model poly PSF generation - n_bins_lda: 20 - - #Downsampling rate to match the oversampled model to the specified telescope's sampling. - output_Q: 3 - - #Oversampling rate used for the OPD/WFE PSF model. - oversampling_rate: 3 - - #Dimension of the pixel PSF postage stamp - output_dim: 32 - - #Dimension of the OPD/Wavefront space." - pupil_diameter: 256 - - #Boolean to define if we use sample weights based on the noise standard deviation estimation - use_sample_weights: True - - #Interpolation type for the physical poly model. Options are: 'none', 'all', 'top_K', 'independent_Zk'." - interpolation_type: None - - # SED intepolation points per bin - sed_interp_pts_per_bin: 0 - - # SED extrapolate - sed_extrapolate: True - - # SED interpolate kind - sed_interp_kind: linear - - # Standard deviation of the multiplicative SED Gaussian noise. - sed_sigma: 0 - - #Limits of the PSF field coordinates for the x axis. - x_lims: [0.0, 1.0e+3] - - #Limits of the PSF field coordinates for the y axis. - y_lims: [0.0, 1.0e+3] - - # Hyperparameters for Parametric model - param_hparams: - # Parameter for the l2 loss function for the Optical path differences (OPD)/WFE - l2_param: 0. - - #Zernike polynomial modes to use on the parametric part. - n_zernikes: 45 - - #Max polynomial degree of the parametric part. chg to max_deg_param - d_max: 2 - - #Flag to save optimisation history for parametric model - save_optim_history_param: true - - # Hyperparameters for non-parametric model - nonparam_hparams: - #Max polynomial degree of the non-parametric part. chg to max_deg_nonparam - d_max_nonparam: 5 - - # Number of graph features - num_graph_features: 10 - - #L1 regularisation parameter for the non-parametric part." - l1_rate: 1.0e-8 - - #Flag to enable Projected learning for DD_features to be used with `poly` or `semiparametric` model. - project_dd_features: False - - #Flag to reset DD_features to be used with `poly` or `semiparametric` model - reset_dd_features: False - - #Flag to save optimisation history for non-parametric model - save_optim_history_nonparam: true - - metrics_hparams: - # Batch size to use for the evaluation. - batch_size: 16 - - #Save RMS error for each super resolved PSF in the test dataset in addition to the mean across the FOV." - #Flag to get Super-Resolution pixel PSF RMSE for each individual test star. - #If `True`, the relative pixel RMSE of each star is added to ther saving dictionary. - opt_stars_rel_pix_rmse: False - - ## Specific parameters - # Parameter for the l2 loss of the OPD. - l2_param: 0. - - ## Define the resolution at which you'd like to measure the shape of the PSFs - #Downsampling rate from the high-resolution pixel modelling space. - # Recommended value: 1 - output_Q: 1 - - #Dimension of the pixel PSF postage stamp; it should be big enough so that most of the signal is contained inside the postage stamp. - # It also depends on the Q values used. - # Recommended value: 64 or higher - output_dim: 64 - - diff --git a/src/wf_psf/tests/data/config/metrics_config_2.yaml b/src/wf_psf/tests/data/config/metrics_config_2.yaml deleted file mode 100644 index 6c862d10..00000000 --- a/src/wf_psf/tests/data/config/metrics_config_2.yaml +++ /dev/null @@ -1,127 +0,0 @@ -metrics: - # Set flag to evaluate model weights; if False, then final updated model will be evaluated - use_callback: True - # Choose the training cycle for the evaluation. Can be: 1, 2, ... - saved_training_cycle: 2 - # Provide path to saved model checkpoints. - chkp_save_path: checkpoint - # Fill model_params if computing metrics_only on a pre-trained model - # ID name - id_name: _sample_w_bis1_2k - # id_name: -coherent_euclid_2000stars - # Path to Trained Model - trained_model_path: /gpfswork/rech/ynx/uuu68hq/wf-outputs/Archive/wf-outputs-202307041437/ - # trained_model_path: /Users/jenniferpollack/Projects/wf-outputs/wf-outputs-202306011821/ - # Name of Trained Model Config file - trained_model_config: config/training_config.yaml - # Name of Plotting Config file - Enter file to run plot metrics else if empty run metrics evaluation only - plotting_config: - #Evaluate the monchromatic RMSE metric. - eval_mono_metric_rmse: False - #Evaluate the OPD RMSE metric. - eval_opd_metric_rmse: True - #Evaluate the super-resolution and the shape RMSE metrics for the train dataset. - eval_train_shape_sr_metric_rmse: True - ground_truth_model: - model_params: - #Model used as ground truth for the evaluation. Options are: 'poly', 'physical'. - model_name: poly - - # Evaluation parameters - #Number of bins used for the ground truth model poly PSF generation - n_bins_lda: 20 - - #Downsampling rate to match the oversampled model to the specified telescope's sampling. - output_Q: 3 - - #Oversampling rate used for the OPD/WFE PSF model. - oversampling_rate: 3 - - #Dimension of the pixel PSF postage stamp - output_dim: 32 - - #Dimension of the OPD/Wavefront space." - pupil_diameter: 256 - - #Boolean to define if we use sample weights based on the noise standard deviation estimation - use_sample_weights: True - - #Interpolation type for the physical poly model. Options are: 'none', 'all', 'top_K', 'independent_Zk'." - interpolation_type: None - - # SED intepolation points per bin - sed_interp_pts_per_bin: 0 - - # SED extrapolate - sed_extrapolate: True - - # SED interpolate kind - sed_interp_kind: linear - - # Standard deviation of the multiplicative SED Gaussian noise. - sed_sigma: 0 - - #Limits of the PSF field coordinates for the x axis. - x_lims: [0.0, 1.0e+3] - - #Limits of the PSF field coordinates for the y axis. - y_lims: [0.0, 1.0e+3] - - # Hyperparameters for Parametric model - param_hparams: - # Parameter for the l2 loss function for the Optical path differences (OPD)/WFE - l2_param: 0. - - #Zernike polynomial modes to use on the parametric part. - n_zernikes: 45 - - #Max polynomial degree of the parametric part. chg to max_deg_param - d_max: 2 - - #Flag to save optimisation history for parametric model - save_optim_history_param: true - - # Hyperparameters for non-parametric model - nonparam_hparams: - #Max polynomial degree of the non-parametric part. chg to max_deg_nonparam - d_max_nonparam: 5 - - # Number of graph features - num_graph_features: 10 - - #L1 regularisation parameter for the non-parametric part." - l1_rate: 1.0e-8 - - #Flag to enable Projected learning for DD_features to be used with `poly` or `semiparametric` model. - project_dd_features: False - - #Flag to reset DD_features to be used with `poly` or `semiparametric` model - reset_dd_features: False - - #Flag to save optimisation history for non-parametric model - save_optim_history_nonparam: true - - metrics_hparams: - # Batch size to use for the evaluation. - batch_size: 16 - - #Save RMS error for each super resolved PSF in the test dataset in addition to the mean across the FOV." - #Flag to get Super-Resolution pixel PSF RMSE for each individual test star. - #If `True`, the relative pixel RMSE of each star is added to ther saving dictionary. - opt_stars_rel_pix_rmse: False - - ## Specific parameters - # Parameter for the l2 loss of the OPD. - l2_param: 0. - - ## Define the resolution at which you'd like to measure the shape of the PSFs - #Downsampling rate from the high-resolution pixel modelling space. - # Recommended value: 1 - output_Q: 1 - - #Dimension of the pixel PSF postage stamp; it should be big enough so that most of the signal is contained inside the postage stamp. - # It also depends on the Q values used. - # Recommended value: 64 or higher - output_dim: 64 - - diff --git a/src/wf_psf/tests/data/config/metrics_config_3.yaml b/src/wf_psf/tests/data/config/metrics_config_3.yaml deleted file mode 100644 index 6c862d10..00000000 --- a/src/wf_psf/tests/data/config/metrics_config_3.yaml +++ /dev/null @@ -1,127 +0,0 @@ -metrics: - # Set flag to evaluate model weights; if False, then final updated model will be evaluated - use_callback: True - # Choose the training cycle for the evaluation. Can be: 1, 2, ... - saved_training_cycle: 2 - # Provide path to saved model checkpoints. - chkp_save_path: checkpoint - # Fill model_params if computing metrics_only on a pre-trained model - # ID name - id_name: _sample_w_bis1_2k - # id_name: -coherent_euclid_2000stars - # Path to Trained Model - trained_model_path: /gpfswork/rech/ynx/uuu68hq/wf-outputs/Archive/wf-outputs-202307041437/ - # trained_model_path: /Users/jenniferpollack/Projects/wf-outputs/wf-outputs-202306011821/ - # Name of Trained Model Config file - trained_model_config: config/training_config.yaml - # Name of Plotting Config file - Enter file to run plot metrics else if empty run metrics evaluation only - plotting_config: - #Evaluate the monchromatic RMSE metric. - eval_mono_metric_rmse: False - #Evaluate the OPD RMSE metric. - eval_opd_metric_rmse: True - #Evaluate the super-resolution and the shape RMSE metrics for the train dataset. - eval_train_shape_sr_metric_rmse: True - ground_truth_model: - model_params: - #Model used as ground truth for the evaluation. Options are: 'poly', 'physical'. - model_name: poly - - # Evaluation parameters - #Number of bins used for the ground truth model poly PSF generation - n_bins_lda: 20 - - #Downsampling rate to match the oversampled model to the specified telescope's sampling. - output_Q: 3 - - #Oversampling rate used for the OPD/WFE PSF model. - oversampling_rate: 3 - - #Dimension of the pixel PSF postage stamp - output_dim: 32 - - #Dimension of the OPD/Wavefront space." - pupil_diameter: 256 - - #Boolean to define if we use sample weights based on the noise standard deviation estimation - use_sample_weights: True - - #Interpolation type for the physical poly model. Options are: 'none', 'all', 'top_K', 'independent_Zk'." - interpolation_type: None - - # SED intepolation points per bin - sed_interp_pts_per_bin: 0 - - # SED extrapolate - sed_extrapolate: True - - # SED interpolate kind - sed_interp_kind: linear - - # Standard deviation of the multiplicative SED Gaussian noise. - sed_sigma: 0 - - #Limits of the PSF field coordinates for the x axis. - x_lims: [0.0, 1.0e+3] - - #Limits of the PSF field coordinates for the y axis. - y_lims: [0.0, 1.0e+3] - - # Hyperparameters for Parametric model - param_hparams: - # Parameter for the l2 loss function for the Optical path differences (OPD)/WFE - l2_param: 0. - - #Zernike polynomial modes to use on the parametric part. - n_zernikes: 45 - - #Max polynomial degree of the parametric part. chg to max_deg_param - d_max: 2 - - #Flag to save optimisation history for parametric model - save_optim_history_param: true - - # Hyperparameters for non-parametric model - nonparam_hparams: - #Max polynomial degree of the non-parametric part. chg to max_deg_nonparam - d_max_nonparam: 5 - - # Number of graph features - num_graph_features: 10 - - #L1 regularisation parameter for the non-parametric part." - l1_rate: 1.0e-8 - - #Flag to enable Projected learning for DD_features to be used with `poly` or `semiparametric` model. - project_dd_features: False - - #Flag to reset DD_features to be used with `poly` or `semiparametric` model - reset_dd_features: False - - #Flag to save optimisation history for non-parametric model - save_optim_history_nonparam: true - - metrics_hparams: - # Batch size to use for the evaluation. - batch_size: 16 - - #Save RMS error for each super resolved PSF in the test dataset in addition to the mean across the FOV." - #Flag to get Super-Resolution pixel PSF RMSE for each individual test star. - #If `True`, the relative pixel RMSE of each star is added to ther saving dictionary. - opt_stars_rel_pix_rmse: False - - ## Specific parameters - # Parameter for the l2 loss of the OPD. - l2_param: 0. - - ## Define the resolution at which you'd like to measure the shape of the PSFs - #Downsampling rate from the high-resolution pixel modelling space. - # Recommended value: 1 - output_Q: 1 - - #Dimension of the pixel PSF postage stamp; it should be big enough so that most of the signal is contained inside the postage stamp. - # It also depends on the Q values used. - # Recommended value: 64 or higher - output_dim: 64 - - diff --git a/src/wf_psf/tests/data/config/metrics_config_500.yaml b/src/wf_psf/tests/data/config/metrics_config_500.yaml deleted file mode 100644 index 1c22e5b2..00000000 --- a/src/wf_psf/tests/data/config/metrics_config_500.yaml +++ /dev/null @@ -1,123 +0,0 @@ -metrics: - # Set flag to evaluate model weights; if False, then final updated model will be evaluated - use_callback: False - # Choose the training cycle for the evaluation. Can be: 1, 2, ... - saved_training_cycle: 2 - # Provide path to saved model checkpoints. - chkp_save_path: checkpoint - # Fill model_params if computing metrics_only on a pre-trained model else leave blank to train model first - # Specify path to Trained Model - trained_model_path: - # Name of Trained Model Config file - trained_model_config: - # Name of Plotting Config file - Enter file to run plot metrics else if empty run metrics evaluation only - plotting_config: plotting_config.yaml - #Evaluate the monchromatic RMSE metric. - eval_mono_metric_rmse: False - #Evaluate the OPD RMSE metric. - eval_opd_metric_rmse: True - #Evaluate the super-resolution and the shape RMSE metrics for the train dataset. - eval_train_shape_sr_metric_rmse: True - ground_truth_model: - model_params: - #Model used as ground truth for the evaluation. Options are: 'poly', 'physical'. - model_name: poly - - # Evaluation parameters - #Number of bins used for the ground truth model poly PSF generation - n_bins_lda: 20 - - #Downsampling rate to match the oversampled model to the specified telescope's sampling. - output_Q: 3 - - #Oversampling rate used for the OPD/WFE PSF model. - oversampling_rate: 3 - - #Dimension of the pixel PSF postage stamp - output_dim: 32 - - #Dimension of the OPD/Wavefront space." - pupil_diameter: 256 - - #Boolean to define if we use sample weights based on the noise standard deviation estimation - use_sample_weights: True - - #Interpolation type for the physical poly model. Options are: 'none', 'all', 'top_K', 'independent_Zk'." - interpolation_type: None - - # SED intepolation points per bin - sed_interp_pts_per_bin: 0 - - # SED extrapolate - sed_extrapolate: True - - # SED interpolate kind - sed_interp_kind: linear - - # Standard deviation of the multiplicative SED Gaussian noise. - sed_sigma: 0 - - #Limits of the PSF field coordinates for the x axis. - x_lims: [0.0, 1.0e+3] - - #Limits of the PSF field coordinates for the y axis. - y_lims: [0.0, 1.0e+3] - - # Hyperparameters for Parametric model - param_hparams: - # Parameter for the l2 loss function for the Optical path differences (OPD)/WFE - l2_param: 0. - - #Zernike polynomial modes to use on the parametric part. - n_zernikes: 45 - - #Max polynomial degree of the parametric part. chg to max_deg_param - d_max: 2 - - #Flag to save optimisation history for parametric model - save_optim_history_param: true - - # Hyperparameters for non-parametric model - nonparam_hparams: - #Max polynomial degree of the non-parametric part. chg to max_deg_nonparam - d_max_nonparam: 5 - - # Number of graph features - num_graph_features: 10 - - #L1 regularisation parameter for the non-parametric part." - l1_rate: 1.0e-8 - - #Flag to enable Projected learning for DD_features to be used with `poly` or `semiparametric` model. - project_dd_features: False - - #Flag to reset DD_features to be used with `poly` or `semiparametric` model - reset_dd_features: False - - #Flag to save optimisation history for non-parametric model - save_optim_history_nonparam: true - - metrics_hparams: - # Batch size to use for the evaluation. - batch_size: 16 - - #Save RMS error for each super resolved PSF in the test dataset in addition to the mean across the FOV." - #Flag to get Super-Resolution pixel PSF RMSE for each individual test star. - #If `True`, the relative pixel RMSE of each star is added to ther saving dictionary. - opt_stars_rel_pix_rmse: False - - ## Specific parameters - # Parameter for the l2 loss of the OPD. - l2_param: 0. - - ## Define the resolution at which you'd like to measure the shape of the PSFs - #Downsampling rate from the high-resolution pixel modelling space. - # Recommended value: 1 - output_Q: 1 - - #Dimension of the pixel PSF postage stamp; it should be big enough so that most of the signal is contained inside the postage stamp. - # It also depends on the Q values used. - # Recommended value: 64 or higher - output_dim: 64 - - diff --git a/src/wf_psf/tests/data/config/metrics_config_empty.yaml b/src/wf_psf/tests/data/config/metrics_config_empty.yaml deleted file mode 100644 index e69de29b..00000000 diff --git a/src/wf_psf/tests/data/config/metrics_config_scanner_error.yaml b/src/wf_psf/tests/data/config/metrics_config_scanner_error.yaml deleted file mode 100644 index a05aa8be..00000000 --- a/src/wf_psf/tests/data/config/metrics_config_scanner_error.yaml +++ /dev/null @@ -1,126 +0,0 @@ -metrics: - # Set flag to evaluate model weights; if False, then final updated model will be evaluated - use_callbacks: Ture - # Choose the training cycle for the evaluation. Can be: 1, 2, ... - saved_training_cycle: 2 - # Provide path to saved model checkpoints. - chkp_save_path: checkpoint - # Fill model_params if computing metrics_only on a pre-trained model - # Path to Trained Model - trained_model_path: /gpfswork/rech/ynx/uuu68hq/wf-outputs/Archive/wf-outputs-202307041437/ - # trained_model_path: /Users/jenniferpollack/Projects/wf-outputs/wf-outputs-202306011821/ - # Name of Trained Model Config file - trained_model_config: config/training_config.yaml - # Name of Plotting Config file - Enter file to run plot metrics else if empty run metrics evaluation only - plotting_config: plotting_config.yaml - #Evaluate the monchromatic RMSE metric. - eval_mono_metric_rmse: False - #Evaluate the OPD RMSE metric. - eval_opd_metric_rmse: True - #Evaluate the super-resolution and the shape RMSE metrics for the train dataset. - eval_train_shape_sr_metric_rmse: True - ground_truth_model: - model_params: - #Model used as ground truth for the evaluation. Options are: 'poly', 'physical'. - model_name: poly - - # Evaluation parameters - #Number of bins used for the ground truth model poly PSF generation - n_bins_lda: 20 - - #Downsampling rate to match the oversampled model to the specified telescope's sampling. - output_Q: 3 - - #Oversampling rate used for the OPD/WFE PSF model. - oversampling_rate: 3 - - #Dimension of the pixel PSF postage stamp - output_dim: 32 - - #Dimension of the OPD/Wavefront space." - pupil_diameter: 256 - - #Boolean to define if we use sample weights based on the noise standard deviation estimation - use_sample_weights: True - - #Interpolation type for the physical poly model. Options are: 'none', 'all', 'top_K', 'independent_Zk'." - interpolation_type: None - - # SED intepolation points per bin - sed_interp_pts_per_bin: 0 - - # SED extrapolate - sed_extrapolate: True - - # SED interpolate kind - sed_interp_kind: linear - - # Standard deviation of the multiplicative SED Gaussian noise. - sed_sigma: 0 - - #Limits of the PSF field coordinates for the x axis. - x_lims: [0.0, 1.0e+3] - - #Limits of the PSF field coordinates for the y axis. - y_lims: [0.0, 1.0e+3] - - # Hyperparameters for Parametric model - param_hparams: - random_seed: - - # Parameter for the l2 loss function for the Optical path differences (OPD)/WFE - l2_param: 0. - - #Zernike polynomial modes to use on the parametric part. - n_zernikes: 45 - - #Max polynomial degree of the parametric part. chg to max_deg_param - d_max: 2 - - #Flag to save optimisation history for parametric model - save_optim_history_param: true - - # Hyperparameters for non-parametric model - nonparam_hparams: - #Max polynomial degree of the non-parametric part. chg to max_deg_nonparam - d_max_nonparam: 5 - - # Number of graph features - num_graph_features: 10 - - #L1 regularisation parameter for the non-parametric part." - l1_rate: 1.0e-8 - - #Flag to enable Projected learning for DD_features to be used with `poly` or `semiparametric` model. - project_dd_features: False - - #Flag to reset DD_features to be used with `poly` or `semiparametric` model - reset_dd_features: False - - #Flag to save optimisation history for non-parametric model - save_optim_history_nonparam: true - - metrics_hparams: - # Batch size to use for the evaluation. - batch_size: 16 - - #Save RMS error for each super resolved PSF in the test dataset in addition to the mean across the FOV." - #Flag to get Super-Resolution pixel PSF RMSE for each individual test star. - #If `True`, the relative pixel RMSE of each star is added to ther saving dictionary. - opt_stars_rel_pix_rmse: False - - ## Specific parameters - # Parameter for the l2 loss of the OPD. - l2_param: 0. - - ## Define the resolution at which you'd like to measure the shape of the PSFs - #Downsampling rate from the high-resolution pixel modelling space. - # Recommended value: 1 - output_Q: 1 - - #Dimension of the pixel PSF postage stamp; it should be big enough so that most of the signal is contained inside the postage stamp. - # It also depends on the Q values used. - # Recommended value: 64 or higher - output_dim: 64 - - diff --git a/src/wf_psf/tests/data/config/metrics_config_typo.yaml b/src/wf_psf/tests/data/config/metrics_config_typo.yaml deleted file mode 100644 index 5458555f..00000000 --- a/src/wf_psf/tests/data/config/metrics_config_typo.yaml +++ /dev/null @@ -1,124 +0,0 @@ -metrics: - # Specify the type of model weights to load by entering "psf_model" to load weights of final psf model or "checkpoint" to load weights from a checkpoint callback. -model_save_path: psf_model - # Choose the training cycle for which to evaluate the psf_model. Can be: 1, 2, ... - saved_training_cycle: 2 - # Fill model_params if computing metrics_only on a pre-trained model else leave blank if training model first - # Specify path to Trained Model - Optional if model is pre-trained - trained_model_path: /gpfswork/rech/ynx/uuu68hq/wf-outputs/wf-outputs-202309221201 - # Name of Trained Model Config file - Optional if model is pre-trained - trained_model_config: config/training_config_200.yaml - # Name of Plotting Config file - Enter file to run plot metrics else if empty run metrics evaluation only - plotting_config: - #Evaluate the monchromatic RMSE metric. - eval_mono_metric_rmse: Flase - #Evaluate the OPD RMSE metric. - eval_opd_metric_rmse: True - #Evaluate the super-resolution and the shape RMSE metrics for the train dataset. - eval_train_shape_sr_metric_rmse: True - ground_truth_model: - model_params: - #Model used as ground truth for the evaluation. Options are: 'poly', 'physical'. - model_name: poly - - # Evaluation parameters - #Number of bins used for the ground truth model poly PSF generation - n_bins_lda: 20 - - #Downsampling rate to match the oversampled model to the specified telescope's sampling. - output_Q: 3 - - #Oversampling rate used for the OPD/WFE PSF model. - oversampling_rate: 3 - - #Dimension of the pixel PSF postage stamp - output_dim: 32 - - #Dimension of the OPD/Wavefront space." - pupil_diameter: 256 - - #Boolean to define if we use sample weights based on the noise standard deviation estimation - use_sample_weights: True - - #Interpolation type for the physical poly model. Options are: 'none', 'all', 'top_K', 'independent_Zk'." - interpolation_type: None - - # SED intepolation points per bin - sed_interp_pts_per_bin: 0 - - # SED extrapolate - sed_extrapolate: True - - # SED interpolate kind - sed_interp_kind: linear - - # Standard deviation of the multiplicative SED Gaussian noise. - sed_sigma: 0 - - #Limits of the PSF field coordinates for the x axis. - x_lims: [0.0, 1.0e+3] - - #Limits of the PSF field coordinates for the y axis. - y_lims: [0.0, 1.0e+3] - - # Hyperparameters for Parametric model - param_hparams: - # Random seed for Tensor Flow Initialization - random_seed: 3877572 - - # Parameter for the l2 loss function for the Optical path differences (OPD)/WFE - l2_param: 0. - - #Zernike polynomial modes to use on the parametric part. - n_zernikes: 45 - - #Max polynomial degree of the parametric part. chg to max_deg_param - d_max: 2 - - #Flag to save optimisation history for parametric model - save_optim_history_param: true - - # Hyperparameters for non-parametric model - nonparam_hparams: - #Max polynomial degree of the non-parametric part. chg to max_deg_nonparam - d_max_nonparam: 5 - - # Number of graph features - num_graph_features: 10 - - #L1 regularisation parameter for the non-parametric part." - l1_rate: 1.0e-8 - - #Flag to enable Projected learning for DD_features to be used with `poly` or `semiparametric` model. - project_dd_features: False - - #Flag to reset DD_features to be used with `poly` or `semiparametric` model - reset_dd_features: False - - #Flag to save optimisation history for non-parametric model - save_optim_history_nonparam: true - - metrics_hparams: - # Batch size to use for the evaluation. - batch_size: 16 - - #Save RMS error for each super resolved PSF in the test dataset in addition to the mean across the FOV." - #Flag to get Super-Resolution pixel PSF RMSE for each individual test star. - #If `True`, the relative pixel RMSE of each star is added to ther saving dictionary. - opt_stars_rel_pix_rmse: False - - ## Specific parameters - # Parameter for the l2 loss of the OPD. - l2_param: 0. - - ## Define the resolution at which you'd like to measure the shape of the PSFs - #Downsampling rate from the high-resolution pixel modelling space. - # Recommended value: 1 - output_Q: 1 - - #Dimension of the pixel PSF postage stamp; it should be big enough so that most of the signal is contained inside the postage stamp. - # It also depends on the Q values used. - # Recommended value: 64 or higher - output_dim: 64 - - diff --git a/src/wf_psf/tests/data/config/plotting_config.yaml b/src/wf_psf/tests/data/config/plotting_config.yaml deleted file mode 100644 index 24f79a92..00000000 --- a/src/wf_psf/tests/data/config/plotting_config.yaml +++ /dev/null @@ -1,23 +0,0 @@ -plotting_params: - # Specify path to parent folder containing wf-psf metrics outputs for all runs, ex: $WORK/wf-outputs/ - metrics_output_path: /gpfswork/rech/ynx/uuu68hq/wf-outputs/ - # Enter directory(s) for metrics of trained PSF models to include in plot, - # ex: metrics_dir: - # - wf-outputs-xxxxxxxxxxx1 - # - wf-outputs-xxxxxxxxxxx2 - metrics_dir: - #Name of Trained Model Metrics Config file - - wf-outputs-202309111434 - - wf-outputs-202306141408 - - wf-outputs-202309121235 - - wf-outputs-202309151235 - - wf-outputs-202309151306 - metrics_config: - # Plot parameter. Training star number of the different models evaluated. - - metrics_config_1.yaml - - metrics_config.yaml - - metrics_config_1.yaml - - metrics_config.yaml - - metrics_config.yaml - # Flag to show plot - plot_show: False \ No newline at end of file diff --git a/src/wf_psf/tests/data/config/plotting_config_1.yaml b/src/wf_psf/tests/data/config/plotting_config_1.yaml deleted file mode 100644 index 55fd762b..00000000 --- a/src/wf_psf/tests/data/config/plotting_config_1.yaml +++ /dev/null @@ -1,17 +0,0 @@ -plotting_params: - # Specify path to parent folder containing wf-psf metrics outputs for all runs, ex: $WORK/wf-outputs/ - metrics_output_path: /Users/jenniferpollack/Projects/jp272790/ - # Enter directory(s) for metrics of trained PSF models to include in plot, - # ex: metrics_dir: - # - wf-outputs-xxxxxxxxxxx1 - # - wf-outputs-xxxxxxxxxxx2 - metrics_dir: - - wf-outputs-202306021300 - - wf-outputs-202305301123 - - wf-outputs-202309121235 - #Name of Trained Model Metrics Config file - metrics_config: metrics_config.yaml - # Plot parameter. Training star number of the different models evaluated. - star_numbers: 200 - # Flag to show plot - plot_show: False \ No newline at end of file diff --git a/src/wf_psf/tests/data/config/training_config.yaml b/src/wf_psf/tests/data/config/training_config.yaml deleted file mode 100644 index 1a4135f7..00000000 --- a/src/wf_psf/tests/data/config/training_config.yaml +++ /dev/null @@ -1,121 +0,0 @@ -training: - # ID name - id_name: -coherent_euclid_200stars - # Name of Data Config file - data_config: data_config.yaml - # Metrics Config file - Enter file to run metrics evaluation else if empty run train only - metrics_config: metrics_config_200.yaml - model_params: - # Model type. Options are: 'mccd', 'graph', 'poly, 'param', 'poly_physical'." - model_name: poly - - #Num of wavelength bins to reconstruct polychromatic objects. - n_bins_lda: 8 - - #Downsampling rate to match the oversampled model to the specified telescope's sampling. - output_Q: 3 - - #Oversampling rate used for the OPD/WFE PSF model. - oversampling_rate: 3 - - #Dimension of the pixel PSF postage stamp - output_dim: 32 - - #Dimension of the OPD/Wavefront space." - pupil_diameter: 256 - - #Boolean to define if we use sample weights based on the noise standard deviation estimation - use_sample_weights: True - - #Interpolation type for the physical poly model. Options are: 'none', 'all', 'top_K', 'independent_Zk'." - interpolation_type: None - - # SED intepolation points per bin - sed_interp_pts_per_bin: 0 - - # SED extrapolate - sed_extrapolate: True - - # SED interpolate kind - sed_interp_kind: linear - - # Standard deviation of the multiplicative SED Gaussian noise. - sed_sigma: 0 - - #Limits of the PSF field coordinates for the x axis. - x_lims: [0.0, 1.0e+3] - - #Limits of the PSF field coordinates for the y axis. - y_lims: [0.0, 1.0e+3] - - # Hyperparameters for Parametric model - param_hparams: - # Random seed for Tensor Flow Initialization - random_seed: 3877572 - - # Parameter for the l2 loss function for the Optical path differences (OPD)/WFE - l2_param: 0. - - #Zernike polynomial modes to use on the parametric part. - n_zernikes: 15 - - #Max polynomial degree of the parametric part. chg to max_deg_param - d_max: 2 - - #Flag to save optimisation history for parametric model - save_optim_history_param: true - - # Hyperparameters for non-parametric model - nonparam_hparams: - #Max polynomial degree of the non-parametric part. chg to max_deg_nonparam - d_max_nonparam: 5 - - # Number of graph features - num_graph_features: 10 - - #L1 regularisation parameter for the non-parametric part." - l1_rate: 1.0e-8 - - #Flag to enable Projected learning for DD_features to be used with `poly` or `semiparametric` model. - project_dd_features: False - - #Flag to reset DD_features to be used with `poly` or `semiparametric` model - reset_dd_features: False - - #Flag to save optimisation history for non-parametric model - save_optim_history_nonparam: true - - # Training hyperparameters - training_hparams: - n_epochs_params: [2, 2] - - n_epochs_non_params: [2, 2] - - batch_size: 32 - - multi_cycle_params: - - # Total amount of cycles to perform. - total_cycles: 1 - - # Train cycle definition. It can be: 'parametric', 'non-parametric', 'complete', 'only-non-parametric' and 'only-parametric'." - cycle_def: complete - - # Make checkpoint at every cycle or just save the checkpoint at the end of the training." - save_all_cycles: False - - #"Saved cycle to use for the evaluation. Can be 'cycle1', 'cycle2', ..." - saved_cycle: cycle1 - - # Learning rates for the parametric parts. It should be a str where numeric values are separated by spaces. - learning_rate_params: [1.0e-2, 1.0e-2] - - # Learning rates for the non-parametric parts. It should be a str where numeric values are separated by spaces." - learning_rate_non_params: [1.0e-1, 1.0e-1] - - # Number of training epochs of the parametric parts. It should be a strign where numeric values are separated by spaces." - n_epochs_params: [20, 20] - - # Number of training epochs of the non-parametric parts. It should be a str where numeric values are separated by spaces." - n_epochs_non_params: [100, 120] - diff --git a/src/wf_psf/tests/data/config/training_config_1000.yaml b/src/wf_psf/tests/data/config/training_config_1000.yaml deleted file mode 100644 index a419a63a..00000000 --- a/src/wf_psf/tests/data/config/training_config_1000.yaml +++ /dev/null @@ -1,121 +0,0 @@ -training: - # ID name - id_name: -coherent_euclid_1000stars - # Name of Data Config file - data_config: data_config.yaml - # Metrics Config file - Enter file to run metrics evaluation else if empty run train only - metrics_config: metrics_config.yaml - model_params: - # Model type. Options are: 'mccd', 'graph', 'poly, 'param', 'poly_physical'." - model_name: poly - - #Num of wavelength bins to reconstruct polychromatic objects. - n_bins_lda: 8 - - #Downsampling rate to match the oversampled model to the specified telescope's sampling. - output_Q: 3 - - #Oversampling rate used for the OPD/WFE PSF model. - oversampling_rate: 3 - - #Dimension of the pixel PSF postage stamp - output_dim: 32 - - #Dimension of the OPD/Wavefront space." - pupil_diameter: 256 - - #Boolean to define if we use sample weights based on the noise standard deviation estimation - use_sample_weights: True - - #Interpolation type for the physical poly model. Options are: 'none', 'all', 'top_K', 'independent_Zk'." - interpolation_type: None - - # SED intepolation points per bin - sed_interp_pts_per_bin: 0 - - # SED extrapolate - sed_extrapolate: True - - # SED interpolate kind - sed_interp_kind: linear - - # Standard deviation of the multiplicative SED Gaussian noise. - sed_sigma: 0 - - #Limits of the PSF field coordinates for the x axis. - x_lims: [0.0, 1.0e+3] - - #Limits of the PSF field coordinates for the y axis. - y_lims: [0.0, 1.0e+3] - - # Hyperparameters for Parametric model - param_hparams: - # Random seed for Tensor Flow Initialization - random_seed: 3877572 - - # Parameter for the l2 loss function for the Optical path differences (OPD)/WFE - l2_param: 0. - - #Zernike polynomial modes to use on the parametric part. - n_zernikes: 15 - - #Max polynomial degree of the parametric part. chg to max_deg_param - d_max: 2 - - #Flag to save optimisation history for parametric model - save_optim_history_param: true - - # Hyperparameters for non-parametric model - nonparam_hparams: - #Max polynomial degree of the non-parametric part. chg to max_deg_nonparam - d_max_nonparam: 5 - - # Number of graph features - num_graph_features: 10 - - #L1 regularisation parameter for the non-parametric part." - l1_rate: 1.0e-8 - - #Flag to enable Projected learning for DD_features to be used with `poly` or `semiparametric` model. - project_dd_features: False - - #Flag to reset DD_features to be used with `poly` or `semiparametric` model - reset_dd_features: False - - #Flag to save optimisation history for non-parametric model - save_optim_history_nonparam: true - - # Training hyperparameters - training_hparams: - n_epochs_params: [2, 2, 2] - - n_epochs_non_params: [2, 2, 2] - - batch_size: 32 - - multi_cycle_params: - - # Total amount of cycles to perform. - total_cycles: 2 - - # Train cycle definition. It can be: 'parametric', 'non-parametric', 'complete', 'only-non-parametric' and 'only-parametric'." - cycle_def: complete - - # Make checkpoint at every cycle or just save the checkpoint at the end of the training." - save_all_cycles: True - - #"Saved cycle to use for the evaluation. Can be 'cycle1', 'cycle2', ..." - saved_cycle: cycle2 - - # Learning rates for the parametric parts. It should be a str where numeric values are separated by spaces. - learning_rate_params: [1.0e-2, 1.0e-2, 1.0e-2] - - # Learning rates for the non-parametric parts. It should be a str where numeric values are separated by spaces." - learning_rate_non_params: [1.0e-1, 1.0e-1, 1.0e-1] - - # Number of training epochs of the parametric parts. It should be a strign where numeric values are separated by spaces." - n_epochs_params: [20, 20, 20] - - # Number of training epochs of the non-parametric parts. It should be a str where numeric values are separated by spaces." - n_epochs_non_params: [100, 120, 120] - diff --git a/src/wf_psf/tests/data/config/training_config_200.yaml b/src/wf_psf/tests/data/config/training_config_200.yaml deleted file mode 100644 index 4740c130..00000000 --- a/src/wf_psf/tests/data/config/training_config_200.yaml +++ /dev/null @@ -1,122 +0,0 @@ -training: - # ID name - id_name: -coherent_euclid_200stars - # Name of Data Config file - data_config: data_config.yaml - # Metrics Config file - Enter file to run metrics evaluation else if empty run train only - metrics_config: metrics_config.yaml - model_params: - # Model type. Options are: 'mccd', 'graph', 'poly, 'param', 'poly_physical'." - model_name: poly - - #Num of wavelength bins to reconstruct polychromatic objects. - n_bins_lda: 8 - - #Downsampling rate to match the oversampled model to the specified telescope's sampling. - output_Q: 3 - - #Oversampling rate used for the OPD/WFE PSF model. - oversampling_rate: 3 - - #Dimension of the pixel PSF postage stamp - output_dim: 32 - - #Dimension of the OPD/Wavefront space." - pupil_diameter: 256 - - #Boolean to define if we use sample weights based on the noise standard deviation estimation - use_sample_weights: True - - #Interpolation type for the physical poly model. Options are: 'none', 'all', 'top_K', 'independent_Zk'." - interpolation_type: None - - # SED intepolation points per bin - sed_interp_pts_per_bin: 0 - - # SED extrapolate - sed_extrapolate: True - - # SED interpolate kind - sed_interp_kind: linear - - # Standard deviation of the multiplicative SED Gaussian noise. - sed_sigma: 0 - - #Limits of the PSF field coordinates for the x axis. - x_lims: [0.0, 1.0e+3] - - #Limits of the PSF field coordinates for the y axis. - y_lims: [0.0, 1.0e+3] - - # Hyperparameters for Parametric model - param_hparams: - # Random seed for Tensor Flow Initialization - random_seed: 3877572 - - # Parameter for the l2 loss function for the Optical path differences (OPD)/WFE - l2_param: 0. - - #Zernike polynomial modes to use on the parametric part. - n_zernikes: 15 - - #Max polynomial degree of the parametric part. chg to max_deg_param - d_max: 2 - - #Flag to save optimisation history for parametric model - save_optim_history_param: true - - # Hyperparameters for non-parametric model - nonparam_hparams: - - #Max polynomial degree of the non-parametric part. chg to max_deg_nonparam - d_max_nonparam: 5 - - # Number of graph features - num_graph_features: 10 - - #L1 regularisation parameter for the non-parametric part." - l1_rate: 1.0e-8 - - #Flag to enable Projected learning for DD_features to be used with `poly` or `semiparametric` model. - project_dd_features: False - - #Flag to reset DD_features to be used with `poly` or `semiparametric` model - reset_dd_features: False - - #Flag to save optimisation history for 'non-parametric model - save_optim_history_nonparam: true - - # Training hyperparameters - training_hparams: - n_epochs_params: [2, 2, 2] - - n_epochs_non_params: [2, 2, 2] - - batch_size: 32 - - multi_cycle_params: - - # Total amount of cycles to perform. - total_cycles: 2 - - # Train cycle definition. It can be: 'parametric', 'non-parametric', 'complete', 'only-non-parametric' and 'only-parametric'." - cycle_def: complete - - # Make checkpoint at every cycle or just save the checkpoint at the end of the training." - save_all_cycles: True - - #"Saved cycle to use for the evaluation. Can be 'cycle1', 'cycle2', ..." - saved_cycle: cycle2 - - # Learning rates for the parametric parts. It should be a str where numeric values are separated by spaces. - learning_rate_params: [1.0e-2, 1.0e-2, 1.0e-2] - - # Learning rates for the non-parametric parts. It should be a str where numeric values are separated by spaces." - learning_rate_non_params: [1.0e-1, 1.0e-1, 1.0e-1] - - # Number of training epochs of the parametric parts. It should be a strign where numeric values are separated by spaces." - n_epochs_params: [20, 20, 20] - - # Number of training epochs of the non-parametric parts. It should be a str where numeric values are separated by spaces." - n_epochs_non_params: [100, 120, 120] - diff --git a/src/wf_psf/tests/data/config/training_config_500.yaml b/src/wf_psf/tests/data/config/training_config_500.yaml deleted file mode 100644 index 26a0bdf1..00000000 --- a/src/wf_psf/tests/data/config/training_config_500.yaml +++ /dev/null @@ -1,121 +0,0 @@ -training: - # ID name - id_name: -coherent_euclid_500stars - # Name of Data Config file - data_config: data_config.yaml - # Metrics Config file - Enter file to run metrics evaluation else if empty run train only - metrics_config: metrics_config.yaml - model_params: - # Model type. Options are: 'mccd', 'graph', 'poly, 'param', 'poly_physical'." - model_name: poly - - #Num of wavelength bins to reconstruct polychromatic objects. - n_bins_lda: 8 - - #Downsampling rate to match the oversampled model to the specified telescope's sampling. - output_Q: 3 - - #Oversampling rate used for the OPD/WFE PSF model. - oversampling_rate: 3 - - #Dimension of the pixel PSF postage stamp - output_dim: 32 - - #Dimension of the OPD/Wavefront space." - pupil_diameter: 256 - - #Boolean to define if we use sample weights based on the noise standard deviation estimation - use_sample_weights: True - - #Interpolation type for the physical poly model. Options are: 'none', 'all', 'top_K', 'independent_Zk'." - interpolation_type: None - - # SED intepolation points per bin - sed_interp_pts_per_bin: 0 - - # SED extrapolate - sed_extrapolate: True - - # SED interpolate kind - sed_interp_kind: linear - - # Standard deviation of the multiplicative SED Gaussian noise. - sed_sigma: 0 - - #Limits of the PSF field coordinates for the x axis. - x_lims: [0.0, 1.0e+3] - - #Limits of the PSF field coordinates for the y axis. - y_lims: [0.0, 1.0e+3] - - # Hyperparameters for Parametric model - param_hparams: - # Random seed for Tensor Flow Initialization - random_seed: 3877572 - - # Parameter for the l2 loss function for the Optical path differences (OPD)/WFE - l2_param: 0. - - #Zernike polynomial modes to use on the parametric part. - n_zernikes: 15 - - #Max polynomial degree of the parametric part. chg to max_deg_param - d_max: 2 - - #Flag to save optimisation history for parametric model - save_optim_history_param: true - - # Hyperparameters for non-parametric model - nonparam_hparams: - #Max polynomial degree of the non-parametric part. chg to max_deg_nonparam - d_max_nonparam: 5 - - # Number of graph features - num_graph_features: 10 - - #L1 regularisation parameter for the non-parametric part." - l1_rate: 1.0e-8 - - #Flag to enable Projected learning for DD_features to be used with `poly` or `semiparametric` model. - project_dd_features: False - - #Flag to reset DD_features to be used with `poly` or `semiparametric` model - reset_dd_features: False - - #Flag to save optimisation history for non-parametric model - save_optim_history_nonparam: true - - # Training hyperparameters - training_hparams: - n_epochs_params: [2, 2, 2] - - n_epochs_non_params: [2, 2, 2] - - batch_size: 32 - - multi_cycle_params: - - # Total amount of cycles to perform. - total_cycles: 2 - - # Train cycle definition. It can be: 'parametric', 'non-parametric', 'complete', 'only-non-parametric' and 'only-parametric'." - cycle_def: complete - - # Make checkpoint at every cycle or just save the checkpoint at the end of the training." - save_all_cycles: True - - #"Saved cycle to use for the evaluation. Can be 'cycle1', 'cycle2', ..." - saved_cycle: cycle2 - - # Learning rates for the parametric parts. It should be a str where numeric values are separated by spaces. - learning_rate_params: [1.0e-2, 1.0e-2, 1.0e-2] - - # Learning rates for the non-parametric parts. It should be a str where numeric values are separated by spaces." - learning_rate_non_params: [1.0e-1, 1.0e-1, 1.0e-1] - - # Number of training epochs of the parametric parts. It should be a strign where numeric values are separated by spaces." - n_epochs_params: [20, 20, 20] - - # Number of training epochs of the non-parametric parts. It should be a str where numeric values are separated by spaces." - n_epochs_non_params: [100, 120, 120] - diff --git a/src/wf_psf/tests/data/config/training_config_test.yaml b/src/wf_psf/tests/data/config/training_config_test.yaml deleted file mode 100644 index 8096fd34..00000000 --- a/src/wf_psf/tests/data/config/training_config_test.yaml +++ /dev/null @@ -1 +0,0 @@ -dsfasd \ No newline at end of file diff --git a/src/wf_psf/training/sandbox.py b/src/wf_psf/training/sandbox.py deleted file mode 100644 index 6ffaa279..00000000 --- a/src/wf_psf/training/sandbox.py +++ /dev/null @@ -1,709 +0,0 @@ -import numpy as np -import tensorflow as tf -import matplotlib.pyplot as plt -from wf_psf.utils.utils import generate_packed_elems -from wf_psf.psf_models.tf_psf_field import build_PSF_model - -""" Place to temporarily save some useful functions. -""" - - -class L1ParamScheduler(tf.keras.callbacks.Callback): - """L1 rate scheduler which sets the L1 rate according to schedule. - - Arguments: - l1_schedule_rule: a function that takes an epoch index - (integer, indexed from 0) and current l1_rate - as inputs and returns a new l1_rate as output (float). - """ - - def __init__(self, l1_schedule_rule): - super(L1ParamScheduler, self).__init__() - self.l1_schedule_rule = l1_schedule_rule - - def on_epoch_begin(self, epoch, logs=None): - # Get the current learning rate from model's optimizer. - l1_rate = float(tf.keras.backend.get_value(self.model.l1_rate)) - # Call schedule function to get the scheduled learning rate. - scheduled_l1_rate = self.l1_schedule_rule(epoch, l1_rate) - # Set the value back to the optimizer before this epoch starts - self.model.set_l1_rate(scheduled_l1_rate) - # tf.keras.backend.set_value(self.model.optimizer.lr, scheduled_lr) - - -def l1_schedule_rule(epoch_n, l1_rate): - if epoch_n != 0 and epoch_n % 10 == 0: - scheduled_l1_rate = l1_rate / 2 - print("\nEpoch %05d: L1 rate is %0.4e." % (epoch_n, scheduled_l1_rate)) - return scheduled_l1_rate - else: - return l1_rate - - -def first_train_cycle( - tf_semiparam_field, - inputs, - outputs, - batch_size, - l_rate_param, - l_rate_non_param, - n_epochs_param, - n_epochs_non_param, - param_callback=None, - non_param_callback=None, -): - ## First parametric train - - # Define the model optimisation - # l_rate_param = 1e-2 - # n_epochs_param = 20 - - loss = tf.keras.losses.MeanSquaredError() - optimizer = tf.keras.optimizers.Adam( - learning_rate=l_rate_param, - beta_1=0.9, - beta_2=0.999, - epsilon=1e-07, - amsgrad=False, - ) - metrics = [tf.keras.metrics.MeanSquaredError()] - - # Set the non-parametric model to zero - # With alpha to zero its already enough - tf_semiparam_field.set_zero_nonparam() - - # Set the non parametric layer to non trainable - # And keep the parametric layer to trainable - tf_semiparam_field.set_trainable_layers(param_bool=True, nonparam_bool=False) - - # Compile the model for the first optimisation - tf_semiparam_field = build_PSF_model( - tf_semiparam_field, optimizer=optimizer, loss=loss, metrics=metrics - ) - - # Train the parametric part - history_param = tf_semiparam_field.fit( - x=inputs, - y=outputs, - batch_size=batch_size, - epochs=n_epochs_param, - callbacks=param_callback, - ) - - # Plot losses - plt.figure() - plt.subplot(211) - plt.plot(history_param.history["loss"]) - plt.xlabel("Number of iterations") - plt.ylabel("Total loss") - plt.subplot(212) - plt.loglog(history_param.history["loss"]) - plt.xlabel("Number of iterations") - plt.ylabel("Total loss") - plt.show() - - ## Non parametric train - # Set the non-parametric model to non-zero - # With alpha to zero its already enough - tf_semiparam_field.set_nonzero_nonparam() - - # Set the non parametric layer to non trainable - # Set the parametric layer to non trainable - tf_semiparam_field.set_trainable_layers(param_bool=False, nonparam_bool=True) - - # Non parametric parameters - # l_rate_non_param = 1.0 - # n_epochs_non_param = 100 - - # Define the model optimisation - loss = tf.keras.losses.MeanSquaredError() - optimizer = tf.keras.optimizers.Adam( - learning_rate=l_rate_non_param, - beta_1=0.9, - beta_2=0.999, - epsilon=1e-07, - amsgrad=False, - ) - metrics = [tf.keras.metrics.MeanSquaredError()] - - # Compile the model again for the second optimisation - tf_semiparam_field = build_PSF_model( - tf_semiparam_field, optimizer=optimizer, loss=loss, metrics=metrics - ) - - # Train the parametric part - history_non_param = tf_semiparam_field.fit( - x=inputs, - y=outputs, - batch_size=batch_size, - epochs=n_epochs_non_param, - callbacks=non_param_callback, - ) - - # Plot losses - plt.figure() - plt.subplot(211) - plt.plot(history_non_param.history["loss"]) - plt.xlabel("Number of iterations") - plt.ylabel("Total loss") - plt.subplot(212) - plt.loglog(history_non_param.history["loss"]) - plt.xlabel("Number of iterations") - plt.ylabel("Total loss") - plt.show() - - return tf_semiparam_field - - -def train_cycle( - tf_semiparam_field, - inputs, - outputs, - batch_size, - l_rate_param, - l_rate_non_param, - n_epochs_param, - n_epochs_non_param, - param_callback=None, - non_param_callback=None, -): - ## Parametric train - - # Define the model optimisation - # l_rate_param = 1e-2 - # n_epochs_param = 20 - - loss = tf.keras.losses.MeanSquaredError() - optimizer = tf.keras.optimizers.Adam( - learning_rate=l_rate_param, - beta_1=0.9, - beta_2=0.999, - epsilon=1e-07, - amsgrad=False, - ) - metrics = [tf.keras.metrics.MeanSquaredError()] - - # Set the trainable layer - tf_semiparam_field.set_trainable_layers(param_bool=True, nonparam_bool=False) - - # Compile the model for the first optimisation - tf_semiparam_field = build_PSF_model( - tf_semiparam_field, optimizer=optimizer, loss=loss, metrics=metrics - ) - - # Train the parametric part - history_param = tf_semiparam_field.fit( - x=inputs, - y=outputs, - batch_size=batch_size, - epochs=n_epochs_param, - callbacks=param_callback, - ) - - # Plot losses - plt.figure() - plt.subplot(211) - plt.plot(history_param.history["loss"]) - plt.xlabel("Number of iterations") - plt.ylabel("Total loss") - plt.subplot(212) - plt.loglog(history_param.history["loss"]) - plt.xlabel("Number of iterations") - plt.ylabel("Total loss") - plt.show() - - ## Non parametric train - # Set the non parametric layer to non trainable - tf_semiparam_field.set_trainable_layers(param_bool=False, nonparam_bool=True) - - # Non parametric parameters - # l_rate_non_param = 1.0 - # n_epochs_non_param = 100 - - # Define the model optimisation - loss = tf.keras.losses.MeanSquaredError() - optimizer = tf.keras.optimizers.Adam( - learning_rate=l_rate_non_param, - beta_1=0.9, - beta_2=0.999, - epsilon=1e-07, - amsgrad=False, - ) - metrics = [tf.keras.metrics.MeanSquaredError()] - - # Compile the model again for the second optimisation - tf_semiparam_field = build_PSF_model( - tf_semiparam_field, optimizer=optimizer, loss=loss, metrics=metrics - ) - - # Train the parametric part - history_non_param = tf_semiparam_field.fit( - x=inputs, - y=outputs, - batch_size=batch_size, - epochs=n_epochs_non_param, - callbacks=non_param_callback, - ) - - # Plot losses - plt.figure() - plt.subplot(211) - plt.plot(history_non_param.history["loss"]) - plt.xlabel("Number of iterations") - plt.ylabel("Total loss") - plt.subplot(212) - plt.loglog(history_non_param.history["loss"]) - plt.xlabel("Number of iterations") - plt.ylabel("Total loss") - plt.show() - - return tf_semiparam_field - - -def compute_metrics( - tf_semiparam_field, - simPSF_np, - test_SEDs, - train_SEDs, - tf_test_pos, - tf_train_pos, - tf_test_stars, - tf_train_stars, - n_bins_lda, - batch_size=16, -): - # Generate SED data list - test_packed_SED_data = [ - generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) for _sed in test_SEDs - ] - - tf_test_packed_SED_data = tf.convert_to_tensor( - test_packed_SED_data, dtype=tf.float32 - ) - tf_test_packed_SED_data = tf.transpose(tf_test_packed_SED_data, perm=[0, 2, 1]) - test_pred_inputs = [tf_test_pos, tf_test_packed_SED_data] - test_predictions = tf_semiparam_field.predict( - x=test_pred_inputs, batch_size=batch_size - ) - - # Initialize the SED data list - packed_SED_data = [ - generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) for _sed in train_SEDs - ] - # First estimate the stars for the observations - tf_packed_SED_data = tf.convert_to_tensor(packed_SED_data, dtype=tf.float32) - tf_packed_SED_data = tf.transpose(tf_packed_SED_data, perm=[0, 2, 1]) - inputs = [tf_train_pos, tf_packed_SED_data] - train_predictions = tf_semiparam_field.predict(x=inputs, batch_size=batch_size) - - # Calculate RMSE values - test_res = np.sqrt(np.mean((tf_test_stars - test_predictions) ** 2)) - train_res = np.sqrt(np.mean((tf_train_stars - train_predictions) ** 2)) - - # Pritn RMSE values - print("Test stars RMSE:\t %.4e" % test_res) - print("Training stars RMSE:\t %.4e" % train_res) - - return test_res, train_res - - -def compute_opd_metrics(tf_semiparam_field, GT_tf_semiparam_field, test_pos, train_pos): - """Compute the OPD metrics.""" - - np_obscurations = np.real(tf_semiparam_field.obscurations.numpy()) - - ## For test positions - # Param part - zernike_coeffs = tf_semiparam_field.tf_poly_Z_field(test_pos) - P_opd_pred = tf_semiparam_field.tf_zernike_OPD(zernike_coeffs) - # Non-Param part - NP_opd_pred = tf_semiparam_field.tf_NP_mccd_OPD.predict(test_pos) - # OPD prediction - opd_pred = tf.math.add(P_opd_pred, NP_opd_pred) - - # GT model - GT_zernike_coeffs = GT_tf_semiparam_field.tf_poly_Z_field(test_pos) - GT_opd_maps = GT_tf_semiparam_field.tf_zernike_OPD(GT_zernike_coeffs) - - # Compute residual and obscure the OPD - res_opd = (GT_opd_maps.numpy() - opd_pred.numpy()) * np_obscurations - - # Calculate RMSE values - test_opd_rmse = np.sqrt(np.mean(res_opd**2)) - - # Pritn RMSE values - print("Test stars OPD RMSE:\t %.4e" % test_opd_rmse) - - ## For train part - # Param part - zernike_coeffs = tf_semiparam_field.tf_poly_Z_field(train_pos) - P_opd_pred = tf_semiparam_field.tf_zernike_OPD(zernike_coeffs) - # Non-Param part - NP_opd_pred = tf_semiparam_field.tf_NP_mccd_OPD.predict(train_pos) - # OPD prediction - opd_pred = tf.math.add(P_opd_pred, NP_opd_pred) - - # GT model - GT_zernike_coeffs = GT_tf_semiparam_field.tf_poly_Z_field(train_pos) - GT_opd_maps = GT_tf_semiparam_field.tf_zernike_OPD(GT_zernike_coeffs) - - # Compute residual and obscure the OPD - res_opd = (GT_opd_maps.numpy() - opd_pred.numpy()) * np_obscurations - - # Calculate RMSE values - train_opd_rmse = np.sqrt(np.mean(res_opd**2)) - - # Pritn RMSE values - print("Train stars OPD RMSE:\t %.4e" % train_opd_rmse) - - return test_opd_rmse, train_opd_rmse - - -def compute_opd_metrics_polymodel( - tf_semiparam_field, GT_tf_semiparam_field, test_pos, train_pos -): - """Compute the OPD metrics.""" - - np_obscurations = np.real(tf_semiparam_field.obscurations.numpy()) - - ## For test positions - # Param part - zernike_coeffs = tf_semiparam_field.tf_poly_Z_field(test_pos) - P_opd_pred = tf_semiparam_field.tf_zernike_OPD(zernike_coeffs) - # Non-Param part - NP_opd_pred = tf_semiparam_field.tf_np_poly_opd(test_pos) - # OPD prediction - opd_pred = tf.math.add(P_opd_pred, NP_opd_pred) - - # GT model - GT_zernike_coeffs = GT_tf_semiparam_field.tf_poly_Z_field(test_pos) - GT_opd_maps = GT_tf_semiparam_field.tf_zernike_OPD(GT_zernike_coeffs) - - # Compute residual and obscure the OPD - res_opd = (GT_opd_maps.numpy() - opd_pred.numpy()) * np_obscurations - - # Calculate RMSE values - test_opd_rmse = np.sqrt(np.mean(res_opd**2)) - - # Pritn RMSE values - print("Test stars OPD RMSE:\t %.4e" % test_opd_rmse) - - ## For train part - # Param part - zernike_coeffs = tf_semiparam_field.tf_poly_Z_field(train_pos) - P_opd_pred = tf_semiparam_field.tf_zernike_OPD(zernike_coeffs) - # Non-Param part - NP_opd_pred = tf_semiparam_field.tf_np_poly_opd(train_pos) - # OPD prediction - opd_pred = tf.math.add(P_opd_pred, NP_opd_pred) - - # GT model - GT_zernike_coeffs = GT_tf_semiparam_field.tf_poly_Z_field(train_pos) - GT_opd_maps = GT_tf_semiparam_field.tf_zernike_OPD(GT_zernike_coeffs) - - # Compute residual and obscure the OPD - res_opd = (GT_opd_maps.numpy() - opd_pred.numpy()) * np_obscurations - - # Calculate RMSE values - train_opd_rmse = np.sqrt(np.mean(res_opd**2)) - - # Pritn RMSE values - print("Train stars OPD RMSE:\t %.4e" % train_opd_rmse) - - return test_opd_rmse, train_opd_rmse - - -def compute_one_opd_rmse(GT_tf_semiparam_field, tf_semiparam_field, pos, is_poly=False): - """Compute the OPD map for one position!.""" - - np_obscurations = np.real(tf_semiparam_field.obscurations.numpy()) - - tf_pos = tf.convert_to_tensor(pos, dtype=tf.float32) - - ## For test positions - # Param part - zernike_coeffs = tf_semiparam_field.tf_poly_Z_field(tf_pos) - P_opd_pred = tf_semiparam_field.tf_zernike_OPD(zernike_coeffs) - # Non-Param part - if is_poly == False: - NP_opd_pred = tf_semiparam_field.tf_NP_mccd_OPD.predict(tf_pos) - else: - NP_opd_pred = tf_semiparam_field.tf_np_poly_opd(tf_pos) - # OPD prediction - opd_pred = tf.math.add(P_opd_pred, NP_opd_pred) - - # GT model - GT_zernike_coeffs = GT_tf_semiparam_field.tf_poly_Z_field(tf_pos) - GT_opd_maps = GT_tf_semiparam_field.tf_zernike_OPD(GT_zernike_coeffs) - - # Compute residual and obscure the OPD - res_opd = (GT_opd_maps.numpy() - opd_pred.numpy()) * np_obscurations - - # Calculate RMSE values - opd_rmse = np.sqrt(np.mean(res_opd**2)) - - return opd_rmse - - -def plot_function(mesh_pos, residual, tf_train_pos, tf_test_pos, title="Error"): - vmax = np.max(residual) - vmin = np.min(residual) - - plt.figure(figsize=(12, 8)) - plt.scatter( - mesh_pos[:, 0], - mesh_pos[:, 1], - s=100, - c=residual.reshape(-1, 1), - cmap="viridis", - marker="s", - vmax=vmax, - vmin=vmin, - ) - plt.colorbar() - plt.scatter( - tf_train_pos[:, 0], - tf_train_pos[:, 1], - c="k", - marker="*", - s=10, - label="Train stars", - ) - plt.scatter( - tf_test_pos[:, 0], - tf_test_pos[:, 1], - c="r", - marker="*", - s=10, - label="Test stars", - ) - plt.title(title) - plt.xlabel("x-axis") - plt.ylabel("y-axis") - plt.show() - - -def plot_residual_maps( - GT_tf_semiparam_field, - tf_semiparam_field, - simPSF_np, - train_SEDs, - tf_train_pos, - tf_test_pos, - n_bins_lda=20, - n_points_per_dim=30, - is_poly=False, -): - # Recover teh grid limits - x_lims = tf_semiparam_field.x_lims - y_lims = tf_semiparam_field.y_lims - - # Generate mesh of testing positions - x = np.linspace(x_lims[0], x_lims[1], n_points_per_dim) - y = np.linspace(y_lims[0], y_lims[1], n_points_per_dim) - x_pos, y_pos = np.meshgrid(x, y) - - mesh_pos = np.concatenate( - (x_pos.flatten().reshape(-1, 1), y_pos.flatten().reshape(-1, 1)), axis=1 - ) - tf_mesh_pos = tf.convert_to_tensor(mesh_pos, dtype=tf.float32) - - # Testing the positions - rec_x_pos = mesh_pos[:, 0].reshape(x_pos.shape) - rec_y_pos = mesh_pos[:, 1].reshape(y_pos.shape) - - # Get random SED from the training catalog - SED_random_integers = np.random.choice( - np.arange(train_SEDs.shape[0]), size=mesh_pos.shape[0], replace=True - ) - # Build the SED catalog for the testing mesh - mesh_SEDs = np.array([train_SEDs[_id, :, :] for _id in SED_random_integers]) - - # Generate SED data list - mesh_packed_SED_data = [ - generate_packed_elems(_sed, simPSF_np, n_bins=n_bins_lda) for _sed in mesh_SEDs - ] - - # Generate inputs - tf_mesh_packed_SED_data = tf.convert_to_tensor( - mesh_packed_SED_data, dtype=tf.float32 - ) - tf_mesh_packed_SED_data = tf.transpose(tf_mesh_packed_SED_data, perm=[0, 2, 1]) - mesh_pred_inputs = [tf_mesh_pos, tf_mesh_packed_SED_data] - - # Predict mesh stars - model_mesh_preds = tf_semiparam_field.predict(x=mesh_pred_inputs, batch_size=16) - GT_mesh_preds = GT_tf_semiparam_field.predict(x=mesh_pred_inputs, batch_size=16) - - # Calculate pixel RMSE for each star - pix_rmse = np.array( - [ - np.sqrt(np.mean((_GT_pred - _model_pred) ** 2)) - for _GT_pred, _model_pred in zip(GT_mesh_preds, model_mesh_preds) - ] - ) - - relative_pix_rmse = np.array( - [ - np.sqrt(np.mean((_GT_pred - _model_pred) ** 2)) - / np.sqrt(np.mean((_GT_pred) ** 2)) - for _GT_pred, _model_pred in zip(GT_mesh_preds, model_mesh_preds) - ] - ) - - # Plot absolute pixel error - plot_function( - mesh_pos, pix_rmse, tf_train_pos, tf_test_pos, title="Absolute pixel error" - ) - # Plot relative pixel error - plot_function( - mesh_pos, - relative_pix_rmse, - tf_train_pos, - tf_test_pos, - title="Relative pixel error", - ) - - # Compute OPD errors - opd_rmse = np.array( - [ - compute_one_opd_rmse( - GT_tf_semiparam_field, tf_semiparam_field, _pos.reshape(1, -1), is_poly - ) - for _pos in mesh_pos - ] - ) - - # Plot absolute pixel error - plot_function( - mesh_pos, opd_rmse, tf_train_pos, tf_test_pos, title="Absolute OPD error" - ) - - -def plot_imgs(mat, cmap="gist_stern", figsize=(20, 20)): - """Function to plot 2D images of a tensor. - The Tensor is (batch,xdim,ydim) and the matrix of subplots is - chosen "intelligently". - """ - - def dp(n, left): # returns tuple (cost, [factors]) - memo = {} - if (n, left) in memo: - return memo[(n, left)] - - if left == 1: - return (n, [n]) - - i = 2 - best = n - bestTuple = [n] - while i * i <= n: - if n % i == 0: - rem = dp(n / i, left - 1) - if rem[0] + i < best: - best = rem[0] + i - bestTuple = [i] + rem[1] - i += 1 - - memo[(n, left)] = (best, bestTuple) - return memo[(n, left)] - - n_images = mat.shape[0] - row_col = dp(n_images, 2)[1] - row_n = int(row_col[0]) - col_n = int(row_col[1]) - - plt.figure(figsize=figsize) - idx = 0 - - for _i in range(row_n): - for _j in range(col_n): - plt.subplot(row_n, col_n, idx + 1) - plt.imshow(mat[idx, :, :], cmap=cmap) - plt.colorbar() - plt.title("matrix id %d" % idx) - - idx += 1 - - plt.show() - - -def add_noise(image, desired_SNR): - """Function to add noise to a 2D image in order to have a desired SNR.""" - sigma_noise = np.sqrt( - (np.sum(image**2)) / (desired_SNR * image.shape[0] * image.shape[1]) - ) - noisy_image = image + np.random.standard_normal(image.shape) * sigma_noise - return noisy_image - - -class MyLRSchedule(tf.keras.optimizers.schedules.LearningRateSchedule): - """Learning rate scheduler. - - To be passed to the optimization algorithm. - - Parameters - ---------- - lr_update_strategy: function(step, params) -> lr - Learning rate update strategy. Should have as input the step number and some parameters - and return a learning rate that corresponds to the input step number. - """ - - def __init__(self, lr_update_strategy, params=None): - self.lr_update_strategy = lr_update_strategy - self.params = params - - def __call__(self, step): - return self.lr_update_strategy(step, self.params) - - -def step_update_strategy(step, params): - """Piecewise constant update strategy. - - Parameters - ---------- - step: int - Optimization step (not to confound with epoch.) - params['batch_size']: int - Batch size. - params['input_elements']: int - Total number of input elements. - params['total_epochs']: int - Total number of epochs. - params['epoch_list']: list of int - List of epoch intervals. It corresponds tot he intervals of the learning rate - list params['lr_list']. - It must verify: - params['epoch_list'][0] = 0 - params['epoch_list'][-1] = params['total_epochs'] - len(params['epoch_list']) = 1 + len(params['lr_list']) - params['lr_list']: list of float - List of learning rate values. See params['epoch_list']. - - Returns - ------- - current_lr: float - Learning rate correspondign to the current step. - - """ - # Calculate the current epoch - one_epoch_in_steps = params["input_elements"] / params["batch_size"] - current_epoch = step / one_epoch_in_steps - - print("step") - print(step) - print("current_epoch") - print(current_epoch) - - for it in range(len(params["lr_list"])): - if ( - params["epoch_list"][it] <= current_epoch - and current_epoch < params["epoch_list"][it + 1] - ): - current_lr = params["lr_list"][it] - break - - print("current_lr") - print(current_lr) - - return current_lr