Skip to main content

No project description provided

Project description

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.

[!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.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.

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cosmosis2cobaya-1.0.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cosmosis2cobaya-1.0-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

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

Hashes for cosmosis2cobaya-1.0.tar.gz
Algorithm Hash digest
SHA256 379fd75d2594cc27287371671cd93cf22bdae1b92714cefed4a5d7c2e456b42a
MD5 4a12280f2baa1493fda35db11df8662d
BLAKE2b-256 18040eb511b43c5df83cf78997248c0707c40e949d0f91eb7bf42483f7c8943a

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosis2cobaya-1.0.tar.gz:

Publisher: publish.yml on JiangJQ2000/cosmosis2cobaya

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for cosmosis2cobaya-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e709c3fc8b420fbfe37fadd6e0838e9d0bac9f865811376c0b04c70fd93133b9
MD5 3ca420cbd5bbcd7d9eda18b8eb65310d
BLAKE2b-256 74c5b1bdb2b02a8fe0a8d2cc524d42447662044904b6d4e03e379508906a66da

See more details on using hashes here.

Provenance

The following attestation bundles were made for cosmosis2cobaya-1.0-py3-none-any.whl:

Publisher: publish.yml on JiangJQ2000/cosmosis2cobaya

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page