Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mesh profile per layer #983

Merged
merged 8 commits into from Dec 12, 2022
Merged

Mesh profile per layer #983

merged 8 commits into from Dec 12, 2022

Conversation

simbilod
Copy link
Collaborator

@simbilod simbilod commented Dec 12, 2022

  • New "buffer_profile" argument in LayerLevel that is used to parametrize arbitrary transformations for a layer when it needs to be represented in a simulator.

For instance, one can assign a round-ish profile (better with more points) to a specific GDS layer in this way:

            undercut=LayerLevel(
                layer=LAYER.UNDERCUT,
                thickness=-undercut_thickness,
                zmin=-box_thickness,
                material="air",
                buffer_profile=[[0, 0.3, 0.6, 0.8, 0.9, 1], [-0, -0.5, -1, -1.5, -2, -2.5]],
                info={"mesh_order": 1},
            ),

The buffer_profile is a tuple of two lists. The first one parametrizes a position from zmin (when = 0) to zmin + thickness (when = 1). The second parametrizes a shrink (for negative sign) or expansion (if positive) to apply to this layer's polygons.

For the following waveguide layout with the middle square being an undercut:

    from gdsfactory.tech import get_layer_stack_generic

    c = gf.component.Component()

    waveguide = c << gf.get_component(gf.components.straight_pin(length=10, taper=None))
    undercut = c << gf.get_component(gf.components.rectangle(size = (5.0, 5.0),
                                                                layer = "UNDERCUT",
                                                                centered = True,)
                                                                ).move(destination=[4,0])
    c.show()

    filtered_layerstack = LayerStack(
        layers={
            k: get_layer_stack_generic().layers[k]
            for k in (
                "slab90",
                "core",
                "via_contact",
                "undercut",
                "box",
                "substrate",
                "clad",
                "metal1",
            ) 
        }
    )

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

    geometry = uz_xsection_mesh(
        c,
        [(4, -15), (4, 15)],
        filtered_layerstack,
        resolutions=resolutions,
        # background_tag="Oxide",
        filename="mesh.msh",
    )

image

the following cross-sectional mesh is obtained along the x=4 line (with different colors = different GDS layers, that a simulator can parse)

image

  • The zmin, thickness, and sidewalls arguments were kept, but are now used to generate rectangular or slanted buffer_profiles
  • LayerLevel also now accepts a "None" layer, which assigns a polygon of the shape bbox to this layer if layer is present. Currently used for substrate, BOX, and cladding.

@joamatab There is duplication with the recent definition of BOX at the global LayerStack level. I think we should let BOX, substrate, etc. be regular LayerLevels that have layer=None so that all other parameters of a layer (zmin, thickness, material, mesh_order, etc) can also be assigned to them, and they can be treated like regular layers in code, including being filtered out or added to a LayerStack.

@HelgeGehring

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 12, 2022

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 2.21%.

Quality metrics Before After Change
Complexity 2.58 ⭐ 3.07 ⭐ 0.49 👎
Method Length 87.80 🙂 95.56 🙂 7.76 👎
Working memory 8.35 🙂 9.10 🙂 0.75 👎
Quality 66.32% 🙂 64.11% 🙂 -2.21% 👎
Other metrics Before After Change
Lines 705 774 69
Changed files Quality Before Quality After Quality Change
gdsfactory/tech.py 65.82% 🙂 64.38% 🙂 -1.44% 👎
gdsfactory/simulation/gmsh/parse_gds.py 73.73% 🙂 72.64% 🙂 -1.09% 👎
gdsfactory/simulation/gmsh/uz_xsection_mesh.py 62.15% 🙂 57.29% 🙂 -4.86% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
gdsfactory/simulation/gmsh/uz_xsection_mesh.py uz_xsection_mesh 8 ⭐ 264 ⛔ 20 ⛔ 34.48% 😞 Try splitting into smaller methods. Extract out complex expressions
gdsfactory/tech.py get_layer_stack_generic 0 ⭐ 475 ⛔ 31 ⛔ 34.71% 😞 Try splitting into smaller methods. Extract out complex expressions
gdsfactory/simulation/gmsh/parse_gds.py tile_shapes 21 😞 115 🙂 9 🙂 50.47% 🙂 Refactor to reduce nesting
gdsfactory/tech.py LayerStack.get_klayout_3d_script 4 ⭐ 101 🙂 16 ⛔ 55.89% 🙂 Extract out complex expressions
gdsfactory/simulation/gmsh/uz_xsection_mesh.py get_uz_bounds_layers 3 ⭐ 124 😞 13 😞 57.69% 🙂 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

@codecov
Copy link

codecov bot commented Dec 12, 2022

Codecov Report

Merging #983 (3af9129) into main (33b468a) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #983      +/-   ##
==========================================
+ Coverage   74.05%   74.06%   +0.01%     
==========================================
  Files         432      432              
  Lines       22214    22216       +2     
  Branches     2984     2986       +2     
==========================================
+ Hits        16450    16454       +4     
+ Misses       4877     4876       -1     
+ Partials      887      886       -1     
Impacted Files Coverage Δ
gdsfactory/tech.py 89.76% <100.00%> (ø)
gdsfactory/component.py 71.05% <0.00%> (+0.07%) ⬆️
gdsfactory/read/from_yaml.py 67.26% <0.00%> (+0.60%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@joamatab
Copy link
Contributor

agreed on the box_layer,

buffer_profile is a bit confusing name
how about z_to_bias?

@simbilod
Copy link
Collaborator Author

simbilod commented Dec 12, 2022 via email

remove  box_thickness and box_thickness from layerStack
@joamatab joamatab merged commit e00cab6 into gdsfactory:main Dec 12, 2022
@joamatab
Copy link
Contributor

I'll send a PR

@simbilod
Copy link
Collaborator Author

simbilod commented Dec 12, 2022 via email

@joamatab
Copy link
Contributor

Also,

How can we draw layers with layer=None in any of the simulation plugins?

@simbilod
Copy link
Collaborator Author

simbilod commented Dec 12, 2022 via email

@simbilod simbilod deleted the mesh_profile branch December 18, 2022 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants