@@ -599,23 +599,6 @@ def _optimization_function(
599599 # pylint:disable=unused-argument, import-outside-toplevel
600600 from pymoo import optimize as pymoooptimize
601601
602- from pymoo .factory import get_algorithm as get_pymoo_algorithm
603-
604- # from pymoo.factory import get_reference_directions
605-
606- # reference direction code for when we want to use the other MOO optimizers in Pymoo
607- # if self.algorithm in [
608- # "rnsga2",
609- # "nsga3",
610- # "unsga3",
611- # "rnsga3",
612- # "moead",
613- # "ctaea",
614- # ]: # algorithms that require reference points or reference directions
615- # the appropriate n_partitions must be looked into
616- # ref_dirs = get_reference_directions("das-dennis", self.num_objectives, n_partitions=12)
617- # algorithm = get_pymoo_algorithm(self.algorithm, ref_dirs)
618- # else:
619602 problem = _create_pymoo_problem (weakself , objective_function )
620603 if weakself .algorithm == "CMAES" :
621604 from pymoo .algorithms .soo .nonconvex .cmaes import CMAES
@@ -635,7 +618,7 @@ def _optimization_function(
635618 bipop = True ,
636619 )
637620 else :
638- algorithm = get_pymoo_algorithm (weakself .algorithm )
621+ algorithm = _get_pymoo_algorithm (weakself .algorithm )
639622 pymoooptimize .minimize (problem , algorithm , seed = weakself ._initial_seed )
640623 return None
641624
@@ -745,24 +728,7 @@ def _optimization_function(
745728 # pylint:disable=unused-argument, import-outside-toplevel
746729 from pymoo import optimize as pymoooptimize
747730
748- from pymoo .factory import get_algorithm as get_pymoo_algorithm
749-
750- # from pymoo.factory import get_reference_directions
751-
752- # reference direction code for when we want to use the other MOO optimizers in Pymoo
753- # if self.algorithm in [
754- # "rnsga2",
755- # "nsga3",
756- # "unsga3",
757- # "rnsga3",
758- # "moead",
759- # "ctaea",
760- # ]: # algorithms that require reference points or reference directions
761- # the appropriate n_partitions must be looked into
762- # ref_dirs = get_reference_directions("das-dennis", self.num_objectives, n_partitions=12)
763- # algorithm = get_pymoo_algorithm(self.algorithm, ref_dirs)
764- # else:
765- algorithm = get_pymoo_algorithm (weakself .algorithm )
731+ algorithm = _get_pymoo_algorithm (weakself .algorithm )
766732 problem = _create_pymoo_problem (weakself , objective_function , False )
767733 pymoooptimize .minimize (problem , algorithm , seed = weakself ._initial_seed )
768734 return None
@@ -834,23 +800,41 @@ def __init__(self, *, algorithm: str) -> None:
834800 super ().__init__ (_PymooBatchMinimizeBase , locals ())
835801
836802
803+ def _get_pymoo_algorithm (name : str ):
804+ """Instantiate a pymoo algorithm by name (replaces removed pymoo.factory.get_algorithm)."""
805+ # pylint:disable=import-outside-toplevel
806+ _PYMOO_ALGORITHMS = {
807+ "de" : "pymoo.algorithms.soo.nonconvex.de.DE" ,
808+ "ga" : "pymoo.algorithms.soo.nonconvex.ga.GA" ,
809+ "brkga" : "pymoo.algorithms.soo.nonconvex.brkga.BRKGA" ,
810+ "nelder-mead" : "pymoo.algorithms.soo.nonconvex.nelder.NelderMead" ,
811+ "pattern-search" : "pymoo.algorithms.soo.nonconvex.pattern.PatternSearch" ,
812+ "cmaes" : "pymoo.algorithms.soo.nonconvex.cmaes.CMAES" ,
813+ "nsga2" : "pymoo.algorithms.moo.nsga2.NSGA2" ,
814+ "rnsga2" : "pymoo.algorithms.moo.rnsga2.RNSGA2" ,
815+ "nsga3" : "pymoo.algorithms.moo.nsga3.NSGA3" ,
816+ "unsga3" : "pymoo.algorithms.moo.unsga3.UNSGA3" ,
817+ "rnsga3" : "pymoo.algorithms.moo.rnsga3.RNSGA3" ,
818+ "moead" : "pymoo.algorithms.moo.moead.MOEAD" ,
819+ "ctaea" : "pymoo.algorithms.moo.ctaea.CTAEA" ,
820+ }
821+ import importlib
822+
823+ qualname = _PYMOO_ALGORITHMS [name ]
824+ module_path , class_name = qualname .rsplit ("." , 1 )
825+ module = importlib .import_module (module_path )
826+ return getattr (module , class_name )()
827+
828+
837829def _create_pymoo_problem (
838830 optimizer : base .Optimizer ,
839831 objective_function : tp .Callable [[tp .ArrayLike ], float ],
840832 elementwise : bool = True ,
841833):
842- kwargs = {}
843- try :
844- # pylint:disable=import-outside-toplevel
845- from pymoo .core .problem import ElementwiseProblem , Problem # type: ignore
846-
847- Base = ElementwiseProblem if elementwise else Problem
848- except ImportError :
849- # Used if pymoo < 0.5.0
850- # pylint:disable=import-outside-toplevel
851- from pymoo .model .problem import Problem as Base # type: ignore
834+ # pylint:disable=import-outside-toplevel
835+ from pymoo .core .problem import ElementwiseProblem , Problem # type: ignore
852836
853- kwargs = { "elementwise_evaluation" : elementwise }
837+ Base = ElementwiseProblem if elementwise else Problem
854838
855839 class _PymooProblem (Base ): # type: ignore
856840 def __init__ (self , optimizer , objective_function ):
@@ -861,7 +845,6 @@ def __init__(self, optimizer, objective_function):
861845 n_constr = 0 , # constraints handled already by nevergrad
862846 xl = - math .pi * 0.5 ,
863847 xu = math .pi * 0.5 ,
864- ** kwargs ,
865848 )
866849
867850 def _evaluate (self , X , out , * args , ** kwargs ):
0 commit comments