Skip to main content

CosmoSIS2cobaya

Utilize CosmoSIS modules in cobaya.

It was used in

Basic Usage

Installation

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_DIRECTORY to the path of cosmosis-standard-library and set COSMOSIS_INI_PATH to the CosmoSIS ini file related to your run (We need it to load the configuration of the CosmoSIS module). Alternatively, if you have python-dotenv installed, you can set them in your .env file.

  • cobaya-run XXXXX.yaml

If it works well, you can modify these yaml files to what you want.

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.boltzmann theory 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. ↩

Metadata

Release files for cosmosis2cobaya 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cosmosis2cobaya 1.0
File Size Uploaded Provenance Actions
cosmosis2cobaya-1.0.tar.gz 13.8 kB With provenance Details for cosmosis2cobaya-1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cosmosis2cobaya 1.0
File Interpreter ABI Platform Actions
cosmosis2cobaya-1.0-py3-none-any.whl Python 3 none any Details for cosmosis2cobaya-1.0-py3-none-any.whl

Total release size: 31.7 kB

Release files / cosmosis2cobaya-1.0.tar.gz

Download URL cosmosis2cobaya-1.0.tar.gz
Size 13.8 kB
Tags Source
SHA-256 checksum
How to use checksums
379fd75d2594cc27287371671cd93cf22bdae1b92714cefed4a5d7c2e456b42a
BLAKE2b-256 checksum
How to use checksums
18040eb511b43c5df83cf78997248c0707c40e949d0f91eb7bf42483f7c8943a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2024.

Transparency log

Release files / cosmosis2cobaya-1.0-py3-none-any.whl

Download URL cosmosis2cobaya-1.0-py3-none-any.whl
Size 17.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e709c3fc8b420fbfe37fadd6e0838e9d0bac9f865811376c0b04c70fd93133b9
BLAKE2b-256 checksum
How to use checksums
74c5b1bdb2b02a8fe0a8d2cc524d42447662044904b6d4e03e379508906a66da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2024.

Transparency log

Security for cosmosis2cobaya 1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cosmosis2cobaya-1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2024.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page