From adad7697d9dd9454bf321d793c3fffa703094b21 Mon Sep 17 00:00:00 2001 From: "Raphael A. P. Oliveira" Date: Tue, 17 Sep 2024 15:37:32 +0200 Subject: [PATCH] Added check of derived parameter names for UltraNest --- examples/example_16/ulens_model_fit.py | 30 +++++++++++++++++++------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index fc929a8d..54b9e68f 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -706,7 +706,6 @@ def run_fit(self): self._check_ulens_model_parameters() self._get_parameters_ordered() self._get_parameters_latex() - self._parse_fitting_parameters() self._set_prior_limits() self._parse_fit_constraints() if self._fit_method == "EMCEE": @@ -714,6 +713,7 @@ def run_fit(self): self._check_fixed_parameters() self._make_model_and_event() + self._parse_fitting_parameters() if self._fit_method == "EMCEE": self._get_starting_parameters() @@ -1488,15 +1488,9 @@ def _parse_fitting_parameters_UltraNest(self): self._check_required_and_allowed_parameters(required, allowed) self._check_parameters_types(settings, bools, ints, floats, strings) self._log_dir_UltraNest = settings.pop("log directory", None) - if self._log_dir_UltraNest is not None: - if not path.exists(self._log_dir_UltraNest): - raise ValueError("log directory value in fitting_parameters" - "does not exist.") - elif not path.isdir(self._log_dir_UltraNest): - raise ValueError("log directory value in fitting_parameters" - "exists, but it is a file.") value = settings.pop("derived parameter names", "") self._derived_param_names_UltraNest = value.split() + self._check_dir_and_parameter_names_Ultranest() keys = {"n_live_points": "min_num_live_points"} same_keys = ["min_num_live_points", 'max_num_improvement_loops', @@ -1504,6 +1498,26 @@ def _parse_fitting_parameters_UltraNest(self): keys = {**keys, **{key: key for key in same_keys}} self._set_dict_safely(self._kwargs_UltraNest, settings, keys) + def _check_dir_and_parameter_names_Ultranest(self): + """ + Checks if the path to `log directory` exists and is a directory, + and also if the number of `derived parameter names` matches the + number of derived fluxes. + """ + if self._log_dir_UltraNest is not None: + if not path.exists(self._log_dir_UltraNest): + raise ValueError("log directory value in fitting_parameters" + "does not exist.") + elif not path.isdir(self._log_dir_UltraNest): + raise ValueError("log directory value in fitting_parameters" + "exists, but it is a file.") + + n_datasets = len(self._datasets) + n_fluxes = self._n_fluxes_per_dataset + if len(self._derived_param_names_UltraNest) != n_datasets * n_fluxes: + raise ValueError("The number of `derived parameter names` must " + "match the number of derived fluxes.") + def _set_prior_limits(self): """ Set minimum and maximum values of the prior space