-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
873bc2d
commit 31bdd03
Showing
5 changed files
with
278 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/env python | ||
from vega import VegaInterface | ||
from mpi4py import MPI | ||
from astropy.io import fits | ||
import argparse | ||
import sys | ||
|
||
|
||
if __name__ == '__main__': | ||
pars = argparse.ArgumentParser( | ||
formatter_class=argparse.ArgumentDefaultsHelpFormatter, | ||
description='Run Vega in parallel.') | ||
|
||
pars.add_argument('config', type=str, default=None, help='Config file') | ||
args = pars.parse_args() | ||
|
||
mpi_comm = MPI.COMM_WORLD | ||
cpu_rank = mpi_comm.Get_rank() | ||
num_cpus = mpi_comm.Get_size() | ||
|
||
def print_func(message): | ||
if cpu_rank == 0: | ||
print(message) | ||
sys.stdout.flush() | ||
mpi_comm.barrier() | ||
|
||
print_func('Initializing Vega') | ||
|
||
# Initialize Vega and get the sampling parameters | ||
vega = VegaInterface(args.config) | ||
sampling_params = vega.sample_params['limits'] | ||
|
||
print_func('Finished initializing Vega') | ||
|
||
# Check if we need the distortion | ||
use_distortion = vega.main_config['control'].getboolean('use_distortion', True) | ||
if not use_distortion: | ||
for key, data in vega.data.items(): | ||
data._distortion_mat = None | ||
test_model = vega.compute_model(vega.params, run_init=True) | ||
|
||
# Run monte carlo | ||
run_montecarlo = vega.main_config['control'].getboolean('run_montecarlo', False) | ||
if not run_montecarlo or (vega.mc_config is None): | ||
raise ValueError('Warning: You called "run_vega_mc_mpi.py" without asking' | ||
' for monte carlo. Add "run_montecarlo = True" to the "[control]" section.') | ||
|
||
# Check if we need to run a forecast | ||
forecast = vega.main_config['control'].getboolean('forecast', False) | ||
if forecast: | ||
raise ValueError('You asked to run a forecast. Use run_vega.py instead.') | ||
|
||
# Get the MC seed and the number of mocks to run | ||
seed = vega.main_config['control'].getint('mc_seed', 0) | ||
num_mc_mocks = vega.main_config['control'].getint('num_mc_mocks', 1) | ||
num_local_mc = num_mc_mocks // num_cpus | ||
if num_mc_mocks % num_cpus != 0: | ||
num_local_mc += 1 | ||
|
||
# Get fiducial model | ||
fiducial_path = vega.main_config['control'].get('mc_fiducial', None) | ||
if fiducial_path is not None: | ||
with fits.open('fiducial_path') as hdul: | ||
fiducial_model = hdul[1].data['DA'] | ||
else: | ||
fiducial_model = vega.compute_model(vega.mc_config['params'], run_init=False) | ||
|
||
# Run the mocks | ||
local_seed = int(seed + cpu_rank) | ||
vega.analysis.run_monte_carlo(fiducial_model, num_mocks=num_local_mc, seed=local_seed) | ||
|
||
# Write output | ||
vega.output.write_monte_carlo() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.