Skip to content

Commit

Permalink
Ruff --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasc-ubc committed Jul 29, 2024
1 parent f807292 commit f67bb5f
Show file tree
Hide file tree
Showing 62 changed files with 136 additions and 259 deletions.
2 changes: 1 addition & 1 deletion klayout_dot_config/python/SiEPIC/_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# Define global Net object that implements netlists and pin searching/connecting
# NET = Net()

from .core import Net, Component
from .core import Net
NET_DISCONNECTED = Net()

# don't use a global one.. based on cells
Expand Down
1 change: 0 additions & 1 deletion klayout_dot_config/python/SiEPIC/calibre_temp.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ def calibreDRC(params = None, cell = None):

version = sys.version
if version.find("2.") > -1:
import commands

progress.set(2, True)
progress.format = "Uploading Layout and Scripts"
Expand Down
10 changes: 5 additions & 5 deletions klayout_dot_config/python/SiEPIC/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def set_SPICE_params(self, arg, verbose = False):
spice_str = self.pdic2str(arg)
else:
return False
newSPICE_text = 'Spice_param:' + spice_str;
newSPICE_text = 'Spice_param:' + spice_str

cell = self.cell
cell_idx = cell.cell_index()
Expand All @@ -286,10 +286,10 @@ def set_SPICE_params(self, arg, verbose = False):

while not(iter_sh.at_end()): # Find cell where SPICE params are stored
if iter_sh.shape().is_text():
shape = iter_sh.shape();
shape = iter_sh.shape()
text = shape.text
if text.string.find("Spice_param:") > -1:
new_text = pya.Text(newSPICE_text, shape.text_trans,shape.text_size ,-1);
new_text = pya.Text(newSPICE_text, shape.text_trans,shape.text_size ,-1)
new_text.halign = text.halign
shape.text = new_text
self.params = spice_str
Expand All @@ -302,7 +302,7 @@ def set_SPICE_params(self, arg, verbose = False):
cell_inst = cell

t = pya.Trans(pya.Trans.R0,pya.Point(0,0)) # Coordinates are with respect to the cell center
new_text = pya.Text(newSPICE_text, t,0.1/ly.dbu ,-1);
new_text = pya.Text(newSPICE_text, t,0.1/ly.dbu ,-1)
cell_inst.shapes(LayerDevRecN).insert(new_text)
self.params = spice_str
return True
Expand Down Expand Up @@ -401,7 +401,7 @@ def update(self):
# print ('SiEPIC.core, Waveguide GUI: tech %s, waveguide_types: %s' % (tech_name, waveguide_types) )
if 0:
# keep only simple waveguides (not compound ones)
waveguide_types_simple = [t for t in waveguide_types if not 'compound_waveguide' in t.keys()]
waveguide_types_simple = [t for t in waveguide_types if 'compound_waveguide' not in t.keys()]
self.waveguides = waveguide_types_simple
try:
self.options = [waveguide['name'] for waveguide in self.waveguides]
Expand Down
1 change: 0 additions & 1 deletion klayout_dot_config/python/SiEPIC/examples.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pya

def dbl_bus_ring_res():
pass
Expand Down
16 changes: 7 additions & 9 deletions klayout_dot_config/python/SiEPIC/extend.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def unique_points(self):


def translate_from_center(self, offset):
from math import pi, cos, sin, acos, sqrt
from math import pi, cos, sin
from .utils import angle_vector
pts = [pt for pt in self.get_dpoints()]
tpts = [pt for pt in self.get_dpoints()]
Expand Down Expand Up @@ -724,7 +724,7 @@ def find_pins(self, verbose=False, polygon_devrec=None, GUI=False):
pins = []

# Pin Recognition layer
if not 'PinRec' in TECHNOLOGY:
if 'PinRec' not in TECHNOLOGY:
if GUI:
pya.MessageBox.warning(
"Problem with Technology", "Problem with active Technology %s: missing layer PinRec" % (TECHNOLOGY['technology_name']), pya.MessageBox.Ok)
Expand Down Expand Up @@ -804,7 +804,7 @@ def find_pins(self, verbose=False, polygon_devrec=None, GUI=False):
it.next()

# Optical IO (Fibre) Recognition layer
if not 'FbrTgt' in TECHNOLOGY:
if 'FbrTgt' not in TECHNOLOGY:
if GUI:
pya.MessageBox.warning(
"Problem with Technology", "Problem with active Technology %s: missing layer FbrTgt"% (TECHNOLOGY['technology_name']), pya.MessageBox.Ok)
Expand Down Expand Up @@ -841,7 +841,7 @@ def find_pins(self, verbose=False, polygon_devrec=None, GUI=False):
it.next()

# Metal Pin Recognition layer
if not 'PinRecM' in TECHNOLOGY:
if 'PinRecM' not in TECHNOLOGY:
if GUI:
pya.MessageBox.warning(
"Problem with Technology", "Problem with active Technology %s: missing layer PinRecM" % (TECHNOLOGY['technology_name']), pya.MessageBox.Ok)
Expand Down Expand Up @@ -990,7 +990,6 @@ def find_components(self, cell_selected=None, inst=None, verbose=False, raiseExc
components = []

from .core import Component
from . import _globals
from .utils import get_technology_by_name
if 'TECHNOLOGY' in dir(self.layout()):
TECHNOLOGY = self.layout().TECHNOLOGY
Expand All @@ -1016,7 +1015,7 @@ def find_components(self, cell_selected=None, inst=None, verbose=False, raiseExc
subcell = iter1.cell() # cell (component) to which this shape belongs
if verbose:
print(' - looking at shape in cell %s. ' % subcell.name)
if cell_selected and not subcell in cell_selected:
if cell_selected and subcell not in cell_selected:
# check if subcell is one of the arguments to this function: cell_selected
if verbose:
print(' - cell_selected and not subcell (%s) in cell_selected (%s). ' % (subcell.name, cell_selected[0].name))
Expand Down Expand Up @@ -1243,7 +1242,7 @@ def get_LumericalINTERCONNECT_analyzers(self, components, verbose=None):
topcell = self

from . import _globals
from .utils import select_paths, get_technology_by_name
from .utils import get_technology_by_name
from .core import Net
TECHNOLOGY = get_technology_by_name(self.layout().technology().name)

Expand Down Expand Up @@ -1407,7 +1406,7 @@ def get_LumericalINTERCONNECT_analyzers_from_opt_in(self, components, verbose=No
if tunable_lasers[i]['wavelength'] == opt_in_dict[0]['wavelength'] and tunable_lasers[i]['polarization'] == opt_in_dict[0]['pol']:
wavelength_start, wavelength_stop, wavelength_points = float(tunable_lasers[i]['wavelength-start']), float(
tunable_lasers[i]['wavelength-stop']), int(tunable_lasers[i]['wavelength-points'])
if not('wavelength_start' in locals()):
if 'wavelength_start' not in locals():
warning = pya.QMessageBox()
warning.setStandardButtons(pya.QMessageBox.Ok)
warning.setText("No laser at %s nm is available. Tunable laser definition is in the technology's DFT.xml file." %
Expand Down Expand Up @@ -1780,7 +1779,6 @@ def plot(self, width = 800, show_labels = True, show_ruler = True, retina = True
retina: IPython.display.Image configuration for retina display, True
'''

from io import BytesIO
from IPython.display import Image, display

# Create a LayoutView, and populate it with the current cell & layout
Expand Down
4 changes: 0 additions & 4 deletions klayout_dot_config/python/SiEPIC/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@

def github_check_SiEPICTools_version():

import sys
import pya

try:
Expand All @@ -69,7 +68,6 @@ def github_check_SiEPICTools_version():
return []

import json
import os
try:
r = requests.get("https://api.github.com/repos/lukasc-ubc/SiEPIC-Tools/releases/latest")
except:
Expand Down Expand Up @@ -97,7 +95,6 @@ def github_check_SiEPICTools_version():

def github_get_filenames(user, repo, filesearch, extension='', auth=None, verbose=None):

import sys
import pya

try:
Expand All @@ -111,7 +108,6 @@ def github_get_filenames(user, repo, filesearch, extension='', auth=None, verbos
return []

import json
import os
filenames = []
folders = []
filesearch = filesearch.replace('%20', ' ')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def swap_rows(arr, frm, to):
#%% the bread and butter
def contraDC_model(params, verbose = True):

import cmath, math
import sys, os, time
import cmath
import math
import numpy as np
import scipy.linalg

Expand Down Expand Up @@ -365,7 +365,6 @@ def cdc_simulation(verbose=True, FDTD_settings = None):

# get selected instances; only one
from ..utils import select_instances
from .. import _globals

# print error message if no or more than one component selected
selected_instances = select_instances()
Expand Down Expand Up @@ -398,9 +397,9 @@ def cdc_simulation(verbose=True, FDTD_settings = None):
params['wavelength_points'] = wavelength_points

if params["sinusoidal"] == False:
sinusoidal = 0;
sinusoidal = 0
else:
sinusoidal = 1;
sinusoidal = 1
error.setText("Error: The simulation model currently does not support sinusoidal gratings.")
response = error.exec_()
return
Expand Down
16 changes: 8 additions & 8 deletions klayout_dot_config/python/SiEPIC/lumerical/fdtd.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import pya

try:
import pyparsing
pass
except:
try:
import pip
Expand Down Expand Up @@ -202,7 +202,7 @@ def generate_component_sparam(do_simulation = True, addto_CML = True, verbose =
else:
fdtd_extra = 0 # 200e-9
FDTDxmin,FDTDxmax,FDTDymin,FDTDymax = (devrec_box.left)*dbum-fdtd_extra, (devrec_box.right)*dbum+fdtd_extra, (devrec_box.bottom)*dbum-fdtd_extra, (devrec_box.top)*dbum+fdtd_extra
sim_time = max(devrec_box.width(),devrec_box.height())*dbum * 4.5;
sim_time = max(devrec_box.width(),devrec_box.height())*dbum * 4.5
lumapi.evalScript(_globals.FDTD, " \
newproject; closeall; \
addfdtd; set('x min',%s); set('x max',%s); set('y min',%s); set('y max',%s); set('z span',%s);\
Expand Down Expand Up @@ -297,7 +297,7 @@ def send_polygons_to_FDTD(polygons):
# Calculate mode sources
# Get field profiles, to find |E| = 1e-6 points to find spans
import sys
if not 'win' in sys.platform: # Windows getVar ("E") doesn't work.
if 'win' not in sys.platform: # Windows getVar ("E") doesn't work.
min_z, max_z = 0,0
for p in [pins[0]]: # if all pins are the same, only do it once
for m in mode_selection_index:
Expand Down Expand Up @@ -744,7 +744,6 @@ def generate_GC_sparam(do_simulation = True, addto_CML = True, verbose = False,
dbum = TECHNOLOGY['dbu']*1e-6 # dbu to m conversion

if do_simulation:
import numpy as np
# run Lumerical FDTD Solutions
from .. import _globals
run_FDTD()
Expand Down Expand Up @@ -807,7 +806,8 @@ def generate_GC_sparam(do_simulation = True, addto_CML = True, verbose = False,
TECHNOLOGY = get_technology()
tech_name = TECHNOLOGY['technology_name']

import os, fnmatch
import os
import fnmatch
dir_path = pya.Application.instance().application_data_path()
search_str = 'grating_coupler_2D.fsp'
matches = []
Expand Down Expand Up @@ -955,7 +955,6 @@ def generate_CDC_bandstructure(W_1 = 450e-9, W_2 = 550e-9, dW_1 = 20e-9, dW_2 =
TECHNOLOGY, lv, ly, cell = get_layout_variables()
dbum = TECHNOLOGY['dbu']*1e-6 # dbu to m conversion

import numpy as np
# run Lumerical FDTD Solutions
from .. import _globals

Expand All @@ -970,7 +969,8 @@ def generate_CDC_bandstructure(W_1 = 450e-9, W_2 = 550e-9, dW_1 = 20e-9, dW_2 =
TECHNOLOGY = get_technology()
tech_name = TECHNOLOGY['technology_name']

import os, fnmatch
import os
import fnmatch
dir_path = pya.Application.instance().application_data_path()
search_str = 'FDTD_CDC_unit_cell.fsp'
matches = []
Expand Down Expand Up @@ -1005,4 +1005,4 @@ def generate_CDC_bandstructure(W_1 = 450e-9, W_2 = 550e-9, dW_1 = 20e-9, dW_2 =
#lambda_0 = lumapi.getVar(_globals.FDTD, "lambda_0")
[bandwidth, lambda_0] = [6e-9, 1550e-9]

return [bandwidth, lambda_0];
return [bandwidth, lambda_0]
18 changes: 9 additions & 9 deletions klayout_dot_config/python/SiEPIC/lumerical/interconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def INTC_installdesignkit(verbose=False):
'''Install a Compact Model Library into Lumerical INTERCONNECT,
using a compressed (.cml) in the PDK, placing it in the KLayout folder.'''

import sys, os, string, pya
import os
import pya
from ..utils import get_technology, get_technology_by_name

# get current technology
Expand Down Expand Up @@ -141,14 +142,14 @@ def INTC_installdesignkit(verbose=False):
# Install technology CML if missing in INTC
# check if the latest version of the CML is in KLayout's tech
if 'INTC_CMLs_path' in TECHNOLOGY and TECHNOLOGY['INTC_CML_path']:
if not ("design kits::"+TECHNOLOGY['technology_name'].lower()+"::"+TECHNOLOGY['INTC_CML_version'].lower().replace('.cml','').lower()) in _globals.INTC_ELEMENTS:
if ("design kits::"+TECHNOLOGY['technology_name'].lower()+"::"+TECHNOLOGY['INTC_CML_version'].lower().replace('.cml','').lower()) not in _globals.INTC_ELEMENTS:
# install CML
print("Lumerical INTC, installdesignkit ('%s', '%s', true);" % (TECHNOLOGY['INTC_CML_path'], dir_path ) )
lumapi.evalScript(_globals.INTC, "installdesignkit ('%s', '%s', true);" % (TECHNOLOGY['INTC_CML_path'], dir_path ) )

# Install other CMLs within technology
for i in range(0,len(TECHNOLOGY['INTC_CMLs_name'])):
if not ("design kits::"+TECHNOLOGY['INTC_CMLs_name'][i].lower()+"::"+TECHNOLOGY['INTC_CMLs_version'][i].lower().replace('.cml','').lower()) in _globals.INTC_ELEMENTS:
if ("design kits::"+TECHNOLOGY['INTC_CMLs_name'][i].lower()+"::"+TECHNOLOGY['INTC_CMLs_version'][i].lower().replace('.cml','').lower()) not in _globals.INTC_ELEMENTS:
# install CML
print("Lumerical INTC, installdesignkit ('%s', '%s', true);" % (TECHNOLOGY['INTC_CMLs_path'][i], dir_path ) )
lumapi.evalScript(_globals.INTC, "installdesignkit ('%s', '%s', true);" % (TECHNOLOGY['INTC_CMLs_path'][i], dir_path ) )
Expand Down Expand Up @@ -219,7 +220,7 @@ def INTC_loaddesignkit(folder_CML, verbose=False):
folder_names = []
new_loaded = False
for folder_name in next(os.walk(folder_CML))[1]:
if not ("design kits::"+folder_name.lower()+"::" in _globals.INTC_ELEMENTS):
if "design kits::"+folder_name.lower()+"::" not in _globals.INTC_ELEMENTS:
folder_path = os.path.join(folder_CML,folder_name)
lumapi.evalScript(_globals.INTC, "loaddesignkit ('%s', '%s');" % (folder_name, folder_path ) )
new_loaded = True
Expand Down Expand Up @@ -277,7 +278,8 @@ def Setup_Lumerical_KLayoutPython_integration(verbose=False):

def INTC_commandline(filename2):
print ("Running Lumerical INTERCONNECT using the command interface.")
import sys, os, string
import sys
import os

if sys.platform.startswith('linux'):
import subprocess
Expand Down Expand Up @@ -321,7 +323,7 @@ def INTC_commandline(filename2):
warning_window = pya.QMessageBox()
warning_window.setText("Warning: The program could not find INTERCONNECT.")
warning_window.setInformativeText("Do you want to specify it manually?")
warning_window.setStandardButtons(pya.QMessageBox.Yes | pya.QMessageBox.Cancel);
warning_window.setStandardButtons(pya.QMessageBox.Yes | pya.QMessageBox.Cancel)
warning_window.setDefaultButton(pya.QMessageBox.Yes)
response = warning_window.exec_()
if(pya.QMessageBox_StandardButton(response) == pya.QMessageBox.Yes):
Expand All @@ -332,7 +334,7 @@ def INTC_commandline(filename2):


def component_simulation(verbose=False, simulate=True):
import sys, os, string
import os
from .. import _globals

# get selected instances
Expand Down Expand Up @@ -454,7 +456,6 @@ def component_simulation(verbose=False, simulate=True):

from .. import _globals
tmp_folder = _globals.TEMP_FOLDER
import os
filename = os.path.join(tmp_folder, '%s_main.spi' % c.component)
filename2 = os.path.join(tmp_folder, '%s.lsf' % c.component)
filename_icp = os.path.join(tmp_folder, '%s.icp' % c.component)
Expand Down Expand Up @@ -562,7 +563,6 @@ def circuit_simulation(verbose=False,opt_in_selection_text=[], matlab_data_files
if '_' in circuit_name[0]:
circuit_name = ''.join(circuit_name.split('_', 1)) # remove leading _

from .. import _globals
tmp_folder = _globals.TEMP_FOLDER
import os
filename = os.path.join(tmp_folder, '%s_main.spi' % circuit_name)
Expand Down
Loading

0 comments on commit f67bb5f

Please sign in to comment.