From 75590a8eb5b7547beed4ddc55ee77e3299ef80bf Mon Sep 17 00:00:00 2001 From: RomanSraj Date: Tue, 28 Jan 2025 17:22:42 +0100 Subject: [PATCH 1/5] Add black config to pyproject.toml --- examples/wrapper_example_2.py | 2 +- pyproject.toml | 3 +++ suprb/logging/default.py | 7 ++++--- suprb/optimizer/rule/es/es.py | 2 +- suprb/suprb.py | 4 +++- tests/test_ns.py | 1 + 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/examples/wrapper_example_2.py b/examples/wrapper_example_2.py index bcd301a8..b52d6644 100644 --- a/examples/wrapper_example_2.py +++ b/examples/wrapper_example_2.py @@ -100,5 +100,5 @@ def load_higdon_gramacy_lee(n_samples=1000, noise=0, random_state=None): return_estimator=True, fit_params={"cleanup": True}, ) - + log_scores(scores) diff --git a/pyproject.toml b/pyproject.toml index 158a5387..952e531b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,3 +4,6 @@ requires = [ "wheel" ] build-backend = "setuptools.build_meta" + +[tool.black] +line-length = 120 diff --git a/suprb/logging/default.py b/suprb/logging/default.py index 213536df..7a30761d 100644 --- a/suprb/logging/default.py +++ b/suprb/logging/default.py @@ -4,6 +4,7 @@ import numpy as np from . import BaseLogger + # from .metrics import matched_training_samples, genome_diversity # from .. import json as suprb_json from suprb.base import BaseRegressor @@ -37,9 +38,9 @@ def log_metric(key, value): def log_metric_stats(metric_name: str, attribute_name: str, lst: list): comprehension = [getattr(e, attribute_name) for e in lst] - log_metric(metric_name + '_min', min(comprehension)) - log_metric(metric_name + '_mean', sum(comprehension) / len(comprehension)) - log_metric(metric_name + '_max', max(comprehension)) + log_metric(metric_name + "_min", min(comprehension)) + log_metric(metric_name + "_mean", sum(comprehension) / len(comprehension)) + log_metric(metric_name + "_max", max(comprehension)) log_metric(metric_name + "_median", np.median(comprehension)) # From the docs of np.percentile: “["median_unbiased" is] probably # the best method if the sample distribution function is unknown”. diff --git a/suprb/optimizer/rule/es/es.py b/suprb/optimizer/rule/es/es.py index f4af4185..b1345078 100644 --- a/suprb/optimizer/rule/es/es.py +++ b/suprb/optimizer/rule/es/es.py @@ -30,7 +30,7 @@ class ES1xLambda(ParallelSingleRuleDiscovery): Can be one of ',', '+' or '&'. ',' replaces the elitist in every generation. '+' may keep the elitist. - '&' is a hybrid approach that essentially performs ',' but with elitists being archived and + '&' is a hybrid approach that essentially performs ',' but with elitists being archived and it ends the optimization process, if no improvement is found in delay generations. delay: int Only relevant if operator is '&'. Controls the number of elitists which need to be worse before stopping. diff --git a/suprb/suprb.py b/suprb/suprb.py index 3b3af9e9..8b9b18d0 100644 --- a/suprb/suprb.py +++ b/suprb/suprb.py @@ -286,7 +286,9 @@ def _validate_rule_discovery(self, default=None): self.rule_discovery_ = clone(self.rule_discovery) if self.rule_discovery is not None else clone(default) def _validate_solution_composition(self, default=None): - self.solution_composition_ = clone(self.solution_composition) if self.solution_composition is not None else clone(default) + self.solution_composition_ = ( + clone(self.solution_composition) if self.solution_composition is not None else clone(default) + ) def _validate_matching_type(self, default=None): self.matching_type_ = clone(self.matching_type) if self.matching_type is not None else clone(default) diff --git a/tests/test_ns.py b/tests/test_ns.py index 517f9124..0437f145 100644 --- a/tests/test_ns.py +++ b/tests/test_ns.py @@ -53,6 +53,7 @@ def setup_test_example(self): def setup_base_model(self): from suprb import optimizer + self.model = SupRB( rule_discovery=ns.NoveltySearch( init=rule.initialization.HalfnormInit(), From 5561afd1d8c75e92193b9c0fe41a105894e5ae26 Mon Sep 17 00:00:00 2001 From: RomanSraj Date: Tue, 28 Jan 2025 17:24:32 +0100 Subject: [PATCH 2/5] Add black to README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index e86bda52..13cc3634 100644 --- a/README.md +++ b/README.md @@ -120,3 +120,9 @@ We provide the experiment scripts used in associated publications under: https:/ If you use this code for research, please cite: Michael Heider, Helena Stegherr, Jonathan Wurth, Roman Sraj, and Jörg Hähner. 2022. **Separating Rule Discovery and Global Solution Composition in a Learning Classifier System.** In Genetic and Evolutionary Computation Conference Companion (GECCO ’22 Companion). https://doi.org/10.1145/3520304.3529014 + + + +## Formatting + +Install black formatter (pip install black) and use it in the root directory of the project to format all python files (black .) From b850b14def2f449f15a1379507719437a2ab08d6 Mon Sep 17 00:00:00 2001 From: heidmic <61311706+heidmic@users.noreply.github.com> Date: Wed, 17 Jun 2026 10:38:29 +0200 Subject: [PATCH 3/5] Add black with code-length 120 to README --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 13cc3634..72750748 100644 --- a/README.md +++ b/README.md @@ -125,4 +125,7 @@ Michael Heider, Helena Stegherr, Jonathan Wurth, Roman Sraj, and Jörg Hähner. ## Formatting -Install black formatter (pip install black) and use it in the root directory of the project to format all python files (black .) +Install black formatter (pip install black) and use it in the root directory of the project to format all python files: +``` +black --line-length 120 . +``` From 6588cbeac12a0b0e9b42a88532acdb0f53c96dfb Mon Sep 17 00:00:00 2001 From: heidmic <61311706+heidmic@users.noreply.github.com> Date: Wed, 17 Jun 2026 11:17:49 +0200 Subject: [PATCH 4/5] Move black formatter instructions in README Added instructions for using the black formatter to format Python files. --- README.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 34e6c74a..e5ee000b 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,13 @@ The commit messages of all the commits in your PR should be properly formatted: Avoid merge commits by using rebase rather than merge when combining branches +### Formatting + +Install black formatter (pip install black) and use it in the root directory of the project to format all python files (line length is automatically set to 120): +``` +black . +``` + ## Publications ### The Concept @@ -124,11 +131,3 @@ If you use this code for research, please cite: Michael Heider, Helena Stegherr, Jonathan Wurth, Roman Sraj, and Jörg Hähner. 2022. **Separating Rule Discovery and Global Solution Composition in a Learning Classifier System.** In Genetic and Evolutionary Computation Conference Companion (GECCO ’22 Companion). https://doi.org/10.1145/3520304.3529014 - - -## Formatting - -Install black formatter (pip install black) and use it in the root directory of the project to format all python files: -``` -black --line-length 120 . -``` From c9665039233587a060dad94407280619b931c7c2 Mon Sep 17 00:00:00 2001 From: heidmic <61311706+heidmic@users.noreply.github.com> Date: Wed, 17 Jun 2026 11:19:33 +0200 Subject: [PATCH 5/5] Update README to clarify black formatter line length --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e5ee000b..13c238ae 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ Avoid merge commits by using rebase rather than merge when combining branches ### Formatting -Install black formatter (pip install black) and use it in the root directory of the project to format all python files (line length is automatically set to 120): +Install black formatter (pip install black) and use it in the root directory of the project to format all python files (line length is set to 120): ``` black . ```