Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion colibri/closure_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def closure_test_colibri_model_pdf(closure_test_model_settings, FIT_XGRID):

# Compute the pdf grid
pdf_grid_func = pdf_model.grid_values_func(FIT_XGRID)
params = jnp.array(closure_test_model_settings["parameters"])
params = jnp.array(list(closure_test_model_settings["parameters"].values()))
pdf_grid = pdf_grid_func(params)

return pdf_grid
17 changes: 17 additions & 0 deletions colibri/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,3 +521,20 @@ def produce_pdf_model(self):
Returns None as the pdf_model is not used in the colibri module.
"""
return None

def parse_closure_test_colibri_model_pdf(self, settings):
"""
Validates that required keys are present and returns the full settings dictionary.
Requires: 'model' and 'parameters'.
Other keys (e.g. 'fitted_flavours') are allowed and passed through.
"""
required_keys = {"model", "parameters"}

missing_keys = required_keys - settings.keys()
if missing_keys:
raise KeyError(
f"Missing required key(s) in closure_test_model_settings: {', '.join(missing_keys)}"
)

# Return a full copy of the settings dictionary (assuming it’s valid)
return dict(settings)
10 changes: 8 additions & 2 deletions colibri/tests/test_closure_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ def test_closure_test_pdf_grid_with_colibri_model(
# Mock the pdf model
mock_pdf_model_from_colibri_model.return_value = mock_colibri_model

settings = {"parameters": [1, 2, 3], "model": "test_model"}
settings = {
"parameters": {"param1": 1, "param2": 2, "param3": 3},
"model": "test_model",
}

grid = closure_test_pdf_grid(
"colibri_model", sample_xgrid, closure_test_model_settings=settings
Expand Down Expand Up @@ -109,7 +112,10 @@ def test_closure_test_colibri_model_pdf(
# Mock the pdf model
mock_pdf_model_from_colibri_model.return_value = mock_colibri_model

settings = {"parameters": [1, 2, 3], "model": "test_model"}
settings = {
"parameters": {"param1": 1, "param2": 2, "param3": 3},
"model": "test_model",
}

pdf_grid = closure_test_colibri_model_pdf(settings, sample_xgrid)
assert pdf_grid.shape == (3, 5)
Expand Down
40 changes: 40 additions & 0 deletions colibri/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,43 @@ def test_produce_commondata_tuple():
closure_test_level = 2
with pytest.raises(ConfigError):
BASE_CONFIG.produce_commondata_tuple(closure_test_level)


@patch("colibri.config.log.warning")
def test_parse_closure_test_colibri_model_pdf(mock_warning):
# Mock the pdf model
settings = {
"parameters": {"param1": 1, "param2": 2},
"model": "test_model",
"fitted_flavours": ["T3", "T8"],
}

# Call the method
result = BASE_CONFIG.parse_closure_test_colibri_model_pdf(settings)

# Assert the result is as expected
expected = {
"parameters": {"param1": 1, "param2": 2},
"model": "test_model",
"fitted_flavours": ["T3", "T8"],
}

assert result == expected

# Check that error is raised if a necessary key is missing

settings_no_model = {
"parameters": {"param1": 1},
"fitted_flavours": ["T3"],
}

with pytest.raises(KeyError, match="Missing required key.*model"):
BASE_CONFIG.parse_closure_test_colibri_model_pdf(settings_no_model)

settings_no_parameters = {
"model": "test_model",
"fitted_flavours": ["T3"],
}

with pytest.raises(KeyError, match="Missing required key.*parameters"):
BASE_CONFIG.parse_closure_test_colibri_model_pdf(settings_no_parameters)
Loading