CobayaSampler / cobaya

Code for Bayesian Analysis
http://cobaya.readthedocs.io/en/latest/
Other
126 stars 125 forks source link

`WantTensors: true` in `extra_args` results in a segfault (when also using `external_primordial_pk: true` #337

Closed lukashergt closed 10 months ago

lukashergt commented 10 months ago

Issue

I would like to use an external primordial power spectrum with tensor modes.

In cobaya/theories/camb/camb.py line 336 it says:

# must set WantTensors manually if using external_primordial_pk

However, when I supply WantTensors: true to extra_args I end up getting a segfault.

Example

Here is a hopefully reproducible example yaml file:

theory:
  theory_primordial_Pk.FeaturePrimordialPk:
    python_path: "."
    k_pivot: 0.05
    n_samples_wavelength: 20
  camb:
    extra_args:
      lens_potential_accuracy: 1
      num_massive_neutrinos: 1
      nnu: 3.044
      theta_H0_range:
      - 20
      - 100
      WantTensors: true
    external_primordial_pk: true
likelihood:
  planck_2018_lowl.TT: null
params:
  amplitude: 0.08
  wavelength: 0.008
  centre: 0.2
  logwidth: 0.1
  # Baseline cosmological parameters
  As: 2.2e-9
  ns: 0.96
  r:
    prior: {min: 0, max: 3}
    ref: {dist: norm, loc: 0, scale: 0.03}
    proposal: 0.03
    latex: r_{0.05}
  H0: 70.0
  ombh2: 0.0224
  omch2: 0.12
  mnu: 0.06
  tau: 0.055
sampler:
  mcmc:
    proposal_scale: 1.9
    oversample_power: 0.4

WITHOUT the WantTensors: true line, this example runs without complaining (but then the tensor modes are not correctly sampled...). WITH the WantTensors: true line, this example segfaults (see error below).

The theory_primordial_Pk.FeaturePrimordialPk I have taken from here, modified only by adding r everywhere after ns and by adding the lines

        state['primordial_tensor_pk'] = {'k': ks, 'Pk': Pks, 'log_regular': False}

and

    def get_primordial_tensor_pk(self):
        return self.current_state['primordial_tensor_pk']

(Not meant to be physically sensible, just meant to be able to reproduce the error...)

Error message

This is the error message that I'm getting:

[output] Output to be read-from/written-into folder '.', with prefix 'test'
[output] Found existing info files with the requested output prefix: 'test'
[output] Will delete previous products ('force' was requested).
[camb] `camb` module loaded successfully from /home/myhome/Documents/Projects/CambPrj/CAMB/camb
[mcmc] Getting initial point... (this may take a few seconds)
[myhost:527224] *** Process received signal ***
[myhost:527224] Signal: Segmentation fault (11)
[myhost:527224] Signal code: Address not mapped (1)
[myhost:527224] Failing at address: 0x18
[myhost:527224] [ 0] /usr/lib/libc.so.6(+0x3e710)[0x7f177245c710]
[myhost:527224] [ 1] /home/myhome/Documents/Projects/CambPrj/CAMB/camb/camblib.so(__initialpower_MOD_tsplinedinitialpower_tensorpower+0x5b)[0x7f176d2f585b]
[myhost:527224] [ 2] /home/myhome/Documents/Projects/CambPrj/CAMB/camb/camblib.so(__cambmain_MOD_cltransfertocl+0x9fd)[0x7f176d33792d]
[myhost:527224] [ 3] /home/myhome/Documents/Projects/CambPrj/CAMB/camb/camblib.so(__camb_MOD_camb_transferstopowers+0x2e8)[0x7f176d34b808]
[myhost:527224] [ 4] /usr/lib/libffi.so.8(+0x74f6)[0x7f17723564f6]
[myhost:527224] [ 5] /usr/lib/libffi.so.8(+0x3f5e)[0x7f1772352f5e]
[myhost:527224] [ 6] /usr/lib/libffi.so.8(ffi_call+0x123)[0x7f1772355b73]
[myhost:527224] [ 7] /home/myhome/.pyenv/versions/3.11.5/lib/python3.11/lib-dynload/_ctypes.cpython-311-x86_64-linux-gnu.so(+0x9a20)[0x7f1772363a20]
[myhost:527224] [ 8] /home/myhome/.pyenv/versions/3.11.5/lib/python3.11/lib-dynload/_ctypes.cpython-311-x86_64-linux-gnu.so(+0x917f)[0x7f177236317f]
[myhost:527224] [ 9] /home/myhome/.pyenv/versions/3.11.5/lib/libpython3.11.so.1.0(_PyObject_MakeTpCall+0x28c)[0x7f17727d91cc]
[myhost:527224] [10] /home/myhome/.pyenv/versions/3.11.5/lib/libpython3.11.so.1.0(_PyEval_EvalFrameDefault+0x76e)[0x7f17727e3aae]
[myhost:527224] [11] /home/myhome/.pyenv/versions/3.11.5/lib/libpython3.11.so.1.0(+0x22ec3f)[0x7f177282ec3f]
[myhost:527224] [12] /home/myhome/.pyenv/versions/3.11.5/lib/libpython3.11.so.1.0(+0x22e1bb)[0x7f177282e1bb]
[myhost:527224] [13] /home/myhome/.pyenv/versions/3.11.5/lib/libpython3.11.so.1.0(_PyEval_EvalFrameDefault+0x55d8)[0x7f17727e8918]
[myhost:527224] [14] /home/myhome/.pyenv/versions/3.11.5/lib/libpython3.11.so.1.0(_PyFunction_Vectorcall+0x17c)[0x7f177280cd9c]
[myhost:527224] [15] /home/myhome/.pyenv/versions/3.11.5/lib/libpython3.11.so.1.0(+0x214c8e)[0x7f1772814c8e]
[myhost:527224] [16] /home/myhome/.pyenv/versions/3.11.5/lib/libpython3.11.so.1.0(_PyObject_MakeTpCall+0x2bb)[0x7f17727d91fb]
[myhost:527224] [17] /home/myhome/.pyenv/versions/3.11.5/lib/libpython3.11.so.1.0(_PyEval_EvalFrameDefault+0x76e)[0x7f17727e3aae]
[myhost:527224] [18] /home/myhome/.pyenv/versions/3.11.5/lib/libpython3.11.so.1.0(_PyFunction_Vectorcall+0x17c)[0x7f177280cd9c]
[myhost:527224] [19] /home/myhome/.pyenv/versions/3.11.5/lib/libpython3.11.so.1.0(PyObject_Call+0xa6)[0x7f17728177a6]
[myhost:527224] [20] /home/myhome/.pyenv/versions/3.11.5/lib/libpython3.11.so.1.0(_PyEval_EvalFrameDefault+0x55d8)[0x7f17727e8918]
[myhost:527224] [21] /home/myhome/.pyenv/versions/3.11.5/lib/libpython3.11.so.1.0(+0x2a520c)[0x7f17728a520c]
[myhost:527224] [22] /home/myhome/.pyenv/versions/3.11.5/lib/libpython3.11.so.1.0(PyEval_EvalCode+0xaf)[0x7f17728a4c0f]
[myhost:527224] [23] /home/myhome/.pyenv/versions/3.11.5/lib/libpython3.11.so.1.0(+0x2c3413)[0x7f17728c3413]
[myhost:527224] [24] /home/myhome/.pyenv/versions/3.11.5/lib/libpython3.11.so.1.0(+0x2bf88a)[0x7f17728bf88a]
[myhost:527224] [25] /home/myhome/.pyenv/versions/3.11.5/lib/libpython3.11.so.1.0(+0x2d31c1)[0x7f17728d31c1]
[myhost:527224] [26] /home/myhome/.pyenv/versions/3.11.5/lib/libpython3.11.so.1.0(_PyRun_SimpleFileObject+0x1b9)[0x7f17728d2c79]
[myhost:527224] [27] /home/myhome/.pyenv/versions/3.11.5/lib/libpython3.11.so.1.0(_PyRun_AnyFileObject+0x44)[0x7f17728d2a14]
[myhost:527224] [28] /home/myhome/.pyenv/versions/3.11.5/lib/libpython3.11.so.1.0(Py_RunMain+0x2f7)[0x7f17728ce6f7]
[myhost:527224] [29] /home/myhome/.pyenv/versions/3.11.5/lib/libpython3.11.so.1.0(Py_BytesMain+0x37)[0x7f1772893b07]
[myhost:527224] *** End of error message ***

Hotfix

I can add the following lines to cobaya/theories/camb/camb.py (line 340ish) which makes things work:

        if self.external_primordial_pk:
            self.extra_attrs["WantTensors"] = True

But this is obviously not the proper way of fixing this.

cmbant commented 10 months ago

Try https://github.com/CobayaSampler/cobaya/pull/339?

lukashergt commented 10 months ago

Yes, fixed by #339, many thanks @cmbant.