Skip to content

Commit 9e80a9e

Browse files
sGourapuraarahlin
andauthored
Improved gcorr iteration script (#31)
Refactor gcorr script to work locally or submitted online, iterate until convergence, and condense outputs into a single directory with easily identifiable intermediate iteration files. Closes #21 --------- Co-authored-by: Alexandra Rahlin <[email protected]> Co-authored-by: Sasha Rahlin <[email protected]>
1 parent 3804f0b commit 9e80a9e

File tree

8 files changed

+897
-544
lines changed

8 files changed

+897
-544
lines changed

scripts/gcorr/README

Lines changed: 56 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,79 +2,71 @@ Code package for calculating correction factors to g_ell using pre-generated
22
simulation maps for each single mask. This procedure assumes you are running
33
this code on a cluster-- it is extremely slow to do otherwise.
44

5-
There are three scripts used:
5+
There is one main script that calls two functions from the xfaster.gcorr_tools
6+
library:
67

7-
1. run_xfaster.py ---- This calls XFaster either to run or submit jobs.
8-
The only part that you'll need to touch is at the beginning-- opts and
9-
submit_opts, to match the options you use for data/for your cluster.
10-
2. compute_gcorr.py ---- A script that computes gcorr.npz file from all the
11-
bandpower.npz files. You'll never need to touch or run this script.
12-
3. iterate.py ---- A iteration script, that calls script 1 and 2 to get a
13-
new gcorr.npz file each time. This is the main script you'll run.
8+
1. xfaster_gcorr ---- This function calls XFaster to run or submit jobs for
9+
gcorr runs.
10+
2. process_gcorr ---- A function that computes the gcorr correction from the
11+
ensemble of bandpowers, updates the running total, and backs up the necessary
12+
files from each iteration.
13+
3. iterate_gcorr.py ---- A iteration script, that calls function 1 and 2 to get
14+
a new gcorr.npz file each time. This is the main script you'll run.
1415

1516
There is also a config file with options specific to computing gcorr.
1617

1718
---------------------
1819
Gcorr run procedure:
1920

2021
1. Edit the gcorr config file to suit your purposes. An example is given.
21-
Required fields are:
22-
* null -- must be true for null tests and false for signal runs
23-
* map_tags -- comma-separated list of map tags
24-
* data_subset -- the globabble data_subset argument to xfaster_run,
25-
but without map tags. So, "full", "chunk*", etc.
26-
* output_root -- the parent directory where your gcorr XFaster runs will
27-
be written
28-
* nsim -- the number of simulations to use to compute gcorr
29-
* [xfaster_opts] -- this is where you'll put any string-type options
30-
that will be directly input to xfaster_run
22+
Required fields are:
23+
* null -- must be true for null tests and false for signal runs
24+
* map_tags -- comma-separated list of map tags
25+
* data_subset -- the globabble data_subset argument to xfaster_run,
26+
but without map tags. So, "full", "chunk*", etc.
27+
* output_root -- the parent directory where your gcorr XFaster runs will
28+
be written
29+
* nsim -- the number of simulations to use to compute gcorr
30+
* [xfaster_opts] -- this is where you'll put any options
31+
that will be directly input to xfaster_run
32+
* [submit_opts] -- this is where you'll put any options
33+
that will be directly input to xfaster_submit,
34+
in addition to those in [xfaster_opts]
3135

32-
2. Edit the beginning of run_xfaster.py for non-string input options
33-
to xfaster_run (opts dictionary) or xfaster_submit (submit_opts).
34-
Here you might change things like lmin, lmax, bin size, etc. and
35-
omp_threads.
36+
2. Run iterate_gcorr.py once to get the full set of XFaster output files in the
37+
output directory. Since we haven't computed gcorr yet, this will set
38+
apply_gcorr=False. Make sure to use as many OMP threads as possible since
39+
this is the step where the sims_xcorr file, which benefits the most from
40+
extra threads, is computed. Your command should look like this:
3641

37-
3. Run run_xfaster.py once to get the full set of XFaster output files.
38-
Since we haven't computed gcorr yet, you must use --no-gcorr. Make sure
39-
to use as many OMP threads as possible since this is the step where the
40-
sims_xcorr file, which benefits the most from extra threads, is computed.
41-
Your command should look like this:
42-
python run_xfaster.py --gcorr-config path-to-my-gcorr-config.ini --no-gcorr
42+
python iterate_gcorr.py path-to-my-gcorr-config.ini
4343

44-
4. Run iterate.py until convergence is reached. In practice, you will do:
45-
iterate.py --gcorr-config path-to-my-gcorr-config.ini
46-
then wait for it to finish. Then look at the correction-to-the-correction
47-
that it both prints and plots (it should converge to 1s for TT, EE, BB),
48-
and if it hasn't converged, up+enter (redo) the same command you just did.
49-
In much more detail, here's what the code does:
50-
1. If this is the first iteration, copy the whole output directory into
51-
one next to it with tag _iter. This is the directory that will now be
52-
updated with new transfer functions and bandpowers on each iteration.
53-
In the code, it's called rundir.
54-
2. Make a plot directory in that _iter directory-- look here for new plots
55-
of the total gcorr and the correction-to-gcorr each iteration.
56-
3. For the first iteration, initialize a starting guess for gcorr as all
57-
ones. This total gcorr is saved as gcorr_<tag>_total.npz in the original
58-
(reference) output directory.
59-
4. If not the first iteration, load up the correction-to-gcorr computed
60-
in the previous iteration. Multiply it by the total gcorr, and save that
61-
to the reference directory as gcorr_total. Also save the previous
62-
iteration's total gcorr as gcorr_<tag>_prev.npz.
63-
5. Plot gcorr total and the correction to gcorr total. Save in rundir/plots.
64-
6. Clear out rundir bandpowers/transfer functions/logs.
65-
7. Call run_xfaster.py for the 0th sim seed while also reloading gcorr.
66-
This does a couple things-- saves the new gcorr in the masks_xcorr file,
67-
so later seeds will use the right thing. And recompute the transfer
68-
function, which doesn't depend on the sim_index, so is only necessary to
69-
do once.
70-
8. After the transfer functions are all on disk, submit individual jobs for
71-
all the other seeds, just doing the bandpowers step for those.
72-
9. Monitor the queue, checking every 10 seconds for jobs still running.
73-
10. Once they're all done, run compute_gcal.py, which saves a
74-
correction-to-gcorr as gcorr_corr_<tag>.npz in the rundir.
75-
11. Print out the values of the correction-to-gcorr.
76-
12. Exit.
44+
3. Run iterate_gcorr.py until convergence is reached. In practice, you will run
45+
the command above and wait for it to finish. If you include the `--max-iters`
46+
option with a non-zero value, the code will try to determine whether
47+
convergence or max_iters has been reached and stop on its own. Otherwise,
48+
you can look at the correction-to-the-correction that it both prints and
49+
plots (it should converge to 1s for TT, EE, BB), and if it hasn't converged,
50+
up+enter (redo) the same command you just did. In much more detail, here's
51+
what the code does:
7752

78-
5. After convergence is reached, copy the gcorr_total file from the refdir
79-
to the mask directory, labeling it mask_map_<tag>_gcorr.npz for signal or
80-
mask_map_<tag>_gcorr_null.npz for null.
53+
1. Call xfaster_gcorr for the 0th sim seed while also reloading gcorr (if
54+
this is not the first iteration). This does a couple things-- saves the
55+
new gcorr in the masks_xcorr file, so later seeds will use the right
56+
thing. And recompute the transfer function, which doesn't depend on the
57+
sim_index, so is only necessary to do once.
58+
2. After the transfer functions are all on disk, submit individual jobs for
59+
all the other seeds, just doing the bandpowers step for those.
60+
3. Once they're all done, run compute_gcal, and save a correction-to-gcorr
61+
as gcorr_corr_<tag>_iter<iter>.npz in the rundir.
62+
4. If not the first iteration, load up the correction-to-gcorr computed for
63+
this iteration. Multiply it by the total gcorr, and save that to the
64+
output directory as gcorr_total_<tag>_iter<iter>.npz.
65+
5. Plot gcorr total and the correction to gcorr total. Save in rundir/plots.
66+
6. Clear out rundir bandpowers/transfer functions/logs.
67+
7. Exit.
68+
69+
4. After convergence is reached, copy the gcorr_total file for the last
70+
iteration from the rundir to the mask directory, labeling it
71+
mask_map_<tag>_gcorr.npz for signal or mask_map_<tag>_gcorr_null.npz for
72+
null.

scripts/gcorr/compute_gcal.py

Lines changed: 0 additions & 145 deletions
This file was deleted.

scripts/gcorr/gcorr_config_null.ini

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,20 @@ signal_type = synfast
1717
# Noise type needed for nulls
1818
noise_type = gaussian
1919
mask_type = rectangle
20-
verbose = debug
20+
likelihood = false
21+
residual_fit = false
22+
foreground_fit = false
23+
tbeb = true
24+
bin_width = 25
25+
lmin = 2
26+
lmax = 500
27+
verbose = info
28+
29+
# Options for submitting to a cluster
30+
[submit_opts]
31+
nodes = 1
32+
ppn = 1
33+
mem = 6
34+
omp_threads = 10
35+
wallt = 4
36+
num_jobs = 10

scripts/gcorr/gcorr_config_signal.ini

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ data_subset = full
66
output_root = ../../example/gcorr_run
77
nsim = 100
88

9-
109
# Options we can directly pass to XFaster
1110
[xfaster_opts]
1211
config = ../../example/config_example.ini
@@ -16,4 +15,20 @@ signal_type = synfast
1615
# noise type ignored for signal gcorr
1716
noise_type = gaussian
1817
mask_type = rectangle
19-
verbose = debug
18+
likelihood = false
19+
residual_fit = false
20+
foreground_fit = false
21+
tbeb = true
22+
bin_width = 25
23+
lmin = 2
24+
lmax = 500
25+
verbose = info
26+
27+
# Options for submitting to a cluster
28+
[submit_opts]
29+
nodes = 1
30+
ppn = 1
31+
mem = 6
32+
omp_threads = 10
33+
wallt = 4
34+
num_jobs = 10

0 commit comments

Comments
 (0)