def testAll(self): metrics_list = {} for design in designs: json_file = os.path.join( os.path.dirname(os.path.abspath(__file__)), "%s.json" % (design)) params = Params.Params() params.load(json_file) # control numpy multithreading os.environ["OMP_NUM_THREADS"] = "%d" % (params.num_threads) metrics_list[design] = [] for device_name in ["gpu"] * 5 + ["cpu"] * 2: for deterministic_name in ["indeterministic"]: params.gpu = 0 if device_name == "cpu" else 1 params.deterministic_flag = 0 if deterministic_name == "indeterministic" else 1 params.global_place_flag = 1 params.legalize_flag = 1 params.detaield_place_flag = 1 params.detailed_place_engine = "" logging.info("%s, %s, %s" % (design, device_name, deterministic_name)) logging.info("parameters = %s" % (params)) # run placement tt = time.time() metrics = Placer.place(params) logging.info("placement takes %.3f seconds" % (time.time() - tt)) # verify global placement results metrics_list[design].append(( metrics[-3][-1][-1].hpwl.cpu().numpy(), metrics[-2].hpwl.cpu().numpy(), metrics[-1].hpwl.cpu().numpy(), )) m = np.array(metrics_list[design]) metrics_list[design] = m gp, lg, dp = m[:, 0], m[:, 1], m[:, 2] gp_mean, lg_mean, dp_mean = np.mean(gp), np.mean(lg), np.mean(dp) rtol = lambda x, avg: max(avg - np.min(x), np.max(x) - avg) / avg gp_rtol, lg_rtol, dp_rtol = rtol(gp, gp_mean), rtol(lg, lg_mean), rtol( dp, dp_mean) logging.info( f"Avg metrics for {design}\n{m}\nGP={gp_mean:g} ({gp_rtol}), LG={lg_mean:g} ({lg_rtol}), DP={dp_mean:g} ({dp_rtol})" ) logging.info("Overall Summary") for design in designs: m = metrics_list[design] gp, lg, dp = m[:, 0], m[:, 1], m[:, 2] gp_mean, lg_mean, dp_mean = np.mean(gp), np.mean(lg), np.mean(dp) rtol = lambda x, avg: max(avg - np.min(x), np.max(x) - avg) / avg gp_rtol, lg_rtol, dp_rtol = rtol(gp, gp_mean), rtol(lg, lg_mean), rtol( dp, dp_mean) logging.info( f"Avg metrics for {design}\n{m}\nGP={gp_mean:g} ({gp_rtol}), LG={lg_mean:g} ({lg_rtol}), DP={dp_mean:g} ({dp_rtol})" )
def testAll(self): for design in designs: json_file = os.path.join( os.path.dirname(os.path.abspath(__file__)), "%s.json" % (design)) params = Params.Params() params.load(json_file) # control numpy multithreading os.environ["OMP_NUM_THREADS"] = "%d" % (params.num_threads) for device_name in devices: for deterministic_name in deterministics: params.gpu = 0 if device_name == "cpu" else 1 params.deterministic_flag = 0 if deterministic_name == "indeterministic" else 1 params.global_place_flag = 1 params.legalize_flag = 1 params.detaield_place_flag = 1 params.detailed_place_engine = "" logging.info("%s, %s, %s" % (design, device_name, deterministic_name)) logging.info("parameters = %s" % (params)) # run placement tt = time.time() metrics = Placer.place(params) logging.info("placement takes %.3f seconds" % (time.time() - tt)) # verify global placement results np.testing.assert_allclose( golden[(design, device_name, deterministic_name)]["GP"], metrics[-3][-1][-1].hpwl.cpu().numpy(), rtol=tolerance[design][0], ) np.testing.assert_allclose( golden[(design, device_name, deterministic_name)]["LG"], metrics[-2].hpwl.cpu().numpy(), rtol=tolerance[design][1], ) np.testing.assert_allclose( golden[(design, device_name, deterministic_name)]["DP"], metrics[-1].hpwl.cpu().numpy(), rtol=tolerance[design][2], )
class Builder(): ready = True picker = None placer = None status_publisher = None block_status_publisher = None def __init__(self): self.status_publisher = rospy.Publisher('/pr2_block_builder/status', Status, latch=True) self.block_status_publisher = rospy.Publisher( '/pr2_block_builder/completion', BlockStatus) self.picker = Picker() self.placer = Placer() rospy.sleep(1) self.sendStatus("ready") def start(self, blocks): if (self.ready): # Prevent further invocations self.ready = False # Send the start status self.sendStatus("started") # Sort the blocks self.sortBlocks(blocks, 0) # Do construction status = self.construct(blocks) # Send the completion status self.sendStatus(status) def stop(self): self.ready = False if self.picker != None: self.picker.cancel() if self.placer != None: self.placer.cancel() def restart(self): self.stop() self.ready = True self.sendStatus("ready") def construct(self, blocks): for i in range(0, len(blocks)): block = blocks[i] # Send the status self.sendBlockStatus(block, "started") # Pick status = self.picker.pick(i) # Place if status == "completed": status = self.placer.place(block) # Send the status self.sendBlockStatus(block, status) # Stop if we've failed or aborted if status != "completed": return status return "completed" def sendStatus(self, status, message=""): rospy.loginfo("Status: %s", status) statusObject = Status() statusObject.status.data = status statusObject.message.data = message self.status_publisher.publish(statusObject) def sendBlockStatus(self, block, status, message=""): rospy.loginfo("Block (%s, %s, %s) %s", block.position.x, block.position.y, block.position.z, status) statusObject = BlockStatus() statusObject.block = block statusObject.status.data = status statusObject.message.data = message self.block_status_publisher.publish(statusObject) def sortBlocks(self, blocks, start): nextBlock = blocks[start] nextBlockIndex = start for i in range(start, len(blocks)): if (blocks[i].position.z < nextBlock.position.z): nextBlock = blocks[i] nextBlockIndex = i elif (blocks[i].position.z == nextBlock.position.z and blocks[i].position.x > nextBlock.position.x): nextBlock = blocks[i] nextBlockIndex = i elif (blocks[i].position.z == nextBlock.position.z and blocks[i].position.x == nextBlock.position.x and blocks[i].position.y > nextBlock.position.y): nextBlock = blocks[i] nextBlockIndex = i blocks[nextBlockIndex] = blocks[start] blocks[start] = nextBlock if (start == len(blocks) - 1): return blocks return self.sortBlocks(blocks, start + 1)
class Builder(): ready = True picker = None placer = None status_publisher = None block_status_publisher = None def __init__(self): self.status_publisher = rospy.Publisher('/pr2_block_builder/status', Status, latch=True) self.block_status_publisher = rospy.Publisher('/pr2_block_builder/completion', BlockStatus) self.picker = Picker() self.placer = Placer() rospy.sleep(1) self.sendStatus("ready") def start(self, blocks): if (self.ready): # Prevent further invocations self.ready = False # Send the start status self.sendStatus("started") # Sort the blocks self.sortBlocks(blocks, 0) # Do construction status = self.construct(blocks) # Send the completion status self.sendStatus(status) def stop(self): self.ready = False if self.picker!=None: self.picker.cancel() if self.placer!=None: self.placer.cancel() def restart(self): self.stop() self.ready = True self.sendStatus("ready") def construct(self, blocks): for i in range(0, len(blocks)): block = blocks[i] # Send the status self.sendBlockStatus(block, "started") # Pick status = self.picker.pick(i) # Place if status=="completed": status = self.placer.place(block, false) # Send the status self.sendBlockStatus(block, status); # Stop if we've failed or aborted if status!="completed": return status return "completed" def sendStatus(self, status, message=""): rospy.loginfo("Status: %s", status) statusObject = Status() statusObject.status.data = status statusObject.message.data = message self.status_publisher.publish(statusObject) def sendBlockStatus(self, block, status, message=""): rospy.loginfo("Block (%s, %s, %s) %s", block.position.x, block.position.y, block.position.z, status) statusObject = BlockStatus() statusObject.block = block statusObject.status.data = status statusObject.message.data = message self.block_status_publisher.publish(statusObject) def sortBlocks(self, blocks, start): dist_block = blocks[i].position.x * blocks[i].position.x + blocks[i].position.y * blocks[i].position.y nextBlock = blocks[start] nextBlockIndex = start dist_nextBlock = dist_block for i in range(start, len(blocks)): dist_block = blocks[i].position.x * blocks[i].position.x + blocks[i].position.y * blocks[i].position.y if (blocks[i].position.z < nextBlock.position.z): nextBlock = blocks[i] nextBlockIndex = i dist_nextBlock = dist_block elif (blocks[i].position.z == nextBlock.position.z and dist_block < dist_nextBlock): nextBlock = blocks[i] nextBlockIndex = i dist_nextBlock = dist_block elif (blocks[i].position.z == nextBlock.position.z and dist_block == dist_nextBlock and blocks[i].position.x < nextBlock.position.x): nextBlock = blocks[i] nextBlockIndex = i dist_nextBlock = dist_block blocks[nextBlockIndex] = blocks[start] blocks[start] = nextBlock if (start == len(blocks)-1): return blocks return self.sortBlocks(blocks, start + 1)