diff --git a/python/sdist/amici/petab/conditions.py b/python/sdist/amici/petab/conditions.py index 97c63439e4..8f7552bb60 100644 --- a/python/sdist/amici/petab/conditions.py +++ b/python/sdist/amici/petab/conditions.py @@ -134,16 +134,21 @@ def _get_par(model_par, value, mapping): # condition table overrides must have been handled already, # e.g. by the PEtab parameter mapping, but parameters from # InitialAssignments may still be present. - if mapping[value] == model_par: + if (mapped_value := mapping[value]) == model_par: # prevent infinite recursion raise - return _get_par(value, mapping[value], mapping) - if model_par in problem_parameters: + return _get_par(value, mapped_value, mapping) + + try: # user-provided return problem_parameters[model_par] + except KeyError: + pass + # prevent nan-propagation in derivative if np.isnan(value): return 0.0 + # constant value return value diff --git a/python/sdist/amici/petab/util.py b/python/sdist/amici/petab/util.py index 48e6ed7786..c6ec96945e 100644 --- a/python/sdist/amici/petab/util.py +++ b/python/sdist/amici/petab/util.py @@ -26,14 +26,15 @@ def get_states_in_condition_table( if petab_problem.model.type_id not in (MODEL_TYPE_SBML, MODEL_TYPE_PYSB): raise NotImplementedError() - species_check_funs = { + species_check_fun = { MODEL_TYPE_SBML: lambda x: _element_is_sbml_state( petab_problem.sbml_model, x ), MODEL_TYPE_PYSB: lambda x: _element_is_pysb_pattern( petab_problem.model.model, x ), - } + }[petab_problem.model.type_id] + states = { resolve_mapping(petab_problem.mapping_df, col): (None, None) if condition is None @@ -48,9 +49,7 @@ def get_states_in_condition_table( else None, ) for col in petab_problem.condition_df.columns - if species_check_funs[petab_problem.model.type_id]( - resolve_mapping(petab_problem.mapping_df, col) - ) + if species_check_fun(resolve_mapping(petab_problem.mapping_df, col)) } if petab_problem.model.type_id == MODEL_TYPE_PYSB: