Skip to content

Commit cec2557

Browse files
author
jonathan.hess
committed
Starting Plotting Templates
1 parent ccdc8be commit cec2557

6 files changed

+183
-9
lines changed

.vscode/launch.json

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"version": "0.2.0",
66
"configurations": [
77

8+
89
{
910
"name": "Python: Schematic Test",
1011
"type": "python",
@@ -29,6 +30,14 @@
2930
"console": "integratedTerminal",
3031
"justMyCode": true
3132
},
33+
{
34+
"name": "Python: Plotting Test",
35+
"type": "python",
36+
"request": "launch",
37+
"program": "tests/plottingtemplatetest.py",
38+
"console": "integratedTerminal",
39+
"justMyCode": true
40+
},
3241
{
3342
"name": "Python: Module",
3443
"type": "python",

environment.yml

+7-4
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ channels:
55
dependencies:
66
# Runtime
77
- attrdict3=2.0.2
8-
- wxPython=4.2.1
8+
- wxPython=4.2.1 #GUI
99
- python=3.11
1010
- pydantic=2.0.3
1111
- pandas=2.0.3
1212
- rich=13.4.2
13-
- skillbridge=1.5.0
13+
- skillbridge=1.5.0 #python-skill communication
14+
- beautifulsoup4 #XML
15+
- lxml
1416
# Development and Testing
15-
- PyInstaller=5.13.0
16-
- conda=23.5.2
17+
- PyInstaller=5.13.0 #build
18+
- conda=23.5.2 #ENV
1719
- mamba=1.4.9
1820
- pip=23.2
1921
- flit=3.9.0
@@ -23,3 +25,4 @@ dependencies:
2325
# documentation
2426
- mkdocs=1.4.3
2527
- mkdocs-material=9.1.19
28+

morpheus/CadenceManager.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,22 @@
1919

2020

2121
class cadenceManager:
22-
def __init__(self,id):
22+
def __init__(self,id, cwd=None, precommand= ""):
2323
self.timeout= 300 #5 minute timeout
24-
self.log_file = os.path.join(os.getcwd(), "virtuoso_log.txt")
25-
self.createNewCadence(id)
24+
if(cwd is None): cwd=os.getcwd()
25+
self.log_file = os.path.join(cwd, "virtuoso_log.txt")
26+
self.createNewCadence(id,cwd, precommand)
2627
self.checkInactive()
2728
#self.loop()
2829

29-
def createNewCadence(self, id):
30+
def createNewCadence(self, id,cwd, precommand):
3031

3132

3233
# Run virtuoso with input from a string
33-
virtuoso_process = subprocess.Popen(["virtuoso", "-nograph"],cwd=os.getcwd(), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
34+
print("start cadence at: "+ cwd)
35+
command = precommand.split() + [ ";icfb", "-nograph"]
36+
#virtuoso_process = subprocess.Popen(command, capture_output=True, shell=True)
37+
virtuoso_process = subprocess.Popen(command ,cwd=cwd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True) #TODO SUPPORT BOTH VIRTUOSO AND ICFB
3438

3539
def log_stdout():
3640
with open(self.log_file, 'w') as log_file:

morpheus/PlottingTemplate.py

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
from distutils.dir_util import copy_tree
2+
from bs4 import BeautifulSoup
3+
from lxml import objectify, etree
4+
5+
from xml.dom import minidom
6+
import os
7+
8+
class PlottingTemplate:
9+
def __init__(self,ws,lib,cell,view) -> None: #for pin terminals
10+
self.ws = ws
11+
self.lib = lib
12+
self.cell = cell
13+
self.view = view
14+
15+
pass
16+
17+
#Import ploting template from existing maestro plotting template
18+
def import_plotting_template(self, pt_lib, pt_cell, pt_view, pTemplate):
19+
20+
21+
#copy the exisitng template
22+
print(self.ws['getWorkingDir']());
23+
cellview = self.ws.dd.GetObj(pt_lib,pt_cell,pt_view) #get the cellview for a filelocation on disk
24+
path = cellview.write_path #get filepath from cellview
25+
print(path);
26+
filepath = path +"/plottingTemplates/"+ pTemplate + "/" + pTemplate+ "_0.cmpt";
27+
with open(filepath, 'r') as f:
28+
file = f.read()
29+
soup = BeautifulSoup(bytes(file, encoding='utf8'),"xml")
30+
xml_object = objectify.parse(filepath) #get_etree
31+
32+
self.root = objectify.fromstring(bytes(file, encoding='utf8'))
33+
attrib = self.root.attrib
34+
#Now that we have the XML we should convert to (remove excess data) a YML/Object format for saving
35+
self.root
36+
self.soup = soup
37+
38+
#get Markers?
39+
40+
print(soup);
41+
42+
43+
44+
#export the loaded template to new maestro cellview
45+
def export_plotting_template(self,pt_lib,pt_cell,pt_view,pTemplate):
46+
47+
cellview = self.ws.dd.GetObj(pt_lib,pt_cell,pt_view) #get the cellview for a filelocation on disk
48+
path = cellview.write_path #get filepath from cellview
49+
#MIN DATA FOR CMPT.group file
50+
51+
# <?xml version="1.0" encoding="UTF-8" ?>
52+
# <!--StateFileType saveLoadState-->
53+
# <topLevel>
54+
# <IndexedProp Name="graphFileList">
55+
# <SimpleProp Value="Template2_0.cmpt" Type="stringValue" />
56+
# </IndexedProp>
57+
# </topLevel>
58+
59+
# file = open(filename, 'w',encoding='utf8')
60+
# file.write(str(self.soup))
61+
# file.close()
62+
63+
filename = path +"/plottingTemplates/"+ pTemplate + "/" + pTemplate+ "_0.cmpt";
64+
os.makedirs(os.path.dirname(filename), exist_ok=True)
65+
#for now just relay the template
66+
file = open(filename, 'w',encoding='utf8')
67+
file.write(str(self.soup))
68+
file.close()
69+
70+
etree.tostring(self.root, pretty_print=True)
71+
self.updateMaestroXML(pt_lib,pt_cell,pt_view,pTemplate)
72+
73+
# root = minidom.Document()
74+
75+
# xml = root.createElement('root')
76+
# root.appendChild(xml)
77+
78+
# productChild = root.createElement('product')
79+
# productChild.setAttribute('name', 'Geeks for Geeks')
80+
81+
# xml.appendChild(productChild)
82+
83+
# xml_str = root.toprettyxml(indent ="\t")
84+
85+
# save_path_file = "gfg.xml"
86+
87+
def updateMaestroXML(self,pt_lib,pt_cell,pt_view,pTemplate):
88+
cellview = self.ws.dd.GetObj(pt_lib,pt_cell,pt_view) #get the cellview for a filelocation on disk
89+
path = cellview.write_path #get filepath from cellview
90+
filepath = path + "/maestro.sdb"
91+
with open(filepath, 'r') as f:
92+
file = f.read()
93+
94+
maestroXML = BeautifulSoup(bytes(file, encoding='utf8'),"xml")
95+
plottingOptions = maestroXML.find_all("plottingoption")
96+
#check if plotting templates are an option
97+
plottingTemplates = [option for option in plottingOptions if "allplottingtemplate" in option.next] #find the plotting templates option
98+
99+
#TODO check if there isnt a plotting templates already
100+
if(plottingTemplates is None):
101+
pass
102+
plottingTemplates = plottingTemplates[0]
103+
#plottingTemplates.append("<")
104+
105+
new_plottingtemplate = maestroXML.new_tag("plottingtemplate")
106+
#<templatelocation>/orpheus_tests/templatetest1/maestro/plottingTemplates/</templatelocation>
107+
new_plottingtemplate.string = pTemplate
108+
location =maestroXML.new_tag("templatelocation")
109+
templates_filepath = path +"/plottingTemplates/";
110+
location.string = templates_filepath
111+
new_plottingtemplate.append(location)
112+
plottingTemplates.append(new_plottingtemplate)
113+
114+
print(maestroXML)
115+
print(plottingOptions)
116+
117+
file = open(filepath, 'w')
118+
file.write(str(maestroXML))
119+
file.close()

tests/plottingtemplatetest.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
3+
import asyncio
4+
from skillbridge import Workspace
5+
import sys
6+
import os.path
7+
parentddir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))
8+
sys.path.append(parentddir)
9+
from morpheus.Schematic import schematic
10+
from morpheus import Config
11+
#sys.path.append(S
12+
# os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
13+
from morpheus import *
14+
from morpheus.PlottingTemplate import PlottingTemplate
15+
16+
17+
from morpheus.CadenceManager import cadenceManager
18+
19+
20+
21+
id = "test"
22+
lib = "morpheus_tests"
23+
cell = "templatetest2"
24+
view = "maestro"
25+
template = "Template1"
26+
27+
manager = cadenceManager(id) #, cwd = "", precommand="")
28+
ws = Workspace.open(id)
29+
30+
31+
pt = PlottingTemplate(ws,lib,cell,view) #setup template2 as the maestro to edit
32+
33+
34+
cell = "templatetest1" #copy from template1
35+
36+
pt.import_plotting_template(lib,cell,view,template)
37+
template = "Template2"
38+
pt.export_plotting_template(lib,cell,view,template) #add same template to same cell
39+
#manager.killCadence()py

virtuoso_log.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)