Skip to content

Commit b75bbe0

Browse files
committed
enable string choice lists in AutoTuner
Signed-off-by: Jeff Ng <[email protected]>
1 parent 1a83f99 commit b75bbe0

File tree

2 files changed

+78
-62
lines changed

2 files changed

+78
-62
lines changed

flow/scripts/variables.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ PLACE_SITE:
320320
Placement site for core cells defined in the technology LEF file.
321321
stages:
322322
- floorplan
323+
type: string
324+
tunable: 1
323325
TAPCELL_TCL:
324326
description: |
325327
Path to Endcap and Welltie cells file.

tools/AutoTuner/src/autotuner/utils.py

Lines changed: 76 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -450,40 +450,44 @@ def apply_condition(config, data):
450450
# algorithms should take different methods (will be added)
451451
if algorithm != "random":
452452
return config
453-
dp_pad_min = data["CELL_PAD_IN_SITES_DETAIL_PLACEMENT"]["minmax"][0]
454-
dp_pad_step = data["CELL_PAD_IN_SITES_DETAIL_PLACEMENT"]["step"]
455-
if dp_pad_step == 1:
456-
config["CELL_PAD_IN_SITES_DETAIL_PLACEMENT"] = tune.sample_from(
457-
lambda spec: np.random.randint(
458-
dp_pad_min, spec.config.CELL_PAD_IN_SITES_GLOBAL_PLACEMENT + 1
453+
if "CELL_PAD_IN_SITES_DETAIL_PLACEMENT" in data:
454+
dp_pad_min = data["CELL_PAD_IN_SITES_DETAIL_PLACEMENT"]["minmax"][0]
455+
dp_pad_step = data["CELL_PAD_IN_SITES_DETAIL_PLACEMENT"]["step"]
456+
if dp_pad_step == 1:
457+
config["CELL_PAD_IN_SITES_DETAIL_PLACEMENT"] = tune.sample_from(
458+
lambda spec: np.random.randint(
459+
dp_pad_min, spec.config.CELL_PAD_IN_SITES_GLOBAL_PLACEMENT + 1
460+
)
459461
)
460-
)
461-
if dp_pad_step > 1:
462-
config["CELL_PAD_IN_SITES_DETAIL_PLACEMENT"] = tune.sample_from(
463-
lambda spec: random.randrange(
464-
dp_pad_min,
465-
spec.config.CELL_PAD_IN_SITES_GLOBAL_PLACEMENT + 1,
466-
dp_pad_step,
462+
if dp_pad_step > 1:
463+
config["CELL_PAD_IN_SITES_DETAIL_PLACEMENT"] = tune.sample_from(
464+
lambda spec: random.randrange(
465+
dp_pad_min,
466+
spec.config.CELL_PAD_IN_SITES_GLOBAL_PLACEMENT + 1,
467+
dp_pad_step,
468+
)
467469
)
468-
)
469470
return config
470471

471472
def read_tune(this):
472473
from ray import tune
473474

474-
min_, max_ = this["minmax"]
475-
if min_ == max_:
476-
# Returning a choice of a single element allow pbt algorithm to
477-
# work. pbt does not accept single values as tunable.
478-
return tune.choice([min_, max_])
479-
if this["type"] == "int":
480-
if this["step"] == 1:
481-
return tune.randint(min_, max_)
482-
return tune.choice(np.ndarray.tolist(np.arange(min_, max_, this["step"])))
483-
if this["type"] == "float":
484-
if this["step"] == 0:
485-
return tune.uniform(min_, max_)
486-
return tune.choice(np.ndarray.tolist(np.arange(min_, max_, this["step"])))
475+
if "minmax" in this:
476+
min_, max_ = this["minmax"]
477+
if min_ == max_:
478+
# Returning a choice of a single element allow pbt algorithm to
479+
# work. pbt does not accept single values as tunable.
480+
return tune.choice([min_, max_])
481+
if this["type"] == "int":
482+
if this["step"] == 1:
483+
return tune.randint(min_, max_)
484+
return tune.choice(np.ndarray.tolist(np.arange(min_, max_, this["step"])))
485+
if this["type"] == "float":
486+
if this["step"] == 0:
487+
return tune.uniform(min_, max_)
488+
return tune.choice(np.ndarray.tolist(np.arange(min_, max_, this["step"])))
489+
if this["type"] == "string":
490+
return tune.choice(this["values"])
487491
return None
488492

489493
def read_tune_ax(name, this):
@@ -493,33 +497,41 @@ def read_tune_ax(name, this):
493497
from ray import tune
494498

495499
dict_ = dict(name=name)
496-
if "minmax" not in this:
497-
return None
498-
min_, max_ = this["minmax"]
499-
if min_ == max_:
500-
dict_["type"] = "fixed"
501-
dict_["value"] = min_
502-
elif this["type"] == "int":
503-
if this["step"] == 1:
504-
dict_["type"] = "range"
505-
dict_["bounds"] = [min_, max_]
506-
dict_["value_type"] = "int"
507-
else:
508-
dict_["type"] = "choice"
509-
dict_["values"] = tune.randint(min_, max_, this["step"])
510-
dict_["value_type"] = "int"
511-
elif this["type"] == "float":
512-
if this["step"] == 1:
513-
dict_["type"] = "choice"
514-
dict_["values"] = tune.choice(
515-
np.ndarray.tolist(np.arange(min_, max_, this["step"]))
516-
)
517-
dict_["value_type"] = "float"
500+
if "minmax" in this:
501+
min_, max_ = this["minmax"]
502+
if min_ == max_:
503+
dict_["type"] = "fixed"
504+
dict_["value"] = min_
505+
elif this["type"] == "int":
506+
if this["step"] == 1:
507+
dict_["type"] = "range"
508+
dict_["bounds"] = [min_, max_]
509+
dict_["value_type"] = "int"
510+
else:
511+
dict_["type"] = "choice"
512+
dict_["values"] = tune.randint(min_, max_, this["step"])
513+
dict_["value_type"] = "int"
514+
elif this["type"] == "float":
515+
if this["step"] == 1:
516+
dict_["type"] = "choice"
517+
dict_["values"] = tune.choice(
518+
np.ndarray.tolist(np.arange(min_, max_, this["step"]))
519+
)
520+
dict_["value_type"] = "float"
521+
else:
522+
dict_["type"] = "range"
523+
dict_["bounds"] = [min_, max_]
524+
dict_["value_type"] = "float"
525+
return dict_
526+
if "values" in this:
527+
dict_["type"] = "choice"
528+
dict_["values"] = this["values"]
529+
if this["type"] == "string":
530+
dict_["value_type"] = "str"
518531
else:
519-
dict_["type"] = "range"
520-
dict_["bounds"] = [min_, max_]
521-
dict_["value_type"] = "float"
522-
return dict_
532+
dict_["value_type"] = this["type"]
533+
return dict_
534+
return None
523535

524536
def read_tune_pbt(name, this):
525537
"""
@@ -528,15 +540,17 @@ def read_tune_pbt(name, this):
528540
"""
529541
from ray import tune
530542

531-
if "minmax" not in this:
532-
return None
533-
min_, max_ = this["minmax"]
534-
if min_ == max_:
535-
return tune.choice([min_, max_])
536-
if this["type"] == "int":
537-
return tune.randint(min_, max_)
538-
if this["type"] == "float":
539-
return tune.uniform(min_, max_)
543+
if "minmax" in this:
544+
min_, max_ = this["minmax"]
545+
if min_ == max_:
546+
return tune.choice([min_, max_])
547+
if this["type"] == "int":
548+
return tune.randint(min_, max_)
549+
if this["type"] == "float":
550+
return tune.uniform(min_, max_)
551+
if "values" in this:
552+
return tune.choice(this["values"])
553+
return None
540554

541555
# Check file exists and whether it is a valid JSON file.
542556
assert os.path.isfile(file_name), f"File {file_name} not found."

0 commit comments

Comments
 (0)