Skip to content

Fix GSL integration abort#1155

Merged
damonge merged 2 commits intomasterfrom
fix_integration_abort
Feb 21, 2024
Merged

Fix GSL integration abort#1155
damonge merged 2 commits intomasterfrom
fix_integration_abort

Conversation

@tilmantroester
Copy link
Member

This is a quick fix for the aborts reported in #1129 by moving the call to disable the GSL error handling from ccl_parameters_create to ccl_cosmology_create.

This uncovered a bunch of other issues though. From the python side, ccl_parameters_create isn't being used any more.
It is still used from within the C code though, mainly in halofit and the mu-Sigma MG stuff. So now there are two places in the code that deal with the non-trivial aspects of the ccl_parameters struct, namely the allocation of the massive neutrino arrays and MG arrays.

Speaking of these arrays, right now you can do some pretty nasty stuff by accessing arbitrary memory because N_nu_mass can be changed from python. I added a fix for one memory leak but there might be others.

import pyccl as ccl
import numpy as np

cosmo = ccl.CosmologyVanillaLCDM()

print(f"{cosmo._params.N_nu_mass=}")
print(f"{cosmo._params.m_nu=}")

print("Set cosmo._params.m_nu")
cosmo._params.m_nu = np.array([0.1, 0.2, 0.3])

print(f"{cosmo._params.N_nu_mass=}")
print(f"{cosmo._params.m_nu=}")

print("Set cosmo._params.N_nu_mass")
cosmo._params.N_nu_mass = 10
print(f"{cosmo._params.N_nu_mass=}")
print(f"{cosmo._params.m_nu=}")

gives

cosmo._params.N_nu_mass=0
cosmo._params.m_nu=[]
Set cosmo._params.m_nu
cosmo._params.N_nu_mass=3
cosmo._params.m_nu=[0.1, 0.2, 0.3]
Set cosmo._params.N_nu_mass
cosmo._params.N_nu_mass=10
cosmo._params.m_nu=[0.1, 0.2, 0.3, 0.0, 5e-324, 1.6e-322, 2.1470999305e-314, 1.5e-323, 9e-323, 1.5543504411933145e-303]

I'm aware that _params is supposed to be private but it shouldn't be that easy to mess with C memory.

@coveralls
Copy link

coveralls commented Feb 9, 2024

Pull Request Test Coverage Report for Build 7915493120

Details

  • 0 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.001%) to 97.464%

Totals Coverage Status
Change from base Build 7915468599: 0.001%
Covered Lines: 6533
Relevant Lines: 6703

💛 - Coveralls

Copy link
Collaborator

@damonge damonge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@damonge damonge merged commit 892655a into master Feb 21, 2024
@damonge damonge deleted the fix_integration_abort branch February 21, 2024 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants