-
Notifications
You must be signed in to change notification settings - Fork 5
/
main_RP_placement.py
91 lines (73 loc) · 3.91 KB
/
main_RP_placement.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# ========================================================================
#
# Script to generate a placement for a circuit, by using simulated annealing.
#
# SPDX-FileCopyrightText: 2023 Jakob Ratschenberger
# Johannes Kepler University, Institute for Integrated Circuits
#
# 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.
# SPDX-License-Identifier: Apache-2.0
# ========================================================================
import argparse
import faulthandler
faulthandler.enable()
from SchematicCapture.utils import setup_circuit, include_primitives_hierarchical
from Magic.utils import instantiate_circuit, add_cells
from rectangle_packing_placement.utils import do_bottom_up_placement
from SchematicCapture.RString import include_RStrings_hierarchical
from Magic.MagicDie import MagicDie
from rectangle_packing_placement.utils import do_bottom_up_placement
import logging
from logging.handlers import RotatingFileHandler
import pickle
#########################################################################
#global variables to control the placement
CIRCUIT_FILE = "Circuits/Examples/DiffAmp.spice" #Input spice-netlist
CIRCUIT_NAME = "DiffAmp" #Name of the circuit
NET_RULES_FILE = "NetRules/net_rules_DiffAmp.json" #Net-rules definition file
N_PLACEMENTS = 1000 #Number of trial placements done per circuit/subcircuit
USE_LOGGER = False #If True, debug information will be logged under "Logs/{CIRCUIT_NAME}_placement.log".
INSTANTIATE_CELLS_IN_MAGIC = False #If True, the devices cell-view will be instantiated in Magic
SIM_ANNEAL_MIN = 0.1 #Maximum spend time for simulated annealing (per circuit/subcircuit) when N_PLACEMENT=None
SIM_ANNEAL_STEPS = 200 #Number of steps done by the simulated annealing to find Tmax and Tmin (per circuit/subcircuit)
DEF_FILE = None #Def file of the circuit
SHOW_STATS = True #Show statistics of the placement
#########################################################################
def main():
if USE_LOGGER:
#Setup a logger
logHandler = RotatingFileHandler(filename=f"Logs/{CIRCUIT_NAME}_placement.log", mode='w', maxBytes=100e3, backupCount=1, encoding='utf-8')
logHandler.setLevel(logging.DEBUG)
logging.basicConfig(handlers=[logHandler], level=logging.DEBUG, format="[%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s")
#setup the circuit
C = setup_circuit(CIRCUIT_FILE, CIRCUIT_NAME, [], net_rules_file=NET_RULES_FILE)
#include primitive compositions into the circuit
include_primitives_hierarchical(C)
include_RStrings_hierarchical(C)
#instantiate the circuit cells in magic
if INSTANTIATE_CELLS_IN_MAGIC:
instantiate_circuit(C,"Magic/Devices")
#add the cells to the devices
add_cells(C, "Magic/Devices")
#define a die for the circuit
die = MagicDie(circuit=C, def_file=DEF_FILE)
#do the placement per simulated annealing
#and store images of the placement under "Images"
do_bottom_up_placement(die, fig_path="Images", simanneal_minutes=SIM_ANNEAL_MIN, simanneal_steps=SIM_ANNEAL_STEPS,
n_placements=N_PLACEMENTS, show_stats=SHOW_STATS)
#save the placed circuit
file = open(f"PlacementCircuits/{CIRCUIT_NAME}_placement.pkl", 'wb')
pickle.dump(die, file)
file.close()
if __name__=='__main__':
main()