Unverified Commit 91564014 by Yucheng Wang Committed by GitHub

Merge pull request #23 from TILOS-AI-Institute/plc_client-open-source

Plc client open source runnable on CT
parents 1751d2a7 d2b1e651
...@@ -9,3 +9,4 @@ CodeElements/Plc_client/plc_client_os.py ...@@ -9,3 +9,4 @@ CodeElements/Plc_client/plc_client_os.py
CodeElements/Plc_client/__pycache__/* CodeElements/Plc_client/__pycache__/*
CodeElements/Plc_client/proto_reader.py CodeElements/Plc_client/proto_reader.py
CodeElements/Plc_client/plc_client.py CodeElements/Plc_client/plc_client.py
CodeElements/Plc_client/failed_proxy_plc/*
\ No newline at end of file
...@@ -85,5 +85,11 @@ $$ ...@@ -85,5 +85,11 @@ $$
Notice a smoothing range can be set for congestion. This is only applied to congestion due to net routing which by counting adjacent cells and adding the averaged congestion to these adjacent cells. More details are provided in the document above. Notice a smoothing range can be set for congestion. This is only applied to congestion due to net routing which by counting adjacent cells and adding the averaged congestion to these adjacent cells. More details are provided in the document above.
## Placement Util
**Disclaimer: We DO NOT own the content of placement_util_os.py. All rights belong to Google Authors. This is a modified version of placement_util.py and we are including in the repo for the sake of testing. Original Code can be viewed [here](https://github.com/google-research/circuit_training/blob/main/circuit_training/environment/placement_util.py)**.
## Observation Extractor
**Disclaimer: We DO NOT own the content of observation_extractor_os.py. All rights belong to Google Authors. This is a modified version of observation_extractor.py and we are including in the repo for the sake of testing. Original Code can be viewed [here](https://github.com/google-research/circuit_training/blob/main/circuit_training/environment/observation_extractor.py)**.
# coding=utf-8
# Copyright 2021 The Circuit Training Team Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""A class to store the observation shape and sizes."""
from typing import Dict, List, Optional, Text, Tuple, Union
import gin
import gym
import numpy as np
import tensorflow as tf
TensorType = Union[np.ndarray, tf.Tensor]
FeatureKeyType = Union[List[Text], Tuple[Text, ...]]
HARD_MACRO = 1
SOFT_MACRO = 2
PORT_CLUSTER = 3
NETLIST_METADATA = (
'normalized_num_edges',
'normalized_num_hard_macros',
'normalized_num_soft_macros',
'normalized_num_port_clusters',
'horizontal_routes_per_micron',
'vertical_routes_per_micron',
'macro_horizontal_routing_allocation',
'macro_vertical_routing_allocation',
'grid_cols',
'grid_rows',
)
GRAPH_ADJACENCY_MATRIX = ('sparse_adj_i', 'sparse_adj_j', 'sparse_adj_weight',
'edge_counts')
NODE_STATIC_FEATURES = (
'macros_w',
'macros_h',
'node_types',
)
STATIC_OBSERVATIONS = (
NETLIST_METADATA + GRAPH_ADJACENCY_MATRIX + NODE_STATIC_FEATURES)
INITIAL_DYNAMIC_OBSERVATIONS = (
'locations_x',
'locations_y',
'is_node_placed',
)
DYNAMIC_OBSERVATIONS = (
'locations_x',
'locations_y',
'is_node_placed',
'current_node',
'mask',
)
ALL_OBSERVATIONS = STATIC_OBSERVATIONS + DYNAMIC_OBSERVATIONS
INITIAL_OBSERVATIONS = STATIC_OBSERVATIONS + INITIAL_DYNAMIC_OBSERVATIONS
@gin.configurable
class ObservationConfig(object):
"""A class that contains shared configs for observation."""
# The default numbers are the maximum number of nodes, edges, and grid size
# on a set of TPU blocks.
# Large numbers may cause GPU/TPU OOM during training.
def __init__(self,
max_num_nodes: int = 5000,
max_num_edges: int = 28400,
max_grid_size: int = 128):
self.max_num_edges = max_num_edges
self.max_num_nodes = max_num_nodes
self.max_grid_size = max_grid_size
@property
def observation_space(self) -> gym.spaces.Space:
"""Env Observation space."""
return gym.spaces.Dict({
'normalized_num_edges':
gym.spaces.Box(low=0, high=1, shape=(1,)),
'normalized_num_hard_macros':
gym.spaces.Box(low=0, high=1, shape=(1,)),
'normalized_num_soft_macros':
gym.spaces.Box(low=0, high=1, shape=(1,)),
'normalized_num_port_clusters':
gym.spaces.Box(low=0, high=1, shape=(1,)),
'horizontal_routes_per_micron':
gym.spaces.Box(low=0, high=100, shape=(1,)),
'vertical_routes_per_micron':
gym.spaces.Box(low=0, high=100, shape=(1,)),
'macro_horizontal_routing_allocation':
gym.spaces.Box(low=0, high=100, shape=(1,)),
'macro_vertical_routing_allocation':
gym.spaces.Box(low=0, high=100, shape=(1,)),
'sparse_adj_weight':
gym.spaces.Box(low=0, high=100, shape=(self.max_num_edges,)),
'sparse_adj_i':
gym.spaces.Box(
low=0,
high=self.max_num_nodes - 1,
shape=(self.max_num_edges,),
dtype=np.int32),
'sparse_adj_j':
gym.spaces.Box(
low=0,
high=self.max_num_nodes - 1,
shape=(self.max_num_edges,),
dtype=np.int32),
'edge_counts':
gym.spaces.Box(
low=0,
high=self.max_num_edges - 1,
shape=(self.max_num_nodes,),
dtype=np.int32),
'node_types':
gym.spaces.Box(
low=0, high=3, shape=(self.max_num_nodes,), dtype=np.int32),
'is_node_placed':
gym.spaces.Box(
low=0, high=1, shape=(self.max_num_nodes,), dtype=np.int32),
'macros_w':
gym.spaces.Box(low=0, high=1, shape=(self.max_num_nodes,)),
'macros_h':
gym.spaces.Box(low=0, high=1, shape=(self.max_num_nodes,)),
'locations_x':
gym.spaces.Box(low=0, high=1, shape=(self.max_num_nodes,)),
'locations_y':
gym.spaces.Box(low=0, high=1, shape=(self.max_num_nodes,)),
'grid_cols':
gym.spaces.Box(low=0, high=1, shape=(1,)),
'grid_rows':
gym.spaces.Box(low=0, high=1, shape=(1,)),
'current_node':
gym.spaces.Box(
low=0, high=self.max_num_nodes - 1, shape=(1,), dtype=np.int32),
'mask':
gym.spaces.Box(
low=0, high=1, shape=(self.max_grid_size**2,), dtype=np.int32),
})
def _to_dict(
flatten_obs: TensorType,
keys: FeatureKeyType,
observation_config: Optional[ObservationConfig] = None
) -> Dict[Text, TensorType]:
"""Unflatten the observation to a dictionary."""
if observation_config:
obs_space = observation_config.observation_space
else:
obs_space = ObservationConfig().observation_space
splits = [obs_space[k].shape[0] for k in keys]
splitted_obs = tf.split(flatten_obs, splits, axis=-1)
return {k: o for o, k in zip(splitted_obs, keys)}
def _flatten(dict_obs: Dict[Text, TensorType],
keys: FeatureKeyType) -> TensorType:
out = [np.asarray(dict_obs[k]) for k in keys]
return np.concatenate(out, axis=-1)
def flatten_static(dict_obs: Dict[Text, TensorType]) -> TensorType:
return _flatten(dict_obs=dict_obs, keys=STATIC_OBSERVATIONS)
def flatten_dynamic(dict_obs: Dict[Text, TensorType]) -> TensorType:
return _flatten(dict_obs=dict_obs, keys=DYNAMIC_OBSERVATIONS)
def flatten_all(dict_obs: Dict[Text, TensorType]) -> TensorType:
return _flatten(dict_obs=dict_obs, keys=ALL_OBSERVATIONS)
def flatten_initial(dict_obs: Dict[Text, TensorType]) -> TensorType:
return _flatten(dict_obs=dict_obs, keys=INITIAL_OBSERVATIONS)
def to_dict_static(
flatten_obs: TensorType,
observation_config: Optional[ObservationConfig] = None
) -> Dict[Text, TensorType]:
"""Convert the flattend numpy array of static observations back to a dict.
Args:
flatten_obs: a numpy array of static observations.
observation_config: Optional observation config.
Returns:
A dict representation of the observations.
"""
return _to_dict(
flatten_obs=flatten_obs,
keys=STATIC_OBSERVATIONS,
observation_config=observation_config)
def to_dict_dynamic(
flatten_obs: TensorType,
observation_config: Optional[ObservationConfig] = None
) -> Dict[Text, TensorType]:
"""Convert the flattend numpy array of dynamic observations back to a dict.
Args:
flatten_obs: a numpy array of dynamic observations.
observation_config: Optional observation config.
Returns:
A dict representation of the observations.
"""
return _to_dict(
flatten_obs=flatten_obs,
keys=DYNAMIC_OBSERVATIONS,
observation_config=observation_config)
def to_dict_all(
flatten_obs: TensorType,
observation_config: Optional[ObservationConfig] = None
) -> Dict[Text, TensorType]:
"""Convert the flattend numpy array of observations back to a dict.
Args:
flatten_obs: a numpy array of observations.
observation_config: Optional observation config.
Returns:
A dict representation of the observations.
"""
return _to_dict(
flatten_obs=flatten_obs,
keys=ALL_OBSERVATIONS,
observation_config=observation_config)
\ No newline at end of file
...@@ -23,13 +23,13 @@ node { ...@@ -23,13 +23,13 @@ node {
attr { attr {
key: "x" key: "x"
value { value {
f: 399 f: 300
} }
} }
attr { attr {
key: "y" key: "y"
value { value {
f: 399 f: 300
} }
} }
attr { attr {
...@@ -44,7 +44,7 @@ node { ...@@ -44,7 +44,7 @@ node {
attr { attr {
key: "height" key: "height"
value { value {
f: 50 f: 200
} }
} }
attr { attr {
...@@ -74,7 +74,7 @@ node { ...@@ -74,7 +74,7 @@ node {
attr { attr {
key: "width" key: "width"
value { value {
f: 50 f: 200
} }
} }
} }
...@@ -96,31 +96,31 @@ node { ...@@ -96,31 +96,31 @@ node {
attr { attr {
key: "x_offset" key: "x_offset"
value { value {
f: -25 f: -75
} }
} }
attr { attr {
key: "y_offset" key: "y_offset"
value { value {
f: -25 f: -75
} }
} }
attr { attr {
key: "x" key: "x"
value { value {
f: 374 f: 0
} }
} }
attr { attr {
key: "y" key: "y"
value { value {
f: 374 f: 0
} }
} }
attr { attr {
key: "weight" key: "weight"
value { value {
f: 1000 f: 1
} }
} }
} }
...@@ -141,31 +141,31 @@ node { ...@@ -141,31 +141,31 @@ node {
attr { attr {
key: "x_offset" key: "x_offset"
value { value {
f: -25 f: -75
} }
} }
attr { attr {
key: "y_offset" key: "y_offset"
value { value {
f: 25 f: 75
} }
} }
attr { attr {
key: "x" key: "x"
value { value {
f: 374 f: 0
} }
} }
attr { attr {
key: "y" key: "y"
value { value {
f: 424 f: 0
} }
} }
attr { attr {
key: "weight" key: "weight"
value { value {
f: 1000 f: 1
} }
} }
} }
...@@ -186,25 +186,25 @@ node { ...@@ -186,25 +186,25 @@ node {
attr { attr {
key: "x_offset" key: "x_offset"
value { value {
f: 25 f: 75
} }
} }
attr { attr {
key: "y_offset" key: "y_offset"
value { value {
f: -25 f: -75
} }
} }
attr { attr {
key: "x" key: "x"
value { value {
f: 75 f: 0
} }
} }
attr { attr {
key: "y" key: "y"
value { value {
f: 25 f: 0
} }
} }
} }
...@@ -225,25 +225,25 @@ node { ...@@ -225,25 +225,25 @@ node {
attr { attr {
key: "x_offset" key: "x_offset"
value { value {
f: 25 f: 75
} }
} }
attr { attr {
key: "y_offset" key: "y_offset"
value { value {
f: 25 f: 75
} }
} }
attr { attr {
key: "x" key: "x"
value { value {
f: 75 f: 0
} }
} }
attr { attr {
key: "y" key: "y"
value { value {
f: 75 f: 0
} }
} }
} }
\ No newline at end of file
# Placement file for Circuit Training # Placement file for Circuit Training
# Source input file(s) : ./output_ariane_NanGate45/22cols_30rows/g500_ub5_nruns10_c5_r3_v3_rc1/netlist.pb.txt # Source input file(s) : environment/test_data/ariane/ariane.txt
# This file : ./output_ariane_NanGate45/22cols_30rows/g500_ub5_nruns10_c5_r3_v3_rc1/initial.plc # This file : environment/test_data/ariane/init.plc
# Original initial placement : # Date : 2022-03-13 09:30:00
# Date : 2022-08-26 08:27:04 # Columns : 50 Rows : 50
# Columns : 22 Rows : 30 # Width : 1599.99 Height : 1598.8
# Width : 1357.360 Height : 1356.880 # Area : 1244102.4819999968
# Area (stdcell+macros) : 1448306.937872215 # Wirelength : 0.0
# Wirelength : 3264054.817 # Wirelength cost : 0.0
# Wirelength cost : 0.0540 # Congestion cost : 0.0
# Congestion cost : 0.8487 # Block : ariane
# Density cost : 0.6405 # Routes per micron, hor : 70.33 ver : 74.51
# Fake net cost : 0.0000 # Routes used by macros, hor : 51.79 ver : 51.79
# 90% Congestion metric: (0.01363636363636364, 0.0006827604141139862) # Smoothing factor : 2
# Project : unset_project # Overlap threshold : 0.004
# Block : unset_block
# Routes per micron, hor : 11.285 ver : 12.605
# Routes used by macros, hor : 7.143 ver : 8.339
# Smoothing factor : 0
# Use incremental cost : False
#
# To view this file (most options are default):
# viewer_binary --netlist_file ./output_ariane_NanGate45/22cols_30rows/g500_ub5_nruns10_c5_r3_v3_rc1/netlist.pb.txt --canvas_width 1357.36 --canvas_height 1356.88 --grid_cols 22 --grid_rows=30 --init_placement ./output_ariane_NanGate45/22cols_30rows/g500_ub5_nruns10_c5_r3_v3_rc1/initial.plc --project unset_project --block_name unset_block --congestion_smooth_range 0 --overlap_threshold 0 --noboundary_check
# or you can simply run:
# viewer_binary --init_placement ./output_ariane_NanGate45/22cols_30rows/g500_ub5_nruns10_c5_r3_v3_rc1/initial.plc
# #
# #
# #
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment