-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #323 from srpathen/main
Adding code that trains on different LLM models and added the introduction to GLayout notebook
- Loading branch information
Showing
33 changed files
with
2,825 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2,239 changes: 2,239 additions & 0 deletions
2,239
docs/source/notebooks/glayout/GLayout_Introduction.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
openfasoc/generators/glayout/glayout/llm/convo_parser/Command.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
from parse_utils import parseKeyValues, parseKwarg, parseTuple, regenKeyValues, regenKwargs, regenTuple | ||
|
||
class Command: | ||
def __init__(self, type: str): | ||
self.type = type | ||
def type(self): | ||
return self.type | ||
def changeParamDependency(self, param, newparam): | ||
return | ||
def changeCompDependency(self, comp, newcomp): | ||
return | ||
|
||
class Import: | ||
def __init__(self, line): | ||
self.line = line | ||
self.type = "import" | ||
self.parseLine() | ||
def parseLine(self): | ||
words = self.line.split(" ") | ||
self.importFile = words[1] | ||
def regenCommand(self): | ||
return f"import {self.importFile}" | ||
|
||
class Param(Command): | ||
def __init__(self, line): | ||
self.line = line | ||
self.type = "create" | ||
self.parseLine() | ||
def parseLine(self): | ||
words = self.line.split(" ") | ||
self.paramType = words[2] | ||
self.name = words[5] | ||
def regenCommand(self): | ||
return f"create a {self.paramType} parameter called {self.name}" | ||
def changeParamDependency(self, param, newparam): | ||
if self.name == param: | ||
self.name = newparam | ||
|
||
# has parameter dependencies | ||
class Place(Command): | ||
def __init__(self, line): | ||
self.line = line | ||
self.type = "place" | ||
self.parseLine() | ||
def parseLine(self): | ||
words = self.line.split(" ") | ||
self.compType = words[2] | ||
if self.compType == "interdigitated": | ||
self.compType += " "+words[3] | ||
self.compName = words[5] | ||
else: | ||
self.compName = words[4] | ||
withIndex = self.line.find(" with ") | ||
if withIndex > -1: | ||
keyValues = self.line[self.line.find(" with ")+len(" with "):] | ||
self.keyValues = parseKeyValues(keyValues) | ||
else: | ||
self.keyValues = None | ||
def changeParamDependency(self, param, newparam): | ||
if self.keyValues == None: | ||
return | ||
for key in self.keyValues: | ||
if self.keyValues[key] == param: | ||
self.keyValues[key] = newparam | ||
if "kwargs" in self.keyValues: | ||
for key in self.keyValues["kwargs"]: | ||
if self.keyValues["kwargs"][key] == param: | ||
self.keyValues["kwargs"][key] = newparam | ||
def changeCompDependency(self, comp, newcomp): | ||
if self.compName == comp: | ||
self.compName = newcomp | ||
def regenCommand(self): | ||
string = f"place a {self.compType} called {self.compName}" | ||
if self.keyValues != None: | ||
string += " with " + regenKeyValues(self.keyValues) | ||
return string | ||
|
||
# Has component dependencies | ||
class Move(Command): | ||
def __init__(self, line): | ||
self.line = line | ||
self.type = "move" | ||
self.parseLine() | ||
def parseLine(self): | ||
words = self.line.split(" ") | ||
self.comp1 = words[1] | ||
self.comp2 = words[-1] | ||
self.moveType = " ".join(words[2:-1]) | ||
def changeCompDependency(self, comp, newcomp): | ||
if self.comp1 == comp: | ||
self.comp1 = newcomp | ||
if self.comp2 == comp: | ||
self.comp2 = newcomp | ||
def regenCommand(self): | ||
return f"move {self.comp1} {self.moveType} {self.comp2}" | ||
|
||
# Has component dependencies, and might have parameter dependencies | ||
class Route(Command): | ||
def __init__(self, line): | ||
self.line = line | ||
self.type = "route" | ||
self.parseLine() | ||
def parseLine(self): | ||
words = self.line.split(" ") | ||
self.port1 = words[2] | ||
self.port2 = words[4] | ||
self.routeType = words[6] | ||
withIndex = self.line.find(" with ") | ||
if withIndex > -1: | ||
keyValues = self.line[self.line.find(" with ")+len(" with "):] | ||
self.keyValues = parseKeyValues(keyValues) | ||
else: | ||
self.keyValues = None | ||
def changeParamDependency(self, param, newparam): | ||
if self.keyValues == None: | ||
return | ||
for key in self.keyValues: | ||
if self.keyValues[key] == param: | ||
self.keyValues[key] = newparam | ||
if "kwargs" in self.keyValues: | ||
for key in self.keyValues["kwargs"]: | ||
if self.keyValues["kwargs"][key] == param: | ||
self.keyValues["kwargs"][key] = newparam | ||
def changeCompDependency(self, comp, newcomp): | ||
comp1 = "" | ||
comp2 = "" | ||
if self.port1.find("_") != -1: | ||
comp1 = self.port1[:self.port1.find("_")] | ||
if self.port2.find("_") != -1: | ||
comp2 = self.port2[:self.port2.find("_")] | ||
if comp1 == comp: | ||
self.port1 = newcomp+self.port1[self.port1.find("_"):] | ||
if comp2 == comp: | ||
self.port2 = newcomp+self.port2[self.port2.find("_"):] | ||
def regenCommand(self): | ||
string = f"route between {self.port1} and {self.port2}" | ||
if self.keyValues != None: | ||
string += " with " + regenKeyValues(self.keyValues) | ||
return string | ||
|
||
class Comment(Command): | ||
def __init__(self, line): | ||
self.line = line | ||
self.type = "comment" | ||
def regenCommand(self): | ||
return self.line | ||
|
||
class Newline(Command): | ||
def __init__(self): | ||
self.type = "newline" | ||
def regenCommand(self): | ||
return "" | ||
|
88 changes: 88 additions & 0 deletions
88
openfasoc/generators/glayout/glayout/llm/convo_parser/convoparser.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from Command import Import, Param, Place, Move, Route, Comment, Newline | ||
from validate_synthetic_data import run_all_tests, instantiate_convo | ||
from glayout.flow.pdk.mappedpdk import MappedPDK | ||
import tempfile | ||
|
||
class Convo: | ||
def __init__(self, compName): | ||
self.compName = compName | ||
self.commands = [] | ||
self.parameters = dict() | ||
self.components = dict() | ||
|
||
def addParam(self, param, type, line): | ||
self.parameters[param]= (type, line) | ||
|
||
def addComp(self, comp, type, line): | ||
self.components[comp] = (type, line) | ||
|
||
def addCommand(self, command): | ||
self.commands.append(command) | ||
|
||
def changeParam(self, param, newparam): | ||
for command in self.commands: | ||
command.changeParamDependency(param, newparam) | ||
old = self.parameters[param] | ||
del self.parameters[param] | ||
self.parameters[newparam] = old | ||
|
||
def changeComp(self, comp, newcomp): | ||
for command in self.commands: | ||
command.changeCompDependency(comp, newcomp) | ||
old = self.components[comp] | ||
del self.components[comp] | ||
self.parameters[newcomp] = old | ||
|
||
def unparametrize(self, param, value): | ||
del self.commands[self.parameters[param][1]] | ||
self.changeParam(param, value) | ||
del self.parameters[param] | ||
|
||
def regen(self): | ||
str = self.compName + "\n" | ||
for command in self.commands: | ||
str += command.regenCommand() + "\n" | ||
str = str[:-2] | ||
return str | ||
|
||
def runDRC(self, pdk: MappedPDK): | ||
temp = tempfile.NamedTemporaryFile() | ||
temp.write(self.regen()) | ||
component = instantiate_convo(pdk, temp.name, return_component=True) | ||
pdk.drc_magic(component, component.name) | ||
|
||
def run_LVSandPEX(self, pdk, netlist): | ||
temp = tempfile.NamedTemporaryFile() | ||
temp.write(self.regen()) | ||
component = instantiate_convo(pdk, temp.name, return_component=True) | ||
pdk.lvs_netgen(component, component.name, copy_intermediate_files=True, netlist=netlist) | ||
|
||
class ConvoParser: | ||
def __init__(self, filename: str): | ||
self.fileContents = open(filename).read() | ||
self.readContents() | ||
|
||
def readContents(self): | ||
commClassMap = {"import":Import, "create":Param, "place":Place, "move": Move, "route":Route} | ||
lines = self.fileContents.split('\n') | ||
self.convo = Convo(lines[0]) | ||
|
||
lineIndex = 0 | ||
for line in lines[1:]: | ||
commandType = line.split(" ")[0] | ||
|
||
if commandType in commClassMap: | ||
command = commClassMap[commandType](line) | ||
self.convo.addCommand(command) | ||
if commandType == "create": | ||
self.convo.addParam(command.name, command.paramType, lineIndex) | ||
elif commandType == "place": | ||
self.convo.addComp(command.compName, command.compType, lineIndex) | ||
|
||
elif len(line) > 0 and line[0] == "#": | ||
self.convo.addCommand(Comment(line)) | ||
|
||
elif line == "": | ||
self.convo.addCommand(Newline()) | ||
|
||
lineIndex += 1 |
Oops, something went wrong.