Skip to content

Commit

Permalink
'Refactored by Sourcery'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourcery AI committed Jan 4, 2023
1 parent ac32dd1 commit 580f054
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 53 deletions.
4 changes: 2 additions & 2 deletions gdsfactory/circuitviz.py
Expand Up @@ -401,10 +401,10 @@ def viz_instance(
}

for layer, polys in polys_by_layer.items():
xs = [[p.points[:, 0]] for p in polys]
ys = [[p.points[:, 1]] for p in polys]
color_info = colors_by_ldt.get(layer)
if color_info:
xs = [[p.points[:, 0]] for p in polys]
ys = [[p.points[:, 1]] for p in polys]
lp = LayerPolygons(
tag=instance_name,
xs=xs,
Expand Down
6 changes: 1 addition & 5 deletions gdsfactory/read/from_yaml.py
Expand Up @@ -599,11 +599,7 @@ def from_yaml(

settings = conf.get("settings", {})

if "mode" in kwargs:
mode = kwargs.pop("mode")
else:
mode = "layout"

mode = kwargs.pop("mode") if "mode" in kwargs else "layout"
for key, value in kwargs.items():
if key not in settings:
raise ValueError(f"{key!r} not in {settings.keys()}")
Expand Down
4 changes: 1 addition & 3 deletions gdsfactory/simulation/eme/meow_eme.py
Expand Up @@ -336,7 +336,7 @@ def compute_sparameters(self) -> Dict[str, np.ndarray]:
if not self.overwrite:
logger.info(f"Simulation loaded from {self.filepath!r}")
return dict(np.load(self.filepath))
elif self.overwrite:
else:
self.filepath.unlink()

start = time.time()
Expand Down Expand Up @@ -374,8 +374,6 @@ def compute_sparameters(self) -> Dict[str, np.ndarray]:

return sp

return sp


if __name__ == "__main__":
c = gf.components.taper(length=10, width2=2)
Expand Down
17 changes: 7 additions & 10 deletions gdsfactory/simulation/fem/mode_solver.py
Expand Up @@ -68,7 +68,7 @@ def compute_cross_section_modes(
epsilon[basis0.get_dofs(elements=layername)] = (
_ACTIVE_PDK.materials_index[layer.material](wl) ** 2
)
if "background_tag" in kwargs.keys():
if "background_tag" in kwargs:
epsilon[basis0.get_dofs(elements=kwargs["background_tag"])] = (
_ACTIVE_PDK.materials_index[kwargs["background_tag"]](wl) ** 2
)
Expand All @@ -86,9 +86,6 @@ def compute_cross_section_modes(

return lams, basis, xs

def plot_cross_section_modes():
return True


if __name__ == "__main__":
filtered_layerstack = LayerStack(
Expand All @@ -105,12 +102,12 @@ def plot_cross_section_modes():

filtered_layerstack.layers["core"].thickness = 0.2

resolutions = {}
resolutions["core"] = {"resolution": 0.02, "distance": 2}
resolutions["clad"] = {"resolution": 0.2, "distance": 1}
resolutions["box"] = {"resolution": 0.2, "distance": 1}
resolutions["slab90"] = {"resolution": 0.05, "distance": 1}

resolutions = {
"core": {"resolution": 0.02, "distance": 2},
"clad": {"resolution": 0.2, "distance": 1},
"box": {"resolution": 0.2, "distance": 1},
"slab90": {"resolution": 0.05, "distance": 1},
}
compute_cross_section_modes(
cross_section="rib",
layerstack=filtered_layerstack,
Expand Down
12 changes: 6 additions & 6 deletions gdsfactory/simulation/fem/test_mode_solver.py
Expand Up @@ -21,12 +21,12 @@ def test_compute_cross_section_mode():

filtered_layerstack.layers["core"].thickness = 0.2

resolutions = {}
resolutions["core"] = {"resolution": 0.02, "distance": 2}
resolutions["clad"] = {"resolution": 0.2, "distance": 1}
resolutions["box"] = {"resolution": 0.2, "distance": 1}
resolutions["slab90"] = {"resolution": 0.05, "distance": 1}

resolutions = {
"core": {"resolution": 0.02, "distance": 2},
"clad": {"resolution": 0.2, "distance": 1},
"box": {"resolution": 0.2, "distance": 1},
"slab90": {"resolution": 0.05, "distance": 1},
}
lams, basis, xs = compute_cross_section_modes(
cross_section="rib",
layerstack=filtered_layerstack,
Expand Down
20 changes: 9 additions & 11 deletions gdsfactory/simulation/gmsh/tests/test_meshing.py
Expand Up @@ -23,19 +23,18 @@ def test_gmsh_uz_xsection_mesh():
}
)

resolutions = {}
resolutions["core"] = {"resolution": 0.05, "distance": 2}
resolutions["slab90"] = {"resolution": 0.03, "distance": 1}
resolutions["via_contact"] = {"resolution": 0.1, "distance": 1}

resolutions = {
"core": {"resolution": 0.05, "distance": 2},
"slab90": {"resolution": 0.03, "distance": 1},
"via_contact": {"resolution": 0.1, "distance": 1},
}
uz_xsection_mesh(
waveguide,
[(4, -15), (4, 15)],
filtered_layerstack,
resolutions=resolutions,
background_tag="Oxide",
)
assert True


def test_gmsh_xy_xsection_mesh():
Expand All @@ -57,15 +56,14 @@ def test_gmsh_xy_xsection_mesh():
}
)

resolutions = {}
resolutions["core"] = {"resolution": 0.05, "distance": 0.1}
resolutions["via_contact"] = {"resolution": 0.1, "distance": 0}

resolutions = {
"core": {"resolution": 0.05, "distance": 0.1},
"via_contact": {"resolution": 0.1, "distance": 0},
}
xy_xsection_mesh(
component=waveguide,
z=0.09,
layerstack=filtered_layerstack,
resolutions=resolutions,
background_tag="Oxide",
)
assert True
25 changes: 11 additions & 14 deletions gdsfactory/technology/layer_views.py
Expand Up @@ -167,22 +167,20 @@ def __init__(
):
"""Initialize LayerView object."""
if (gds_layer is not None) and (gds_datatype is not None):
if "layer" in data.keys() and data["layer"] is not None:
if "layer" in data and data["layer"] is not None:
raise KeyError(
"Specify either 'layer' or both 'gds_layer' and 'gds_datatype'."
)
data["layer"] = (gds_layer, gds_datatype)

if color is not None:
if ("fill_color" in data.keys()) or ("frame_color" in data.keys()):
if "fill_color" in data or "frame_color" in data:
raise KeyError(
"Specify either a single 'color' or both 'frame_color' and 'fill_color'."
)
data["fill_color"] = data["frame_color"] = color
if brightness is not None:
if ("fill_brightness" in data.keys()) or (
"frame_brightness" in data.keys()
):
if "fill_brightness" in data or "frame_brightness" in data:
raise KeyError(
"Specify either a single 'brightness' or both 'frame_brightness' and 'fill_brightness'."
)
Expand Down Expand Up @@ -270,9 +268,9 @@ def _build_klayout_xml_element(self, tag: str, name: str) -> ET.Element:
"marked": str(self.marked).lower(),
"xfill": str(self.xfill).lower(),
"animation": self.animation,
"name": name
if not self.layer_in_name
else f"{name} {self.layer[0]}/{self.layer[1]}",
"name": f"{name} {self.layer[0]}/{self.layer[1]}"
if self.layer_in_name
else name,
"source": f"{self.layer[0]}/{self.layer[1]}@1"
if self.layer is not None
else "*/*@*",
Expand Down Expand Up @@ -414,7 +412,7 @@ def __init__(
logger.info(
f"Importing LayerViews from KLayout layer properties file: {filepath}."
)
elif (filepath.suffix == ".yaml") or (filepath.suffix == ".yml"):
elif filepath.suffix in [".yaml", ".yml"]:
lvs = LayerViews.from_yaml(layer_file=filepath)
logger.info(f"Importing LayerViews from YAML file: {filepath}.")
else:
Expand All @@ -428,7 +426,7 @@ def __init__(
layer_map = layer_map.dict()

if layer_map is not None:
data.update({"layer_map": layer_map})
data["layer_map"] = layer_map

super().__init__(**data)

Expand All @@ -454,10 +452,9 @@ def add_layer_view(
raise ValueError(
f"Adding {name!r} already defined {list(self.layer_views.keys())}"
)
else:
if layer_view is None:
layer_view = LayerView(name=name, **kwargs)
self.layer_views[name] = layer_view
if layer_view is None:
layer_view = LayerView(name=name, **kwargs)
self.layer_views[name] = layer_view

# If the dither pattern is a CustomDitherPattern, add it to custom_patterns
dither_pattern = layer_view.hatch_pattern
Expand Down
4 changes: 2 additions & 2 deletions gdsfactory/tests/test_klayout/test_klayout_tech.py
Expand Up @@ -14,9 +14,9 @@ def test_klayout_tech_create(
data_regression: DataRegressionFixture, check: bool = True
) -> None:

lyp = LayerDisplayProperties.from_lyp(str(PATH.klayout_lyp))

if check:
lyp = LayerDisplayProperties.from_lyp(str(PATH.klayout_lyp))

data_regression.check(lyp.dict())


Expand Down

0 comments on commit 580f054

Please sign in to comment.