diff --git a/cobaya/parameterization.py b/cobaya/parameterization.py index d0d5a1076..e30e778e6 100644 --- a/cobaya/parameterization.py +++ b/cobaya/parameterization.py @@ -201,22 +201,35 @@ def __init__( for p in chain(self._sampled, self._derived): if not is_valid_variable_name(p): is_in = p in self._sampled - eg_in = ( - " p_prime:\n prior: ...\n %s: 'lambda p_prime: p_prime'\n" % p - ) - eg_out = f" p_prime: 'lambda {p}: {p}'\n" + is_input_func = p in self._input_funcs + if is_in or is_input_func: + eg = ( + f" p_prime:\n" + f" prior: ...\n" + f" {p}:\n" + f" value: 'lambda p_prime: p_prime'\n" + f" derived: False\n" + ) + if is_in: + msg = ( + "If this is an input parameter of a likelihood or " + "theory, whose name you cannot change, define an " + f"associated sampled one with a valid name:\n\n{eg}" + ) + else: + msg = ( + "This is an input parameter defined as a function. " + f"Add 'derived: False' to prevent it being saved:\n\n{eg}" + ) + else: + msg = ( + "If this is an output parameter of a likelihood or theory " + "whose name you cannot change, do not request it as derived." + ) raise LoggedError( self.log, - "Parameter name '%s' is not a valid Python variable name " - "(it needs to start with a letter or '_').\n" - "If this is an %s parameter of a likelihood or theory, " - "whose name you cannot change,%s define an associated " - "%s one with a valid name 'p_prime' as: \n\n%s", - p, - "input" if is_in else "output", - "" if is_in else " remove it and", - "sampled" if is_in else "derived", - eg_in if is_in else eg_out, + f"Parameter name '{p}' is not a valid Python variable name " + f"(it needs to start with a letter or '_').\n{msg}", ) # input params depend on input and sampled only, @@ -312,10 +325,7 @@ def get_sampled_params_proposals(self) -> dict[str, float | None]: Returns a dictionary of proposal values for sampled parameters. Returns None for parameters without a proposal value defined. """ - return { - p: self._infos[p].get("proposal") - for p in self._sampled - } + return {p: self._infos[p].get("proposal") for p in self._sampled} def sampled_input_dependence(self) -> dict[str, list[str]]: return deepcopy(self._sampled_input_dependence)