### PolyChord Configuration in Input File Source: https://github.com/cobayasampler/cobaya/blob/master/docs/sampler_polychord.md Example of how to specify the PolyChord path in a cobaya input YAML file. This tells cobaya where to find the manually installed PolyChord library. ```yaml sampler: polychord: path: /path/to/polychord/PolyChordLite ``` -------------------------------- ### Install Basic Cosmo Codes and Likelihoods Source: https://github.com/cobayasampler/cobaya/blob/master/docs/installation_cosmo.md Installs a foundational set of cosmological requisites including CAMB, CLASS, Planck, BAO, and SN. Specify a custom installation path using the -p flag. ```bash cobaya-install cosmo -p /path/to/packages ``` -------------------------------- ### Install Cobaya from Downloaded Release Source: https://github.com/cobayasampler/cobaya/blob/master/docs/installation.md Install Cobaya from a downloaded release archive in editable mode. This method is simpler but does not facilitate code contributions. ```bash $ cd /path/to/cobaya/ $ python -m pip install --editable cobaya ``` -------------------------------- ### install.install() function Source: https://github.com/cobayasampler/cobaya/blob/master/docs/installation_cosmo.md The `install` function programmatically installs external packages required by specified components. It accepts component names, input dictionaries, or YAML file names. ```APIDOC ## install.install(*infos, **kwargs) ### Description Installs the external packages required by the components mentioned in `infos`. `infos` can be input dictionaries, single component names, or names of yaml files ### Parameters * **force** – force re-installation of apparently installed packages (default: `False`). * **test** – just check whether components are installed (default: `False`). * **upgrade** – force upgrade of obsolete components (default: `False`). * **skip** – keywords of components that will be skipped during installation. * **skip_global** – skip installation of already-available Python modules (default: `False`). * **debug** – produce verbose debug output (default: `False`). * **path** – optional path where to install the packages (defaults to any packages_path entry given in the info dictionaries). * **code** – set to `False` to skip code packages (default: `True`). * **data** – set to `False` to skip data packages (default: `True`). * **no_progress_bars** – no progress bars shown; use when output is saved into a text file (e.g. when running on a cluster) (default: `False`). * **no_set_global** – do not store the installation path for later runs (default: `False`). ### Returns `True` if all components are installed without skips, `False` if some components skipped, None (or exception raised) otherwise ``` -------------------------------- ### Install a specific component Source: https://github.com/cobayasampler/cobaya/blob/master/docs/installation_cosmo.md Use this command to install individual likelihood or theory components, including your own or third-party likelihood classes. ```bash $ cobaya-install component_name --packages-path /path/to/packages ``` -------------------------------- ### Install Cobaya Packages with cobaya-install Source: https://context7.com/cobayasampler/cobaya/llms.txt Use the cobaya-install CLI to download and compile necessary external codes and data. Specify packages and the installation path. ```bash # Install all dependencies declared in your input YAML $ cobaya-install your_input.yaml -p /path/to/packages # Install specific packages by name $ cobaya-install camb planck_2018_highl_plik -p /path/to/packages # Check what is already installed $ cobaya-install your_input.yaml -p /path/to/packages --just-check # Then run with the packages path (or set it in the YAML as packages_path) $ cobaya-run your_input.yaml -p /path/to/packages ``` -------------------------------- ### Define InstallableLikelihood with GitHub Options Source: https://github.com/cobayasampler/cobaya/blob/master/docs/cosmo_external_likelihood_class.md Inherit from `InstallableLikelihood` and specify installation options using a class-level dictionary. This supports automatic data installation from GitHub repositories. ```python from cobaya.likelihoods.base_classes import InstallableLikelihood class MyLikelihood(InstallableLikelihood): install_options = {"github_repository": "MyGithub/my_repository", "github_release": "master"} ... ``` -------------------------------- ### Install Likelihoods from YAML Input File Source: https://github.com/cobayasampler/cobaya/blob/master/docs/installation_cosmo.md Installs only the necessary external packages required by the specified YAML input file. This is useful for installing dependencies for a specific run configuration. ```bash cobaya-install MyFile.yaml ``` -------------------------------- ### Install Packages Based on Input Files Source: https://github.com/cobayasampler/cobaya/blob/master/docs/installation_cosmo.md Installs all external packages required by one or more YAML input files. The --packages-path option specifies the directory for installation. This command can also accept --skip and --skip-global arguments. ```bash cobaya-install input_1.yaml input_2.yaml [etc] --packages-path /path/to/packages ``` -------------------------------- ### Define InstallableLikelihood with Download URL Source: https://github.com/cobayasampler/cobaya/blob/master/docs/cosmo_external_likelihood_class.md Alternatively, specify installation options using a download URL for `InstallableLikelihood`. ```python from cobaya.likelihoods.base_classes import InstallableLikelihood class MyLikelihood(InstallableLikelihood): install_options = {"download_url":"..url.."} ... ``` -------------------------------- ### Manual CLASS Installation Source: https://github.com/cobayasampler/cobaya/blob/master/docs/theory_class.md Steps to manually download and build the CLASS code. Ensure the 'CLASS' folder is correctly placed and built. ```bash cd /path/to/cosmo/ git clone https://github.com/lesgourg/class_public.git CLASS --depth=1 cd CLASS python setup.py build ``` -------------------------------- ### Check OpenBLAS Installation (Debian-based) Source: https://github.com/cobayasampler/cobaya/blob/master/docs/installation.md On Debian-like systems, use this command to check if the libopenblas-base package is installed. If not, install it using 'sudo apt install libopenblas-base'. ```bash $ dpkg -s libopenblas-base | grep Status ``` -------------------------------- ### Install Packages from Python Script Source: https://github.com/cobayasampler/cobaya/blob/master/docs/installation_cosmo.md Programmatically installs external cosmological packages using cobaya's install function from a Python script or notebook. Input information can be provided as dictionaries. ```python from cobaya.install import install install(info1, info2, [etc], path='/path/to/packages') ``` -------------------------------- ### Install Cobaya in Development Mode with Git Source: https://github.com/cobayasampler/cobaya/blob/master/docs/installation.md Clone the Cobaya repository and install it in editable mode. This allows immediate use of code changes without reinstallation. The `[test]` extra installs testing dependencies. ```bash $ git clone https://YOUR_USERNAME@github.com/YOUR_USERNAME/cobaya.git $ python -m pip install --editable cobaya[test] --upgrade ``` ```bash $ git clone https://github.com/CobayaSampler/cobaya.git $ python -m pip install --editable cobaya[test] --upgrade ``` -------------------------------- ### Install Specific Component Source: https://github.com/cobayasampler/cobaya/blob/master/docs/installation_cosmo.md Installs a specific component (likelihood or theory) and its requisites. This command can also be used for custom likelihood classes. ```APIDOC ## cobaya-install component_name --packages-path /path/to/packages This command installs the specified component and its dependencies. The `--packages-path` argument specifies the directory where packages should be installed. ``` -------------------------------- ### Check cobaya installation Source: https://github.com/cobayasampler/cobaya/blob/master/docs/installation.md Verify that cobaya is installed correctly by attempting to import it in a Python interpreter. This command should execute without any error messages. ```bash $ python -c "import cobaya" ``` -------------------------------- ### Install CAMB using pip Source: https://github.com/cobayasampler/cobaya/blob/master/docs/theory_camb.md Install the CAMB Python package using pip. This command includes pre-built binary wheels for all platforms. ```bash $ pip install camb (or uv equivalent). This includes pre-built binary wheels for all platforms. ``` -------------------------------- ### Get Component Documentation Source: https://github.com/cobayasampler/cobaya/blob/master/docs/cosmo_basic_runs.md Use `cobaya-doc` to get available options and default values for a given component. The output is YAML-compatible by default, or Python-compatible with the `-p` flag. Call with no arguments to list all available components. ```bash $ cobaya-doc [component_name] ``` ```bash $ cobaya-doc -p [component_name] ``` ```bash $ cobaya-doc ``` -------------------------------- ### Manual PolyChord Installation Source: https://github.com/cobayasampler/cobaya/blob/master/docs/sampler_polychord.md Instructions for manually cloning and compiling the PolyChord Lite library. Ensure to set the 'path' in your input file to the PolyChordLite directory. ```bash cd /path/to/polychord git clone https://github.com/PolyChord/PolyChordLite.git cd PolyChordLite make pychord MPI=1 python setup.py build ``` -------------------------------- ### Detailed `evaluate` Sampler Configuration with Overrides Source: https://github.com/cobayasampler/cobaya/blob/master/docs/sampler_evaluate.md Example demonstrating parameter definitions with priors and reference points, and how `evaluate:override` takes precedence for parameter `d`. ```yaml params: a: prior: min: -1 max: 1 ref: 0.5 b: prior: min: -1 max: 1 ref: dist: norm loc: 0 scale: 0.1 c: prior: min: -1 max: 1 d: prior: min: -1 max: 1 ref: 0.4 sampler: evaluate: override: d: 0.2 ``` -------------------------------- ### Sampler Run Method Example Source: https://github.com/cobayasampler/cobaya/blob/master/docs/sampler.md Illustrates the typical structure of the run method in a sampler, involving a loop that continues until a convergence criterion is met. ```python while not [convergence criterion]: [do one more step] [update the collection of samples] ``` -------------------------------- ### Configure PolyChord Sampler Source: https://github.com/cobayasampler/cobaya/blob/master/docs/sampler.md Specify the PolyChord sampler and its installation path in the input file. ```yaml sampler: polychord: path: /path/to/cosmo/PolyChord ``` -------------------------------- ### CMBlikes Example YAML Configuration Source: https://github.com/cobayasampler/cobaya/blob/master/docs/cosmo_external_likelihood_class.md Example YAML configuration for a `CMBlikes` likelihood, specifying data path, dataset file, and optional overrides for parameters and maximum ell. ```yaml # Path to the data: where the planck_supp_data_and_covmats has been cloned path: null dataset_file: lensing/2018/smicadx12_Dec5_ftl_mv2_ndclpp_p_teb_consext8.dataset # Overriding of .dataset parameters dataset_params: # Overriding of the maximum ell computed l_max: # Aliases for automatic covariance matrix alias: [lensing] # Speed in evaluations/second speed: 50 params: !defaults [../planck_2018_highl_plik/params_calib] ``` -------------------------------- ### Gaussian Likelihood Configuration Source: https://github.com/cobayasampler/cobaya/blob/master/docs/likelihood_gaussian.md Configuration example for a 2D Gaussian likelihood with explicit input parameters. ```APIDOC ## `gaussian` likelihood A simple single-mode Gaussian likelihood with optional normalization. ## Usage The mean and covariance matrix must be specified with the options `mean` and `cov` respectively. The dimensionality of the likelihood is determined from these options. The `normalized` parameter (default: `True`) controls whether to include the full normalization constant. When `False`, only the chi-squared term is computed, which is useful when only relative likelihoods matter. ```yaml likelihood: gaussian: mean: [0.5, 1.0] cov: [[0.1, 0.05], [0.05, 0.2]] normalized: True input_params: ['x', 'y'] params: x: prior: min: 0 max: 1 y: prior: min: 0 max: 2 ``` The option `input_params_prefix` can be used instead of explicit `input_params`, similar to [gaussian_mixture](likelihood_gaussian_mixture.md). The number of parameters must match the dimensionality defined by the mean and covariance. For 1D cases, scalar values can be used: ```yaml likelihood: gaussian: mean: 0.5 cov: 0.04 input_params: ['x'] ``` The default option values for this likelihood are: ```yaml # Simple Gaussian likelihood # Mean vector mean: # Covariance matrix cov: # Whether to include normalization constant (default: True) normalized: True # Prefix of parameter names (if not using explicit input_params) input_params_prefix: "" ``` ``` -------------------------------- ### Install Cython for CLASS Python Wrapper Source: https://github.com/cobayasampler/cobaya/blob/master/docs/theory_class.md Install Cython, a prerequisite for the CLASS Python wrapper. If using a modified CLASS version older than v3.2.1, use 'cython<3'. ```bash python -m pip install 'cython' ``` -------------------------------- ### Show Default Packages Path Source: https://github.com/cobayasampler/cobaya/blob/master/docs/installation_cosmo.md Displays the current default installation path for cobaya packages. This path is used if --packages-path is not explicitly provided. ```bash cobaya-install --show-packages-path ``` -------------------------------- ### Run Cobaya Sampler Source: https://github.com/cobayasampler/cobaya/blob/master/docs/cobaya-example.ipynb Import and execute the Cobaya run function with the provided configuration. This starts the Bayesian inference process. ```python from cobaya import run updated_info, sampler = run(info) ``` -------------------------------- ### Test mpi4py installation Source: https://github.com/cobayasampler/cobaya/blob/master/docs/installation.md Verify the mpi4py installation by running a simple script that prints the mpi4py version using two MPI processes. ```bash $ mpirun -n 2 python -c "from mpi4py import MPI, __version__; print(__version__ if MPI.COMM_WORLD.Get_rank() else '')" ``` -------------------------------- ### Install PySide6 for Local Desktop Version Source: https://github.com/cobayasampler/cobaya/blob/master/docs/cosmo_basic_runs.md Install PySide6 if you encounter issues with the local desktop version of Cobaya. This is a prerequisite for certain graphical interface features. ```bash $ python -m pip install PySide6 ``` -------------------------------- ### Manual Installation of BICEP/Keck Likelihood Source: https://github.com/cobayasampler/cobaya/blob/master/docs/likelihood_bk.md Provides commands for manually installing the BICEP/Keck likelihood. This involves downloading, extracting, and placing the likelihood files in a specified directory. ```bash cd /path/to/likelihoods mkdir bicep_keck_2018 cd bicep_keck_2018 wget http://bicepkeck.org/BK18_datarelease/BK18_cosmomc.tgz tar xvf BK18_cosmomc.tgz rm BK18_cosmomc.tgz ``` -------------------------------- ### Install or upgrade mpi4py Source: https://github.com/cobayasampler/cobaya/blob/master/docs/installation.md Install the mpi4py Python wrapper with version 3.0.0 or higher. Use --no-binary :all: to ensure it's built from source, which is often required for MPI compatibility. ```bash $ python -m pip install "mpi4py>=3" --upgrade --no-binary :all: ``` -------------------------------- ### Basic Parameter Specification Example Source: https://github.com/cobayasampler/cobaya/blob/master/docs/params_prior.md Defines fixed, sampled, and derived parameters with their respective prior and reference distributions, LaTeX labels, and sampler-specific properties. ```yaml params: A: 1 # fixed! B1: # sampled! with uniform prior on [-1,1] and ref pdf N(mu=0,sigma=0.25) prior: min: -1 max: 1 ref: dist: norm loc: 0 scale: 0.25 latex: \mathcal{B}_2 proposal: 0.25 B2: # sampled! with prior N(mu=0.5,sigma=3) and fixed reference value 1 prior: dist: norm loc: 0.5 scale: 3 ref: 1 # fixed reference value: all chains start here! latex: \mathcal{B}_2 proposal: 0.5 C: # derived! min: 0 latex: \mathcal{C} ``` -------------------------------- ### Check cobaya shell script installation Source: https://github.com/cobayasampler/cobaya/blob/master/docs/installation.md Confirm that cobaya's shell scripts are accessible by running `cobaya-run`. A successful installation will prompt for an input file instead of showing a 'command not found' error. ```bash $ cobaya-run ``` -------------------------------- ### Minimize Class Initialization Source: https://github.com/cobayasampler/cobaya/blob/master/docs/sampler_minimize.md Initializes the minimizer by setting problem boundaries, selecting starting points, and configuring the affine transformation. ```APIDOC ## class samplers.minimize.Minimize ### Minimize(info_sampler: dict[str, Any], model: Model, output: Output | None = None, packages_path: str | None = None, name: str | None = None) #### initialize() Initializes the minimizer: sets the boundaries of the problem, selects starting points and sets up the affine transformation. ``` -------------------------------- ### Install or upgrade cobaya Source: https://github.com/cobayasampler/cobaya/blob/master/docs/installation.md Install the latest release of cobaya or upgrade an existing installation using pip. The --upgrade flag ensures you get the newest version. ```bash $ python -m pip install cobaya --upgrade ``` -------------------------------- ### Force reinstallation of a component Source: https://github.com/cobayasampler/cobaya/blob/master/docs/installation_cosmo.md Use the `-f` or `--force` option to re-install a package that is already installed, for example, if you have modified it manually. ```bash $ cobaya-install camb -f --packages-path /path/to/packages ``` -------------------------------- ### Initialize Sampler with Model and Output Driver Source: https://github.com/cobayasampler/cobaya/blob/master/docs/models.md Sets up a sampler (e.g., MCMC) with a given model and an optional output driver for saving chains and results. The output driver can be configured with a prefix and options for resuming or forcing overwrites. ```python from cobaya.output import get_output out = get_output(prefix="chains/my_model", resume=False, force=True) ``` ```python # Initialise and run the sampler (low number of samples, as an example) info_sampler = {"mcmc": {"max_samples": 100}} from cobaya.sampler import get_sampler mcmc = get_sampler(info_sampler, model=model, output=out) ``` -------------------------------- ### Instantiating a Model and Running Posterior Source: https://github.com/cobayasampler/cobaya/blob/master/docs/cosmo_external_likelihood_class.md Demonstrates how to instantiate a full Cobaya model with a custom likelihood and theory, then calculate the log posterior for specific parameters. ```python packages_path = '/path/to/your/packages' info = { 'params': fiducial_params, 'likelihood': {'my_likelihood': MyLikelihood}, 'theory': {'camb': None}, 'packages': packages_path} from cobaya.model import get_model model = get_model(info) model.logposterior({'H0':71.1, 'my_param': 1.40, ...}) ``` -------------------------------- ### External Likelihood Class Implementation Source: https://context7.com/cobayasampler/cobaya/llms.txt This example demonstrates defining a custom likelihood by subclassing `cobaya.likelihood.Likelihood`. It includes `initialize` for setup, `get_requirements` for theory requests, and `logp` for calculating the log-probability. Class attributes can be overridden via YAML configuration. ```python # my_likelihood_class.py import numpy as np from scipy import stats from cobaya.likelihood import Likelihood class GaussianBandLikelihood(Likelihood): # These class attributes become overridable YAML options mean: float = 1.0 sigma: float = 0.1 def initialize(self): """Called once at startup — load data, pre-compute things, etc.""" self.data = np.array([0.95, 1.02, 1.01]) # simulated measurements def get_requirements(self): """Request quantities from a theory code, if needed.""" return {} # no theory code needed here def logp(self, **params_values): x = params_values["x"] return float(np.sum(stats.norm.logpdf(self.data, loc=x, scale=self.sigma))) # Use in an info dictionary info = { "likelihood": { "band": { "external": GaussianBandLikelihood, "mean": 1.0, "sigma": 0.05, } }, "params": {"x": {"prior": {"min": 0, "max": 2}, "proposal": 0.05}}, "sampler": {"mcmc": None}, } from cobaya import run updated_info, sampler = run(info) ``` -------------------------------- ### Install Specific Planck 2018 Likelihoods Source: https://github.com/cobayasampler/cobaya/blob/master/docs/installation_cosmo.md Installs the Planck 2018 high-likelihood data, specifically the TT,TE,EE modes, if not already installed by a general 'cosmo' installation. ```bash cobaya-install planck_2018_highl_plik.TTTEEE ``` -------------------------------- ### Install CAMB Locally as a Python Package Source: https://github.com/cobayasampler/cobaya/blob/master/docs/theory_camb.md Make a local CAMB installation available to Python generally by installing it in editable mode. This is useful after building from source. ```bash python -m pip install -e /path/to/CAMB ``` -------------------------------- ### Configure Sampler and Run Cobaya Source: https://github.com/cobayasampler/cobaya/blob/master/docs/example_advanced.md Sets up the MCMC sampler with convergence criteria (Rminus1_stop) and limits on tries, then runs the Cobaya sampler with the provided info dictionary. The output includes updated info and the sampler object. ```python info["sampler"] = {"mcmc": {"Rminus1_stop": 0.001, "max_tries": 1000}} from cobaya import run updated_info, sampler = run(info) ``` -------------------------------- ### samples(combined: bool = False, skip_samples: float = 0, to_getdist: bool = False) Source: https://github.com/cobayasampler/cobaya/blob/master/docs/sampler_mcmc.md Returns the sample of accepted steps. ```APIDOC ## samples(combined: bool = False, skip_samples: float = 0, to_getdist: bool = False) ### Description Returns the sample of accepted steps. ### Parameters #### Keyword Arguments - **combined** (bool, default: False) - If `True` and running more than one MPI process, returns for all processes a single sample collection including all parallel chains concatenated, instead of the chain of the current process only. For this to work, this method needs to be called from all MPI processes simultaneously. - **skip_samples** (int or float, default: 0) - Skips some amount of initial samples (if `int`), or an initial fraction of them (if `float < 1`). If concatenating (`combined=True`), skipping is applied before concatenation. Forces the return of a copy. - **to_getdist** (bool, default: False) - If `True`, returns a single `getdist.MCSamples` instance, containing all samples, for all MPI processes (`combined` is ignored). ### Returns The sample of accepted steps. ### Return Type [SampleCollection](output.md#collection.SampleCollection), getdist.MCSamples ``` -------------------------------- ### Specify CAMB Installation Path in Cobaya Input Source: https://github.com/cobayasampler/cobaya/blob/master/docs/theory_camb.md When using a manually installed or modified version of CAMB, specify its path in the cobaya input YAML file. This ensures cobaya uses your custom installation instead of a system-wide one. ```yaml theory: camb: path: /path/to/theories/CAMB ``` -------------------------------- ### products(combined: bool = False, skip_samples: float = 0, to_getdist: bool = False) Source: https://github.com/cobayasampler/cobaya/blob/master/docs/sampler_mcmc.md Returns the products of the sampling process. ```APIDOC ## products(combined: bool = False, skip_samples: float = 0, to_getdist: bool = False) ### Description Returns the products of the sampling process. ### Parameters #### Keyword Arguments - **combined** (bool, default: False) - If `True` and running more than one MPI process, the `sample` key of the returned dictionary contains a sample including all parallel chains concatenated, instead of the chain of the current process only. For this to work, this method needs to be called from all MPI processes simultaneously. - **skip_samples** (int or float, default: 0) - Skips some amount of initial samples (if `int`), or an initial fraction of them (if `float < 1`). If concatenating (`combined=True`), skipping is applied previously to concatenation. Forces the return of a copy. - **to_getdist** (bool, default: False) - If `True`, the `sample` key of the returned dictionary contains a single `getdist.MCSamples` instance including all samples (`combined` is ignored). ### Returns A dictionary containing the sample of accepted steps under `sample` (as `cobaya.collection.SampleCollection` by default, or as `getdist.MCSamples` if `to_getdist=True`), and a progress report table under `"progress"`. ### Return Type dict ``` -------------------------------- ### Force Re-installation of Packages Source: https://github.com/cobayasampler/cobaya/blob/master/docs/installation_cosmo.md Installs or re-installs specified packages, even if they are already present. Use with caution as it may overwrite existing installations. ```bash cobaya-install --force ``` -------------------------------- ### Install mpi4py with Conda Source: https://github.com/cobayasampler/cobaya/blob/master/docs/installation.md If using Anaconda, install mpi4py from the appropriate channel. Use 'conda-forge' for GNU compilers or 'intel' for Intel compilers. ```bash $ conda install -c [repo] mpi4py ``` -------------------------------- ### Cobaya Configuration and Imports Source: https://github.com/cobayasampler/cobaya/blob/master/docs/cobaya-example.ipynb Sets up the necessary environment for running Cobaya, including backend configurations and importing the run function. Handles potential import errors by adjusting the system path. ```python # Configuration %matplotlib inline %config InlineBackend.figure_format = 'retina' import os import platform import sys try: from cobaya import run except ImportError: sys.path.insert(0, os.path.realpath(os.path.join(os.getcwd(), "../..", "cobaya"))) from cobaya import run ``` -------------------------------- ### NERSC job script template example Source: https://github.com/cobayasampler/cobaya/blob/master/docs/run_job.md An example of a job submission script template for NERSC, including placeholders for job parameters and OpenMP settings. ```shell #!/bin/bash #SBATCH -N {NUMNODES} #SBATCH -q {QUEUE} #SBATCH -J {JOBNAME} #SBATCH -C haswell #SBATCH -t {WALLTIME} #OpenMP settings: export OMP_NUM_THREADS={OMP} export OMP_PLACES=threads export OMP_PROC_BIND=spread ###set things to be used by the python script, which extracts text from here with ##XX: ... ## ### command to use for each run in the batch ##RUN: time srun -n {NUMMPI} -c {OMP} --cpu_bind=cores {PROGRAM} {INI} > {JOBSCRIPTDIR}/{INIBASE}.log 2>&1 ## ``` -------------------------------- ### Install External Likelihood from GitHub Source: https://github.com/cobayasampler/cobaya/blob/master/docs/cosmo_external_likelihood_class.md Use the `package_install` block to specify a GitHub repository and minimum version for an external likelihood. Cobaya will automatically download and install it. ```yaml likelihood: planck_2018_lowl.TT_native: null planck_2018_lowl.EE_native: null planck_NPIPE_highl_CamSpec.TTTEEE: null planckpr4lensing: package_install: github_repository: carronj/planck_PR4_lensing min_version: 1.0.2 ``` -------------------------------- ### Run Cobaya with Input File Source: https://github.com/cobayasampler/cobaya/blob/master/docs/cosmo_basic_runs.md Execute a Cobaya run using a specified YAML input file. Output files are generated, and results can be visualized with `getdist-gui`. ```bash cobaya-run [your_input_file_name.yaml] ``` -------------------------------- ### output.get_info_path(folder, prefix, infix=None, kind='updated', ext='.yaml') Source: https://github.com/cobayasampler/cobaya/blob/master/docs/output.md Constructs the path to info files saved by the Output class, allowing specification of folder, prefix, infix, kind, and extension. ```APIDOC ## output.get_info_path(folder, prefix, infix=None, kind='updated', ext='.yaml') Gets path to info files saved by Output. ``` -------------------------------- ### Example of an improper prior in Cobaya Source: https://github.com/cobayasampler/cobaya/blob/master/docs/params_prior.md This example shows how to define an improper prior with infinite bounds. Avoid using improper priors as they can lead to unexpected errors. ```yaml params: a: prior: min: -.inf max: .inf ``` -------------------------------- ### Manage Grid Runs with cobaya-grid-* tools Source: https://context7.com/cobayasampler/cobaya/llms.txt Utilize Cobaya's grid-run system for scanning models by creating, submitting, listing, checking convergence, and analyzing results from a grid configuration file. ```bash # Create a grid of runs from a grid config file $ cobaya-grid-create gridconfig.yaml /path/to/grid/output # Submit/run all grid jobs (SLURM example) $ cobaya-grid-run /path/to/grid/output --batchqueue SLURM # List running jobs $ cobaya-grid-list /path/to/grid/output # Check convergence of all chains $ cobaya-grid-converge /path/to/grid/output # Run GetDist on all converged chains $ cobaya-grid-getdist /path/to/grid/output # Generate LaTeX parameter tables from grid results $ cobaya-grid-tables /path/to/grid/output --output tables/ ``` ```yaml # gridconfig.yaml structure (excerpt) # from cobaya.yaml import yaml_load_file ``` -------------------------------- ### Automatic Package Installation via YAML Source: https://github.com/cobayasampler/cobaya/blob/master/docs/likelihood_external.md Automatically install external packages from a GitHub repository using the `package_install` option in your Cobaya input YAML. Specify the repository and minimum version required. ```yaml likelihood: planckpr4lensing: package_install: github_repository: carronj/planck_PR4_lensing min_version: 1.0.2 ``` -------------------------------- ### BCalculator Theory Class Example Source: https://github.com/cobayasampler/cobaya/blob/master/docs/theories_and_dependencies.md Example of a theory class that provides 'B' and the derived parameter 'b_derived'. It shows how to define what the class can provide and how to conditionally set internal parameters based on requirements. ```python from cobaya.theory import Theory class BCalculator(Theory): def initialize(self): self.kmax = 0 def get_can_provide_params(self): return ['b_derived'] def get_can_provide(self): return ['B'] def must_provide(self, **requirements): if 'B' in requirements: self.kmax = max(self.kmax, requirements['B'].get('kmax',10)) ``` -------------------------------- ### Cobaya Sampler Configuration Example Source: https://context7.com/cobayasampler/cobaya/llms.txt This dictionary defines a typical configuration for the Cobaya sampler, including base settings, models, and parameters. It is used to load configuration from a YAML file or directly in Python. ```python grid_config_example = { "base_info": { "theory": {"camb": None}, "sampler": {"mcmc": {"Rminus1_stop": 0.02, "covmat": "auto"}}, "packages_path": "/path/to/packages", }, "models": { "LCDM": { "likelihood": {"planck_2018_lowl.TT": None, "planck_2018_highl_plik.TT": None}, "params": {"H0": {"prior": {"min": 40, "max": 100}}} }, "wCDM": { "likelihood": {"planck_2018_lowl.TT": None, "planck_2018_highl_plik.TT": None}, "params": { "H0": {"prior": {"min": 40, "max": 100}}, "w": {"prior": {"min": -3, "max": 0}, "ref": -1, "proposal": 0.05}, }, }, }, } ``` -------------------------------- ### ACalculator Theory Class Example Source: https://github.com/cobayasampler/cobaya/blob/master/docs/theories_and_dependencies.md Example of a theory class that calculates 'A' based on 'B' and a derived parameter 'b_derived'. It demonstrates how to specify requirements, provide calculated values, and offer custom methods for retrieving results. ```python from cobaya.theory import Theory class ACalculator(Theory): def initialize(self): """called from __init__ to initialize""" def initialize_with_provider(self, provider): """ Initialization after other components initialized, using Provider class instance which is used to return any dependencies (see calculate below). """ self.provider = provider def get_requirements(self): """ Return dictionary of derived parameters or other quantities that are needed by this component and should be calculated by another theory class. """ return {'b_derived': None} def must_provide(self, **requirements): if 'A' in requirements: # e.g. calculating A requires B computed using same kmax (default 10) return {'B': {'kmax': requirements['A'].get('kmax', 10)}} def get_can_provide_params(self): return ['Aderived'] def calculate(self, state, want_derived=True, **params_values_dict): state['A'] = self.provider.get_result('B') * self.provider.get_param('b_derived') state['derived'] = {'Aderived': 10} def get_A(self, normalization=1): return self.current_state['A'] * normalization ``` -------------------------------- ### Configure Cobaya Model with External Likelihood Source: https://github.com/cobayasampler/cobaya/blob/master/docs/cosmo_external_likelihood.md Sets up the Cobaya model by defining parameters (fixed, sampled, derived), specifying the external likelihood function, its requirements (e.g., Cl tt spectrum), and the theory engine. This configuration is used to instantiate the model for analysis. ```python info = { "params": { # Fixed "ombh2": 0.022, "omch2": 0.12, "H0": 68, "tau": 0.07, "mnu": 0.06, "nnu": 3.046, # Sampled "As": {"prior": {"min": 1e-9, "max": 4e-9}, "latex": "A_s"}, "ns": {"prior": {"min": 0.9, "max": 1.1}, "latex": "n_s"}, "noise_std_pixel": { "prior": {"dist": "norm", "loc": 20, "scale": 5}, "latex": r"\sigma_\mathrm{pix}", }, # Derived "Map_Cl_at_500": {"latex": r"C_{500,\mathrm{map}}"}, }, "likelihood": { "my_cl_like": { "external": my_like, # Declare required quantities! "requires": {"Cl": {"tt": l_max}}, # Declare derived parameters! "output_params": ["Map_Cl_at_500"], } }, "theory": {"camb": {"stop_at_error": True}}, "packages_path": packages_path, } from cobaya.model import get_model model = get_model(info) ``` -------------------------------- ### get_version() Source: https://github.com/cobayasampler/cobaya/blob/master/docs/theory.md Get version information for this component. ```APIDOC ## get_version() ### Description Get version information for this component. ### Returns - str | dict[str, Any] | None: Version information, which can be a string, a dictionary of values, or None. ``` -------------------------------- ### get_can_provide_params Source: https://github.com/cobayasampler/cobaya/blob/master/docs/theory_camb.md Gets a list of derived parameters that this component can calculate. ```APIDOC ## get_can_provide_params() ### Description Get a list of derived parameters that this component can calculate. The default implementation returns the result based on the params attribute set via the .yaml file or class params (with derived:True for derived parameters). ### Returns Iterable of parameter names. ``` -------------------------------- ### initialize() Source: https://github.com/cobayasampler/cobaya/blob/master/docs/theory.md Initializes the class (called from __init__, before other initializations). ```APIDOC ## initialize() ### Description Initializes the class. This method is called from `__init__` before other initializations are performed. ### Returns - None ```