Skip to content
@CLASS-SZ

CLASS-SZ

GitHub stars Documentation Status PyPI version arXiv

CLASS_SZ

Cosmic Linear Anisotropy Solving System with Machine Learning Accelerated and Accurate CMB, LSS, and Halo Model Observables Computations.

Class_sz is compatible with Jax and now allows for automatic differentiation on some of its output, see here for an example on the matter power spectrum. The code can now be used in Hamiltonian Monte Carlo and Simulation Based Inference pipelines.

Documentation

Check our evolving documentation.

Installation

To install the code, run:

pip install classy_sz

(Note that this does not currenty run on Windows OS. If you have a Windows laptop, just install WSL and make your life easier.)

We have uploaded pre-compiled wheels on PyPi, so the pip install should work on all recent Mac and Linux OS with Python version > 3.9. If it doesn't work for you, please get in touch!

Package Data (optional)

By default, the neural nets emulators (~1GB of files) will be installed in your home directory.

If you're working on a computing cluster or prefer to store the data elsewhere, you can specify a custom directory.

To specify where you want to store the neural nets data, run the following command in your terminal before importing the package:

export PATH_TO_CLASS_SZ_DATA=/path/to/store/class_sz/data
mkdir -p $PATH_TO_CLASS_SZ_DATA/class_sz_data_directory

This command sets the PATH_TO_CLASS_SZ_DATA variable for the current session.

To ensure this variable is set every time you open a terminal, you can add this line to your ~/.bashrc or ~/.bash_profile file automatically using the echo command.

For ~/.bashrc (common for most Linux systems), type in your terminal:

echo -e "\n# Set path for CLASS-SZ data\nexport PATH_TO_CLASS_SZ_DATA=/path/to/store/class_sz/data" >> ~/.bashrc
echo -e "\n# Create directory for CLASS-SZ data\nmkdir -p \$PATH_TO_CLASS_SZ_DATA/class_sz_data_directory" >> ~/.bashrc

To apply the changes immediately:

source ~/.bashrc

(If you use macOS, use .bash_profile instead of bashrc, replace accordingly above.)

Now, every time you open a terminal, the PATH_TO_CLASS_SZ_DATA environment variable will automatically be set to your specified directory, ensuring the neural nets emulators are always stored in the correct location.

(You may also take a look at our legacy example notebooks, although these are no longer maintained and may not run. We are in the process of moving the material to the docs during 2025.)

Accelerated Computations

To run the machine learning accelerated computations, the idea is to use:

class_sz.compute_class_szfast()

In a bit more details, say you are interested in CMB $C_\ell$'s:

from classy_sz import Class as Class_sz

cosmo_params = {
'omega_b': 0.02242,
'omega_cdm':  0.11933,
'H0': 67.66, 
'tau_reio': 0.0561,
'ln10^{10}A_s': 3.047,
'n_s': 0.9665,

'N_ncdm': 1,
'N_ur': 2.0328,
'm_ncdm': 0.06    
}
class_sz = Class_sz()
class_sz.set(cosmo_params)
class_sz.set({
'output':'tCl,lCl,pCl',
'skip_background_and_thermo': 1, # do you want exact solution for background? yes: 1, no: 0 (if "no" you can access exact background quantities via emulators).
})

class_sz.compute_class_szfast()

lensed_cls = class_sz.lensed_cl()
l_fast = lensed_cls['ell']
cl_tt_fast = lensed_cls['tt']
cl_ee_fast = lensed_cls['ee']
cl_te_fast = lensed_cls['te']
cl_pp_fast = lensed_cls['pp']

Some Basic Info

CLASS_SZ is as fast as it gets, with full parallelization, implementation of high-accuracy neural network emulators, and Fast Fourier Transforms.

CLASS_SZ has been built as an extension of Julien Lesgourgues's CLASS code, therefore the halo model and LSS calculations (essentially based on distances and matter clustering) are always consistent with the cosmological model computed by CLASS. We are doing our best to keep up with CLASS version updates. We are currently working on updating to CLASS v3.

CLASS_SZ is initially based on Eiichiro Komatsu’s Fortran code SZFAST.

CLASS_SZ's outputs are regularly cross-checked with other CMBxLSS codes, such as:

Using the Code

The class_sz code is public.

If you use it, please cite:

If you use accelerated computations, please cite:

If you use thermal SZ power spectrum and cluster counts calculations, please cite:

In all these cases, please also cite the original CLASS papers:

As well as other references listed here: http://class-code.net

Pinned Loading

  1. notebooks notebooks Public

    Tutorial notebooks for the class_sz code

    Jupyter Notebook 4 1

  2. class_sz class_sz Public

    Cosmic Linear Anisotropy Solving System with Machine Learning Accelerated CMB, LSS and Halo Model Observables Computations

    C 13 4

Repositories

Showing 6 of 6 repositories
  • class_sz Public

    Cosmic Linear Anisotropy Solving System with Machine Learning Accelerated CMB, LSS and Halo Model Observables Computations

    CLASS-SZ/class_sz’s past year of commit activity
    C 13 MIT 4 1 0 Updated Jan 25, 2025
  • notebooks Public

    Tutorial notebooks for the class_sz code

    CLASS-SZ/notebooks’s past year of commit activity
    Jupyter Notebook 4 1 0 0 Updated Jan 24, 2025
  • classy_szfast Public
    CLASS-SZ/classy_szfast’s past year of commit activity
    Python 0 1 0 0 Updated Jan 10, 2025
  • .github Public
    CLASS-SZ/.github’s past year of commit activity
    0 0 0 0 Updated Dec 17, 2024
  • class_sz_data Public

    data for the class_sz code

    CLASS-SZ/class_sz_data’s past year of commit activity
    Python 0 0 0 0 Updated Dec 13, 2024
  • get_cosmopower_emus Public

    utility package to automatically download emulators

    CLASS-SZ/get_cosmopower_emus’s past year of commit activity
    Python 0 0 0 0 Updated Dec 13, 2024

Top languages

Loading…

Most used topics

Loading…