6868from uuid import uuid4 as uuid
6969from collections import namedtuple
7070from multiprocessing import cpu_count
71+ import time
7172
7273import numpy as np
7374import torch
9192 parse_config ,
9293 read_config ,
9394 read_metrics ,
94- prepare_ray_server ,
9595 CONSTRAINTS_SDC ,
9696 FASTROUTE_TCL ,
9797)
101101# The worst of optimized metric
102102ERROR_METRIC = 9e99
103103# Path to the FLOW_HOME directory
104- ORFS_FLOW_DIR = os .path .abspath (
105- os .path .join (os .path .dirname (__file__ ), "../../../../flow" )
106- )
104+ if "ORFS_FLOW_DIR" in os .environ :
105+ ORFS_FLOW_DIR = os .environ ["ORFS_FLOW_DIR" ]
106+ else :
107+ ORFS_FLOW_DIR = os .path .abspath (
108+ os .path .join (os .path .dirname (__file__ ), "../../../../flow" )
109+ )
110+ if "INSTALL_PATH" in os .environ :
111+ INSTALL_PATH = os .environ ["INSTALL_PATH" ]
112+ else :
113+ INSTALL_PATH = os .path .abspath (os .path .join (ORFS_FLOW_DIR , "../tools/install" ))
114+ LOCAL_DIR = ""
115+
107116# Global variable for args
108117args = None
109118
@@ -448,7 +457,7 @@ def parse_arguments():
448457
449458 # If the experiment name is the default, add a UUID to the end.
450459 if args .experiment == "test" :
451- id = str (uuid ())[:8 ]
460+ id = time . strftime ( "%Y%m%d-%H%M%S" ) + "-" + str (uuid ())[:4 ]
452461 args .experiment = f"{ args .mode } -{ id } "
453462 else :
454463 args .experiment += f"-{ args .mode } "
@@ -558,31 +567,38 @@ def save_best(results):
558567
559568def sweep ():
560569 """Run sweep of parameters"""
561- if args .server is not None :
562- # For remote sweep we create the following directory structure:
563- # 1/ 2/ 3/ 4/
564- # <repo>/<logs>/<platform>/<design>/
565- repo_dir = os .path .abspath (LOCAL_DIR + "/../" * 4 )
566- else :
567- repo_dir = os .path .abspath (os .path .join (ORFS_FLOW_DIR , ".." ))
570+ repo_dir = os .path .abspath (os .path .join (ORFS_FLOW_DIR , ".." ))
568571 print (f"[INFO TUN-0012] Log folder { LOCAL_DIR } ." )
569- queue = Queue ()
570572 parameter_list = list ()
573+ total_combinations = 1
571574 for name , content in config_dict .items ():
575+ print (f"[INFO TUN-0013] Sweeping { name } over { content } ." )
572576 if not isinstance (content , list ):
573577 print (f"[ERROR TUN-0015] { name } sweep is not supported." )
574578 sys .exit (1 )
575579 if content [- 1 ] == 0 :
576580 print ("[ERROR TUN-0014] Sweep does not support step value zero." )
577581 sys .exit (1 )
578- parameter_list .append ([{name : i } for i in np .arange (* content )])
582+ parameter_list .append ([{name : i } for i in np .round (np .arange (* content ), 4 ).tolist ()])
583+ total_combinations *= len (parameter_list [- 1 ])
584+ print (f"[INFO TUN-0017] Total of { total_combinations } combinations." )
585+ if total_combinations > 1000 :
586+ print (
587+ "[WARN TUN-0033] The total number of combinations is very large."
588+ " Do you wish to continue? (y/n)"
589+ )
590+ if input ().lower () != "y" :
591+ sys .exit (1 )
579592 parameter_list = list (product (* parameter_list ))
593+ queue = Queue ()
580594 for parameter in parameter_list :
581- temp = dict ()
595+ params_to_sweep = dict ()
582596 for value in parameter :
583- temp .update (value )
584- queue .put ([args , repo_dir , temp , SDC_ORIGINAL , FR_ORIGINAL , INSTALL_PATH ])
585- workers = [consumer .remote (queue ) for _ in range (args .jobs )]
597+ params_to_sweep .update (value )
598+ queue .put ([args , repo_dir , params_to_sweep , SDC_ORIGINAL , FR_ORIGINAL , INSTALL_PATH ])
599+ max_jobs = min (args .jobs , queue .qsize ())
600+ print (f"[INFO TUN-0008] Starting sweep with { max_jobs } workers." )
601+ workers = [consumer .remote (queue ) for _ in range (max_jobs )]
586602 print ("[INFO TUN-0009] Waiting for results." )
587603 ray .get (workers )
588604 print ("[INFO TUN-0010] Sweep complete." )
@@ -592,14 +608,13 @@ def main():
592608 global args , SDC_ORIGINAL , FR_ORIGINAL , LOCAL_DIR , INSTALL_PATH , ORFS_FLOW_DIR , config_dict , reference , best_params
593609 args = parse_arguments ()
594610
611+ LOCAL_DIR = os .path .join (ORFS_FLOW_DIR , f"logs/{ args .platform } /{ args .design } " )
595612 # Read config and original files before handling where to run in case we
596613 # need to upload the files.
597614 config_dict , SDC_ORIGINAL , FR_ORIGINAL = read_config (
598615 os .path .abspath (args .config ), args .mode , getattr (args , "algorithm" , None )
599616 )
600617
601- LOCAL_DIR , ORFS_FLOW_DIR , INSTALL_PATH = prepare_ray_server (args )
602-
603618 if args .mode == "tune" :
604619 best_params = set_best_params (args .platform , args .design )
605620 search_algo = set_algorithm (
0 commit comments