Skip to content

Commit

Permalink
Ruff format fixes
Browse files Browse the repository at this point in the history
"ruff format"
  • Loading branch information
lukasc-ubc committed Jul 29, 2024
1 parent f67bb5f commit 6e55bb2
Show file tree
Hide file tree
Showing 158 changed files with 16,305 additions and 9,312 deletions.
39 changes: 23 additions & 16 deletions klayout_dot_config/pymacros/development/example_sax.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
# https://github.com/flaport/sax

from SiEPIC.install import install
install('sax')

install("sax")


def coupler(coupling=0.5):
kappa = coupling**0.5
tau = (1-coupling)**0.5
sdict = sax.reciprocal({
("in0", "out0"): tau,
("in0", "out1"): 1j*kappa,
("in1", "out0"): 1j*kappa,
("in1", "out1"): tau,
})
tau = (1 - coupling) ** 0.5
sdict = sax.reciprocal(
{
("in0", "out0"): tau,
("in0", "out1"): 1j * kappa,
("in1", "out0"): 1j * kappa,
("in1", "out1"): tau,
}
)
return sdict


coupler(coupling=0.3)

print(coupler(coupling=0.3))


def waveguide(wl=1.55, wl0=1.55, neff=2.34, ng=3.4, length=10.0, loss=0.0):
import numpy as np

Expand All @@ -27,10 +32,11 @@ def waveguide(wl=1.55, wl0=1.55, neff=2.34, ng=3.4, length=10.0, loss=0.0):
neff = neff - dwl * dneff_dwl
phase = 2 * np.pi * neff * length / wl
amplitude = np.asarray(10 ** (-loss * length / 20), dtype=complex)
transmission = amplitude * np.exp(1j * phase)
transmission = amplitude * np.exp(1j * phase)
sdict = sax.reciprocal({("in0", "out0"): transmission})
return sdict


waveguide(length=100.0)

