Run Euclid inference campaigns with
cloelike likelihoods: generate
synthetic data vectors, sample posteriors and analyse the chains, from YAML
campaign files such as those of
dr1-inference-configs.
The interface is four modules, one per step, each also a cloerun command:
| Module | Command | Does |
|---|---|---|
cloerun.campaign |
cloerun campaign FILE |
Resolves the runs of a campaign and runs each one in its run.mode |
cloerun.sdv |
cloerun sdv FILE |
Writes the theory at the fiducial point as a synthetic data vector |
cloerun.chain |
cloerun chain FILE |
Samples the posterior (--test: one loglike at the fiducial point) |
cloerun.analyse |
cloerun analyse FILE |
Writes a summary table and a triangle plot of finished chains |
Everything else (config parsing, probes, priors, samplers) lives in the
private cloerun._core.
Currently supported:
- Photometric probes (angular power spectra,
cloelike.EuclidLikelihood_photo_Cls):WL(cosmic shear),GCph,GGL,2x2pt(GGL + GCph) and3x2pt. - Spectroscopic probes:
GCspectro_Pls(power spectrum multipoles),GCspectro_BAO(BAO alphas) andGCspectro_Pls_BAO(both). - Sampler:
nautilus.
cloerun works with cloelib v0.11
and cloelike v0.3, together with
cosmolib,
euclidlib and the external
libraries of the theory model you pick (CAMB, HMcode2020Emu, FAST-PT
for TATT and the nonlinear galaxy bias, COMET or PBJ for the spectroscopic
multipoles, ...). The steps below give this layout:
cloe-org/
├── cloelib/
├── cloelike/
├── cloerun/ this repository
└── dr1-inference/ the campaign configs
-
Create the
cloe-orgenvironment ofcloe-org-environments, which brings the external libraries:git clone https://github.com/cloe-org/cloe-org-environments.git mamba env create -f cloe-org-environments/environments/cloe-org-env-macOS-v2026.1.yaml # or -linux- mamba activate cloe-org-env-v2026.1 # cloe-org-env with the linux files
-
Install
cloelibv0.11 andcloelikev0.3:mkdir cloe-org && cd cloe-org git clone --branch v0.11 https://github.com/cloe-org/cloelib.git git clone --branch v0.3 https://github.com/cloe-org/cloelike.git pip install -e cloelib -e cloelike
-
Install
cloerun, which also installs thecloeruncommand:git clone https://github.com/cloe-org/cloerun.git pip install -e "cloerun[analyse]"Without local clones of
cloelibandcloelike,pip install -e "cloerun[cloe,analyse]"installs both releases from GitHub instead of step 2. -
Get the campaign configs, e.g. those of the Euclid DR1 analysis:
git clone https://github.com/cloe-org/dr1-inference-configs.git dr1-inference
From the cloe-org/ folder, with the configs of dr1-inference/:
C=dr1-inference/cosmic-shear
cloerun sdv $C/config.yaml # synthetic data vector of the config
cloerun chain $C/config.yaml --test # one loglike at the fiducial point
cloerun chain $C/config.yaml # sample
cloerun campaign $C/campaign.yaml # every run, in its run.mode
cloerun campaign $C/campaign.yaml --dry-run # print the resolved configs
cloerun chain $C/campaign.yaml --run chain_WL_baseline # one run of the campaign
cloerun analyse $C/campaign.yaml --run chain_WL_baseline --params omch2 H0 S8
cloerun chain cloerun/examples/gcspectro_pls_nautilus.yaml # a spectroscopic chainEvery command takes a campaign file, a single pipeline config (config.yaml)
or a cloerun config (see cloerun configs), and:
-
--run NAME(repeat for several) selects runs of a campaign. -
--output-dir DIRis where the outputs go (${output_dir}). By default it is the campaign'soutput_dir, or./chainsfor a single config, so that nothing is written into the configs repository. -
--set PATH=VALUE(repeat for several) changes one setting of every run without editing the shared configs, as a component would: a dottedPATH, and a yamlVALUE. Use it for what only holds on your machine, e.g. the data paths or a smaller sampler:cloerun chain $C/config.yaml \ --set run.root_dir=/path/to/dr1/data \ --set inference.sampler.settings.n_live=400 \ --set inference.sampler.settings.pool=8 \ --set inference.sampler.run_settings.timeout=3600
--test evaluates the log-likelihood at the fiducial values of the config,
and at the prior median of the sampled parameters without one.
cloerun <command> --help lists the options; python -m cloerun works as
well.
From Python:
from cloerun import load_runs, run_chain, write_sdv
from cloerun.analyse import analyse_run
for name, config, mode in load_runs("campaign.yaml", ["chain_WL_baseline"]):
chain = run_chain(config)
analyse_run(config, parameters=["omch2", "H0", "S8"])A campaign file lists runs, each built from a config (base) or from
another run (parent), and modified by named components. A base is a
pipeline config (the photometric DR1 runs) or a
cloerun config (any probe, including the spectroscopic
ones):
output_dir: /path/to/output/directory
output_name: campaign_scalecuts
runs:
- name: chain_WL_baseline
base: config.yaml
- name: chain_WL_baseline_w0wa
parent: chain_WL_baseline
components: [priors_w0wa]
components:
priors_w0wa:
w0: -3.0 -1.0 -0.33
wa: -3.0 0.0 3.0Each key of a component is merged where that key is in the config: at the
top level (run, modelling, inference; probe, data, sampler, ...
of a cloerun config), else at the one place it appears (scale_cuts,
data_vector, a parameter such as w0, ...). A dotted key
(modelling.coupling.mode) gives the place explicitly, which is needed for
keys that appear in several places (mode, file, ...).
A spectroscopic campaign, from the examples:
output_dir: chains
output_name: spectro_campaign
runs:
- name: bao_baseline
base: examples/gcspectro_bao_nautilus.yaml
components: [checkpoints]
- name: bao_tight_bbn # same run, tighter BBN prior
parent: bao_baseline
components: [tight_bbn]
- name: pls_eft
base: examples/gcspectro_pls_nautilus.yaml
components:
checkpoints:
sampler.settings:
filepath: ${output_dir}/${name}.hdf5
tight_bbn:
ombh2: {dist: norm, loc: 0.0219961, scale: 0.0001}The outputs of a run built from a cloerun config go to the campaign's
${output_dir}, named after the run; its other settings are kept. Such runs
are chains (cloerun chain --test evaluates one loglike); cloerun sdv only
supports the photometric probes.
Strings may use ${name} (the run), ${output_dir}
(<output_dir>/<output_name>, where the outputs of the runs are written) and
${root_dir} (run.root_dir). Relative paths are resolved against the
campaign file for base and output_dir, and against the pipeline config
otherwise.
A pipeline config has three blocks:
run:mode--chain,sdv(write the theory at the fiducial point tomodelling.output.file, to read back asdata_vector) ortest-- androot_dir.modelling:probe(WL,GCph,GGL,2x2pt,3x2pt),parameters(the parameter file),nz(file_shefor the shear sample andfile_posfor the positions sample: FITS, or a text table of z and one column per bin such as the Spacebornenz_shear.txt;zs_min,zs_max,zs_num),theory,systematics(passed tocloelikewithsettings),coupling(mode,mixing_matrices),binning(kind:log,linear,sqrt, orfromfilewith a textfilewhose first column is ell, used when there is no data vector to read the multipoles from) andoutput.file.inference:likelihood(data_vector,covariance,covariance_key,noise_free_mock),scale_cuts(per_block, withWL,GGLandGC, orfrom_file, a yaml file of one range per spectrum),derived_outputs(sigma8_0,S8, stored as chain columns) andsampler. Thesdvmode does not read it, so it may be left out.
In the parameter file, value is fixed, min start max is a flat prior and
gauss mean sigma a Gaussian one, with start and mean the fiducial
values. logAs and dz_she_{i} are read as logA and dz_shear_{i};
Omega_k0, alpha_s, CIA and the n(z) widths default to 0, 0, 0.0134
and 1; and the parameters the likelihood does not read (e.g. the galaxy
bias of a WL run) are dropped, so one parameter file serves every probe.
sampler.settings.pool evaluates the likelihood in that many processes; the
likelihood is rebuilt once in each of them, so this works on macOS too.
The pipeline configs are translated into cloerun configs, which can also be
written directly: see the annotated examples/3x2pt_nautilus.yaml for the
photometric options and examples/gcspectro_pls_nautilus.yaml for the
spectroscopic ones. cloerun campaign --dry-run prints the cloerun config of
each run. File paths in data are relative to data.base_directory, itself
relative to the directory of the config file.
The examples read the synthetic data of the
cloe-org Zenodo community,
the same files as the playground
notebooks and scripts. By default they expect them in ../data, next to this
repository:
| Examples | Files | Zenodo record |
|---|---|---|
3x2pt, wl |
nz_example.fits |
15092862 |
3x2pt, wl |
synthetic_coupled_cells.fits, mixmats_example.fits, covmat_2D.npz |
19071608 |
gcspectro_pls, gcspectro_pls_bao |
mps_pk_*, cov_pk_Gauss_GCspectro_comet_*, mixmat_pk_* |
18711304 |
gcspectro_bao, gcspectro_pls_bao |
EUC_LE3_BAO_* |
19729182 |
gcspectro_pls_bao |
cov_pk_Gauss_GCspectro_FS+BAO_* |
21219969 |
gcspectro_xils |
mps_xi_GCspectro_*, cov_xi_Gauss_GCspectro_* |
21026624 |
For the photometric examples:
mkdir -p ../data && cd ../data
curl -LO https://zenodo.org/records/15092862/files/nz_example.fits
curl -LO https://zenodo.org/records/19071608/files/synthetic_coupled_cells.fits
curl -LO https://zenodo.org/records/19071608/files/mixmats_example.fits
curl -LO https://zenodo.org/records/19071608/files/covmat_2D.npz
cd - && cloerun chain examples/wl_nautilus.yamlFor the spectroscopic examples (about 40 MB):
mkdir -p ../data && cd ../data
for record in 18711304 19729182 21219969 21026624; do
curl -s https://zenodo.org/api/records/$record \
| python -c "import json, sys; [print(f['key'], f['links']['self']) for f in json.load(sys.stdin)['files']]" \
| while read -r name url; do curl -sL -o "$name" "$url"; done
done
cd - && cloerun chain examples/gcspectro_bao_nautilus.yamlThe spectroscopic examples need COMET (comet-emu) for the multipoles, or
PBJ (pbjcosmo) with spectro_power.code: PBJ.
In the photometric configs:
probepicks the theory model:background,linear_perturbationsandnonlinear_perturbations(CAMB,HMcode2020Emu,EE2), an optionalbaryon_boost(HMcode2020,FLAMINGO) and themode(coupledwith the mixing matrices, ordecoupled).probe.settingsis passed as it is to thecloelikelikelihood:ia_model(NLA,TATT,null),galaxy_bias_model(poly,per_bin,per_bin_int,nonlinear),include_rsd,nonlinear_param_keys, ...datagives the n(z) (nz, ornz_positionsandnz_shear), the redshift grid they are resampled on (z_grid), the angular power spectra (cells), the mixing matrices (mixing) and the covariance (covariance,.npzor.npy, withcovariance_keyfor a.npz). The covariance can cover the full 3x2pt data vector (blocks ordered WL, GGL, GCph) for any probe: the blocks of the probe are extracted from it.scale_cutsgives one multipole range per block (WL,GGL,GCph), and optionally per-spectrum ranges underoverrides, e.g.POS-SHE-1-3: [10, 300].- Per-bin parameters are one scalar per tomographic bin in
cloelike(dz_shear_1, ...,b1_photo_bin0, ...). Write them once with the{i}placeholder, infixed_parametersorsampled_parameters:dz_shear_{i}: {dist: norm, loc: 0.0, scale: 0.01}expands to every bin, with the indexingcloelikeuses for that parameter. An explicit name, e.g.dz_shear_3, overrides the template for that bin. data.noise_free_mock: truereplaces the data vector with the theory at the fiducial point:fixed_parametersplusfiducial_parameters. The synthetic data was generated with a single model, so this is the way to get a posterior centred on the fiducial with any other model.
Sampling omch2, ombh2, logA or h enables their conversion to the native
parameters automatically (see cloerun._core.derived_parameters).
Probes, samplers and theory backends are behind small lookup tables in
cloerun._core.loader (PROBES, SAMPLERS, BACKGROUNDS, PERTURBATIONS,
NONLINEAR_PERTURBATIONS, BARYON_BOOSTS, SPECTRO_POWERS): adding one is a
new module plus one entry there.
A chain writes two files to output.directory (${output_dir} for a
campaign), both named after the run:
<name>.npz: the chain, in the same format whatever the sampler (seecloerun.chain.Chain): a 2Dsamplesarray and acolumnslist, always[logweight, loglikelihood, <parameter_1>, ..., <parameter_N>], followed by thederived_outputsif any. Load it withChain.load(path), or directly withnumpy.load.<name>.config.yaml: the cloerun config of the run, with asoftware_versionsblock recording the installed versions ofcloerun,cloelike,cloelib,euclidlib,numpy,scipyand of the packages the run depends on.
cloerun analyse adds, next to them:
<name>.summary.md: weighted mean, standard deviation, 16/50/84% quantiles of every column, with the fiducial value and the shift of the mean from it in posterior sigmas.<name>.triangle.pdf: agetdisttriangle plot of the--params(default: all but the per-bin nuisance parameters), with the fiducial values marked.
pip install -e ".[test,analyse]"
pytest
