In this page, we show how to sample a 3x2pt likelihood using cosmolike and LINNA.

Code

Cosmolike and LINNA wrapper are located in linna/cosmolike_run.py, which can be run as

python cosmolike_run.py emcee {gpu node} ../yamlfile/training_3x2pt.yaml  {directory of additional yamlfiles}.

Yaml file

An example yaml file is shown in linna/yamlfile/training_3x2pt.yaml

[1]:
! cat ../..//yamlfile/training_3x2pt.yaml
#An example yaml file of using linna for cosmolike
#####Cosmolike setting#######
include: ['samplers_multinest_p1.yaml', 'DESY1_params.yaml']
analysis_choice: ["selection_bias"]
chain_file: "analysis/dataanalysis/desy1/datav/test/ch"
data_file: "analysis/speedup/ml/data/demo_data/combined.txt"
cov_file:  "analysis/dataanalysis/desy1/datav_oak//covariance/cov_v8/cov"
statsnames  : ['xip', 'xim', 'gammat', 'wtheta']
run_mode    : CLASS
rmarea_int : False
rmphotoz_int : False
nonlinear: 0
omega_nuh2_range : [0.0005, 0.00083, 0.01]
h0_range : [0.55, 0.7, 0.91]
omega_b_range : [0.03,0.048, 0.07]
A_s_range : [5.e-10,2.19e-9,5.e-9]
shear_m_sigma: [0.023,0.023,0.023,0.023]
lens_z_bias_mean: [0.008, -0.005, 0.006, 0.0, 0.0]
lens_z_bias_sigma: [0.007,0.007,0.006, 0.01,0.01]

####LINNA setting#####
outdir : "/home/users/chto/code/lighthouse/analysis/speedup/ml/datav/3x2pt_test2/" #output directory

#####################
#  EMCEE parameters #
#####################
nkeepArr : [2, 2, 5, 5] #number of correlation time to keep
ntimesArr : [5, 5, 10, 15] #number of correlation time to terminate
ntautolArr : [0.03, 0.03, 0.02, 0.01] #tolerance of correlation time error
meanshiftArr: [0.2, 0.2, 0.2, 0.2]
stdshiftArr: [0.15,0.15,0.15,0.15]
#####################
# Training parameter#
#####################
temperatureArr : [4.0, 2.0, 1.0, 1.0] #Temperature of posterior
ntrainArr : [10000, 10000, 10000, 10000] #Number of training data
nvalArr : [500, 500, 500, 500] #Number of validation data
nnmodel: "ChtoModelv2" #Neural network model implemented in nn.py
num_epochs: 4500       #Maximum number of epoch for training
batch_size: 500        #Batch size of training
trainingoption: 1      #Randomly sample the chain for training data

Job script

In cosmological analysis, one usually submit jobs on the supercomputer. In linna/jobscript/example_sampler.job, we give an exmaple slurm job script, which can be submitted using

sbatch example_sampler.job

[2]:
! cat ../../jobscript/example_sampler.job
#!/bin/bash
#SBATCH --job-name=linna
#SBATCH --output=./job/linna_%A_%a.out
#SBATCH --error=./job/linna_%A_%a.err
#SBATCH --array=0
#SBATCH --time=24:00:00
#SBATCH -p kipac
#SBATCH --mem-per-cpu=4G
#SBATCH --cpus-per-task=1
#SBATCH --ntasks=128
#SBATCH --mail-user=chto
#SBATCH --mail-type=ALL
srun --kill-on-bad-exit=1 python ../linna/cosmolike_run.py emcee sh03-12n07 ../yamlfile/training_3x2pt.yaml /home/users/chto/code/lighthouse/analysis/yamlfiles/
  • sh03-12n07 is the node that has a gpu.

  • ../yamlfile/training_3x2pt.yaml is the yamlfile

  • /home/users/chto/code/lighthouse/analysis/yamlfiles/ is the directory that contains more yamlfiles, which are included in training_3x2pt.yaml via include

If you find requesting GPU resources is annoying, don’t worry. Linna does it automatically for you. You can add the following lines in the yaml file.

automaticgpu:
    qos: "gpu"           #name of GPU queue
    time: "18:00:00"     #Run time
    gpuconstraint: "GPU_CC:7.5|GPU_CC:8.0|GPU_CC:8.6" #GPU type constraint