77from reportengine .checks import make_argcheck
88import jax .numpy as jnp
99import jax
10- from colibri .theory_predictions import make_pred_data , fast_kernel_arrays
11-
12- from colibri .utils import get_fit_path , get_pdf_model , pdf_models_equal
10+ from colibri .utils import get_fit_path , get_pdf_model
1311
1412
1513@make_argcheck
16- def check_pdf_models_equal (prior_settings , pdf_model , theoryid ):
14+ def check_pdf_models_equal (prior_settings , forward_map , theoryid ):
1715 """
1816 Decorator that can be added to functions to check that the
1917 PDF model used as prior (eg when using prior_settings["type"] == "prior_from_gauss_posterior")
20- matches the PDF model used in the current fit (pdf_model ).
18+ matches the PDF model used in the current fit (via ``forward_map.pdf_param_names`` ).
2119 """
2220
2321 if prior_settings .prior_distribution == "prior_from_gauss_posterior" :
2422
2523 prior_fit = prior_settings .prior_distribution_specs ["prior_fit" ]
2624 prior_pdf_model = get_pdf_model (prior_fit )
2725
28- if not pdf_models_equal ( prior_pdf_model , pdf_model ):
26+ if prior_pdf_model . param_names != list ( forward_map . pdf_param_names ):
2927 raise ValueError (
30- f"PDF model { pdf_model } does not match prior settings { prior_pdf_model } "
28+ f"PDF param names from forward_map { list (forward_map .pdf_param_names )} "
29+ f"do not match prior PDF model param names { prior_pdf_model .param_names } "
3130 )
3231
3332 # load filter.yml runcard of the prior fit
@@ -41,19 +40,20 @@ def check_pdf_models_equal(prior_settings, pdf_model, theoryid):
4140 )
4241
4342
44- @make_argcheck
45- def check_pdf_model_is_linear (pdf_model , FIT_XGRID , data ):
43+ def check_pdf_model_is_linear (forward_map , fast_kernel_arrays ):
4644 """
4745 Decorator that can be added to functions to check that the
4846 PDF model is linear.
47+
48+ Note that the FK arrays are taken as an argument rather than rebuilt here,
49+ so that they are guaranteed to be consistent with the
50+ ``fill_fk_xgrid_with_zeros`` setting ``forward_map`` was built with.
4951 """
5052
51- pred_data = make_pred_data (data , FIT_XGRID )
52- fk = fast_kernel_arrays (data , FIT_XGRID )
53+ fk = fast_kernel_arrays
5354
54- parameters = pdf_model .param_names
55- pred_and_pdf = pdf_model .pred_and_pdf_func (FIT_XGRID , forward_map = pred_data )
56- intercept = pred_and_pdf (jnp .zeros (len (parameters )), fk )[0 ]
55+ parameters = forward_map .param_names
56+ intercept , _ = forward_map (fk , jnp .zeros (len (parameters )))
5757
5858 # Run the check for 10 random points in the parameter space
5959 for i in range (10 ):
@@ -65,16 +65,16 @@ def check_pdf_model_is_linear(pdf_model, FIT_XGRID, data):
6565
6666 # Test additivity
6767 add_check = jnp .isclose (
68- pred_and_pdf ( x1 , fk )[0 ] + pred_and_pdf ( x2 , fk )[0 ],
69- pred_and_pdf ( x1 + x2 , fk )[0 ] + intercept ,
68+ forward_map ( fk , x1 )[0 ] + forward_map ( fk , x2 )[0 ],
69+ forward_map ( fk , x1 + x2 )[0 ] + intercept ,
7070 )
7171
7272 # Test homogeneity
7373 c = jax .random .uniform (key , (1 ,))
7474
7575 homogeneity_check = jnp .isclose (
76- c * (pred_and_pdf ( x1 , fk )[0 ] - intercept ),
77- pred_and_pdf ( c * x1 , fk )[0 ] - intercept ,
76+ c * (forward_map ( fk , x1 )[0 ] - intercept ),
77+ forward_map ( fk , c * x1 )[0 ] - intercept ,
7878 )
7979
8080 if not add_check .all () or not homogeneity_check .all ():
0 commit comments