No project description provided
Project description
CosmoSIS2cobaya
Utilize CosmoSIS modules in cobaya.
It was used in
Basic Usage
Installation
-
Make sure you have installed python>=3.9, CosmoSIS and cosmosis-standard-library properly [^1].
-
Install cosmosis2cobaya with
pip install cosmosis2cobaya.
Run the preconfigured weak lensing and galaxy clustering likelihoods
In example/, there are some preconfigured weak lensing and galaxy clustering yaml file you can start with.
-
Set environment variable
COSMOSIS_ROOT_DIRECTORYto the path of cosmosis-standard-library and setCOSMOSIS_INI_PATHto the CosmoSIS ini file related to your run (We need it to load the configuration of the CosmoSIS module). Alternatively, if you havepython-dotenvinstalled, you can set them in your.envfile. -
cobaya-run XXXXX.yaml
If it works well, you can modify these yaml files to what you want.
[!NOTE] We do not treat each dataset as a single likelihood in order to take full advantage of blocking for speedup.
Advanced usage
cosmosis2cobaya allows you to use almost any module (called component, theory, likelihood in cobaya) from CosmoSIS in cobaya. But first, let's clarify some of the differences between CosmoSIS and cobaya.
-
There are two ways to automatically organize modules: either give the execution order of the modules and then let the data automatically flow in and out, or first give the data that flows in and out of each module and then automatically determine the execution order based on the dependencies. CosmoSIS is the former and cobaya is the latter. So in order to port the CosmoSIS module to cobaya, we must first determine what data goes in and out.
-
Because the execution order is given in CosmoSIS, data with the same name can be read and written repeatedly. But in cobaya, data names are used to determine dependencies, so they can only be written (created) by one module.
-
CosmoSIS is case insensitive to data names but cobaya is case sensitive. Although we try to make it case-insensitive at the transit layer, it is recommended to always use lowercase data names.
-
Unused parameters are not allowed in cobaya. And they may also cause unexpected errors.
-
Since cobaya already has Boltzmann components, we use them directly and convert to the CosmoSIS data format using the
cosmosis2cobaya.boltzmanntheory component. This component also accepts some CosmoSIS options.
With these in mind, we can adapt as follows.
Conversion of parameters and priors
There is a helper script ini2yaml.py help you to convert parameters and priors:
python3 ini2yaml.py <CosmoSIS input file>.ini
Remember to remove unused parameters before pasting into the params: section of the yaml.
Write cobaya components
For each module, create a file at the same path in cosmosis2cobaya as the file value of the corresponding section in the CosmoSIS ini file ( certainly with a .py extension).
Its content is like
from cosmosis2cobaya._base import base
class tatt_interface(base):
def cosmosis_datablock_inputs(self):
return ['cosmological_parameters', 'matter_power_lin', 'matter_power_nl', 'fastpt', 'intrinsic_alignment_parameters']
def cosmosis_datablock_outputs(self):
return [
'intrinsic_power',
'intrinsic_power_ee',
'intrinsic_power_bb',
'matter_intrinsic_power',
'intrinsic_alignment_parameters'
]
class IA(tatt_interface):
pass
For theory (those will not give likelihood values), inherit a class (tatt_interface in the template above) from cosmosis2cobaya._base.base.
For likelihoods (those will give likelihood values), inherit from cosmosis2cobaya._base.base_Likelihood.
It is recommended to use the same class name as the file name.
Implement cosmosis_datablock_inputs and cosmosis_datablock_outputs, which return the names of the data read/written by CosmoSIS, respectively.
The results returned by the CosmoSIS module setup() can be read from self.module.data.
Assuming the file path is cosmosis2cobaya/intrinsic_alignments/tatt/tatt_interface.py, now you can use it in cobaya:
theory:
cosmosis2cobaya.intrinsic_alignments.tatt.tatt_interface:
To load the configuration from the CosmoSIS ini file, we use the class name (tatt_interface in the above) as the section name to search for in the ini.
However, sometimes the class name is different from the section name or we have to use the module multiple times.
We can inherit from that class, using another class name (IA in the example above) and use it in cobaya:
theory:
cosmosis2cobaya.intrinsic_alignments.tatt.tatt_interface.IA:
However, sometimes the section name in ini cannot be used as the class name, then the section name can be specified by the attribute name, e.g.:
class TwoPt_point_mass(TwoPointLikelihood):
name = '2pt_like'
To avoid writing data with the same name multiple times, rename the data in yaml:
theory:
cosmosis2cobaya.boltzmann:
renames_output:
matter_power_lin: matter_power_lin__0
matter_power_nl: matter_power_nl__0
cosmosis2cobaya.extrapolate:
renames_input:
matter_power_lin: matter_power_lin__0
matter_power_nl: matter_power_nl__0
# what_cosmosis_modules_see: what_cobaya_see
There is a helper script dot2yaml.py help you to generate them for the dot file (see here how to generate it):
python3 dot2yaml.py <dot file> <ini file>
But it can go wrong when there are loops in the pipeline graph (e.g. des-y3_and_kids-1000) or the module name is duplicated with the data name (e.g. kids-1000).
[^1]: https://github.com/JiangJQ2000/cosmosis2cobaya/blob/master/.github/workflows/test.yml provides an example of manual installation on a Debian-based system.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cosmosis2cobaya-1.0.tar.gz.
File metadata
- Download URL: cosmosis2cobaya-1.0.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
379fd75d2594cc27287371671cd93cf22bdae1b92714cefed4a5d7c2e456b42a
|
|
| MD5 |
4a12280f2baa1493fda35db11df8662d
|
|
| BLAKE2b-256 |
18040eb511b43c5df83cf78997248c0707c40e949d0f91eb7bf42483f7c8943a
|
Provenance
The following attestation bundles were made for cosmosis2cobaya-1.0.tar.gz:
Publisher:
publish.yml on JiangJQ2000/cosmosis2cobaya
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cosmosis2cobaya-1.0.tar.gz -
Subject digest:
379fd75d2594cc27287371671cd93cf22bdae1b92714cefed4a5d7c2e456b42a - Sigstore transparency entry: 148370386
- Sigstore integration time:
-
Permalink:
JiangJQ2000/cosmosis2cobaya@86cb92a833b5d14637d2f67d719a1b3023613a95 -
Branch / Tag:
refs/tags/v1.0 - Owner: https://github.com/JiangJQ2000
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@86cb92a833b5d14637d2f67d719a1b3023613a95 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cosmosis2cobaya-1.0-py3-none-any.whl.
File metadata
- Download URL: cosmosis2cobaya-1.0-py3-none-any.whl
- Upload date:
- Size: 17.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e709c3fc8b420fbfe37fadd6e0838e9d0bac9f865811376c0b04c70fd93133b9
|
|
| MD5 |
3ca420cbd5bbcd7d9eda18b8eb65310d
|
|
| BLAKE2b-256 |
74c5b1bdb2b02a8fe0a8d2cc524d42447662044904b6d4e03e379508906a66da
|
Provenance
The following attestation bundles were made for cosmosis2cobaya-1.0-py3-none-any.whl:
Publisher:
publish.yml on JiangJQ2000/cosmosis2cobaya
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cosmosis2cobaya-1.0-py3-none-any.whl -
Subject digest:
e709c3fc8b420fbfe37fadd6e0838e9d0bac9f865811376c0b04c70fd93133b9 - Sigstore transparency entry: 148370388
- Sigstore integration time:
-
Permalink:
JiangJQ2000/cosmosis2cobaya@86cb92a833b5d14637d2f67d719a1b3023613a95 -
Branch / Tag:
refs/tags/v1.0 - Owner: https://github.com/JiangJQ2000
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@86cb92a833b5d14637d2f67d719a1b3023613a95 -
Trigger Event:
push
-
Statement type: