diff --git a/.github/workflows/unit-build.yml b/.github/workflows/unit-build.yml index e5b40289..d35ba7c5 100644 --- a/.github/workflows/unit-build.yml +++ b/.github/workflows/unit-build.yml @@ -31,7 +31,6 @@ jobs: pip install .[docs] pip install .[profilers] pip install pytest-cov - pip install -r requirements_adaptive.txt - name: Test with pytest run: | pytest --cov=golem test/unit diff --git a/examples/molecule_search/guacamol_benchmark.py b/examples/molecule_search/guacamol_benchmark.py index aacd88d2..e768c42a 100644 --- a/examples/molecule_search/guacamol_benchmark.py +++ b/examples/molecule_search/guacamol_benchmark.py @@ -99,7 +99,7 @@ def generate_optimized_molecules(self, scoring_function: ScoringFunction, number # Take only the first graph's appearance in history individuals \ = list({hash(self.graph_gen_params.adapter.restore(ind.graph)): ind - for gen in history.individuals + for gen in history.generations for ind in reversed(list(gen))}.values()) top_individuals = sorted(individuals, diff --git a/experiments/mab/mab_synthetic_experiment_helper.py b/experiments/mab/mab_synthetic_experiment_helper.py index 47afac74..b549e5e7 100644 --- a/experiments/mab/mab_synthetic_experiment_helper.py +++ b/experiments/mab/mab_synthetic_experiment_helper.py @@ -126,9 +126,9 @@ def show_action_probabilities(self, bandit_type: MutationAgentTypeEnum, stats_ac else: centers = sorted(self.cluster.cluster_centers_) for i in range(self.cluster.n_clusters): - titles = [title + f' for cluster with center {int(centers[i])}' for title in titles] + titles_centers = [title + f' for cluster with center {int(centers[i])}' for title in titles] plot_action_values(stats=stats_action_value_log[i], action_tags=actions, - titles=titles) + titles=titles_centers) plt.show() def show_average_action_probabilities(self, show_action_probabilities: dict, actions): @@ -193,7 +193,7 @@ def initial_population_func(graph_size: List[int] = None, pop_size: int = None, launch_num = 1 target_size = 50 - bandits_to_compare = [MutationAgentTypeEnum.contextual_bandit] + bandits_to_compare = [MutationAgentTypeEnum.contextual_bandit, MutationAgentTypeEnum.bandit] setup_parameters_func = partial(setup_parameters, target_size=target_size, trial_timeout=timeout) initial_population_func = partial(initial_population_func, graph_size=[random.randint(5, 10) for _ in range(10)] + @@ -204,5 +204,5 @@ def initial_population_func(graph_size: List[int] = None, pop_size: int = None, n_clusters=2, is_visualize=True) helper.compare_bandits(initial_population_func=initial_population_func, setup_parameters=setup_parameters_func) - # helper.show_boxplots() - # helper.show_fitness_lines() + helper.show_boxplots() + helper.show_fitness_lines() diff --git a/golem/core/optimisers/adaptive/neural_mab.py b/golem/core/optimisers/adaptive/neural_mab.py index 9e8a2be4..8dd4beca 100644 --- a/golem/core/optimisers/adaptive/neural_mab.py +++ b/golem/core/optimisers/adaptive/neural_mab.py @@ -2,7 +2,13 @@ import math from typing import List, Any, Union, Dict -import torch +from golem.utilities.requirements_notificator import warn_requirement + +try: + import torch +except ModuleNotFoundError: + warn_requirement('torch', 'other_requirements/requirements_adaptive.txt') + import numpy as np from mabwiser.mab import MAB, LearningPolicy, NeighborhoodPolicy from mabwiser.utils import Arm, Constants, Num diff --git a/golem/visualisation/opt_history/diversity.py b/golem/visualisation/opt_history/diversity.py index 4a9e1fa1..45bca78d 100644 --- a/golem/visualisation/opt_history/diversity.py +++ b/golem/visualisation/opt_history/diversity.py @@ -46,7 +46,7 @@ def plot_diversity_dynamic_gif(history: 'OptHistory', metric_names = history.objective.metric_names # dtype=float removes None, puts np.nan # indexed by [population, metric, individual] after transpose (.T) - pops = history.individuals[1:-1] # ignore initial pop and final choices + pops = history.generations[1:-1] # ignore initial pop and final choices fitness_distrib = [np.array([ind.fitness.values for ind in pop], dtype=float).T for pop in pops] @@ -95,7 +95,7 @@ def update_axes(iframe: int): def plot_diversity_dynamic(history: 'OptHistory', show: bool = True, save_path: Optional[str] = None, dpi: int = 100): labels = history.objective.metric_names - h = history.individuals[:-1] # don't consider final choices + h = history.generations[:-1] # don't consider final choices xs = np.arange(len(h)) # Compute diversity by metrics diff --git a/golem/visualisation/opt_history/fitness_line.py b/golem/visualisation/opt_history/fitness_line.py index 73bc4401..ac9e8044 100644 --- a/golem/visualisation/opt_history/fitness_line.py +++ b/golem/visualisation/opt_history/fitness_line.py @@ -294,7 +294,7 @@ def plot_average_fitness_line_per_generations(axis: plt.Axes, histories, label: fitness_value_per_generation = [] for history in histories: - generations = history.individuals + generations = history.generations for gen_num, gen in enumerate(generations): for ind in gen: if ind.native_generation != gen_num: diff --git a/golem/visualisation/opt_viz_extra.py b/golem/visualisation/opt_viz_extra.py index f8e3c5bc..2b71606c 100644 --- a/golem/visualisation/opt_viz_extra.py +++ b/golem/visualisation/opt_viz_extra.py @@ -47,7 +47,7 @@ def pareto_gif_create(self, objectives_names: Tuple[str] = ('ROC-AUC', 'Complexity')): files = [] pareto_fronts = self.history.archive_history - individuals = self.history.individuals + individuals = self.history.generations array_for_analysis = individuals if individuals else pareto_fronts all_objectives = extract_objectives(array_for_analysis, objectives_numbers) min_x, max_x = min(all_objectives[0]) - 0.01, max(all_objectives[0]) + 0.01 @@ -173,7 +173,7 @@ def _create_boxplot(self, individuals: List[Any], generation_num: int = None, plt.savefig(path, bbox_inches='tight') def boxplots_gif_create(self, objectives_names: Tuple[str] = ('ROC-AUC', 'Complexity')): - individuals = self.history.individuals + individuals = self.history.generations objectives = extract_objectives(individuals) objectives = list(itertools.chain(*objectives)) min_y, max_y = min(objectives), max(objectives) diff --git a/requirements_adaptive.txt b/other_requirements/requirements_adaptive.txt similarity index 100% rename from requirements_adaptive.txt rename to other_requirements/requirements_adaptive.txt diff --git a/test/unit/optimizers/test_composing_history.py b/test/unit/optimizers/test_composing_history.py index 429640b8..a2716d2c 100644 --- a/test/unit/optimizers/test_composing_history.py +++ b/test/unit/optimizers/test_composing_history.py @@ -66,7 +66,7 @@ def _test_individuals_in_history(history: OptHistory): uids = set() ids = set() for ind in itertools.chain(*history.generations): - # All individuals in `history.individuals` must have a native generation. + # All individuals in `history.generations` must have a native generation. assert ind.has_native_generation assert ind.fitness if ind.native_generation == 0: