cobaya icon indicating copy to clipboard operation
cobaya copied to clipboard

cobaya parameter error

Open fasensior opened this issue 3 months ago • 1 comments

Hi!

I have a likelihood with a list of parameters built as "al0_-1", "al2_-1", etc. When I try to sample them with cobaya, as

        "al0_-1": {
            "prior": {"min": 0, "max": 20},
            "latex": "al0_-1",
            "ref": {"dist": "norm", "loc": 0, "scale": 0.01},
        },

cobaya raises an error:

[003249.70] [0/1] 11-25 12:07  parameterization          ERROR    Parameter name 'al0_-1' is not a valid Python variable name (it needs to start with a letter or '_').
If this is an input parameter of a likelihood or theory, whose name you cannot change, define an associated sampled one with a valid name 'p_prime' as: 

  p_prime:
    prior: ...
  al0_-1: 'lambda p_prime: p_prime'

I understand this comes from the fact that there is a dash in the middle of the variable. Using the solution it proposes, and defining a 2nd parameter such as

        "al0_m1": {
            "prior": {"min": 0, "max": 20},
            "latex": "al0_-1",
            "ref": {"dist": "norm", "loc": 0, "scale": 0.01},
        },
        "al0_-1":"lambda al0_m1:al0_m1",

I am shown a different (but related) error that reads

[003399.53] [0/1] 11-25 12:09  parameterization          ERROR    Parameter name 'al0_-1' is not a valid Python variable name (it needs to start with a letter or '_').
If this is an output parameter of a likelihood or theory, whose name you cannot change, remove it and define an associated derived one with a valid name 'p_prime' as: 

  p_prime: 'lambda al0_-1: al0_-1'

If at this point I remove "al0_-1" and use this previous definition of "al0_m1" like "al0_m1":"lambda al0_-1 : al0_-1", I get a completely different error [003572.81] [0/1] 11-25 12:12 tools ERROR Failed to load external function: 'SyntaxError('invalid syntax', ('<string>', 1, 12, 'lambda al0_-1 : al0_-1', 1, 13))' which I understand is the same problem with the hyphen being reserved exclusively for subtractions.

I am not sure how to proceed. I cannot change the name of the variables because the likelihood that I am sampling uses the minus (or the lack of minus) to obtain the order the polynomial that is related with the parameter.

fasensior avatar Nov 25 '25 11:11 fasensior

The best thing is likely to change the likelihood to e.g. use al0_m1 rather than al0_-1.

cmbant avatar Nov 26 '25 09:11 cmbant