mzi, _ = sax.circuit(
Expand Down Expand Up @@ -60,18 +66,19 @@ def waveguide(wl=1.55, wl0=1.55, neff=2.34, ng=3.4, length=10.0, loss=0.0):
import numpy as np

wl = np.linspace(1.53, 1.57, 1000)
result = mzi(wl=wl, lft={'coupling': 0.3}, top={'length': 200.0}, rgt={'coupling': 0.8})
result = mzi(wl=wl, lft={"coupling": 0.3}, top={"length": 200.0}, rgt={"coupling": 0.8})


# Plot using Plotly:
import plotly.express as px
import pandas as pd # https://pandas.pydata.org/docs/user_guide/10min.html
import pandas as pd # https://pandas.pydata.org/docs/user_guide/10min.html

# Two lines:
t1 = np.abs(result['in0', 'out0'])**2
t2 = np.abs(result['in0', 'out1'])**2
t1 = np.abs(result["in0", "out0"]) ** 2
t2 = np.abs(result["in0", "out1"]) ** 2

df = pd.DataFrame(np.stack((t1, t2)).transpose(), index=wl, columns=['Output 1','Output 2'])
fig = px.line(df, labels={'index':'Wavelength', 'value':'Transmission'}, markers=True)
df = pd.DataFrame(
np.stack((t1, t2)).transpose(), index=wl, columns=["Output 1", "Output 2"]
)
fig = px.line(df, labels={"index": "Wavelength", "value": "Transmission"}, markers=True)
fig.show()

Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
'''
"""
from SiEPIC.install import install
install('nextcloud-api-wrapper','nextcloud')
nextcloud.api_wrappers.WebDAV.upload_file('lukas', '/tmp/test.gds', 'https://qdot-nexus.phas.ubc.ca:25683/s/b74MAb2Bdz6SLAm', timestamp=None)
-- didn't work, unknown error in the API
'''
"""


'''
"""
from SiEPIC.install import install
install('pyocclient','owncloud')
Expand All @@ -21,26 +20,24 @@
oc = owncloud.Client.from_public_link(public_link)
oc.drop_file('/tmp/test.gds')
'''
"""

'''
"""
from SiEPIC.install import install
install('pycurl')
-- install error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [1 lines of output]
ERROR: Unknown option: --egg-base
'''
"""

'''
"""
from SiEPIC.install import install
install('pyncclient')
-- install error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [1 lines of output]
ERROR: Unknown option: --egg-base
'''


"""
41 changes: 27 additions & 14 deletions klayout_dot_config/python/SiEPIC/__init__.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
'''
"""
SiEPIC-Tools package for KLayout
'''
"""

__version__ = '0.5.12'
__version__ = "0.5.12"

print("KLayout SiEPIC-Tools version %s" %__version__)
print("KLayout SiEPIC-Tools version %s" % __version__)

import pya
if '__version__' in dir(pya):

if "__version__" in dir(pya):
# pya.__version__ was introduced in KLayout version 0.28.6
KLAYOUT_VERSION = int(pya.__version__.split('.')[1])
KLAYOUT_VERSION = int(pya.__version__.split(".")[1])
else:
KLAYOUT_VERSION = int(pya.Application.instance().version().split('.')[1])
KLAYOUT_VERSION_3 = int(pya.Application.instance().version().split('.')[2])
if KLAYOUT_VERSION < 28:
KLAYOUT_VERSION = int(pya.Application.instance().version().split(".")[1])
KLAYOUT_VERSION_3 = int(pya.Application.instance().version().split(".")[2])

if KLAYOUT_VERSION < 28:
# pya.Technologies was introduced in 0.27: https://www.klayout.de/doc-qt5/code/class_Library.html#method24
# SiEPIC-Tools is being updated to use this functionality, hence will no longer be supported for KLayout 0.26
raise Exception('\nSiEPIC-Tools is no longer compatible with older versions (0.26) of KLayout.\nPlease download an install the latest version from www.klayout.de')
raise Exception(
"\nSiEPIC-Tools is no longer compatible with older versions (0.26) of KLayout.\nPlease download an install the latest version from www.klayout.de"
)
else:
from . import _globals

if _globals.Python_Env == "KLayout_GUI":
from . import extend, _globals, core, examples, github, scripts, utils, setup, install, verification
from . import (
extend,
_globals,
core,
examples,
github,
scripts,
utils,
setup,
install,
verification,
)
else:
from . import _globals, core, utils, extend, verification, scripts

76 changes: 43 additions & 33 deletions klayout_dot_config/python/SiEPIC/_globals.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,69 @@

import pya
Python_Env = "" # tag which defines whether we are loading library in script or GUI env
if 'Application' in dir(pya):

Python_Env = "" # tag which defines whether we are loading library in script or GUI env
if "Application" in dir(pya):
try:
# import pya, which is available when running within KLayout
if pya.Application.instance().main_window():
Python_Env = "KLayout_GUI"
print('Python Environment: KLayout GUI')
print("Python Environment: KLayout GUI")
else:
Python_Env = "KLayout_batch"
print('Python Environment: KLayout batch mode')
print("Python Environment: KLayout batch mode")
except:
Python_Env = "Script"
else:
Python_Env = "Script"

# Netlist extraction will merge straight+bend sections into waveguide (1),
# or extract each bend, straight section, etc. (0)
#WAVEGUIDE_extract_simple = 1
# WAVEGUIDE_extract_simple = 1
SIMPLIFY_NETLIST_EXTRACTION = True

if Python_Env == "KLayout_GUI":
# Create GUI's
from .core import WaveguideGUI, MonteCarloGUI

WG_GUI = WaveguideGUI()
MC_GUI = MonteCarloGUI()

# ******** lukasc
# don't use a global one.. based on cells
# Define global Net object that implements netlists and pin searching/connecting
# NET = Net()

from .core import Net

NET_DISCONNECTED = Net()

# don't use a global one.. based on cells
# Define global Component object
#COMPONENT = Component()
# COMPONENT = Component()


# Define an Enumeration type for Python
# TODO: maybe move to standard enum for python3
# https://docs.python.org/3/library/enum.html
def enum(*sequential, **named):
enums = dict(zip(sequential, range(len(sequential))), **named)
return type('Enum', (), enums)
return type("Enum", (), enums)


# Define enumeration for pins
PIN_TYPES = enum('OPTICALIO', 'OPTICAL', 'ELECTRICAL')
PIN_TYPES = enum("OPTICALIO", "OPTICAL", "ELECTRICAL")
PIN_LENGTH = 20 # 10 nm on each side. Previous was 2x50 nm, but shorter works well for Waveguide DRC checking


MODULE_NUMPY = False
try:
import numpy

MODULE_NUMPY = True
except ImportError:
from .install import install

try:
MODULE_NUMPY = install('numpy')
MODULE_NUMPY = install("numpy")
except Exception as e:
print("Could not install numpy with pip. ERROR:", e)

Expand All @@ -67,65 +72,70 @@ def enum(*sequential, **named):
import scipy
except ImportError:
from .install import install

try:
install('scipy')
install("scipy")
except Exception as e:
print("Could not install scipy with pip. ERROR:", e)


#ACTIONS = []
# ACTIONS = []

if '__version__' in dir(pya):
if "__version__" in dir(pya):
# pya.__version__ was introduced in KLayout version 0.28.6
KLAYOUT_VERSION = int(pya.__version__.split('.')[1])
KLAYOUT_VERSION_3 = int(pya.__version__.split('.')[2])
KLAYOUT_VERSION = int(pya.__version__.split(".")[1])
KLAYOUT_VERSION_3 = int(pya.__version__.split(".")[2])
else:
KLAYOUT_VERSION = int(pya.Application.instance().version().split('.')[1])
KLAYOUT_VERSION_3 = int(pya.Application.instance().version().split('.')[2])
KLAYOUT_VERSION = int(pya.Application.instance().version().split(".")[1])
KLAYOUT_VERSION_3 = int(pya.Application.instance().version().split(".")[2])

# Waveguide DevRec: space between the waveguide and the DevRec polygon
WG_DEVREC_SPACE = 1

# Path to Waveguide, path snapping to nearest pin. Search for pin with this distance:
PATH_SNAP_PIN_MAXDIST = 20

INTC_ELEMENTS = ''

INTC_ELEMENTS = ""
if Python_Env == "KLayout_GUI":
# Load INTC element library details KLayout application data path
import os
path = os.path.join(pya.Application.instance().application_data_path(), 'Lumerical_CMLs')

path = os.path.join(
pya.Application.instance().application_data_path(), "Lumerical_CMLs"
)
path = os.path.join(path, "Lumerical_INTC_CMLs.txt")
if os.path.exists(path):
print('loading Lumerical_INTC_CMLs.txt')
print("loading Lumerical_INTC_CMLs.txt")
fh = open(path, "r")
INTC_ELEMENTS = fh.read()
fh.close()

try:
INTC
except:
INTC = None
print('resetting Lumerical INTERCONNECT Python integration')
print("resetting Lumerical INTERCONNECT Python integration")

try:
FDTD
except:
FDTD = None
print('resetting Lumerical FDTD Python integration')
print("resetting Lumerical FDTD Python integration")

try:
MODE
except:
MODE = None
print('resetting Lumerical MODE Python integration')
print("resetting Lumerical MODE Python integration")

try:
LUMAPI
except:
LUMAPI = None
print('resetting Lumerical Python integration')
if 'TEMP_FOLDER' not in locals():
print("resetting Lumerical Python integration")

if "TEMP_FOLDER" not in locals():
import tempfile

TEMP_FOLDER = tempfile.mkdtemp()
Loading

0 comments on commit 6e55bb2

Please sign in to comment.