From 9e8299a67b8d0ed487dff8d637554460a5c8587b Mon Sep 17 00:00:00 2001 From: Antoine Grosnit 80055266 Date: Fri, 21 Oct 2022 01:40:37 +0800 Subject: [PATCH] [UPDATE]. Clean Tr. --- combopt/README.md | 5 +- .../acq_optimizers/acq_optimizer_base.py | 2 +- .../genetic_algorithm_acq_optimizer.py | 2 +- .../interleaved_search_acq_optimizer.py | 4 +- .../local_search_acq_optimizer.py | 4 - combopt/comb_opt/factory.py | 11 +- combopt/comb_opt/models/gp/combo_gp.py | 2 +- combopt/comb_opt/optimizers/__init__.py | 2 +- combopt/comb_opt/optimizers/bocs.py | 6 +- combopt/comb_opt/optimizers/cocabo.py | 4 +- combopt/comb_opt/optimizers/combo.py | 2 +- .../comb_opt/optimizers/genetic_algorithm.py | 10 +- .../optimizers/mix_and_match/__init__.py | 8 +- .../mix_and_match/gp_diff_ker_ga_acq_optim.py | 2 +- .../mix_and_match/gp_diff_ker_is_acq_optim.py | 6 +- .../mix_and_match/gp_o_ker_ga_acq_optim.py | 2 +- .../mix_and_match/gp_o_ker_is_acq_optim.py | 4 +- .../mix_and_match/gp_o_ker_ls_acq_optim.py | 2 +- .../mix_and_match/gp_o_ker_sa_acq_optim.py | 2 +- .../mix_and_match/gp_to_ker_ga_acq_optim.py | 2 +- .../mix_and_match/gp_to_ker_ls_acq_optim.py | 2 +- .../mix_and_match/gp_to_ker_sa_acq_optim.py | 2 +- .../optimizers/simulated_annealing.py | 11 ++ .../tasks/antibody_design/cdrh3_design.py | 12 +- .../comb_opt/tasks/antibody_design/utils.py | 67 +++++---- .../comb_opt/tasks/eda_seq_opt/utils/utils.py | 7 +- .../eda_seq_opt/utils/utils_build_in_seq.py | 27 +++- .../eda_seq_opt/utils/utils_design_groups.py | 8 +- .../tasks/eda_seq_opt/utils/utils_epfl.py | 138 ++++++++++++------ combopt/comb_opt/utils/pymoo_utils.py | 3 + .../benchmark_baselines_ackley.py | 9 +- .../benchmark_baselines_ackley53.py | 6 +- .../benchmark_baselines_aig_optim_basic.py | 6 +- .../benchmark_baselines_aig_optim_hyp.py | 18 +-- .../benchmark_baselines_antibody_design.py | 43 ++++-- .../benchmark_baselines_mig_optim_basic.py | 14 +- .../benchmark_baselines_mixed_levy.py | 5 +- .../benchmark_baselines_pest_control.py | 6 +- .../benchmark_baselines_rna_inverse_fold.py | 13 +- .../benchmark_baselines_svm_opt.py | 4 +- .../benchmark_baselines_xgboost_opt.py | 4 +- .../run_benchmark_baselines_nominal_tasks.sh | 7 +- .../mix_and_match/mix_and_match_ackley.py | 66 --------- .../mix_and_match_aig_optim_basic.py | 66 --------- .../mix_and_match/mix_and_match_antibody.py | 55 ------- .../mix_and_match_antibody_design.py | 122 ++++++++++++++++ .../mix_and_match/mix_and_match_pest.py | 123 +++++++++++----- .../mix_and_match/mix_and_match_rna.py | 55 ------- .../mix_and_match_rna_inverse_fold.py | 121 +++++++++++++++ .../generate_benchmarking_baselines_plot.py | 13 +- ...e_benchmarking_mixing_and_matching_plot.py | 4 +- ... => test_gp_ssk_kernel_tr_sa_acq_optim.py} | 4 +- combopt/tests/optimizers/test_pymoo_ga.py | 4 +- combopt/tests/test_multitask_exact_gp.py | 1 - 54 files changed, 672 insertions(+), 456 deletions(-) delete mode 100644 combopt/experiments/mix_and_match/mix_and_match_ackley.py delete mode 100644 combopt/experiments/mix_and_match/mix_and_match_aig_optim_basic.py delete mode 100644 combopt/experiments/mix_and_match/mix_and_match_antibody.py create mode 100644 combopt/experiments/mix_and_match/mix_and_match_antibody_design.py delete mode 100644 combopt/experiments/mix_and_match/mix_and_match_rna.py create mode 100644 combopt/experiments/mix_and_match/mix_and_match_rna_inverse_fold.py rename combopt/tests/optimizers/mix_and_match/{test_gp_ssk_kernel_tr_ga_acq_optim.py => test_gp_ssk_kernel_tr_sa_acq_optim.py} (72%) diff --git a/combopt/README.md b/combopt/README.md index d38497f7..9c48c5fb 100644 --- a/combopt/README.md +++ b/combopt/README.md @@ -16,7 +16,8 @@ Download all submodules > git submodule update --init --recursive -[Optional] If you plan to use the Antibody design task, install AbsolutNoLib by following the instructions from https://github.com/csi-greifflab/Absolut +[Optional] If you plan to use the Antibody design task, install AbsolutNoLib by following the instructions +from https://github.com/csi-greifflab/Absolut Create a virtual environment and activate it @@ -42,7 +43,7 @@ Install the package itself - Random TSP ### Real-world -- Antibody Design (Needs to download `Absolut!` ~ 39GB) #TODO: indicate how to install absolute +- Antibody Design (Needs to download `Absolut!`) - RNA Inverse Folding - EDA Sequence Optimisation (AIG sequence optimisation) - EDA Sequence and Parameter Optimisation (AIG sequence and parameter optimisation) diff --git a/combopt/comb_opt/acq_optimizers/acq_optimizer_base.py b/combopt/comb_opt/acq_optimizers/acq_optimizer_base.py index 8866f910..0210a014 100644 --- a/combopt/comb_opt/acq_optimizers/acq_optimizer_base.py +++ b/combopt/comb_opt/acq_optimizers/acq_optimizer_base.py @@ -43,7 +43,7 @@ def optimize(self, **kwargs ) -> torch.Tensor: """ - Function used to optimise the acquisition function. Should return a 2D tensor with shape + Function used to optimize the acquisition function. Should return a 2D tensor with shape (n_suggestions, n_dims), where n_dims is the dimensionality of x. If an optimizer does not support return batches of data, this can be handled by imposing with "assert diff --git a/combopt/comb_opt/acq_optimizers/genetic_algorithm_acq_optimizer.py b/combopt/comb_opt/acq_optimizers/genetic_algorithm_acq_optimizer.py index 3ce0f239..0c63e678 100644 --- a/combopt/comb_opt/acq_optimizers/genetic_algorithm_acq_optimizer.py +++ b/combopt/comb_opt/acq_optimizers/genetic_algorithm_acq_optimizer.py @@ -142,7 +142,7 @@ def __init__(self, self.ga_allow_repeating_x = ga_allow_repeating_x assert self.search_space.num_nominal + self.search_space.num_ordinal == self.search_space.num_dims, \ - 'The Categorical GA acq optimiser currently only supports nominal and ordinal variables' + 'The Categorical GA acq optimizer currently only supports nominal and ordinal variables' def optimize(self, x: torch.Tensor, n_suggestions: int, diff --git a/combopt/comb_opt/acq_optimizers/interleaved_search_acq_optimizer.py b/combopt/comb_opt/acq_optimizers/interleaved_search_acq_optimizer.py index 070152f7..c168bc68 100644 --- a/combopt/comb_opt/acq_optimizers/interleaved_search_acq_optimizer.py +++ b/combopt/comb_opt/acq_optimizers/interleaved_search_acq_optimizer.py @@ -59,7 +59,7 @@ def __init__(self, self.inverse_mapping = [(self.numeric_dims + self.search_space.nominal_dims).index(i) for i in range(self.search_space.num_dims)] - # Determine the learning rate used to optimise numeric variables if needed + # Determine the learning rate used to optimize numeric variables if needed if len(self.numeric_dims) > 0: if num_lr is None: if self.search_space.num_disc > 0: @@ -194,6 +194,8 @@ def _optimize(self, is_valid = True else: tol_ -= 1 + if tol_ < 0: + break if tol_ < 0: break diff --git a/combopt/comb_opt/acq_optimizers/local_search_acq_optimizer.py b/combopt/comb_opt/acq_optimizers/local_search_acq_optimizer.py index f349b401..8c3f76e9 100644 --- a/combopt/comb_opt/acq_optimizers/local_search_acq_optimizer.py +++ b/combopt/comb_opt/acq_optimizers/local_search_acq_optimizer.py @@ -117,8 +117,6 @@ def _optimize(self, search_space=self.search_space, tr_manager=tr_manager, n_points=self.n_random_vertices, - is_numeric=self.is_numeric, - is_mixed=self.is_mixed, numeric_dims=self.numeric_dims, discrete_choices=self.discrete_choices, max_n_perturb_num=self.max_n_perturb_num, @@ -184,8 +182,6 @@ def _optimize(self, search_space=self.search_space, tr_manager=tr_manager, n_points=1, - is_numeric=self.is_numeric, - is_mixed=self.is_mixed, numeric_dims=self.numeric_dims, discrete_choices=self.discrete_choices, max_n_perturb_num=self.max_n_perturb_num, diff --git a/combopt/comb_opt/factory.py b/combopt/comb_opt/factory.py index 99a4208b..ad715893 100644 --- a/combopt/comb_opt/factory.py +++ b/combopt/comb_opt/factory.py @@ -208,9 +208,14 @@ def task_factory(task_name: str, dtype: torch.dtype = torch.float32, **kwargs) - elif task_name == 'antibody_design': if 'antigen' not in kwargs: - print('Target antigen not specified. Using antigen 1ADQ_A.') - task = CDRH3Design(antigen=kwargs.get('antigen', '1ADQ_A'), cdrh3_length=kwargs.get('cdrh3_length', 11), - num_cpus=kwargs.get('num_cpus', 1), first_cpu=kwargs.get('first_cpu', 0)) + print('Target antigen not specified. Using antigen 2DD8_S.') + task = CDRH3Design( + antigen=kwargs.get('antigen', '2DD8_S'), + cdrh3_length=kwargs.get('cdrh3_length', 11), + num_cpus=kwargs.get('num_cpus', 1), + first_cpu=kwargs.get('first_cpu', 0), + absolut_dir=kwargs.get('absolut_dir', None) + ) search_space = search_space_factory('antibody_design', dtype, cdrh3_length=kwargs.get('cdrh3_length', 11)) elif task_name == "rna_inverse_fold": diff --git a/combopt/comb_opt/models/gp/combo_gp.py b/combopt/comb_opt/models/gp/combo_gp.py index ca7e8a22..8cfe7c99 100644 --- a/combopt/comb_opt/models/gp/combo_gp.py +++ b/combopt/comb_opt/models/gp/combo_gp.py @@ -461,7 +461,7 @@ def cholesky_update(self, constmean: float, log_amp: float, log_beta: torch.Floa self.gram_mat_update(constmean, log_amp, log_beta, log_likelihood_noise) eye_mat = torch.diag(self.gram_mat.new_ones(self.gram_mat.size(0))) - for jitter_const in [0, 1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3]: + for jitter_const in [0, 1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2]: chol_jitter = torch.trace(self.gram_mat).item() * jitter_const try: # cholesky is lower triangular matrix diff --git a/combopt/comb_opt/optimizers/__init__.py b/combopt/comb_opt/optimizers/__init__.py index 5f5de08e..4d7f378f 100644 --- a/combopt/comb_opt/optimizers/__init__.py +++ b/combopt/comb_opt/optimizers/__init__.py @@ -14,7 +14,7 @@ from comb_opt.optimizers.casmopolitan import Casmopolitan from comb_opt.optimizers.cocabo import CoCaBO from comb_opt.optimizers.combo import COMBO -from comb_opt.optimizers.genetic_algorithm import PymooGeneticAlgorithm +from comb_opt.optimizers.genetic_algorithm import PymooGeneticAlgorithm, GeneticAlgorithm from comb_opt.optimizers.local_search import LocalSearch from comb_opt.optimizers.multi_armed_bandit import MultiArmedBandit from comb_opt.optimizers.optimizer_base import OptimizerBase diff --git a/combopt/comb_opt/optimizers/bocs.py b/combopt/comb_opt/optimizers/bocs.py index ac941507..02f117a1 100644 --- a/combopt/comb_opt/optimizers/bocs.py +++ b/combopt/comb_opt/optimizers/bocs.py @@ -27,7 +27,9 @@ class BOCS(BoBase): @property def name(self) -> str: if self.use_tr: - name = f'LR ({self.model_estimator}) - Tr-Based LS acq optim' + name = f'LR ({self.model_estimator}) - Tr-Based SA acq optim' + elif self.model_estimator == "sparse_horseshoe": # Standard BOCS + name = "BOCS" else: name = f'BOCS ({self.model_estimator})' return name @@ -70,7 +72,7 @@ def __init__(self, warning_message = 'This is the general form implementation of BOCS (see Appendix A of ' + \ 'https://arxiv.org/abs/1806.08838), which differs from the standard implementation ' + \ 'for purely binary problems. The differences are: (1) binary variables are ' + \ - 'represented by their one hot encoding, and (2) SA is used to optimise the acquisition' + \ + 'represented by their one hot encoding, and (2) SA is used to optimize the acquisition' + \ 'in place of SDP.' warnings.warn(warning_message, category=UserWarning) diff --git a/combopt/comb_opt/optimizers/cocabo.py b/combopt/comb_opt/optimizers/cocabo.py index c60d3ed1..3a648eb9 100644 --- a/combopt/comb_opt/optimizers/cocabo.py +++ b/combopt/comb_opt/optimizers/cocabo.py @@ -45,6 +45,8 @@ def name(self) -> str: name = f'GP ({self.model_numeric_kernel_name}) - MAB acq optim' elif self.is_nominal: name = f'GP ({self.model_cat_kernel_name}) - MAB acq optim' + else: + raise ValueError() return name @@ -54,7 +56,7 @@ def __init__(self, model_numeric_kernel_name: str = 'mat52', model_num_kernel_ard: bool = True, model_num_kernel_lengthscale_constr: Optional[Interval] = None, - model_cat_kernel_name='transformed_overlap', + model_cat_kernel_name='overlap', model_cat_kernel_ard: bool = True, model_cat_kernel_lengthscale_constr: Optional[Interval] = None, model_noise_prior: Optional[Prior] = None, diff --git a/combopt/comb_opt/optimizers/combo.py b/combopt/comb_opt/optimizers/combo.py index 9ced8d7a..7fd442c2 100644 --- a/combopt/comb_opt/optimizers/combo.py +++ b/combopt/comb_opt/optimizers/combo.py @@ -46,7 +46,7 @@ def __init__(self, acq_optim_n_greedy_ascent_init: int = 20, acq_optim_n_spray: int = 10, acq_optim_max_n_ascent: float = float('inf'), - use_tr: bool = True, + use_tr: bool = False, tr_restart_acq_name: str = 'lcb', tr_restart_n_cand: Optional[int] = None, tr_min_nominal_radius: Optional[Union[int, float]] = None, diff --git a/combopt/comb_opt/optimizers/genetic_algorithm.py b/combopt/comb_opt/optimizers/genetic_algorithm.py index b3c4187f..65ff563b 100644 --- a/combopt/comb_opt/optimizers/genetic_algorithm.py +++ b/combopt/comb_opt/optimizers/genetic_algorithm.py @@ -12,6 +12,10 @@ import numpy as np import pandas as pd import torch + +from pymoo.config import Config +Config.warnings['not_compiled'] = False + from pymoo.algorithms.base.genetic import GeneticAlgorithm from pymoo.algorithms.soo.nonconvex.ga import FitnessSurvival from pymoo.algorithms.soo.nonconvex.ga import comp_by_cv_and_fitness @@ -222,9 +226,9 @@ class CategoricalGeneticAlgorithm(OptimizerBase): @property def name(self) -> str: if self.tr_manager is not None: - name = 'Tr-based Categorical Genetic Algorithm' + name = 'Tr-based Genetic Algorithm' else: - name = 'Categorical Genetic Algorithm' + name = 'Genetic Algorithm' return name def __init__(self, @@ -603,7 +607,7 @@ def _mutate(self, x: torch.Tensor) -> torch.Tensor: class GeneticAlgorithm(OptimizerBase): """ - A Genetic Algorithm (GA) optimiser that determines which exact GA algorithm to use based on the variable types in + A Genetic Algorithm (GA) optimizer that determines which exact GA algorithm to use based on the variable types in the search space. If the search space contains only nominal variables, an elitist GA algorithm will be used. If the search space contains any other variable type combinations, the Mixed Variable GA from pymoo will be used (see https://pymoo.org/customization/mixed.html). On purely combinatorial problems, the elitist GA algorithm can diff --git a/combopt/comb_opt/optimizers/mix_and_match/__init__.py b/combopt/comb_opt/optimizers/mix_and_match/__init__.py index 29ad32c8..2339acc9 100644 --- a/combopt/comb_opt/optimizers/mix_and_match/__init__.py +++ b/combopt/comb_opt/optimizers/mix_and_match/__init__.py @@ -8,13 +8,17 @@ # PARTICULAR PURPOSE. See the MIT License for more details. from comb_opt.optimizers.mix_and_match.gp_diff_ker_ga_acq_optim import GpDiffusionGaAcqOptim +from comb_opt.optimizers.mix_and_match.gp_diff_ker_is_acq_optim import GpDiffusionIsAcqOptim from comb_opt.optimizers.mix_and_match.gp_diff_ker_sa_acq_optim import GpDiffusionSaAcqOptim -from comb_opt.optimizers.mix_and_match.gp_diff_ker_is_acq_optim import GpDiffusionTrLsAcqOptim +from comb_opt.optimizers.mix_and_match.gp_o_ker_ga_acq_optim import GpOGaAcqOptim +from comb_opt.optimizers.mix_and_match.gp_o_ker_is_acq_optim import GpOIsAcqOptim +from comb_opt.optimizers.mix_and_match.gp_o_ker_ls_acq_optim import GpOLsAcqOptim +from comb_opt.optimizers.mix_and_match.gp_o_ker_sa_acq_optim import GpOSaAcqOptim from comb_opt.optimizers.mix_and_match.gp_ssk_ker_ls_acq_optim import GpSskLsAcqOptim from comb_opt.optimizers.mix_and_match.gp_ssk_ker_sa_acq_optim import GpSskSaAcqOptim from comb_opt.optimizers.mix_and_match.gp_to_ker_ls_acq_optim import GpToLsAcqOptim from comb_opt.optimizers.mix_and_match.gp_to_ker_ga_acq_optim import GpToGaAcqOptim from comb_opt.optimizers.mix_and_match.gp_to_ker_sa_acq_optim import GpToSaAcqOptim from comb_opt.optimizers.mix_and_match.lr_ga_acq_optim import LrGaAcqOptim -from comb_opt.optimizers.mix_and_match.lr_ls_acq_optim import LrLsAcqOptim from comb_opt.optimizers.mix_and_match.lr_is_acq_optim import LrIsAcqOptim +from comb_opt.optimizers.mix_and_match.lr_ls_acq_optim import LrLsAcqOptim diff --git a/combopt/comb_opt/optimizers/mix_and_match/gp_diff_ker_ga_acq_optim.py b/combopt/comb_opt/optimizers/mix_and_match/gp_diff_ker_ga_acq_optim.py index 4d09ba32..58cdeb32 100644 --- a/combopt/comb_opt/optimizers/mix_and_match/gp_diff_ker_ga_acq_optim.py +++ b/combopt/comb_opt/optimizers/mix_and_match/gp_diff_ker_ga_acq_optim.py @@ -48,7 +48,7 @@ def __init__(self, acq_optim_ga_num_elite: int = 10, acq_optim_ga_store_x: bool = False, acq_optim_ga_allow_repeating_x: bool = True, - use_tr: bool = True, + use_tr: bool = False, tr_restart_acq_name: str = 'lcb', tr_restart_n_cand: Optional[int] = None, tr_min_nominal_radius: Optional[Union[int, float]] = None, diff --git a/combopt/comb_opt/optimizers/mix_and_match/gp_diff_ker_is_acq_optim.py b/combopt/comb_opt/optimizers/mix_and_match/gp_diff_ker_is_acq_optim.py index 6122fa74..43919266 100644 --- a/combopt/comb_opt/optimizers/mix_and_match/gp_diff_ker_is_acq_optim.py +++ b/combopt/comb_opt/optimizers/mix_and_match/gp_diff_ker_is_acq_optim.py @@ -22,7 +22,7 @@ from comb_opt.utils.graph_utils import laplacian_eigen_decomposition -class GpDiffusionTrLsAcqOptim(BoBase): +class GpDiffusionIsAcqOptim(BoBase): @property def name(self) -> str: @@ -48,7 +48,7 @@ def __init__(self, acq_optim_num_optimizer: str = 'sgd', acq_optim_num_lr: Optional[float] = 1e-3, acq_optim_nominal_tol: int = 100, - use_tr: bool = True, + use_tr: bool = False, tr_restart_acq_name: str = 'lcb', tr_restart_n_cand: Optional[int] = None, tr_min_nominal_radius: Optional[Union[int, float]] = None, @@ -168,6 +168,6 @@ def __init__(self, self.use_tr = use_tr - super(GpDiffusionTrLsAcqOptim, self).__init__(search_space, n_init, model, acq_func, acq_optim, tr_manager, + super(GpDiffusionIsAcqOptim, self).__init__(search_space, n_init, model, acq_func, acq_optim, tr_manager, dtype, device) diff --git a/combopt/comb_opt/optimizers/mix_and_match/gp_o_ker_ga_acq_optim.py b/combopt/comb_opt/optimizers/mix_and_match/gp_o_ker_ga_acq_optim.py index c9b31c3a..3c317e14 100644 --- a/combopt/comb_opt/optimizers/mix_and_match/gp_o_ker_ga_acq_optim.py +++ b/combopt/comb_opt/optimizers/mix_and_match/gp_o_ker_ga_acq_optim.py @@ -57,7 +57,7 @@ def __init__(self, acq_optim_ga_num_elite: int = 10, acq_optim_ga_store_x: bool = False, acq_optim_ga_allow_repeating_x: bool = True, - use_tr: bool = True, + use_tr: bool = False, tr_restart_acq_name: str = 'lcb', tr_restart_n_cand: Optional[int] = None, tr_min_num_radius: Optional[Union[int, float]] = None, diff --git a/combopt/comb_opt/optimizers/mix_and_match/gp_o_ker_is_acq_optim.py b/combopt/comb_opt/optimizers/mix_and_match/gp_o_ker_is_acq_optim.py index 2477f0e4..2fb3a638 100644 --- a/combopt/comb_opt/optimizers/mix_and_match/gp_o_ker_is_acq_optim.py +++ b/combopt/comb_opt/optimizers/mix_and_match/gp_o_ker_is_acq_optim.py @@ -58,7 +58,7 @@ def __init__(self, acq_optim_num_optimizer: str = 'sgd', acq_optim_num_lr: Optional[float] = 1e-3, acq_optim_nominal_tol: int = 100, - use_tr: bool = True, + use_tr: bool = False, tr_restart_acq_name: str = 'lcb', tr_restart_n_cand: Optional[int] = None, tr_min_num_radius: Optional[Union[int, float]] = None, @@ -142,7 +142,7 @@ def __init__(self, numeric_kernel_name='mat52', numeric_kernel_use_ard=model_num_kernel_ard, numeric_lengthscale_constraint=model_num_kernel_lengthscale_constr, - nominal_kernel_name='transformed_overlap', + nominal_kernel_name='overlap', nominal_kernel_use_ard=model_cat_kernel_ard, nominal_lengthscale_constraint=model_cat_kernel_lengthscale_constr) diff --git a/combopt/comb_opt/optimizers/mix_and_match/gp_o_ker_ls_acq_optim.py b/combopt/comb_opt/optimizers/mix_and_match/gp_o_ker_ls_acq_optim.py index d9a6e03f..863c86f1 100644 --- a/combopt/comb_opt/optimizers/mix_and_match/gp_o_ker_ls_acq_optim.py +++ b/combopt/comb_opt/optimizers/mix_and_match/gp_o_ker_ls_acq_optim.py @@ -56,7 +56,7 @@ def __init__(self, acq_optim_n_greedy_ascent_init: int = 20, acq_optim_n_spray: int = 10, acq_optim_max_n_ascent: float = float('inf'), - use_tr: bool = True, + use_tr: bool = False, tr_restart_acq_name: str = 'lcb', tr_restart_n_cand: Optional[int] = None, tr_min_num_radius: Optional[Union[int, float]] = None, diff --git a/combopt/comb_opt/optimizers/mix_and_match/gp_o_ker_sa_acq_optim.py b/combopt/comb_opt/optimizers/mix_and_match/gp_o_ker_sa_acq_optim.py index 11b6b7a7..6c46767f 100644 --- a/combopt/comb_opt/optimizers/mix_and_match/gp_o_ker_sa_acq_optim.py +++ b/combopt/comb_opt/optimizers/mix_and_match/gp_o_ker_sa_acq_optim.py @@ -54,7 +54,7 @@ def __init__(self, acq_optim_num_iter: int = 200, acq_optim_init_temp: int = 1, acq_optim_tolerance: int = 100, - use_tr: bool = True, + use_tr: bool = False, tr_restart_acq_name: str = 'lcb', tr_restart_n_cand: Optional[int] = None, tr_min_num_radius: Optional[Union[int, float]] = None, diff --git a/combopt/comb_opt/optimizers/mix_and_match/gp_to_ker_ga_acq_optim.py b/combopt/comb_opt/optimizers/mix_and_match/gp_to_ker_ga_acq_optim.py index dcf6d608..880cafa1 100644 --- a/combopt/comb_opt/optimizers/mix_and_match/gp_to_ker_ga_acq_optim.py +++ b/combopt/comb_opt/optimizers/mix_and_match/gp_to_ker_ga_acq_optim.py @@ -57,7 +57,7 @@ def __init__(self, acq_optim_ga_num_elite: int = 10, acq_optim_ga_store_x: bool = False, acq_optim_ga_allow_repeating_x: bool = True, - use_tr: bool = True, + use_tr: bool = False, tr_restart_acq_name: str = 'lcb', tr_restart_n_cand: Optional[int] = None, tr_min_num_radius: Optional[Union[int, float]] = None, diff --git a/combopt/comb_opt/optimizers/mix_and_match/gp_to_ker_ls_acq_optim.py b/combopt/comb_opt/optimizers/mix_and_match/gp_to_ker_ls_acq_optim.py index d3916973..1515e801 100644 --- a/combopt/comb_opt/optimizers/mix_and_match/gp_to_ker_ls_acq_optim.py +++ b/combopt/comb_opt/optimizers/mix_and_match/gp_to_ker_ls_acq_optim.py @@ -56,7 +56,7 @@ def __init__(self, acq_optim_n_greedy_ascent_init: int = 20, acq_optim_n_spray: int = 10, acq_optim_max_n_ascent: float = float('inf'), - use_tr: bool = True, + use_tr: bool = False, tr_restart_acq_name: str = 'lcb', tr_restart_n_cand: Optional[int] = None, tr_min_num_radius: Optional[Union[int, float]] = None, diff --git a/combopt/comb_opt/optimizers/mix_and_match/gp_to_ker_sa_acq_optim.py b/combopt/comb_opt/optimizers/mix_and_match/gp_to_ker_sa_acq_optim.py index 3f664f61..4fa853e8 100644 --- a/combopt/comb_opt/optimizers/mix_and_match/gp_to_ker_sa_acq_optim.py +++ b/combopt/comb_opt/optimizers/mix_and_match/gp_to_ker_sa_acq_optim.py @@ -54,7 +54,7 @@ def __init__(self, acq_optim_num_iter: int = 200, acq_optim_init_temp: int = 1, acq_optim_tolerance: int = 100, - use_tr: bool = True, + use_tr: bool = False, tr_restart_acq_name: str = 'lcb', tr_restart_n_cand: Optional[int] = None, tr_min_num_radius: Optional[Union[int, float]] = None, diff --git a/combopt/comb_opt/optimizers/simulated_annealing.py b/combopt/comb_opt/optimizers/simulated_annealing.py index 2aaeee14..a778c642 100644 --- a/combopt/comb_opt/optimizers/simulated_annealing.py +++ b/combopt/comb_opt/optimizers/simulated_annealing.py @@ -286,3 +286,14 @@ def sample_unseen_nominal_neighbour(self, x_nominal: torch.Tensor): x_nominal_neighbour = x_nominal_neighbour.view(-1) return x_nominal_neighbour + + def fill_field_after_pkl_load(self, search_space: SearchSpace, **kwargs): + """ As some elements are not pickled, need to reinstantiate them """ + self.search_space = search_space + + def __getstate__(self): + d = dict(self.__dict__) + to_remove = ["search_space"] # fields to remove when pickling this object + for attr in to_remove: + del d[attr] + return d diff --git a/combopt/comb_opt/tasks/antibody_design/cdrh3_design.py b/combopt/comb_opt/tasks/antibody_design/cdrh3_design.py index 7f87e554..13ee5f4b 100644 --- a/combopt/comb_opt/tasks/antibody_design/cdrh3_design.py +++ b/combopt/comb_opt/tasks/antibody_design/cdrh3_design.py @@ -9,6 +9,7 @@ import os import subprocess +from typing import Optional import numpy as np import pandas as pd @@ -24,7 +25,8 @@ class CDRH3Design(TaskBase): def name(self) -> str: return f'{self.antigen} Antibody Design' - def __init__(self, antigen: str = '1ADQ_A', cdrh3_length: int = 11, num_cpus: int = 10, first_cpu: int = 0): + def __init__(self, antigen: str = '1ADQ_A', cdrh3_length: int = 11, num_cpus: int = 10, first_cpu: int = 0, + absolut_dir: Optional[str] = None): super(CDRH3Design, self).__init__() self.num_cpus = num_cpus self.first_cpu = first_cpu @@ -35,15 +37,19 @@ def __init__(self, antigen: str = '1ADQ_A', cdrh3_length: int = 11, num_cpus: in self.amino_acid_to_idx = {aa: i for i, aa in enumerate(self.amino_acids)} self.idx_to_amino_acid = {value: key for key, value in self.amino_acid_to_idx.items()} - self.AbsolutNoLib_dir = get_AbsolutNoLib_dir() + self.AbsolutNoLib_dir = get_AbsolutNoLib_dir(absolut_dir) self.valid_antigens = get_valid_antigens(self.AbsolutNoLib_dir) + self.need_to_check_precomputed_antigen_structure = True assert antigen in self.valid_antigens, f'Specified antigen is not valid. Please choose of from: \n\n {self.valid_antigens}' - download_precomputed_antigen_structure(self.AbsolutNoLib_dir, self.antigen) def evaluate(self, x: pd.DataFrame) -> np.ndarray: assert os.path.exists(os.path.join(self.AbsolutNoLib_dir, 'antigen_data', f'{self.antigen}')) + if self.need_to_check_precomputed_antigen_structure: + download_precomputed_antigen_structure(self.AbsolutNoLib_dir, self.antigen) + self.need_to_check_precomputed_antigen_structure = False + # Change working directory current_dir = os.getcwd() os.chdir(os.path.join(self.AbsolutNoLib_dir, 'antigen_data', f'{self.antigen}')) diff --git a/combopt/comb_opt/tasks/antibody_design/utils.py b/combopt/comb_opt/tasks/antibody_design/utils.py index 21f5142a..db21e714 100644 --- a/combopt/comb_opt/tasks/antibody_design/utils.py +++ b/combopt/comb_opt/tasks/antibody_design/utils.py @@ -34,32 +34,35 @@ def get_valid_antigens(AbsolutNoLib_dir: str): return antigens -def get_AbsolutNoLib_dir() -> str: - path = os.path.join(pathlib.Path(__file__).parent.resolve(), 'path_to_AbsolutNoLib.txt') - try: - f = open(path, "r") - AbsolutNoLib_dir = f.readlines()[0] - if AbsolutNoLib_dir[-1] == '\n': - AbsolutNoLib_dir = AbsolutNoLib_dir[:-1] - if AbsolutNoLib_dir.split('/')[-1] == 'AbsolutNoLib': - AbsolutNoLib_dir = os.path.join('/', *AbsolutNoLib_dir.split('/')[:-1]) - f.close() - - assert os.path.exists( - os.path.join(AbsolutNoLib_dir, - 'AbsolutNoLib')), f'AbsolutNoLib can\'t be found in provided directory {AbsolutNoLib_dir},' \ - f' check path specified in {path}' - return AbsolutNoLib_dir - - except FileNotFoundError as _: - abs_path_to_absolut_no_lib = '/my/absolute/path/to/AbsolutNoLib' - error_message = f'\n\n------ Friendly first run error message ------\n\n' \ - f'File {path} not found. \n\n' \ - f' --> Please create it and fill it with one line describing the absolute path to the ' \ - f'AbsulutNoLib executable e.g. by running\n' \ - f"\techo '{abs_path_to_absolut_no_lib}' > {path}\n" \ - f'\n and then rerun your program.' - raise FileNotFoundError(error_message) +def get_AbsolutNoLib_dir(path_to_AbsolutNoLib: Optional[str] = None) -> str: + if path_to_AbsolutNoLib is None: + path = os.path.join(pathlib.Path(__file__).parent.resolve(), 'path_to_AbsolutNoLib.txt') + try: + f = open(path, "r") + AbsolutNoLib_dir = f.readlines()[0] + if AbsolutNoLib_dir[-1] == '\n': + AbsolutNoLib_dir = AbsolutNoLib_dir[:-1] + f.close() + + except FileNotFoundError as _: + abs_path_to_absolut_no_lib = '/my/absolute/path/to/AbsolutNoLib' + error_message = f'\n\n------ Friendly first run error message ------\n\n' \ + f'File {path} not found. \n\n' \ + f' --> Please create it and fill it with one line describing the absolute path to the ' \ + f'AbsulutNoLib executable e.g. by running\n' \ + f"\techo '{abs_path_to_absolut_no_lib}' > {path}\n" \ + f'\n and then rerun your program.' + raise FileNotFoundError(error_message) + else: + AbsolutNoLib_dir = path_to_AbsolutNoLib + if AbsolutNoLib_dir.split('/')[-1] == 'AbsolutNoLib': + AbsolutNoLib_dir = os.path.join('/', *AbsolutNoLib_dir.split('/')[:-1]) + + assert os.path.exists( + os.path.join(AbsolutNoLib_dir, + 'AbsolutNoLib')), f'AbsolutNoLib can\'t be found in provided directory {AbsolutNoLib_dir},' \ + f' check path specified in {path_to_AbsolutNoLib}' + return AbsolutNoLib_dir def download_precomputed_antigen_structure(AbsolutNoLib_dir: str, antigen: str, num_cpus: Optional[int] = 1, @@ -85,10 +88,14 @@ def download_precomputed_antigen_structure(AbsolutNoLib_dir: str, antigen: str, sequences = [] - with open(f'TempCDR3_{antigen}.txt', 'w') as f: - line = f"{1}\t{seq}\n" - f.write(line) - sequences.append(seq) + try: + with open(f'TempCDR3_{antigen}.txt', 'w') as f: + line = f"{1}\t{seq}\n" + f.write(line) + sequences.append(seq) + except PermissionError: + print(os.getcwd()) + raise repertoire_output = subprocess.run(absolut_run_command, capture_output=True, text=True) diff --git a/combopt/comb_opt/tasks/eda_seq_opt/utils/utils.py b/combopt/comb_opt/tasks/eda_seq_opt/utils/utils.py index 000a748f..52d4432f 100644 --- a/combopt/comb_opt/tasks/eda_seq_opt/utils/utils.py +++ b/combopt/comb_opt/tasks/eda_seq_opt/utils/utils.py @@ -189,8 +189,8 @@ def get_design_name(design_filepath: str) -> str: def get_design_prop(seq: List[str], design_file: str, evaluator: str, print_stat_stages: Optional[np.ndarray], - new_op: bool, obj_func: Optional[Callable[[float, float], float]] = None, - verbose: bool = False) \ + new_op: bool, sweep: bool = False, + obj_func: Optional[Callable[[float, float], float]] = None, verbose: bool = False) \ -> Tuple[int, int, Dict[str, Any]]: """ Get property of the design after applying sequence of operations @@ -199,6 +199,7 @@ def get_design_prop(seq: List[str], design_file: str, evaluator: str, print_stat seq: sequence of operations design_file: path to the design evaluator: whether to use yosys-abc (`yosys`) or abc_py (`abcpy`) or compiled abc repo (`abc`) + sweep: add sweep before sequence verbose: verbosity level obj_func: a function taking lut and level as input and outputting some value (target in a minimisation task) @@ -213,6 +214,8 @@ def get_design_prop(seq: List[str], design_file: str, evaluator: str, print_stat seq += ['&get -n -m;'] abc_command = 'read ' + design_file + '; ' + if sweep: + abc_command += "sweep; sweep -s;" abc_command += ' '.join(seq) if new_op: if "&ps" not in abc_command[-19:]: diff --git a/combopt/comb_opt/tasks/eda_seq_opt/utils/utils_build_in_seq.py b/combopt/comb_opt/tasks/eda_seq_opt/utils/utils_build_in_seq.py index 7fe34e6c..a86583ef 100644 --- a/combopt/comb_opt/tasks/eda_seq_opt/utils/utils_build_in_seq.py +++ b/combopt/comb_opt/tasks/eda_seq_opt/utils/utils_build_in_seq.py @@ -115,6 +115,26 @@ def seq_length() -> int: return len(Resyn2.aux_sequence) + 1 +class DResyn2Speedup(BuildInSeq): + aux_sequence = dresyn2_seq + + def __init__(self, design_file: str, lut_inputs: int): + """ + balance; drw; drf; balance; drw; drw –z; balance; drf –z; drw –z; balance; + if -K ...; speedup; if -K ... -C 16 -F; speedup; if -K ... -C 16 -F; speedup; if -K ... -C 16 -F; + """ + + super().__init__(design_file=design_file) + assert lut_inputs == 4, f"Usually this is used with -K 4 and not -K {lut_inputs}" + self.sequence = ["strash;"] + self.aux_sequence + [f"if -K {lut_inputs}"] + for _ in range(3): + self.sequence += ["speedup", f"if -K {lut_inputs} -C 16 -F 2"] + + @staticmethod + def seq_length() -> int: + return len(DResyn2Speedup.aux_sequence) + 4 + + class InitDesign(BuildInSeq): aux_sequence = [] @@ -153,6 +173,7 @@ def seq_length() -> int: resyn2=Resyn2, strash_resyn2=StrResyn2, str_init=StrInitDesign, + dresyn2_speedup=DResyn2Speedup ) @@ -197,7 +218,11 @@ def ref_path(self) -> str: path_id += f'_{self.evaluator}' if self.n_eval_ref != 1: path_id += f"_n-eval-{self.n_eval_ref}" - return os.path.join(get_results_storage_path_root(), 'refs', self.ref_abc_seq, path_id, self.design_name) + try: + return os.path.join(get_results_storage_path_root(), 'refs', self.ref_abc_seq, path_id, self.design_name) + except Exception: + print(get_results_storage_path_root(), 'refs', self.ref_abc_seq, path_id, self.design_name) + raise def get_refs(self, ignore_existing: bool = False) -> Tuple[float, float, float]: if os.path.exists(os.path.join(self.ref_path(), 'refs.pkl')) and not ignore_existing: diff --git a/combopt/comb_opt/tasks/eda_seq_opt/utils/utils_design_groups.py b/combopt/comb_opt/tasks/eda_seq_opt/utils/utils_design_groups.py index 324f6f38..89edd275 100644 --- a/combopt/comb_opt/tasks/eda_seq_opt/utils/utils_design_groups.py +++ b/combopt/comb_opt/tasks/eda_seq_opt/utils/utils_design_groups.py @@ -1,5 +1,5 @@ # Comes from BOiLS - +import glob import os from typing import List, Dict @@ -17,6 +17,10 @@ 'epfl_mtm': EPFL_MTM, } +for file in glob.glob(f"{get_circuits_path_root()}/*.blif"): + circ_name = os.path.basename(file[:-5]) + DESIGN_GROUPS[circ_name] = [circ_name] + EPFLS = [EPFL_ARITHMETIC, EPFL_CONTROL, EPFL_MTM] for epfl in EPFLS: for design in epfl: @@ -41,7 +45,7 @@ def get_designs_path(designs_id: str, frac_part: str = None) -> List[str]: if designs_id in DESIGN_GROUPS_PERSO: group = DESIGN_GROUPS_PERSO[designs_id] except ModuleNotFoundError: - pass + raise for design_id in group: designs_filepath.append(os.path.join(get_circuits_path_root(), f'{design_id}.blif')) if frac_part is None: diff --git a/combopt/comb_opt/tasks/eda_seq_opt/utils/utils_epfl.py b/combopt/comb_opt/tasks/eda_seq_opt/utils/utils_epfl.py index f290d3b0..a624ee27 100644 --- a/combopt/comb_opt/tasks/eda_seq_opt/utils/utils_epfl.py +++ b/combopt/comb_opt/tasks/eda_seq_opt/utils/utils_epfl.py @@ -1,53 +1,103 @@ -""" 11th July 2022 """ - EPFL_BEST_LUT = { - 'adder': {'corr. LUT': [185], 'corr. lvl': [119]}, + 'adder': {'corr. LUT': [129], 'corr. lvl': [126]}, 'bar': {'corr. LUT': [512], 'corr. lvl': [4]}, - 'div': {'corr. LUT': [3248], 'corr. lvl': [1194]}, - 'hyp': {'corr. LUT': [39826], 'corr. lvl': [4492]}, - 'log2': {'corr. LUT': [6513], 'corr. lvl': [132]}, - 'max': {'corr. LUT': [522], 'corr. lvl': [189]}, - 'multiplier': {'corr. LUT': [4792], 'corr. lvl': [114]}, - 'sin': {'corr. LUT': [1205], 'corr. lvl': [61]}, - 'sqrt': {'corr. LUT': [3027], 'corr. lvl': [1096]}, - 'square': {'corr. LUT': [3232], 'corr. lvl': [76]}, - 'arbiter': {'corr. LUT': [304], 'corr. lvl': [80]}, - 'ctrl': {'corr. LUT': [26], 'corr. lvl': [2]}, - 'cavlc': {'corr. LUT': [68], 'corr. lvl': [3]}, + 'div': {'corr. LUT': [3096], 'corr. lvl': [1095]}, + 'hyp': {'corr. LUT': [39452], 'corr. lvl': [4496]}, + 'log2': {'corr. LUT': [6131], 'corr. lvl': [199]}, + 'max': {'corr. LUT': [511], 'corr. lvl': [183]}, + 'multiplier': {'corr. LUT': [4352], 'corr. lvl': [163]}, + 'sin': {'corr. LUT': [1101], 'corr. lvl': [61]}, + 'sqrt': {'corr. LUT': [2993], 'corr. lvl': [1082]}, + 'square': {'corr. LUT': [3018], 'corr. lvl': [123]}, + 'arbiter': {'corr. LUT': [270], 'corr. lvl': [66]}, + 'ctrl': {'corr. LUT': [25], 'corr. lvl': [2]}, + 'cavlc': {'corr. LUT': [54], 'corr. lvl': [6]}, 'dec': {'corr. LUT': [264], 'corr. lvl': [2]}, - 'i2c': {'corr. LUT': [200], 'corr. lvl': [10]}, - 'int2float': {'corr. LUT': [24], 'corr. lvl': [4]}, - 'mem_ctrl': {'corr. LUT': [2019], 'corr. lvl': [21]}, - 'priority': {'corr. LUT': [100], 'corr. lvl': [26]}, - 'router': {'corr. LUT': [50], 'corr. lvl': [5]}, - 'voter': {'corr. LUT': [1279], 'corr. lvl': [19]}, - 'sixteen': {'corr. LUT': [3511769], 'corr. lvl': [32]}, - 'twenty': {'corr. LUT': [4393495], 'corr. lvl': [33]}, - 'twentythree': {'corr. LUT': [4908145], 'corr. lvl': [34]}, + 'i2c': {'corr. LUT': [182], 'corr. lvl': [7]}, + 'int2float': {'corr. LUT': [20], 'corr. lvl': [3]}, + 'mem_ctrl': {'corr. LUT': [1735], 'corr. lvl': [14]}, + 'priority': {'corr. LUT': [94], 'corr. lvl': [19]}, + 'router': {'corr. LUT': [19], 'corr. lvl': [5]}, + 'voter': {'corr. LUT': [1217], 'corr. lvl': [21]}, + 'sixteen': {'corr. LUT': [3282958], 'corr. lvl': [23]}, + 'twenty': {'corr. LUT': [4166467], 'corr. lvl': [24]}, + 'twentythree': {'corr. LUT': [4708920], 'corr. lvl': [25]}, } EPFL_BEST_LVL = { - 'adder': {'corr. LUT': [379], 'corr. lvl': [5]}, + 'adder': {'corr. LUT': [348], 'corr. lvl': [5]}, + 'bar': {'corr. LUT': [512], 'corr. lvl': [4]}, + 'div': {'corr. LUT': [23922], 'corr. lvl': [179]}, + 'hyp': {'corr. LUT': [176880], 'corr. lvl': [493]}, + 'log2': {'corr. LUT': [8715], 'corr. lvl': [52]}, + 'max': {'corr. LUT': [1201], 'corr. lvl': [7]}, + 'multiplier': {'corr. LUT': [12851], 'corr. lvl': [25]}, + 'sin': {'corr. LUT': [683558], 'corr. lvl': [10]}, + 'sqrt': {'corr. LUT': [41599], 'corr. lvl': [173]}, + 'square': {'corr. LUT': [3830], 'corr. lvl': [10]}, + 'arbiter': {'corr. LUT': [370], 'corr. lvl': [5]}, + 'ctrl': {'corr. LUT': [25], 'corr. lvl': [2]}, + 'cavlc': {'corr. LUT': [60], 'corr. lvl': [3]}, + 'dec': {'corr. LUT': [264], 'corr. lvl': [2]}, + 'i2c': {'corr. LUT': [195], 'corr. lvl': [3]}, + 'int2float': {'corr. LUT': [20], 'corr. lvl': [3]}, + 'mem_ctrl': {'corr. LUT': [1888], 'corr. lvl': [6]}, + 'priority': {'corr. LUT': [119], 'corr. lvl': [4]}, + 'router': {'corr. LUT': [25], 'corr. lvl': [3]}, + 'voter': {'corr. LUT': [1405], 'corr. lvl': [11]}, + 'sixteen': {'corr. LUT': [3387001], 'corr. lvl': [14]}, + 'twenty': {'corr. LUT': [4381634], 'corr. lvl': [14]}, + 'twentythree': {'corr. LUT': [4913996], 'corr. lvl': [15]}, +} + +SHADOW_EPFL_BEST_LUT = { + 'adder': {'corr. LUT': [129], 'corr. lvl': [126]}, + 'bar': {'corr. LUT': [512], 'corr. lvl': [4]}, + 'div': {'corr. LUT': [3096], 'corr. lvl': [1095]}, + 'hyp': {'corr. LUT': [39452], 'corr. lvl': [4496]}, + 'log2': {'corr. LUT': [6131], 'corr. lvl': [199]}, + 'max': {'corr. LUT': [511], 'corr. lvl': [183]}, + 'multiplier': {'corr. LUT': [4352], 'corr. lvl': [163]}, + 'sin': {'corr. LUT': [1101], 'corr. lvl': [61]}, + 'sqrt': {'corr. LUT': [2993], 'corr. lvl': [1082]}, + 'square': {'corr. LUT': [3018], 'corr. lvl': [123]}, + 'arbiter': {'corr. LUT': [270], 'corr. lvl': [66]}, + 'ctrl': {'corr. LUT': [25], 'corr. lvl': [2]}, + 'cavlc': {'corr. LUT': [54], 'corr. lvl': [6]}, + 'dec': {'corr. LUT': [264], 'corr. lvl': [2]}, + 'i2c': {'corr. LUT': [182], 'corr. lvl': [7]}, + 'int2float': {'corr. LUT': [20], 'corr. lvl': [3]}, + 'mem_ctrl': {'corr. LUT': [1735], 'corr. lvl': [14]}, + 'priority': {'corr. LUT': [94], 'corr. lvl': [19]}, + 'router': {'corr. LUT': [19], 'corr. lvl': [5]}, + 'voter': {'corr. LUT': [1217], 'corr. lvl': [21]}, + 'sixteen': {'corr. LUT': [3282958], 'corr. lvl': [23]}, + 'twenty': {'corr. LUT': [4166467], 'corr. lvl': [24]}, + 'twentythree': {'corr. LUT': [4708920], 'corr. lvl': [25]}, +} + +SHADOW_EPFL_BEST_LVL = { + 'adder': {'corr. LUT': [348], 'corr. lvl': [5]}, 'bar': {'corr. LUT': [512], 'corr. lvl': [4]}, - 'div': {'corr. LUT': [29369], 'corr. lvl': [197]}, - 'hyp': {'corr. LUT': [144809], 'corr. lvl': [501]}, - 'log2': {'corr. LUT': [8894], 'corr. lvl': [52]}, - 'max': {'corr. LUT': [811], 'corr. lvl': [10]}, - 'multiplier': {'corr. LUT': [13670], 'corr. lvl': [25]}, - 'sin': {'corr. LUT': [683103], 'corr. lvl': [10]}, - 'sqrt': {'corr. LUT': [25876], 'corr. lvl': [192]}, - 'square': {'corr. LUT': [4021], 'corr. lvl': [10]}, - 'arbiter': {'corr. LUT': [1162], 'corr. lvl': [5]}, - 'ctrl': {'corr. LUT': [26], 'corr. lvl': [2]}, - 'cavlc': {'corr. LUT': [68], 'corr. lvl': [3]}, + 'div': {'corr. LUT': [23922], 'corr. lvl': [179]}, + 'hyp': {'corr. LUT': [176880], 'corr. lvl': [493]}, + 'log2': {'corr. LUT': [8715], 'corr. lvl': [52]}, + 'max': {'corr. LUT': [1201], 'corr. lvl': [7]}, + 'multiplier': {'corr. LUT': [12851], 'corr. lvl': [25]}, + 'sin': {'corr. LUT': [681558], 'corr. lvl': [10]}, + 'sqrt': {'corr. LUT': [41599], 'corr. lvl': [173]}, + 'square': {'corr. LUT': [3830], 'corr. lvl': [10]}, + 'arbiter': {'corr. LUT': [370], 'corr. lvl': [5]}, + 'ctrl': {'corr. LUT': [25], 'corr. lvl': [2]}, + 'cavlc': {'corr. LUT': [60], 'corr. lvl': [3]}, 'dec': {'corr. LUT': [264], 'corr. lvl': [2]}, - 'i2c': {'corr. LUT': [221], 'corr. lvl': [3]}, - 'int2float': {'corr. LUT': [27], 'corr. lvl': [3]}, - 'mem_ctrl': {'corr. LUT': [2225], 'corr. lvl': [6]}, - 'priority': {'corr. LUT': [132], 'corr. lvl': [4]}, - 'router': {'corr. LUT': [56], 'corr. lvl': [3]}, - 'voter': {'corr. LUT': [1386], 'corr. lvl': [12]}, - 'sixteen': {'corr. LUT': [5396002], 'corr. lvl': [16]}, - 'twenty': {'corr. LUT': [6928118], 'corr. lvl': [16]}, - 'twentythree': {'corr. LUT': [7922493], 'corr. lvl': [17]}, + 'i2c': {'corr. LUT': [195], 'corr. lvl': [3]}, + 'int2float': {'corr. LUT': [20], 'corr. lvl': [3]}, + 'mem_ctrl': {'corr. LUT': [1888], 'corr. lvl': [6]}, + 'priority': {'corr. LUT': [119], 'corr. lvl': [4]}, + 'router': {'corr. LUT': [25], 'corr. lvl': [3]}, + 'voter': {'corr. LUT': [1405], 'corr. lvl': [11]}, + 'sixteen': {'corr. LUT': [3387001], 'corr. lvl': [14]}, + 'twenty': {'corr. LUT': [4381634], 'corr. lvl': [14]}, + 'twentythree': {'corr. LUT': [4913996], 'corr. lvl': [15]}, } diff --git a/combopt/comb_opt/utils/pymoo_utils.py b/combopt/comb_opt/utils/pymoo_utils.py index 073e072c..6be2bdb5 100644 --- a/combopt/comb_opt/utils/pymoo_utils.py +++ b/combopt/comb_opt/utils/pymoo_utils.py @@ -3,6 +3,9 @@ import numpy as np import pandas as pd import torch +from pymoo.config import Config +Config.warnings['not_compiled'] = False + from pymoo.core.problem import Problem from pymoo.core.repair import Repair from pymoo.core.variable import Real, Integer, Choice, Binary, Variable diff --git a/combopt/experiments/benchmark_baselines/benchmark_baselines_ackley.py b/combopt/experiments/benchmark_baselines/benchmark_baselines_ackley.py index 9d42d8b3..b44ff227 100644 --- a/combopt/experiments/benchmark_baselines/benchmark_baselines_ackley.py +++ b/combopt/experiments/benchmark_baselines/benchmark_baselines_ackley.py @@ -7,8 +7,8 @@ sys.path.insert(0, str(Path(os.path.realpath(__file__)).parent.parent.parent)) from comb_opt.factory import task_factory -from comb_opt.optimizers import RandomSearch, LocalSearch, SimulatedAnnealing, PymooGeneticAlgorithm, BOCS, BOSS, \ - COMBO, Casmopolitan, BOiLS, MultiArmedBandit +from comb_opt.optimizers import RandomSearch, LocalSearch, SimulatedAnnealing, BOCS, BOSS, \ + COMBO, Casmopolitan, BOiLS, MultiArmedBandit, GeneticAlgorithm from comb_opt.utils.experiment_utils import run_experiment if __name__ == '__main__': @@ -25,13 +25,14 @@ rs_optim = RandomSearch(search_space=search_space, dtype=dtype) ls_optim = LocalSearch(search_space=search_space, dtype=dtype) sa_optim = SimulatedAnnealing(search_space=search_space, dtype=dtype) - ga_optim = PymooGeneticAlgorithm(search_space=search_space, dtype=dtype) + ga_optim = GeneticAlgorithm(search_space=search_space, dtype=dtype) bocs = BOCS(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) boss = BOSS(search_space=search_space, n_init=bo_n_init, model_max_batch_size=50, dtype=dtype, device=bo_device) combo = COMBO(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) casmopolitan = Casmopolitan(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) boils = BOiLS(search_space=search_space, n_init=bo_n_init, model_max_batch_size=50, dtype=dtype, device=bo_device) - mab_optim = MultiArmedBandit(search_space=search_space, batch_size=1, max_n_iter=200, noisy_black_box=False, dtype=dtype) + mab_optim = MultiArmedBandit(search_space=search_space, batch_size=1, max_n_iter=200, noisy_black_box=False, + dtype=dtype) optimizers = [boss, boils, casmopolitan, combo, bocs, rs_optim, ls_optim, sa_optim, ga_optim, mab_optim] diff --git a/combopt/experiments/benchmark_baselines/benchmark_baselines_ackley53.py b/combopt/experiments/benchmark_baselines/benchmark_baselines_ackley53.py index 6fc2ca74..8d2cbdb1 100644 --- a/combopt/experiments/benchmark_baselines/benchmark_baselines_ackley53.py +++ b/combopt/experiments/benchmark_baselines/benchmark_baselines_ackley53.py @@ -7,8 +7,8 @@ sys.path.insert(0, str(Path(os.path.realpath(__file__)).parent.parent.parent)) from comb_opt.factory import task_factory -from comb_opt.optimizers import RandomSearch, LocalSearch, SimulatedAnnealing, PymooGeneticAlgorithm, Casmopolitan, \ - CoCaBO +from comb_opt.optimizers import RandomSearch, LocalSearch, SimulatedAnnealing, Casmopolitan, \ + CoCaBO, GeneticAlgorithm from comb_opt.utils.experiment_utils import run_experiment if __name__ == '__main__': @@ -32,7 +32,7 @@ rs_optim = RandomSearch(search_space=search_space, dtype=dtype) ls_optim = LocalSearch(search_space=search_space, dtype=dtype) sa_optim = SimulatedAnnealing(search_space=search_space, dtype=dtype) - ga_optim = PymooGeneticAlgorithm(search_space=search_space, dtype=dtype) + ga_optim = GeneticAlgorithm(search_space=search_space, dtype=dtype) casmopolitan = Casmopolitan(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) cocabo = CoCaBO(search_space=search_space, n_init=bo_n_init) diff --git a/combopt/experiments/benchmark_baselines/benchmark_baselines_aig_optim_basic.py b/combopt/experiments/benchmark_baselines/benchmark_baselines_aig_optim_basic.py index 42e98c4e..4430e8af 100644 --- a/combopt/experiments/benchmark_baselines/benchmark_baselines_aig_optim_basic.py +++ b/combopt/experiments/benchmark_baselines/benchmark_baselines_aig_optim_basic.py @@ -7,8 +7,8 @@ sys.path.insert(0, str(Path(os.path.realpath(__file__)).parent.parent.parent)) from comb_opt.factory import task_factory -from comb_opt.optimizers import RandomSearch, LocalSearch, SimulatedAnnealing, PymooGeneticAlgorithm, BOCS, BOSS, COMBO, \ - Casmopolitan, BOiLS, MultiArmedBandit +from comb_opt.optimizers import RandomSearch, LocalSearch, SimulatedAnnealing, BOCS, BOSS, COMBO, \ + Casmopolitan, BOiLS, MultiArmedBandit, GeneticAlgorithm from comb_opt.utils.experiment_utils import run_experiment if __name__ == '__main__': @@ -25,7 +25,7 @@ rs_optim = RandomSearch(search_space=search_space, dtype=dtype) ls_optim = LocalSearch(search_space=search_space, dtype=dtype) sa_optim = SimulatedAnnealing(search_space=search_space, dtype=dtype) - ga_optim = PymooGeneticAlgorithm(search_space=search_space, dtype=dtype) + ga_optim = GeneticAlgorithm(search_space=search_space, dtype=dtype) bocs = BOCS(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) boss = BOSS(search_space=search_space, n_init=bo_n_init, model_max_batch_size=50, dtype=dtype, device=bo_device) combo = COMBO(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) diff --git a/combopt/experiments/benchmark_baselines/benchmark_baselines_aig_optim_hyp.py b/combopt/experiments/benchmark_baselines/benchmark_baselines_aig_optim_hyp.py index f00b3d57..1b5c78b3 100644 --- a/combopt/experiments/benchmark_baselines/benchmark_baselines_aig_optim_hyp.py +++ b/combopt/experiments/benchmark_baselines/benchmark_baselines_aig_optim_hyp.py @@ -7,8 +7,8 @@ sys.path.insert(0, str(Path(os.path.realpath(__file__)).parent.parent.parent)) from comb_opt.factory import task_factory -from comb_opt.optimizers import RandomSearch, LocalSearch, SimulatedAnnealing, PymooGeneticAlgorithm, Casmopolitan, \ - CoCaBO +from comb_opt.optimizers import RandomSearch, LocalSearch, SimulatedAnnealing, Casmopolitan, \ + CoCaBO, GeneticAlgorithm from comb_opt.utils.experiment_utils import run_experiment if __name__ == '__main__': @@ -25,18 +25,18 @@ rs_optim = RandomSearch(search_space=search_space, dtype=dtype) ls_optim = LocalSearch(search_space=search_space, dtype=dtype) sa_optim = SimulatedAnnealing(search_space=search_space, dtype=dtype) - ga_optim = PymooGeneticAlgorithm(search_space=search_space, dtype=dtype) + ga_optim = GeneticAlgorithm(search_space=search_space, dtype=dtype) casmopolitan = Casmopolitan(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) cocabo = CoCaBO(search_space=search_space, n_init=bo_n_init) optimizers = [ # casmopolitan, - # cocabo, - rs_optim, - ls_optim, - sa_optim, - ga_optim, + cocabo, + # rs_optim, + # ls_optim, + # sa_optim, + # ga_optim, ] run_experiment(task=task, optimizers=optimizers, random_seeds=random_seeds, max_num_iter=max_num_iter, - very_verbose=1) + very_verbose=0) diff --git a/combopt/experiments/benchmark_baselines/benchmark_baselines_antibody_design.py b/combopt/experiments/benchmark_baselines/benchmark_baselines_antibody_design.py index 66e464fd..ab9fbb70 100644 --- a/combopt/experiments/benchmark_baselines/benchmark_baselines_antibody_design.py +++ b/combopt/experiments/benchmark_baselines/benchmark_baselines_antibody_design.py @@ -1,3 +1,4 @@ +import argparse import os import sys from pathlib import Path @@ -7,35 +8,55 @@ sys.path.insert(0, str(Path(os.path.realpath(__file__)).parent.parent.parent)) from comb_opt.factory import task_factory -from comb_opt.optimizers import RandomSearch, LocalSearch, SimulatedAnnealing, PymooGeneticAlgorithm, BOCS, BOSS, COMBO, \ - CoCaBO, Casmopolitan, BOiLS, MultiArmedBandit +from comb_opt.optimizers import RandomSearch, LocalSearch, SimulatedAnnealing, BOCS, BOSS, COMBO, \ + BOiLS, MultiArmedBandit, GeneticAlgorithm, Casmopolitan from comb_opt.utils.experiment_utils import run_experiment if __name__ == '__main__': + parser = argparse.ArgumentParser(add_help=True, description='BOF - Baselines - Antibody design') + parser.add_argument("--device_id", type=int, default=0, help="Cuda device id (cpu is used if id is negative)") + parser.add_argument("--absolut_dir", type=str, default=None, help="Path to AbsolutNoLib") + + args = parser.parse_args() + task_name = 'antibody_design' - task_kwargs = {'num_cpus': 10, 'first_cpu': 10} + task_kwargs = {'num_cpus': 5, 'first_cpu': 0, 'absolut_dir': args.absolut_dir} + dtype = torch.float32 + task, search_space = task_factory(task_name, dtype, **task_kwargs) + bo_n_init = 20 - bo_device = torch.device('cuda:0') + if args.device_id >= 0 and torch.cuda.is_available(): + bo_device = torch.device(f'cuda:{args.device_id}') + else: + bo_device = torch.device("cpu") + max_num_iter = 200 - dtype = torch.float32 random_seeds = [42, 43, 44, 45, 46] - task, search_space = task_factory(task_name, dtype, **task_kwargs) - rs_optim = RandomSearch(search_space=search_space, dtype=dtype) ls_optim = LocalSearch(search_space=search_space, dtype=dtype) sa_optim = SimulatedAnnealing(search_space=search_space, dtype=dtype) - ga_optim = PymooGeneticAlgorithm(search_space=search_space, dtype=dtype) + ga_optim = GeneticAlgorithm(search_space=search_space, dtype=dtype) bocs = BOCS(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) boss = BOSS(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) combo = COMBO(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) - cocabo = CoCaBO(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) - casmopolitan = Casmopolitan(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) boils = BOiLS(search_space=search_space, n_init=bo_n_init, model_max_batch_size=50, dtype=dtype, device=bo_device) + casmopolitan = Casmopolitan(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) mab_optim = MultiArmedBandit(search_space=search_space, batch_size=1, max_n_iter=200, noisy_black_box=False, dtype=dtype) - optimizers = [boss, boils, casmopolitan, combo, bocs, mab_optim, rs_optim, ls_optim, sa_optim, ga_optim] + optimizers = [ + # casmopolitan, + # boss, + # boils, + # combo, + # bocs, + # mab_optim, + # rs_optim, + # ls_optim, + # sa_optim, + # ga_optim + ] run_experiment(task=task, optimizers=optimizers, random_seeds=random_seeds, max_num_iter=max_num_iter, very_verbose=True) diff --git a/combopt/experiments/benchmark_baselines/benchmark_baselines_mig_optim_basic.py b/combopt/experiments/benchmark_baselines/benchmark_baselines_mig_optim_basic.py index 6e7d3a21..2626c682 100644 --- a/combopt/experiments/benchmark_baselines/benchmark_baselines_mig_optim_basic.py +++ b/combopt/experiments/benchmark_baselines/benchmark_baselines_mig_optim_basic.py @@ -8,7 +8,7 @@ from comb_opt.factory import task_factory from comb_opt.optimizers import RandomSearch, LocalSearch, SimulatedAnnealing, BOCS, BOSS, COMBO, \ - Casmopolitan, BOiLS, PymooGeneticAlgorithm, MultiArmedBandit + Casmopolitan, BOiLS, MultiArmedBandit, GeneticAlgorithm from comb_opt.utils.experiment_utils import run_experiment if __name__ == '__main__': @@ -25,7 +25,7 @@ rs_optim = RandomSearch(search_space=search_space, dtype=dtype) ls_optim = LocalSearch(search_space=search_space, dtype=dtype) sa_optim = SimulatedAnnealing(search_space=search_space, dtype=dtype) - ga_optim = PymooGeneticAlgorithm(search_space=search_space, dtype=dtype) + ga_optim = GeneticAlgorithm(search_space=search_space, dtype=dtype) bocs = BOCS(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) boss = BOSS(search_space=search_space, n_init=bo_n_init, model_max_batch_size=50, dtype=dtype, device=bo_device) combo = COMBO(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) @@ -35,15 +35,15 @@ casmopolitan = Casmopolitan(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) optimizers = [ - boss, + # boss, # boils, - casmopolitan, + # casmopolitan, # combo, - bocs, + # bocs, # rs_optim, - ls_optim, + # ls_optim, # sa_optim, - ga_optim, + # ga_optim, # mab_optim ] diff --git a/combopt/experiments/benchmark_baselines/benchmark_baselines_mixed_levy.py b/combopt/experiments/benchmark_baselines/benchmark_baselines_mixed_levy.py index 23d48e6e..bca36109 100644 --- a/combopt/experiments/benchmark_baselines/benchmark_baselines_mixed_levy.py +++ b/combopt/experiments/benchmark_baselines/benchmark_baselines_mixed_levy.py @@ -7,7 +7,8 @@ sys.path.insert(0, str(Path(os.path.realpath(__file__)).parent.parent.parent)) from comb_opt.factory import task_factory -from comb_opt.optimizers import RandomSearch, LocalSearch, SimulatedAnnealing, PymooGeneticAlgorithm, CoCaBO, Casmopolitan +from comb_opt.optimizers import RandomSearch, LocalSearch, SimulatedAnnealing, CoCaBO, \ + Casmopolitan, GeneticAlgorithm from comb_opt.utils.experiment_utils import run_experiment if __name__ == '__main__': @@ -31,7 +32,7 @@ rs_optim = RandomSearch(search_space=search_space, dtype=dtype) ls_optim = LocalSearch(search_space=search_space, dtype=dtype) sa_optim = SimulatedAnnealing(search_space=search_space, dtype=dtype) - ga_optim = PymooGeneticAlgorithm(search_space=search_space, dtype=dtype) + ga_optim = GeneticAlgorithm(search_space=search_space, dtype=dtype) casmopolitan = Casmopolitan(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) cocabo = CoCaBO(search_space=search_space, n_init=bo_n_init) diff --git a/combopt/experiments/benchmark_baselines/benchmark_baselines_pest_control.py b/combopt/experiments/benchmark_baselines/benchmark_baselines_pest_control.py index a0d21ca8..5fc33374 100644 --- a/combopt/experiments/benchmark_baselines/benchmark_baselines_pest_control.py +++ b/combopt/experiments/benchmark_baselines/benchmark_baselines_pest_control.py @@ -7,8 +7,8 @@ sys.path.insert(0, str(Path(os.path.realpath(__file__)).parent.parent.parent)) from comb_opt.factory import task_factory -from comb_opt.optimizers import RandomSearch, LocalSearch, SimulatedAnnealing, PymooGeneticAlgorithm, BOCS, BOSS, COMBO, \ - Casmopolitan, BOiLS, MultiArmedBandit +from comb_opt.optimizers import RandomSearch, LocalSearch, SimulatedAnnealing, BOCS, BOSS, COMBO, \ + Casmopolitan, BOiLS, MultiArmedBandit, GeneticAlgorithm from comb_opt.utils.experiment_utils import run_experiment if __name__ == '__main__': @@ -25,7 +25,7 @@ rs_optim = RandomSearch(search_space=search_space, dtype=dtype) ls_optim = LocalSearch(search_space=search_space, dtype=dtype) sa_optim = SimulatedAnnealing(search_space=search_space, dtype=dtype) - ga_optim = PymooGeneticAlgorithm(search_space=search_space, dtype=dtype) + ga_optim = GeneticAlgorithm(search_space=search_space, dtype=dtype) bocs = BOCS(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) boss = BOSS(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) combo = COMBO(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) diff --git a/combopt/experiments/benchmark_baselines/benchmark_baselines_rna_inverse_fold.py b/combopt/experiments/benchmark_baselines/benchmark_baselines_rna_inverse_fold.py index 0de6333a..cad9053f 100644 --- a/combopt/experiments/benchmark_baselines/benchmark_baselines_rna_inverse_fold.py +++ b/combopt/experiments/benchmark_baselines/benchmark_baselines_rna_inverse_fold.py @@ -7,25 +7,26 @@ sys.path.insert(0, str(Path(os.path.realpath(__file__)).parent.parent.parent)) from comb_opt.factory import task_factory -from comb_opt.optimizers import RandomSearch, LocalSearch, SimulatedAnnealing, PymooGeneticAlgorithm, BOCS, BOSS, COMBO, \ - Casmopolitan, BOiLS, MultiArmedBandit +from comb_opt.optimizers import RandomSearch, LocalSearch, SimulatedAnnealing, BOCS, BOSS, COMBO, \ + Casmopolitan, BOiLS, MultiArmedBandit, GeneticAlgorithm from comb_opt.utils.experiment_utils import run_experiment if __name__ == '__main__': task_name = 'rna_inverse_fold' task_kwargs = {'target': 65} + dtype = torch.float32 + + task, search_space = task_factory(task_name, dtype, **task_kwargs) + bo_n_init = 20 bo_device = torch.device('cuda:1') max_num_iter = 200 - dtype = torch.float32 random_seeds = [42, 43, 44, 45, 46] - task, search_space = task_factory(task_name, dtype, **task_kwargs) - rs_optim = RandomSearch(search_space=search_space, dtype=dtype) ls_optim = LocalSearch(search_space=search_space, dtype=dtype) sa_optim = SimulatedAnnealing(search_space=search_space, dtype=dtype) - ga_optim = PymooGeneticAlgorithm(search_space=search_space, dtype=dtype) + ga_optim = GeneticAlgorithm(search_space=search_space, dtype=dtype) bocs = BOCS(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) boss = BOSS(search_space=search_space, n_init=bo_n_init, model_max_batch_size=50, dtype=dtype, device=bo_device) combo = COMBO(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) diff --git a/combopt/experiments/benchmark_baselines/benchmark_baselines_svm_opt.py b/combopt/experiments/benchmark_baselines/benchmark_baselines_svm_opt.py index c4d4ff09..8777c372 100644 --- a/combopt/experiments/benchmark_baselines/benchmark_baselines_svm_opt.py +++ b/combopt/experiments/benchmark_baselines/benchmark_baselines_svm_opt.py @@ -8,7 +8,7 @@ from comb_opt.factory import task_factory from comb_opt.optimizers import RandomSearch, LocalSearch, SimulatedAnnealing, Casmopolitan, CoCaBO, \ - PymooGeneticAlgorithm + GeneticAlgorithm from comb_opt.utils.experiment_utils import run_experiment if __name__ == '__main__': @@ -24,7 +24,7 @@ rs_optim = RandomSearch(search_space=search_space, dtype=dtype) ls_optim = LocalSearch(search_space=search_space, dtype=dtype) sa_optim = SimulatedAnnealing(search_space=search_space, dtype=dtype) - ga_optim = PymooGeneticAlgorithm(search_space=search_space, dtype=dtype) + ga_optim = GeneticAlgorithm(search_space=search_space, dtype=dtype) casmopolitan = Casmopolitan(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) cocabo = CoCaBO(search_space=search_space, n_init=bo_n_init) diff --git a/combopt/experiments/benchmark_baselines/benchmark_baselines_xgboost_opt.py b/combopt/experiments/benchmark_baselines/benchmark_baselines_xgboost_opt.py index 61681117..aac73b25 100644 --- a/combopt/experiments/benchmark_baselines/benchmark_baselines_xgboost_opt.py +++ b/combopt/experiments/benchmark_baselines/benchmark_baselines_xgboost_opt.py @@ -8,7 +8,7 @@ from comb_opt.factory import task_factory from comb_opt.optimizers import RandomSearch, LocalSearch, SimulatedAnnealing, Casmopolitan, CoCaBO, \ - PymooGeneticAlgorithm + GeneticAlgorithm from comb_opt.utils.experiment_utils import run_experiment if __name__ == '__main__': @@ -25,7 +25,7 @@ rs_optim = RandomSearch(search_space=search_space, dtype=dtype) ls_optim = LocalSearch(search_space=search_space, dtype=dtype) sa_optim = SimulatedAnnealing(search_space=search_space, dtype=dtype) - ga_optim = PymooGeneticAlgorithm(search_space=search_space, dtype=dtype) + ga_optim = GeneticAlgorithm(search_space=search_space, dtype=dtype) casmopolitan = Casmopolitan(search_space=search_space, n_init=bo_n_init, dtype=dtype, device=bo_device) cocabo = CoCaBO(search_space=search_space, n_init=bo_n_init) diff --git a/combopt/experiments/benchmark_baselines/run_benchmark_baselines_nominal_tasks.sh b/combopt/experiments/benchmark_baselines/run_benchmark_baselines_nominal_tasks.sh index 05b702b1..e8a6ed3a 100644 --- a/combopt/experiments/benchmark_baselines/run_benchmark_baselines_nominal_tasks.sh +++ b/combopt/experiments/benchmark_baselines/run_benchmark_baselines_nominal_tasks.sh @@ -1,7 +1,6 @@ #!/bin/bash TASKS=( ackley aig_optim_basic antibody_design mig_optim pest_control rna_inverse_fold ) -TASKS=( ackley aig_optim_basic pest_control rna_inverse_fold ) HEAD=./experiments/benchmark_baselines/benchmark_baselines_ @@ -10,4 +9,8 @@ for task_id in $(seq 0 $((${#TASKS[@]} - 1))); do cmd="taskset -c 25-30 python $HEAD${task}.py" echo $cmd $cmd -done \ No newline at end of file +done + +# taskset -c 5-9 python experiments/benchmark_baselines/benchmark_baselines_antibody_design.py --device_id 1 --absolut_dir /home/kamild/projects/combopt/libs/Absolut2/src/AbsolutNoLib +# taskset -c 10-14 python experiments/mix_and_match/mix_and_match_antibody_design.py --device_id 0 --absolut_dir /home/kamild/projects/combopt/libs/Absolut3/src/AbsolutNoLib +# taskset -c 15-19 python experiments/mix_and_match/mix_and_match_antibody_design.py --use_tr --device_id 1 --absolut_dir /home/kamild/projects/combopt/libs/Absolut4/src/AbsolutNoLib diff --git a/combopt/experiments/mix_and_match/mix_and_match_ackley.py b/combopt/experiments/mix_and_match/mix_and_match_ackley.py deleted file mode 100644 index 5df442f8..00000000 --- a/combopt/experiments/mix_and_match/mix_and_match_ackley.py +++ /dev/null @@ -1,66 +0,0 @@ -import os -import sys -from pathlib import Path - -import torch - -sys.path.insert(0, str(Path(os.path.realpath(__file__)).parent.parent.parent)) - -from comb_opt.factory import task_factory -from comb_opt.utils.experiment_utils import run_experiment - -from comb_opt.optimizers.mix_and_match.gp_to_ker_ga_acq_optim import GpToGaAcqOptim -from comb_opt.optimizers.mix_and_match.gp_to_ker_sa_acq_optim import GpToSaAcqOptim -from comb_opt.optimizers.mix_and_match.gp_to_ker_ls_acq_optim import GpToLsAcqOptim -from comb_opt.optimizers.mix_and_match.gp_diff_ker_ga_acq_optim import GpDiffusionGaAcqOptim -from comb_opt.optimizers.mix_and_match.gp_diff_ker_sa_acq_optim import GpDiffusionSaAcqOptim -from comb_opt.optimizers.mix_and_match.gp_diff_ker_is_acq_optim import GpDiffusionTrLsAcqOptim -from comb_opt.optimizers.mix_and_match.gp_ssk_ker_ls_acq_optim import GpSskLsAcqOptim -from comb_opt.optimizers.mix_and_match.gp_ssk_ker_sa_acq_optim import GpSskSaAcqOptim -from comb_opt.optimizers.mix_and_match.lr_ga_acq_optim import LrSparseHsGaAcqOptim -from comb_opt.optimizers.mix_and_match.lr_is_acq_optim import LrSparseHsTrLsAcqOptim -from comb_opt.optimizers.mix_and_match.lr_ls_acq_optim import LrSparseHsExhaustiveLsAcqOptim - -if __name__ == '__main__': - task_name = 'ackley' - task_kwargs = {'num_dims': 20, 'variable_type': 'nominal', 'num_categories': 11} - bo_n_init = 20 - bo_device = torch.device('cuda:1') - max_num_iter = 200 - dtype = torch.float32 - random_seeds = [42, 43, 44, 45, 46] - - task, search_space = task_factory(task_name, dtype, **task_kwargs) - - gp_to_ga = GpToGaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - gp_to_sa = GpToSaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - gp_to_exhaustive_ls = GpToLsAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - - gp_diffusion_ga = GpDiffusionGaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - gp_diffusion_sa = GpDiffusionSaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - gp_diffusion_tr_ls = GpDiffusionTrLsAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - - gp_ssk_sa = GpSskSaAcqOptim(search_space, bo_n_init, model_max_batch_size=50, dtype=dtype, device=bo_device) - gp_ssk_exhaustive_ls = GpSskLsAcqOptim(search_space, bo_n_init, model_max_batch_size=50, dtype=dtype, - device=bo_device) - - lr_sparse_hs_ga = LrSparseHsGaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - lr_sparse_hs_tr_ls = LrSparseHsTrLsAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - lr_sparse_hs_exhaustive_ls = LrSparseHsExhaustiveLsAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - - optimizers = [ - gp_ssk_sa, - gp_ssk_exhaustive_ls, - gp_diffusion_ga, - gp_diffusion_sa, - gp_diffusion_tr_ls, - gp_to_ga, - gp_to_sa, - gp_to_exhaustive_ls, - lr_sparse_hs_ga, - lr_sparse_hs_tr_ls, - lr_sparse_hs_exhaustive_ls - ] - - run_experiment(task=task, optimizers=optimizers, random_seeds=random_seeds, max_num_iter=max_num_iter, - very_verbose=False) diff --git a/combopt/experiments/mix_and_match/mix_and_match_aig_optim_basic.py b/combopt/experiments/mix_and_match/mix_and_match_aig_optim_basic.py deleted file mode 100644 index 5e76f900..00000000 --- a/combopt/experiments/mix_and_match/mix_and_match_aig_optim_basic.py +++ /dev/null @@ -1,66 +0,0 @@ -import os -import sys -from pathlib import Path - -import torch - -sys.path.insert(0, str(Path(os.path.realpath(__file__)).parent.parent.parent)) - -from comb_opt.factory import task_factory -from comb_opt.utils.experiment_utils import run_experiment - -from comb_opt.optimizers.mix_and_match.gp_to_ker_ga_acq_optim import GpToGaAcqOptim -from comb_opt.optimizers.mix_and_match.gp_to_ker_sa_acq_optim import GpToSaAcqOptim -from comb_opt.optimizers.mix_and_match.gp_to_ker_ls_acq_optim import GpToLsAcqOptim -from comb_opt.optimizers.mix_and_match.gp_diff_ker_ga_acq_optim import GpDiffusionGaAcqOptim -from comb_opt.optimizers.mix_and_match.gp_diff_ker_sa_acq_optim import GpDiffusionSaAcqOptim -from comb_opt.optimizers.mix_and_match.gp_diff_ker_is_acq_optim import GpDiffusionTrLsAcqOptim -from comb_opt.optimizers.mix_and_match.gp_ssk_ker_ls_acq_optim import GpSskLsAcqOptim -from comb_opt.optimizers.mix_and_match.gp_ssk_ker_sa_acq_optim import GpSskSaAcqOptim -from comb_opt.optimizers.mix_and_match.lr_ga_acq_optim import LrSparseHsGaAcqOptim -from comb_opt.optimizers.mix_and_match.lr_is_acq_optim import LrSparseHsTrLsAcqOptim -from comb_opt.optimizers.mix_and_match.lr_ls_acq_optim import LrSparseHsExhaustiveLsAcqOptim - -if __name__ == '__main__': - task_name = 'aig_optimization' - task_kwargs = {'designs_group_id': "sin", "operator_space_id": "basic", "objective": "both"} - bo_n_init = 20 - bo_device = torch.device('cuda:0') - max_num_iter = 200 - dtype = torch.float32 - random_seeds = [42, 43, 44, 45, 46] - - task, search_space = task_factory(task_name, dtype, **task_kwargs) - - gp_to_ga = GpToGaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - gp_to_sa = GpToSaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - gp_to_exhaustive_ls = GpToLsAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - - gp_diffusion_ga = GpDiffusionGaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - gp_diffusion_sa = GpDiffusionSaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - gp_diffusion_tr_ls = GpDiffusionTrLsAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - - gp_ssk_sa = GpSskSaAcqOptim(search_space, bo_n_init, model_max_batch_size=50, dtype=dtype, device=bo_device) - gp_ssk_exhaustive_ls = GpSskLsAcqOptim(search_space, bo_n_init, model_max_batch_size=50, dtype=dtype, - device=bo_device) - - lr_sparse_hs_ga = LrSparseHsGaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - lr_sparse_hs_tr_ls = LrSparseHsTrLsAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - lr_sparse_hs_exhaustive_ls = LrSparseHsExhaustiveLsAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - - optimizers = [ - gp_ssk_sa, - gp_ssk_exhaustive_ls, - gp_diffusion_ga, - gp_diffusion_sa, - gp_diffusion_tr_ls, - gp_to_ga, - gp_to_sa, - gp_to_exhaustive_ls, - lr_sparse_hs_ga, - lr_sparse_hs_tr_ls, - lr_sparse_hs_exhaustive_ls - ] - - run_experiment(task=task, optimizers=optimizers, random_seeds=random_seeds, max_num_iter=max_num_iter, - very_verbose=False) diff --git a/combopt/experiments/mix_and_match/mix_and_match_antibody.py b/combopt/experiments/mix_and_match/mix_and_match_antibody.py deleted file mode 100644 index 6195889e..00000000 --- a/combopt/experiments/mix_and_match/mix_and_match_antibody.py +++ /dev/null @@ -1,55 +0,0 @@ -import os -import sys -from pathlib import Path - -import torch - -sys.path.insert(0, str(Path(os.path.realpath(__file__)).parent.parent.parent)) - -from comb_opt.factory import task_factory -from comb_opt.utils.experiment_utils import run_experiment - -from comb_opt.optimizers.mix_and_match.gp_to_ker_ga_acq_optim import GpToGaAcqOptim -from comb_opt.optimizers.mix_and_match.gp_to_ker_sa_acq_optim import GpToSaAcqOptim -from comb_opt.optimizers.mix_and_match.gp_to_ker_ls_acq_optim import GpToLsAcqOptim -from comb_opt.optimizers.mix_and_match.gp_diff_ker_ga_acq_optim import GpDiffusionGaAcqOptim -from comb_opt.optimizers.mix_and_match.gp_diff_ker_sa_acq_optim import GpDiffusionSaAcqOptim -from comb_opt.optimizers.mix_and_match.gp_diff_ker_is_acq_optim import GpDiffusionTrLsAcqOptim -from comb_opt.optimizers.mix_and_match.gp_ssk_ker_sa_acq_optim import GpSskSaAcqOptim -from comb_opt.optimizers.mix_and_match.gp_ssk_ker_ls_acq_optim import GpSskLsAcqOptim -from comb_opt.optimizers.mix_and_match.lr_ga_acq_optim import LrSparseHsGaAcqOptim -from comb_opt.optimizers.mix_and_match.lr_is_acq_optim import LrSparseHsTrLsAcqOptim -from comb_opt.optimizers.mix_and_match.lr_ls_acq_optim import LrSparseHsExhaustiveLsAcqOptim - -if __name__ == '__main__': - task_name = 'antibody_design' - task_kwargs = {'num_cpus': 10, 'first_cpu': 10} - bo_n_init = 20 - bo_device = torch.device('cuda:1') - max_num_iter = 200 - dtype = torch.float32 - random_seeds = [42, 43, 44, 45, 46] - - task, search_space = task_factory(task_name, dtype, **task_kwargs) - - gp_to_ga = GpToGaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - gp_to_sa = GpToSaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - gp_to_exhaustive_ls = GpToLsAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - - gp_diffusion_ga = GpDiffusionGaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - gp_diffusion_sa = GpDiffusionSaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - gp_diffusion_tr_ls = GpDiffusionTrLsAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - - gp_ssk_sa = GpSskSaAcqOptim(search_space, bo_n_init, model_max_batch_size=50, dtype=dtype, device=bo_device) - gp_ssk_exhaustive_ls = GpSskLsAcqOptim(search_space, bo_n_init, model_max_batch_size=50, dtype=dtype, - device=bo_device) - - lr_sparse_hs_ga = LrSparseHsGaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - lr_sparse_hs_tr_ls = LrSparseHsTrLsAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - lr_sparse_hs_exhaustive_ls = LrSparseHsExhaustiveLsAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - - optimizers = [gp_ssk_sa, gp_ssk_exhaustive_ls, gp_diffusion_ga, gp_diffusion_sa, gp_diffusion_tr_ls, gp_to_ga, - gp_to_sa, gp_to_exhaustive_ls, lr_sparse_hs_ga, lr_sparse_hs_tr_ls, lr_sparse_hs_exhaustive_ls] - - run_experiment(task=task, optimizers=optimizers, random_seeds=random_seeds, max_num_iter=max_num_iter, - very_verbose=False) diff --git a/combopt/experiments/mix_and_match/mix_and_match_antibody_design.py b/combopt/experiments/mix_and_match/mix_and_match_antibody_design.py new file mode 100644 index 00000000..e4f40347 --- /dev/null +++ b/combopt/experiments/mix_and_match/mix_and_match_antibody_design.py @@ -0,0 +1,122 @@ +import argparse +import os +import sys +from pathlib import Path + +import torch + +sys.path.insert(0, str(Path(os.path.realpath(__file__)).parent.parent.parent)) + +from comb_opt.factory import task_factory +from comb_opt.utils.experiment_utils import run_experiment + +from comb_opt.optimizers import COMBO, BOCS, BOSS, BOiLS, Casmopolitan +from comb_opt.optimizers.mix_and_match.gp_diff_ker_ga_acq_optim import GpDiffusionGaAcqOptim +from comb_opt.optimizers.mix_and_match.gp_diff_ker_is_acq_optim import GpDiffusionIsAcqOptim +from comb_opt.optimizers.mix_and_match.gp_diff_ker_sa_acq_optim import GpDiffusionSaAcqOptim +from comb_opt.optimizers.mix_and_match.gp_o_ker_ga_acq_optim import GpOGaAcqOptim +from comb_opt.optimizers.mix_and_match.gp_o_ker_is_acq_optim import GpOIsAcqOptim +from comb_opt.optimizers.mix_and_match.gp_o_ker_ls_acq_optim import GpOLsAcqOptim +from comb_opt.optimizers.mix_and_match.gp_o_ker_sa_acq_optim import GpOSaAcqOptim +from comb_opt.optimizers.mix_and_match.gp_ssk_ker_ls_acq_optim import GpSskLsAcqOptim +from comb_opt.optimizers.mix_and_match.gp_ssk_ker_sa_acq_optim import GpSskSaAcqOptim +from comb_opt.optimizers.mix_and_match.gp_to_ker_ls_acq_optim import GpToLsAcqOptim +from comb_opt.optimizers.mix_and_match.gp_to_ker_ga_acq_optim import GpToGaAcqOptim +from comb_opt.optimizers.mix_and_match.gp_to_ker_sa_acq_optim import GpToSaAcqOptim +from comb_opt.optimizers.mix_and_match.lr_ga_acq_optim import LrGaAcqOptim +from comb_opt.optimizers.mix_and_match.lr_is_acq_optim import LrIsAcqOptim +from comb_opt.optimizers.mix_and_match.lr_ls_acq_optim import LrLsAcqOptim + +if __name__ == '__main__': + parser = argparse.ArgumentParser(add_help=True, description='BOF - Mix And Match - Antibody design') + parser.add_argument("--device_id", type=int, default=0, help="Cuda device id (cpu is used if id is negative)") + parser.add_argument("--absolut_dir", type=str, default=None, help="Path to AbsolutNoLib") + parser.add_argument("--use_tr", action="store_true", help="Whether to use Trust-Region based methods") + + args = parser.parse_args() + + task_name = 'antibody_design' + task_kwargs = {'num_cpus': 5, 'first_cpu': 0, 'absolut_dir': args.absolut_dir} + dtype = torch.float32 + + task, search_space = task_factory(task_name, dtype, **task_kwargs) + + bo_n_init = 20 + if args.device_id >= 0 and torch.cuda.is_available(): + bo_device = torch.device(f'cuda:{args.device_id}') + else: + bo_device = torch.device("cpu") + + max_num_iter = 200 + random_seeds = [42, 43, 44, 45, 46] + + use_tr = args.use_tr + + opt_kwargs = dict(dtype=dtype, device=bo_device, use_tr=use_tr) + + gp_to_ga = GpToGaAcqOptim(search_space, bo_n_init, **opt_kwargs) + gp_to_sa = GpToSaAcqOptim(search_space, bo_n_init, **opt_kwargs) + gp_to_exhaustive_ls = GpToLsAcqOptim(search_space, bo_n_init, **opt_kwargs) + gp_to_is = None + if not use_tr: + gp_to_is = Casmopolitan(search_space, bo_n_init, **opt_kwargs) + + gp_o_ga = GpOGaAcqOptim(search_space=search_space, n_init=bo_n_init, **opt_kwargs) + gp_o_sa = GpOSaAcqOptim(search_space=search_space, n_init=bo_n_init, **opt_kwargs) + gp_o_ls = GpOLsAcqOptim(search_space=search_space, n_init=bo_n_init, **opt_kwargs) + gp_o_is = GpOIsAcqOptim(search_space=search_space, n_init=bo_n_init, **opt_kwargs) + + gp_diffusion_ga = GpDiffusionGaAcqOptim(search_space, bo_n_init, **opt_kwargs) + gp_diffusion_sa = GpDiffusionSaAcqOptim(search_space, bo_n_init, **opt_kwargs) + gp_diffusion_is = GpDiffusionIsAcqOptim(search_space, bo_n_init, **opt_kwargs) + gp_diffusion_ls = None + if use_tr: + gp_diffusion_ls = COMBO(search_space, bo_n_init, **opt_kwargs) + + gp_ssk_sa = GpSskSaAcqOptim(search_space, bo_n_init, model_max_batch_size=50, **opt_kwargs) + gp_ssk_ls = GpSskLsAcqOptim(search_space, bo_n_init, model_max_batch_size=50, **opt_kwargs) + gp_ssk_ga = None + if use_tr: + gp_ssk_ga = BOSS(search_space, bo_n_init, model_max_batch_size=50, **opt_kwargs) + gp_ssk_is = None + if not use_tr: + gp_ssk_is = BOiLS(search_space, bo_n_init, model_max_batch_size=50, **opt_kwargs) + + lr_sparse_hs_ga = LrGaAcqOptim(search_space, bo_n_init, **opt_kwargs) + lr_sparse_hs_ls = LrLsAcqOptim(search_space, bo_n_init, **opt_kwargs) + lr_sparse_hs_is = LrIsAcqOptim(search_space, bo_n_init, **opt_kwargs) + lr_sparse_hs_sa = None + if use_tr: + lr_sparse_hs_sa = BOCS(search_space, bo_n_init, **opt_kwargs) + + optimizers = [ + # gp_ssk_sa, + # gp_ssk_ls, + # gp_diffusion_ga, + # gp_diffusion_sa, + # gp_diffusion_is, + # gp_to_ga, + # gp_to_sa, + # gp_o_ga, + # gp_o_sa, + # gp_o_ls, + # gp_o_is, + # lr_sparse_hs_ga, + # lr_sparse_hs_ls, + # lr_sparse_hs_is + ] + + optional_opts = [ + # gp_to_is, + # gp_diffusion_ls, + # lr_sparse_hs_sa, + # gp_ssk_ga, + gp_ssk_is, + ] + + for opt in optional_opts: + if opt is not None: + optimizers.append(opt) + + run_experiment(task=task, optimizers=optimizers, random_seeds=random_seeds, max_num_iter=max_num_iter, + very_verbose=True) diff --git a/combopt/experiments/mix_and_match/mix_and_match_pest.py b/combopt/experiments/mix_and_match/mix_and_match_pest.py index 1ad151b0..e8a38a13 100644 --- a/combopt/experiments/mix_and_match/mix_and_match_pest.py +++ b/combopt/experiments/mix_and_match/mix_and_match_pest.py @@ -1,3 +1,4 @@ +import argparse import os import sys from pathlib import Path @@ -9,58 +10,112 @@ from comb_opt.factory import task_factory from comb_opt.utils.experiment_utils import run_experiment -from comb_opt.optimizers.mix_and_match.gp_to_ker_ga_acq_optim import GpToGaAcqOptim -from comb_opt.optimizers.mix_and_match.gp_to_ker_sa_acq_optim import GpToSaAcqOptim -from comb_opt.optimizers.mix_and_match.gp_to_ker_ls_acq_optim import GpToLsAcqOptim +from comb_opt.optimizers import COMBO, BOCS, BOSS, BOiLS, Casmopolitan from comb_opt.optimizers.mix_and_match.gp_diff_ker_ga_acq_optim import GpDiffusionGaAcqOptim +from comb_opt.optimizers.mix_and_match.gp_diff_ker_is_acq_optim import GpDiffusionIsAcqOptim from comb_opt.optimizers.mix_and_match.gp_diff_ker_sa_acq_optim import GpDiffusionSaAcqOptim -from comb_opt.optimizers.mix_and_match.gp_diff_ker_is_acq_optim import GpDiffusionTrLsAcqOptim +from comb_opt.optimizers.mix_and_match.gp_o_ker_ga_acq_optim import GpOGaAcqOptim +from comb_opt.optimizers.mix_and_match.gp_o_ker_is_acq_optim import GpOIsAcqOptim +from comb_opt.optimizers.mix_and_match.gp_o_ker_ls_acq_optim import GpOLsAcqOptim +from comb_opt.optimizers.mix_and_match.gp_o_ker_sa_acq_optim import GpOSaAcqOptim from comb_opt.optimizers.mix_and_match.gp_ssk_ker_ls_acq_optim import GpSskLsAcqOptim from comb_opt.optimizers.mix_and_match.gp_ssk_ker_sa_acq_optim import GpSskSaAcqOptim -from comb_opt.optimizers.mix_and_match.lr_ga_acq_optim import LrSparseHsGaAcqOptim -from comb_opt.optimizers.mix_and_match.lr_is_acq_optim import LrSparseHsTrLsAcqOptim -from comb_opt.optimizers.mix_and_match.lr_ls_acq_optim import LrSparseHsExhaustiveLsAcqOptim +from comb_opt.optimizers.mix_and_match.gp_to_ker_ls_acq_optim import GpToLsAcqOptim +from comb_opt.optimizers.mix_and_match.gp_to_ker_ga_acq_optim import GpToGaAcqOptim +from comb_opt.optimizers.mix_and_match.gp_to_ker_sa_acq_optim import GpToSaAcqOptim +from comb_opt.optimizers.mix_and_match.lr_ga_acq_optim import LrGaAcqOptim +from comb_opt.optimizers.mix_and_match.lr_is_acq_optim import LrIsAcqOptim +from comb_opt.optimizers.mix_and_match.lr_ls_acq_optim import LrLsAcqOptim if __name__ == '__main__': + parser = argparse.ArgumentParser(add_help=True, description='BOF - Mix And Match - Pest') + parser.add_argument("--device_id", type=int, default=0, help="Cuda device id (cpu is used if id is negative)") + parser.add_argument("--use_tr", action="store_true", help="Whether to use Trust-Region based methods") + + args = parser.parse_args() + task_name = 'pest' task_kwargs = {} + dtype = torch.float32 + + task, search_space = task_factory(task_name, dtype, **task_kwargs) + bo_n_init = 20 - bo_device = torch.device('cuda:3') + if args.device_id >= 0 and torch.cuda.is_available(): + bo_device = torch.device(f'cuda:{args.device_id}') + else: + bo_device = torch.device("cpu") + max_num_iter = 200 - dtype = torch.float32 random_seeds = [42, 43, 44, 45, 46] - task, search_space = task_factory(task_name, dtype, **task_kwargs) + use_tr = args.use_tr - gp_to_ga = GpToGaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - gp_to_sa = GpToSaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - gp_to_exhaustive_ls = GpToLsAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) + opt_kwargs = dict(dtype=dtype, device=bo_device, use_tr=use_tr) - gp_diffusion_ga = GpDiffusionGaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - gp_diffusion_sa = GpDiffusionSaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - gp_diffusion_tr_ls = GpDiffusionTrLsAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) + gp_to_ga = GpToGaAcqOptim(search_space, bo_n_init, **opt_kwargs) + gp_to_sa = GpToSaAcqOptim(search_space, bo_n_init, **opt_kwargs) + gp_to_exhaustive_ls = GpToLsAcqOptim(search_space, bo_n_init, **opt_kwargs) + gp_to_is = None + if not use_tr: + gp_to_is = Casmopolitan(search_space, bo_n_init, **opt_kwargs) - gp_ssk_sa = GpSskSaAcqOptim(search_space, bo_n_init, model_max_batch_size=50, dtype=dtype, device=bo_device) - gp_ssk_exhaustive_ls = GpSskLsAcqOptim(search_space, bo_n_init, model_max_batch_size=50, dtype=dtype, - device=bo_device) + gp_o_ga = GpOGaAcqOptim(search_space=search_space, n_init=bo_n_init, **opt_kwargs) + gp_o_sa = GpOSaAcqOptim(search_space=search_space, n_init=bo_n_init, **opt_kwargs) + gp_o_ls = GpOLsAcqOptim(search_space=search_space, n_init=bo_n_init, **opt_kwargs) + gp_o_is = GpOIsAcqOptim(search_space=search_space, n_init=bo_n_init, **opt_kwargs) - lr_sparse_hs_ga = LrSparseHsGaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - lr_sparse_hs_tr_ls = LrSparseHsTrLsAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - lr_sparse_hs_exhaustive_ls = LrSparseHsExhaustiveLsAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) + gp_diffusion_ga = GpDiffusionGaAcqOptim(search_space, bo_n_init, **opt_kwargs) + gp_diffusion_sa = GpDiffusionSaAcqOptim(search_space, bo_n_init, **opt_kwargs) + gp_diffusion_is = GpDiffusionIsAcqOptim(search_space, bo_n_init, **opt_kwargs) + gp_diffusion_ls = None + if use_tr: + gp_diffusion_ls = COMBO(search_space, bo_n_init, **opt_kwargs) + + gp_ssk_sa = GpSskSaAcqOptim(search_space, bo_n_init, model_max_batch_size=50, **opt_kwargs) + gp_ssk_ls = GpSskLsAcqOptim(search_space, bo_n_init, model_max_batch_size=50, **opt_kwargs) + gp_ssk_ga = None + if use_tr: + gp_ssk_ga = BOSS(search_space, bo_n_init, model_max_batch_size=50, **opt_kwargs) + gp_ssk_is = None + if not use_tr: + gp_ssk_is = BOiLS(search_space, bo_n_init, model_max_batch_size=50, **opt_kwargs) + + lr_sparse_hs_ga = LrGaAcqOptim(search_space, bo_n_init, **opt_kwargs) + lr_sparse_hs_ls = LrLsAcqOptim(search_space, bo_n_init, **opt_kwargs) + lr_sparse_hs_is = LrIsAcqOptim(search_space, bo_n_init, **opt_kwargs) + lr_sparse_hs_sa = None + if use_tr: + lr_sparse_hs_sa = BOCS(search_space, bo_n_init, **opt_kwargs) optimizers = [ - gp_ssk_sa, - gp_ssk_exhaustive_ls, - gp_diffusion_ga, - gp_diffusion_sa, - gp_diffusion_tr_ls, - gp_to_ga, - gp_to_sa, - gp_to_exhaustive_ls, - lr_sparse_hs_ga, - lr_sparse_hs_tr_ls, - lr_sparse_hs_exhaustive_ls + # gp_ssk_sa, + gp_ssk_ls, + # gp_diffusion_ga, + # gp_diffusion_sa, + gp_diffusion_is, + # gp_to_ga, + # gp_to_sa, + # gp_o_ga, + # gp_o_sa, + # gp_o_ls, + gp_o_is, + # lr_sparse_hs_ga, + # lr_sparse_hs_ls, + lr_sparse_hs_is ] + optional_opts = [ + # gp_to_is, + gp_diffusion_ls, + lr_sparse_hs_sa, + gp_ssk_ga, + # gp_ssk_is, + ] + + for opt in optional_opts: + if opt is not None: + optimizers.append(opt) + run_experiment(task=task, optimizers=optimizers, random_seeds=random_seeds, max_num_iter=max_num_iter, - very_verbose=False) + very_verbose=True) diff --git a/combopt/experiments/mix_and_match/mix_and_match_rna.py b/combopt/experiments/mix_and_match/mix_and_match_rna.py deleted file mode 100644 index 5a796c48..00000000 --- a/combopt/experiments/mix_and_match/mix_and_match_rna.py +++ /dev/null @@ -1,55 +0,0 @@ -import os -import sys -from pathlib import Path - -import torch - -sys.path.insert(0, str(Path(os.path.realpath(__file__)).parent.parent.parent)) - -from comb_opt.factory import task_factory -from comb_opt.utils.experiment_utils import run_experiment - -from comb_opt.optimizers.mix_and_match.gp_to_ker_ga_acq_optim import GpToGaAcqOptim -from comb_opt.optimizers.mix_and_match.gp_to_ker_sa_acq_optim import GpToSaAcqOptim -from comb_opt.optimizers.mix_and_match.gp_to_ker_ls_acq_optim import GpToLsAcqOptim -from comb_opt.optimizers.mix_and_match.gp_diff_ker_ga_acq_optim import GpDiffusionGaAcqOptim -from comb_opt.optimizers.mix_and_match.gp_diff_ker_sa_acq_optim import GpDiffusionSaAcqOptim -from comb_opt.optimizers.mix_and_match.gp_diff_ker_is_acq_optim import GpDiffusionTrLsAcqOptim -from comb_opt.optimizers.mix_and_match.gp_ssk_ker_ls_acq_optim import GpSskLsAcqOptim -from comb_opt.optimizers.mix_and_match.gp_ssk_ker_sa_acq_optim import GpSskSaAcqOptim -from comb_opt.optimizers.mix_and_match.lr_ga_acq_optim import LrSparseHsGaAcqOptim -from comb_opt.optimizers.mix_and_match.lr_is_acq_optim import LrSparseHsTrLsAcqOptim -from comb_opt.optimizers.mix_and_match.lr_ls_acq_optim import LrSparseHsExhaustiveLsAcqOptim - -if __name__ == '__main__': - task_name = 'rna_inverse_fold' - task_kwargs = {'target': 65} - bo_n_init = 20 - bo_device = torch.device('cuda:0') - max_num_iter = 200 - dtype = torch.float32 - random_seeds = [42, 43, 44, 45, 46] - - task, search_space = task_factory(task_name, dtype, **task_kwargs) - - gp_to_ga = GpToGaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - gp_to_sa = GpToSaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - gp_to_exhaustive_ls = GpToLsAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - - gp_diffusion_ga = GpDiffusionGaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - gp_diffusion_sa = GpDiffusionSaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - gp_diffusion_tr_ls = GpDiffusionTrLsAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - - gp_ssk_sa = GpSskSaAcqOptim(search_space, bo_n_init, model_max_batch_size=50, dtype=dtype, device=bo_device) - gp_ssk_exhaustive_ls = GpSskLsAcqOptim(search_space, bo_n_init, model_max_batch_size=50, dtype=dtype, - device=bo_device) - - lr_sparse_hs_ga = LrSparseHsGaAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - lr_sparse_hs_tr_ls = LrSparseHsTrLsAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - lr_sparse_hs_exhaustive_ls = LrSparseHsExhaustiveLsAcqOptim(search_space, bo_n_init, dtype=dtype, device=bo_device) - - optimizers = [gp_ssk_sa, gp_ssk_exhaustive_ls, gp_diffusion_ga, gp_diffusion_sa, gp_diffusion_tr_ls, gp_to_ga, - gp_to_sa, gp_to_exhaustive_ls, lr_sparse_hs_ga, lr_sparse_hs_tr_ls, lr_sparse_hs_exhaustive_ls] - - run_experiment(task=task, optimizers=optimizers, random_seeds=random_seeds, max_num_iter=max_num_iter, - very_verbose=False) diff --git a/combopt/experiments/mix_and_match/mix_and_match_rna_inverse_fold.py b/combopt/experiments/mix_and_match/mix_and_match_rna_inverse_fold.py new file mode 100644 index 00000000..9aa8813a --- /dev/null +++ b/combopt/experiments/mix_and_match/mix_and_match_rna_inverse_fold.py @@ -0,0 +1,121 @@ +import argparse +import os +import sys +from pathlib import Path + +import torch + +sys.path.insert(0, str(Path(os.path.realpath(__file__)).parent.parent.parent)) + +from comb_opt.factory import task_factory +from comb_opt.utils.experiment_utils import run_experiment + +from comb_opt.optimizers import COMBO, BOCS, BOSS, BOiLS, Casmopolitan +from comb_opt.optimizers.mix_and_match.gp_diff_ker_ga_acq_optim import GpDiffusionGaAcqOptim +from comb_opt.optimizers.mix_and_match.gp_diff_ker_is_acq_optim import GpDiffusionIsAcqOptim +from comb_opt.optimizers.mix_and_match.gp_diff_ker_sa_acq_optim import GpDiffusionSaAcqOptim +from comb_opt.optimizers.mix_and_match.gp_o_ker_ga_acq_optim import GpOGaAcqOptim +from comb_opt.optimizers.mix_and_match.gp_o_ker_is_acq_optim import GpOIsAcqOptim +from comb_opt.optimizers.mix_and_match.gp_o_ker_ls_acq_optim import GpOLsAcqOptim +from comb_opt.optimizers.mix_and_match.gp_o_ker_sa_acq_optim import GpOSaAcqOptim +from comb_opt.optimizers.mix_and_match.gp_ssk_ker_ls_acq_optim import GpSskLsAcqOptim +from comb_opt.optimizers.mix_and_match.gp_ssk_ker_sa_acq_optim import GpSskSaAcqOptim +from comb_opt.optimizers.mix_and_match.gp_to_ker_ls_acq_optim import GpToLsAcqOptim +from comb_opt.optimizers.mix_and_match.gp_to_ker_ga_acq_optim import GpToGaAcqOptim +from comb_opt.optimizers.mix_and_match.gp_to_ker_sa_acq_optim import GpToSaAcqOptim +from comb_opt.optimizers.mix_and_match.lr_ga_acq_optim import LrGaAcqOptim +from comb_opt.optimizers.mix_and_match.lr_is_acq_optim import LrIsAcqOptim +from comb_opt.optimizers.mix_and_match.lr_ls_acq_optim import LrLsAcqOptim + +if __name__ == '__main__': + parser = argparse.ArgumentParser(add_help=True, description='BOF - Mix And Match - RNA folding') + parser.add_argument("--device_id", type=int, default=0, help="Cuda device id (cpu is used if id is negative)") + parser.add_argument("--use_tr", action="store_true", help="Whether to use Trust-Region based methods") + + args = parser.parse_args() + + task_name = 'rna_inverse_fold' + task_kwargs = {'target': 65} + dtype = torch.float32 + + task, search_space = task_factory(task_name, dtype, **task_kwargs) + + bo_n_init = 20 + if args.device_id >= 0 and torch.cuda.is_available(): + bo_device = torch.device(f'cuda:{args.device_id}') + else: + bo_device = torch.device("cpu") + + max_num_iter = 200 + random_seeds = [42, 43, 44, 45, 46] + + use_tr = args.use_tr + + opt_kwargs = dict(dtype=dtype, device=bo_device, use_tr=use_tr) + + gp_to_ga = GpToGaAcqOptim(search_space, bo_n_init, **opt_kwargs) + gp_to_sa = GpToSaAcqOptim(search_space, bo_n_init, **opt_kwargs) + gp_to_exhaustive_ls = GpToLsAcqOptim(search_space, bo_n_init, **opt_kwargs) + gp_to_is = None + if not use_tr: + gp_to_is = Casmopolitan(search_space, bo_n_init, **opt_kwargs) + + gp_o_ga = GpOGaAcqOptim(search_space=search_space, n_init=bo_n_init, **opt_kwargs) + gp_o_sa = GpOSaAcqOptim(search_space=search_space, n_init=bo_n_init, **opt_kwargs) + gp_o_ls = GpOLsAcqOptim(search_space=search_space, n_init=bo_n_init, **opt_kwargs) + gp_o_is = GpOIsAcqOptim(search_space=search_space, n_init=bo_n_init, **opt_kwargs) + + gp_diffusion_ga = GpDiffusionGaAcqOptim(search_space, bo_n_init, **opt_kwargs) + gp_diffusion_sa = GpDiffusionSaAcqOptim(search_space, bo_n_init, **opt_kwargs) + gp_diffusion_is = GpDiffusionIsAcqOptim(search_space, bo_n_init, **opt_kwargs) + gp_diffusion_ls = None + if use_tr: + gp_diffusion_ls = COMBO(search_space, bo_n_init, **opt_kwargs) + + gp_ssk_sa = GpSskSaAcqOptim(search_space, bo_n_init, model_max_batch_size=50, **opt_kwargs) + gp_ssk_ls = GpSskLsAcqOptim(search_space, bo_n_init, model_max_batch_size=50, **opt_kwargs) + gp_ssk_ga = None + if use_tr: + gp_ssk_ga = BOSS(search_space, bo_n_init, model_max_batch_size=50, **opt_kwargs) + gp_ssk_is = None + if not use_tr: + gp_ssk_is = BOiLS(search_space, bo_n_init, model_max_batch_size=50, **opt_kwargs) + + lr_sparse_hs_ga = LrGaAcqOptim(search_space, bo_n_init, **opt_kwargs) + lr_sparse_hs_ls = LrLsAcqOptim(search_space, bo_n_init, **opt_kwargs) + lr_sparse_hs_is = LrIsAcqOptim(search_space, bo_n_init, **opt_kwargs) + lr_sparse_hs_sa = None + if use_tr: + lr_sparse_hs_sa = BOCS(search_space, bo_n_init, **opt_kwargs) + + optimizers = [ + # gp_ssk_sa, + # gp_ssk_ls, + # gp_diffusion_ga, + # gp_diffusion_sa, + gp_diffusion_is, + # gp_to_ga, + # gp_to_sa, + # gp_o_ga, + # gp_o_sa, + # gp_o_ls, + gp_o_is, + # lr_sparse_hs_ga, + # lr_sparse_hs_ls, + lr_sparse_hs_is + ] + + optional_opts = [ + gp_to_is, + # gp_diffusion_ls, + # lr_sparse_hs_sa, + # gp_ssk_ga, + gp_ssk_is, + ] + + for opt in optional_opts: + if opt is not None: + optimizers.append(opt) + + run_experiment(task=task, optimizers=optimizers, random_seeds=random_seeds, max_num_iter=max_num_iter, + very_verbose=True) diff --git a/combopt/paper/generate_benchmarking_baselines_plot.py b/combopt/paper/generate_benchmarking_baselines_plot.py index 96c9cc86..ce886ca5 100644 --- a/combopt/paper/generate_benchmarking_baselines_plot.py +++ b/combopt/paper/generate_benchmarking_baselines_plot.py @@ -25,7 +25,8 @@ parser.add_argument("--final_plot", "-f", action="store_true", help="Make the final plot style, Setting this to true will result in a plotting time ~60 s." " Set to false when experimenting with the aesthetics of the plot") - parser.add_argument("--start_step", "-s", type=int, default=0, help="Plot performance of optimizers from step `start_step`") + parser.add_argument("--start_step", "-s", type=int, default=0, + help="Plot performance of optimizers from step `start_step`") args = parser.parse_args() @@ -43,10 +44,18 @@ # 'Bayesmark task | Mod-lasso | DB diabetes | Metr-mae', # 'Bayesmark task | Mod-lasso | DB boston | Metr-mae', # 'Bayesmark task | Mod-linear | DB diabetes | Metr-mae', - # 'Bayesmark task | Mod-linear | DB boston | Metr-mae', ] + + def task_label(task_name: str) -> str: + if task_name == 'EDA Sequence Optimization - Design sin - Ops basic - Pattern basic - Obj both': + return "EDA Sequence Optimization" + elif task_name == 'MIG Sequence Optimisation - sqrt - both': + return 'MIG Sequence Optimisation' + return task_name + + method_names = [ 'BOCS', 'COMBO', diff --git a/combopt/paper/generate_benchmarking_mixing_and_matching_plot.py b/combopt/paper/generate_benchmarking_mixing_and_matching_plot.py index 566cb8f6..542c8095 100644 --- a/combopt/paper/generate_benchmarking_mixing_and_matching_plot.py +++ b/combopt/paper/generate_benchmarking_mixing_and_matching_plot.py @@ -42,11 +42,11 @@ 'BOCS', 'LR (Sparse HS) - GA acq optim', 'LR (Sparse HS) - LS acq optim', - 'LR (Sparse HS) - TR-based LS acq optim' + 'LR (Sparse HS) - Tr-based LS acq optim' 'COMBO', 'GP (Diffusion) - GA acq optim', 'GP (Diffusion) - SA acq optim', - 'GP (Diffusion) - TR-based LS acq optim' + 'GP (Diffusion) - Tr-based LS acq optim' 'Casmopolitan', 'GP (TO) - GA acq optim', 'GP (TO) - SA acq optim', diff --git a/combopt/tests/optimizers/mix_and_match/test_gp_ssk_kernel_tr_ga_acq_optim.py b/combopt/tests/optimizers/mix_and_match/test_gp_ssk_kernel_tr_sa_acq_optim.py similarity index 72% rename from combopt/tests/optimizers/mix_and_match/test_gp_ssk_kernel_tr_ga_acq_optim.py rename to combopt/tests/optimizers/mix_and_match/test_gp_ssk_kernel_tr_sa_acq_optim.py index a07990fb..63ac4e74 100644 --- a/combopt/tests/optimizers/mix_and_match/test_gp_ssk_kernel_tr_ga_acq_optim.py +++ b/combopt/tests/optimizers/mix_and_match/test_gp_ssk_kernel_tr_sa_acq_optim.py @@ -1,10 +1,10 @@ from comb_opt.factory import task_factory -from comb_opt.optimizers.mix_and_match.gp_ssk_kernel_tr_ga_acq_optim import GpSskTrGaAcqOptim +from comb_opt.optimizers.mix_and_match import GpSskSaAcqOptim if __name__ == '__main__': task, search_space = task_factory('ackley', num_dims=20, variable_type='nominal', num_categories=5) - optimizer = GpSskTrGaAcqOptim(search_space, 10, tr_verbose=True) + optimizer = GpSskSaAcqOptim(search_space, 10, use_tr=True, tr_verbose=True) n = 2000 for i in range(n): diff --git a/combopt/tests/optimizers/test_pymoo_ga.py b/combopt/tests/optimizers/test_pymoo_ga.py index daf4a2a7..6cc90463 100644 --- a/combopt/tests/optimizers/test_pymoo_ga.py +++ b/combopt/tests/optimizers/test_pymoo_ga.py @@ -32,7 +32,7 @@ import torch from comb_opt.factory import task_factory -from comb_opt.optimizers.genetic_algorithm import PymooGeneticAlgorithm, NominalGeneticAlgorithm +from comb_opt.optimizers.genetic_algorithm import PymooGeneticAlgorithm, CategoricalGeneticAlgorithm def print_results(our_results, our_time, pymoo_results, pymoo_time, pop_size, num_iter, num_dims, num_categories, @@ -83,7 +83,7 @@ def print_results(our_results, our_time, pymoo_results, pymoo_time, pop_size, nu pymoo_optimizer = PymooGeneticAlgorithm(search_space, pop_size, tournament_selection=tournament_selection) pymoo_optimizer.set_x_init(x_init) - our_optimizer = NominalGeneticAlgorithm(search_space) + our_optimizer = CategoricalGeneticAlgorithm(search_space) our_optimizer.set_x_init(x_init) start = time.time() diff --git a/combopt/tests/test_multitask_exact_gp.py b/combopt/tests/test_multitask_exact_gp.py index 97988d1c..ee0cb8d9 100644 --- a/combopt/tests/test_multitask_exact_gp.py +++ b/combopt/tests/test_multitask_exact_gp.py @@ -2,7 +2,6 @@ import torch from gpytorch.kernels import ScaleKernel, MaternKernel -from comb_opt.debugging.check_model_fit import plot_posterior from comb_opt.factory import task_factory from comb_opt.models.gp.exact_gp import ExactGPModel