From 6278be840ecc7629a301a700824a9fd6ab058431 Mon Sep 17 00:00:00 2001 From: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com> Date: Thu, 10 Sep 2026 14:08:47 +0100 Subject: [PATCH] Filter CLI-only optimizer parameters --- code/free_embedding_experiment.py | 10 ++++-- code/free_embedding_experiment_test.py | 45 ++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 code/free_embedding_experiment_test.py diff --git a/code/free_embedding_experiment.py b/code/free_embedding_experiment.py index eed8c34..542dfba 100644 --- a/code/free_embedding_experiment.py +++ b/code/free_embedding_experiment.py @@ -37,6 +37,7 @@ """ import datetime +import inspect import itertools import json import os @@ -516,8 +517,13 @@ def run_experiment_base(config_params: Dict[str, Any]) -> Dict[str, Any]: } opt_start = time.time() - params_for_opt = dict(config_params) - params_for_opt.pop("q", None) + optimize_param_names = set(inspect.signature(optimize_embeddings).parameters) + optimize_param_names.difference_update(("experiment_data", "q")) + params_for_opt = { + name: value + for name, value in config_params.items() + if name in optimize_param_names + } opt_results = optimize_embeddings( experiment_data=experiment_data, q=len(qrels), **params_for_opt ) diff --git a/code/free_embedding_experiment_test.py b/code/free_embedding_experiment_test.py new file mode 100644 index 0000000..a49d2e3 --- /dev/null +++ b/code/free_embedding_experiment_test.py @@ -0,0 +1,45 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Tests for the free embedding experiment.""" + +import unittest + +import free_embedding_experiment as experiment + + +class RunExperimentBaseTest(unittest.TestCase): + + def test_cli_only_parameters_are_not_forwarded(self): + config = { + **experiment.DEFAULT_EXPERIMENT_PARAMS, + "n": 3, + "d": 2, + "k": 1, + "device": "cpu", + "num_iterations": 1, + "show_progress": False, + "log_interval": 1, + "results_output_path": "results.json", + "enable_critical_n_search": 3, + } + + result = experiment.run_experiment_base(config) + + self.assertNotIn("error", result["metrics"]) + self.assertEqual(result["parameters"], config) + + +if __name__ == "__main__": + unittest.main()