From 20760babaed8a489e8e4f19152aa86349a656d88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20M=C3=B8llmann?= Date: Thu, 5 Mar 2026 13:13:07 +0100 Subject: [PATCH 1/2] Refactor get_best_individual_sympy to handle multiple individuals and update documentation accordingly --- src/flex/gp/regressor.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/flex/gp/regressor.py b/src/flex/gp/regressor.py index c690bb7..b11f228 100644 --- a/src/flex/gp/regressor.py +++ b/src/flex/gp/regressor.py @@ -44,7 +44,7 @@ class GPSymbolicRegressor(RegressorMixin, BaseEstimator): - Elitism and overlapping or non-overlapping generations - Parallel fitness evaluation using Ray - Validation-set monitoring - - Conversion of the best individual to a SymPy expression + - Conversion of the best individuals to a SymPy expression Args: pset_config: set of primitives and terminals (loosely or strongly typed). @@ -942,25 +942,31 @@ def __save_train_fit_history(self, output_path: str): join(output_path, "val_score_history.npy"), self.__val_score_history ) - def get_best_individual_sympy( + def get_best_individuals_sympy( self, sympy_conversion_rules: Dict = conversion_rules, special_term_name: str = "c", + n_ind: int = 1, ): - """Returns the SymPy expression of the best individual. + """Returns the SymPy expression of the best individuals. Args: sympy_conversion_rules: mapping from GP primitives (DEAP) to SymPy primitives. special_term_name: name used for constants during SymPy conversion. + n_ind: number of best individuals to convert to SymPy. Returns: - sympy representation of the best individual if conversion is enabled. - """ - - best_sympy = parse_expr( - stringify_for_sympy(self._best, sympy_conversion_rules, special_term_name) - ) + sympy representation of the best individuals. + """ + best_inds = self.get_best_individuals(n_ind=n_ind) + best_sympy = [None] * n_ind + for i in range(n_ind): + best_sympy[i] = parse_expr( + stringify_for_sympy( + best_inds[i], sympy_conversion_rules, special_term_name + ) + ) return best_sympy def get_train_fit_history(self): From bc98cd3d362fb502dcee6a597356df3288fbbf40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20M=C3=B8llmann?= Date: Thu, 5 Mar 2026 13:32:19 +0100 Subject: [PATCH 2/2] Add petsc and petsc4py to environment dependencies --- environment.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/environment.yaml b/environment.yaml index e86a419..bdd43d9 100644 --- a/environment.yaml +++ b/environment.yaml @@ -18,6 +18,8 @@ dependencies: - typeguard - yaml - pygraphviz + - petsc + - petsc4py - pip - pip: - git+https://github.com/cpml-au/dctkit