def __init__(self, init_state, problem_model, get_score): Annealer.__init__(self, init_state) self.problem_model = problem_model self.get_score = get_score # if you don't want to see any update in the output self.updates = 0 self.steps = 100000
def __init__(self, experiment_info, initial_state, exit_time, log=None, network_socket=None): """ :param experiment_info: ExperimentInfo object :param initial_state: EnemyConfig object :param exit_time: Exit time :param log: A log object :param network_socket: For future network connection """ assert isinstance(experiment_info, ExperimentInfo) self._experiment_info = experiment_info assert isinstance(log, DataLog) self._experiment_info = experiment_info assert isinstance(initial_state, EnemyConfiguration) Annealer.__init__(self, initial_state) self.steps = experiment_info.tuning_max_iterations self.objective_function = ObjectiveFunction( experiment_info=experiment_info, log=log, socket_connect=network_socket) self._exit_time = exit_time
def __init__(self, available_pos, netlists, board, board_pos, current_state, is_legal): self.available_pos = available_pos self.netlists = netlists self.board = board self.blk_pos = board_pos assert (len(current_state) <= len(available_pos)) self.is_legal = is_legal rand = random.Random() rand.seed(0) state = current_state Annealer.__init__(self, initial_state=state, rand=rand)
def __init__(self, block_pos, available_pos, netlists, board_pos, is_legal=None, exclude_list=("u", "m", "i")): # by default IO will be excluded # place note that in this case available_pos includes empty cells # as well # we need to reverse index the block pos since we are swapping spaces state = {} self.excluded_blocks = {} for blk_id in block_pos: b_type = blk_id[0] pos = block_pos[blk_id] # always exclude the cluster centroid if b_type in exclude_list or b_type == "x": self.excluded_blocks[blk_id] = pos else: state[pos] = blk_id self.available_pos = available_pos assert (len(self.available_pos) >= len(block_pos)) self.netlists = netlists self.board_pos = board_pos if is_legal is not None: # this one does not check whether the board is occupied or not self.is_legal = is_legal else: self.is_legal = lambda p, block_id: True self.exclude_list = exclude_list rand = random.Random() rand.seed(0) Annealer.__init__(self, initial_state=state, rand=rand)
def __init__(self, initial_state, max_epsilon_step_change): self.max_epsilon_step_change = max_epsilon_step_change Annealer.__init__(self, initial_state=initial_state)
def __init__(self, clusters, netlists, board, board_pos, board_meta, is_legal=None, is_cell_legal=None, place_factor=6, fold_reg=True, seed=0): """Notice that each clusters has to be a condensed node in a networkx graph whose edge denotes how many intra-cluster connections. """ self.clusters = clusters self.netlists = netlists self.board = board self.board_pos = board_pos.copy() self.square_sizes = {} # look up table for clusters if is_legal is None: self.is_legal = self.__is_legal else: self.is_legal = is_legal if is_cell_legal is None: self.is_cell_legal = lambda p, cb: True else: self.is_cell_legal = is_cell_legal board_info = board_meta[-1] self.board_layout = board_meta[0] self.clb_type = board_info["clb_type"] self.clb_margin = board_info["margin"] rand = random.Random() rand.seed(seed) self.squeeze_iter = 5 self.place_factor = place_factor self.fold_reg = fold_reg self.center_of_board = (len(self.board[0]) // 2, len(self.board) // 2) # Keyi: # because the way it's designed, we can actually shuffle clusters # so that there is a chance it will fit after re-ordering # set a limit how much shuffling we are going to do cluster_ids = list(clusters.keys()) # determine loop range if len(cluster_ids) < 2: loop_range = 1 elif len(cluster_ids) <= 6: loop_range = math.factorial(len(cluster_ids)) else: loop_range = len(cluster_ids) * (len(cluster_ids) - 1) state = None for i in range(loop_range): try: state = self.__init_placement(cluster_ids, rand) break except ClusterException as _: state = None rand.shuffle(cluster_ids) if state is None: raise ClusterException(len(cluster_ids)) Annealer.__init__(self, initial_state=state, rand=rand) self.netlists = reduce_cluster_graph(netlists, clusters, board_pos)
def __init__(self, blocks, total_cells, netlists, raw_netlist, board, board_pos, is_legal=None, fold_reg=True, seed=0): """Please notice that netlists has to be prepared already, i.e., replace the remote partition with a pseudo block. Also assumes that available_pos is the same size as blocks. If not, you have to shrink it the available_pos. The board can be an empty board. """ self.blocks = blocks # TODO: # switch every thing into dictionary based available_pos = total_cells["p"] self.total_cells = total_cells self.available_pos = available_pos self.netlists = netlists self.blk_pos = board_pos self.board = board if fold_reg: assert (len(blocks) >= len(available_pos)) else: assert (len(blocks) == len(available_pos)) if is_legal is None: if fold_reg: self.is_legal = self.__is_legal_fold else: self.is_legal = lambda pos, blk_id, s: True else: self.is_legal = is_legal self.fold_reg = fold_reg # figure out which position on which regs cannot be on the top self.reg_no_pos = {} if fold_reg: linked_nets, _, _ = group_reg_nets(raw_netlist) for net_id in netlists: net = netlists[net_id] if net_id in linked_nets: for reg_net_id in linked_nets[net_id]: if reg_net_id in netlists: net += netlists[reg_net_id] for blk in net: # we only care about the wire it's driving if blk[0] == "r" and blk in self.blocks: if blk not in self.reg_no_pos: self.reg_no_pos[blk] = set() for bb in net: if bb == blk: continue if bb in self.blocks: self.reg_no_pos[blk].add(bb) rand = random.Random() rand.seed(seed) state = self.__init_placement(rand) Annealer.__init__(self, initial_state=state, rand=rand) # schedule self.steps = len(blocks) * 125 self.num_nets = len(netlists) # fast calculation self.moves = set() self.blk_index = self.__index_netlists(netlists, blocks) self.pre_state = deepcopy(state) self.pre_energy = self.init_energy()