-
Notifications
You must be signed in to change notification settings - Fork 52
EMode plugin #591
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
Open
estanton22
wants to merge
8
commits into
gdsfactory:main
Choose a base branch
from
estanton22:emode_plugin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
EMode plugin #591
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dfba6b5
added basic emode plugin
12538c7
added documentaion for the emode plugin
5df7f2b
removed emode tests
f45ffee
integrating LayerStack with EMode
c66b109
cleaned up utils
49935a8
first functioning EMode plugin with LayerStack
368bb56
fixed emodeconnection install error for docs compiling
75c4e6b
Merge branch 'main' into emode_plugin
estanton22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| from emodeconnection import open_file, get, inspect | ||
| from .utils import EMode | ||
|
|
||
| __all__ = ["EMode", "open_file", "get", "inspect"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
|
|
||
| import gplugins.emode as emc | ||
| from gdsfactory.cross_section import rib | ||
| from gdsfactory.generic_tech import LAYER_STACK | ||
| from gdsfactory.technology import LayerStack | ||
|
|
||
|
|
||
| ## Set up GDSFactory LayerStack and CrossSection in units of microns | ||
| layer_stack = LayerStack( | ||
| layers={ | ||
| k: LAYER_STACK.layers[k] | ||
| for k in ( | ||
| "core", | ||
| "clad", | ||
| "slab90", | ||
| "box", | ||
| ) | ||
| } | ||
| ) | ||
|
|
||
| layer_stack.layers["core"].thickness = 0.22 | ||
| layer_stack.layers["core"].zmin = 0 | ||
|
|
||
| layer_stack.layers["slab90"].thickness = 0.09 | ||
| layer_stack.layers["slab90"].zmin = 0 | ||
|
|
||
| layer_stack.layers["box"].thickness = 1.5 | ||
| layer_stack.layers["box"].zmin = -1.5 | ||
|
|
||
| layer_stack.layers["clad"].thickness = 1.5 | ||
| layer_stack.layers["clad"].zmin = 0 | ||
|
|
||
| ## Connect and initialize EMode | ||
| em = emc.EMode() | ||
|
|
||
| ## build_waveguide converts units to nanometers, which EMode's default | ||
| modes = em.build_waveguide( | ||
| cross_section=rib(width=0.6), | ||
| layer_stack=layer_stack, | ||
| wavelength=1.55, | ||
| num_modes=1, | ||
| x_resolution=0.010, | ||
| y_resolution=0.010, | ||
| window_width = 3.0, | ||
| window_height = 3.0, | ||
| background_refractive_index='Air', | ||
| max_effective_index=2.631, | ||
| ) | ||
|
|
||
| ## Launch FDM solver | ||
| em.FDM() | ||
|
|
||
| ## Display the effective indices, TE fractions, and core confinement | ||
| em.report() | ||
|
|
||
| ## Plot the field and refractive index profiles | ||
| em.plot() | ||
|
|
||
| ## Close EMode | ||
| em.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import emodeconnection as emc | ||
| from gdsfactory import CrossSection | ||
| from gdsfactory.technology import LayerStack | ||
|
|
||
| class EMode(emc.EMode): | ||
| def build_waveguide( | ||
| self, | ||
| cross_section: CrossSection, | ||
| layer_stack: LayerStack, | ||
| **kwargs, | ||
| ) -> None: | ||
| """Builds a waveguide structure in EMode based on GDSFactory CrossSection and LayerStack. | ||
|
|
||
| Args: | ||
| cross_section: A GDSFactory CrossSection object defining the waveguide's geometry. | ||
| layer_stack: A GDSFactory LayerStack object defining the material layers. | ||
| **kwargs: Additional keyword arguments to be passed directly to EMode's settings() function. | ||
| """ | ||
| nm = 1e3 # convert microns to nanometers | ||
| dim_keys = [ | ||
| 'wavelength', | ||
| 'x_resolution', | ||
| 'y_resolution', | ||
| 'window_width', | ||
| 'window_height', | ||
| 'bend_radius', | ||
| 'expansion_resolution', | ||
| 'expansion_size', | ||
| 'propagation_resolution', | ||
| ] | ||
|
|
||
| # Pass all kwargs directly to EMode's settings function | ||
| kwargs = {key: (value * nm if key in dim_keys else value) for key, value in kwargs.items()} | ||
| self.settings(**kwargs) | ||
|
|
||
| # Get a list of EMode materials for cleaning GDSFactory material names | ||
| emode_materials = self.get('materials') | ||
|
|
||
| # Process layer_stack to create EMode shapes | ||
| max_order = max([info.mesh_order for name, info in layer_stack.layers.items()]) | ||
| min_zmin = min([info.zmin for name, info in layer_stack.layers.items()]) | ||
|
|
||
| for layer_name, layer_info in layer_stack.layers.items(): | ||
|
|
||
| material = next( | ||
| (mat for mat in emode_materials if mat.lower() == layer_info.material.lower()), | ||
| layer_info.material | ||
| ) | ||
|
|
||
| shape_info = { | ||
| 'name': layer_name, | ||
| 'refractive_index': material, | ||
| 'height': layer_info.thickness * nm, | ||
| 'mask': layer_info.width_to_z * nm, | ||
| 'sidewall_angle': layer_info.sidewall_angle, | ||
| 'etch_depth': layer_info.thickness * nm if layer_info.width_to_z > 0 else 0, | ||
| 'position': [0.0, (layer_info.zmin - min_zmin + layer_info.thickness/2) * nm], | ||
| 'priority': max_order - layer_info.mesh_order + 1, | ||
| } | ||
|
|
||
| # Find a matching CrossSection for this layer | ||
| xsection_ind = [k for k, s in enumerate(cross_section.sections) if str(layer_info.layer) == str(s.layer) or str(layer_info.derived_layer) == str(s.layer)] | ||
|
|
||
| # Apply settings from the matching CrossSection | ||
| if len(xsection_ind) > 0: | ||
| xsection = cross_section.sections[xsection_ind[0]] | ||
| shape_info['mask'] = xsection.width * nm | ||
| shape_info['mask_offset'] = xsection.offset * nm | ||
|
|
||
| self.shape(**shape_info) | ||
|
|
||
| return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "dec55ff8", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "# EMode - Photonic Device Simulation\n", | ||
| "\n", | ||
| "The EMode plugin integrates simulation capabilities from [**EMode Photonix**](https://emodephotonix.com) with GDSFactory. This plugin enables the analysis of photonic devices through:\n", | ||
| "\n", | ||
| "- Waveguide mode solving using a Finite-Difference Frequency Domain (FDFD) method.\n", | ||
| "- Propagation simulations using the Eigenmode Expansion (EME) method.\n", | ||
| "\n", | ||
| "Cross-sectional simulations are available with a free EMode<sup>2D</sup> license. The propagation module requires an EMode<sup>3D</sup> license.\n", | ||
| "\n", | ||
| "See the complete EMode documentation at [**EMode Docs**](https://docs.emodephotonix.com).\n", | ||
| "\n", | ||
| "Get an EMode license at the [**EMode Shop**](https://emodephotonix.com/get-emode).\n", | ||
| "\n", | ||
| "## Software Requirement\n", | ||
| "\n", | ||
| "This plugin requires that the EMode software is already installed on the user's computer. Please refer to the installation guide at [docs.emodephotonix.com/installation](https://docs.emodephotonix.com/installation) for detailed instructions.\n", | ||
| "\n", | ||
| "## Using EMode Examples with gplugins\n", | ||
| "\n", | ||
| "All of the [**EMode examples**](https://docs.emodephotonix.com/examples) can be adapted for use with the GDSFactory plugin. Simply replace the standard EMode import:" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 7, | ||
| "id": "f0fbf103", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "import emodeconnection as emc" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "6f832fad", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "with the plugin-specific import:" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "8b62c1bf", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "import gplugins.emode as emc" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "1f863dfd", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "The ``gplugins.emode`` import provides the same interface and usage as the ``emodeconnection`` package, detailed in the [EMode Python connection documentation](https://docs.emodephotonix.com/emodeconnection_python)." | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "Python 3 (ipykernel)", | ||
| "language": "python", | ||
| "name": "python3" | ||
| }, | ||
| "language_info": { | ||
| "codemirror_mode": { | ||
| "name": "ipython", | ||
| "version": 3 | ||
| }, | ||
| "file_extension": ".py", | ||
| "mimetype": "text/x-python", | ||
| "name": "python", | ||
| "nbconvert_exporter": "python", | ||
| "pygments_lexer": "ipython3", | ||
| "version": "3.10.8" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 5 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (typo): Typo: "Sparameters" should likely be "S-parameters".
"S-parameters" is the correct term for scattering parameters in this context.