fixes delta lengths and netlist patching for notebook workflow_3_cascaded_mzi.ipynb#678
Open
jonbenfri wants to merge 2 commits intogdsfactory:mainfrom
Open
fixes delta lengths and netlist patching for notebook workflow_3_cascaded_mzi.ipynb#678jonbenfri wants to merge 2 commits intogdsfactory:mainfrom
workflow_3_cascaded_mzi.ipynb#678jonbenfri wants to merge 2 commits intogdsfactory:mainfrom
Conversation
Contributor
Reviewer's GuideUpdates the cascaded MZI workflow notebook to correct the MZI path length definitions, preserve signed delta lengths in the layout, and introduce a recursive netlist patching helper that is exercised in an active simulation cell, along with minor text and environment metadata cleanup. Sequence diagram for using patch_netlist_mod in circuit simulationsequenceDiagram
actor User
participant Notebook
participant patch_netlist_mod
participant sax
participant circuit
User->>Notebook: Run simulation cell
Notebook->>Notebook: layout = gf.c.mzi_lattice(...)
Notebook->>patch_netlist_mod: patch_netlist_mod(netlist=layout.get_netlist(recursive=True), models, models_to_patch)
patch_netlist_mod-->>Notebook: patched_netlist, patched_models
Notebook->>sax: circuit(patched_netlist, patched_models)
sax-->>Notebook: circuit
Notebook->>circuit: s = circuit(wl=lda)
circuit-->>Notebook: scattering_parameters s
Notebook->>Notebook: Plot responses o1->o3 and o1->o4
Notebook-->>User: Display transmission spectra
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The new
patch_netlist_modfunction largely duplicates the logic inpatch_netlist; consider refactoring into a single, more general helper (e.g., with arecursiveflag or shared inner routine) to avoid divergence between the two implementations. - In
patch_netlist_mod, the loop variablemodelis reused both as the key fornetlist[model]and then as the instance dict (model = instances[name]), which is confusing and error-prone; use distinct variable names for the key and the instance object.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `patch_netlist_mod` function largely duplicates the logic in `patch_netlist`; consider refactoring into a single, more general helper (e.g., with a `recursive` flag or shared inner routine) to avoid divergence between the two implementations.
- In `patch_netlist_mod`, the loop variable `model` is reused both as the key for `netlist[model]` and then as the instance dict (`model = instances[name]`), which is confusing and error-prone; use distinct variable names for the key and the instance object.
## Individual Comments
### Comment 1
<location path="notebooks/workflow_3_cascaded_mzi.ipynb" line_range="715-729" />
<code_context>
+ " # For recursive netlist\n",
+ " for model in netlist.keys():\n",
+ " instances = netlist[model][\"instances\"]\n",
+ " for name in instances:\n",
+ " model = instances[name]\n",
+ " if model[\"component\"] in models_to_patch:\n",
+ " component = model[\"component\"]\n",
</code_context>
<issue_to_address>
**suggestion:** Avoid reusing `model` as both the outer key and the inner instance dict.
Reusing `model` for both the netlist key and the instance dict (`for model in netlist.keys():` then `model = instances[name]`) makes the code hard to follow and easy to misuse later (e.g., confusing the key with the instance data). Please use distinct names like `netlist_name` and `instance` to clarify what’s being iterated and mutated.
```suggestion
"def patch_netlist_mod(netlist, models, models_to_patch):\n",
" # For recursive netlist\n",
" for netlist_name in netlist.keys():\n",
" instances = netlist[netlist_name][\"instances\"]\n",
" for name in instances:\n",
" instance = instances[name]\n",
" if instance[\"component\"] in models_to_patch:\n",
" component = instance[\"component\"]\n",
" i = 0\n",
" new_component = f\"{component}_v{i}\"\n",
" while new_component in models:\n",
" i += 1\n",
" new_component = f\"{component}_v{i}\"\n",
" settings = instance[\"settings\"]\n",
" settings_filtered = {\n",
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes issue #677.
Summary by Sourcery
Update the cascaded MZI workflow notebook to correct MZI path length definitions and enable proper recursive netlist patching and simulation plotting.
New Features:
Bug Fixes:
Documentation:
Chores: