@@ -344,7 +344,7 @@ def easy_objective(config):
344
344
# do cleanup operation here
345
345
return
346
346
```
347
- search_alg: An instance of BlendSearch as the search algorithm
347
+ search_alg: An instance/string of the search algorithm
348
348
to be used. The same instance can be used for iterative tuning.
349
349
e.g.,
350
350
@@ -481,12 +481,25 @@ def easy_objective(config):
481
481
else :
482
482
logger .setLevel (logging .CRITICAL )
483
483
484
- from .searcher .blendsearch import BlendSearch , CFO
484
+ from .searcher .blendsearch import BlendSearch , CFO , RandomSearch
485
485
486
486
if lexico_objectives is not None :
487
- logger .warning ("If lexico_objectives is not None, search_alg is forced to be CFO" )
488
- search_alg = None
489
- if search_alg is None :
487
+ if "modes" not in lexico_objectives .keys ():
488
+ lexico_objectives ["modes" ] = ["min" ] * len (lexico_objectives ["metrics" ])
489
+ for t_metric , t_mode in zip (lexico_objectives ["metrics" ], lexico_objectives ["modes" ]):
490
+ if t_metric not in lexico_objectives ["tolerances" ].keys ():
491
+ lexico_objectives ["tolerances" ][t_metric ] = 0
492
+ if t_metric not in lexico_objectives ["targets" ].keys ():
493
+ lexico_objectives ["targets" ][t_metric ] = - float ("inf" ) if t_mode == "min" else float ("inf" )
494
+ if search_alg is None or isinstance (search_alg , str ):
495
+ if isinstance (search_alg , str ):
496
+ assert search_alg in [
497
+ "BlendSearch" ,
498
+ "CFO" ,
499
+ "CFOCat" ,
500
+ "RandomSearch" ,
501
+ ], f"search_alg={ search_alg } is not recognized. 'BlendSearch', 'CFO', 'CFOcat' and 'RandomSearch' are supported."
502
+
490
503
flaml_scheduler_resource_attr = (
491
504
flaml_scheduler_min_resource
492
505
) = flaml_scheduler_max_resource = flaml_scheduler_reduction_factor = None
@@ -500,20 +513,30 @@ def easy_objective(config):
500
513
flaml_scheduler_max_resource = max_resource
501
514
flaml_scheduler_reduction_factor = reduction_factor
502
515
scheduler = None
503
- if lexico_objectives is None :
504
- try :
505
- import optuna as _
516
+ if lexico_objectives :
517
+ # TODO: Modify after supporting BlendSearch in lexicographic optimization
518
+ SearchAlgorithm = CFO
519
+ logger .info (
520
+ f"Using search algorithm { SearchAlgorithm .__name__ } for lexicographic optimization. Note that when providing other search algorithms, we use CFO instead temporarily."
521
+ )
522
+ metric = lexico_objectives ["metrics" ][0 ] or DEFAULT_METRIC
523
+ else :
524
+ if not search_alg or search_alg == "BlendSearch" :
525
+ try :
526
+ import optuna as _
506
527
507
- SearchAlgorithm = BlendSearch
528
+ SearchAlgorithm = BlendSearch
529
+ logger .info ("Using search algorithm {}." .format (SearchAlgorithm .__name__ ))
530
+ except ImportError :
531
+ if search_alg == "BlendSearch" :
532
+ raise ValueError ("To use BlendSearch, run: pip install flaml[blendsearch]" )
533
+ else :
534
+ SearchAlgorithm = CFO
535
+ logger .warning ("Using CFO for search. To use BlendSearch, run: pip install flaml[blendsearch]" )
536
+ else :
537
+ SearchAlgorithm = locals ()[search_alg ]
508
538
logger .info ("Using search algorithm {}." .format (SearchAlgorithm .__name__ ))
509
- except ImportError :
510
- SearchAlgorithm = CFO
511
- logger .warning ("Using CFO for search. To use BlendSearch, run: pip install flaml[blendsearch]" )
512
539
metric = metric or DEFAULT_METRIC
513
- else :
514
- SearchAlgorithm = CFO
515
- logger .info ("Using search algorithm {}." .format (SearchAlgorithm .__name__ ))
516
- metric = lexico_objectives ["metrics" ][0 ] or DEFAULT_METRIC
517
540
search_alg = SearchAlgorithm (
518
541
metric = metric ,
519
542
mode = mode ,
@@ -535,8 +558,12 @@ def easy_objective(config):
535
558
)
536
559
else :
537
560
if metric is None or mode is None :
538
- metric = metric or search_alg .metric or DEFAULT_METRIC
539
- mode = mode or search_alg .mode
561
+ if lexico_objectives :
562
+ metric = lexico_objectives ["metrics" ][0 ] or metric or search_alg .metric or DEFAULT_METRIC
563
+ mode = lexico_objectives ["modes" ][0 ] or mode or search_alg .mode
564
+ else :
565
+ metric = metric or search_alg .metric or DEFAULT_METRIC
566
+ mode = mode or search_alg .mode
540
567
if ray_available and use_ray :
541
568
if ray_version .startswith ("1." ):
542
569
from ray .tune .suggest import ConcurrencyLimiter
@@ -555,6 +582,13 @@ def easy_objective(config):
555
582
):
556
583
search_alg .use_incumbent_result_in_evaluation = use_incumbent_result_in_evaluation
557
584
searcher = search_alg .searcher if isinstance (search_alg , ConcurrencyLimiter ) else search_alg
585
+ if lexico_objectives :
586
+ # TODO: Modify after supporting BlendSearch in lexicographic optimization
587
+ assert search_alg .__class__ .__name__ in [
588
+ "CFO" ,
589
+ ], "If lexico_objectives is not None, the search_alg must be CFO for now."
590
+ search_alg .lexico_objective = lexico_objectives
591
+
558
592
if isinstance (searcher , BlendSearch ):
559
593
setting = {}
560
594
if time_budget_s :
0 commit comments