Skip to content

Fix all_models notebook lint suppression placement and readability issues#667

Merged
nikosavola merged 1 commit into
mainfrom
copilot/move-ruff-disable-comment
Jul 1, 2026
Merged

Fix all_models notebook lint suppression placement and readability issues#667
nikosavola merged 1 commit into
mainfrom
copilot/move-ruff-disable-comment

Conversation

Copilot AI commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

This updates the all_models notebook source to match the requested lint/readability fixes: the E402 suppression is now applied at the correct location, and ambiguous inline assignments/positional arguments were rewritten for clarity. The paired .ipynb was regenerated from jupytext to keep notebook artifacts in sync.

  • Lint suppression placement (E402)

    • Moved # ruff: disable[E402] to immediately precede the late imports it is intended to suppress (before jax.numpy import), instead of placing it after PDK.activate().
  • Readable variable assignment (remove walrus in calls)

    • Replaced inline walrus assignments in capacitor(...) and inductor(...) calls with explicit prior assignments:
      • capacitance = 100e-15
      • inductance = 1e-9
  • Named arguments for coupling capacitance example

    • Rewrote cpw_cpw_coupling_capacitance(TEST_FREQUENCY, 100, 100, "cpw") to explicit keyword arguments for self-documenting intent.
# ruff: disable[E402]
import jax.numpy as jnp

capacitance = 100e-15
S_cap = capacitor(f=f, capacitance=capacitance)

cpw_cpw_coupling_capacitance(
    f=TEST_FREQUENCY, length=100, gap=100, cross_section="cpw"
)
Original prompt
Please apply the following diffs and create a pull request.
Once the PR is ready, give it a title based on the messages of the fixes being applied.

[{"message":"The ruff disable comment should be placed before the imports that trigger E402 (module level import not at top of file), not after PDK.activate(). Move this comment to line 35 before the jax.numpy import to properly suppress the warning for late imports.","fixFiles":[{"filePath":"notebooks/src/all_models.py","diff":"diff --git a/notebooks/src/all_models.py b/notebooks/src/all_models.py\n--- a/notebooks/src/all_models.py\n+++ b/notebooks/src/all_models.py\n@@ -32,6 +32,7 @@\n \n # %%\n \n+# ruff: disable[E402]\n import jax.numpy as jnp\n import matplotlib.pyplot as plt\n \n@@ -39,8 +40,6 @@\n \n PDK.activate()\n \n-# ruff: disable[E402]\n-\n # %% [markdown]\n # ## Constants\n \n"}]},{"message":"Using the walrus operator (:=) for variable assignment within a function call reduces readability. Consider assigning capacitance on a separate line before the function call for clarity.","fixFiles":[{"filePath":"notebooks/src/all_models.py","diff":"diff --git a/notebooks/src/all_models.py b/notebooks/src/all_models.py\n--- a/notebooks/src/all_models.py\n+++ b/notebooks/src/all_models.py\n@@ -174,7 +174,8 @@\n plt.legend()\n plt.show(block=False)\n \n-S_cap = capacitor(f=f, capacitance=(capacitance := 100e-15))\n+capacitance = 100e-15\n+S_cap = capacitor(f=f, capacitance=capacitance)\n # print(S_cap)\n plt.figure()\n # Polar plot of S21 and S11\n"}]},{"message":"Using the walrus operator (:=) for variable assignment within a function call reduces readability. Consider assigning inductance on a separate line before the function call for clarity.","fixFiles":[{"filePath":"notebooks/src/all_models.py","diff":"diff --git a/notebooks/src/all_models.py b/notebooks/src/all_models.py\n--- a/notebooks/src/all_models.py\n+++ b/notebooks/src/all_models.py\n@@ -213,7 +213,8 @@\n plt.title(f\"Capacitor $S$-parameters ($C={capacitance * 1e15}\\\\,$fF)\")\n plt.show(block=False)\n \n-S_ind = inductor(f=f, inductance=(inductance := 1e-9))\n+inductance = 1e-9\n+S_ind = inductor(f=f, inductance=inductance)\n # print(S_ind)\n plt.figure()\n plt.subplot(121, projection=\"polar\")\n"}]},{"message":"The positional arguments 100, 100, \\\"cpw\\\" are unclear without context. Consider using named arguments to improve code readability, e.g., cpw_cpw_coupling_capacitance(f=TEST_FREQUENCY, length=100, gap=100, cross_section=\\\"cpw\\\").","fixFiles":[{"filePath":"notebooks/src/all_models.py","diff":"diff --git a/notebooks/src/all_models.py b/notebooks/src/all_models.py\n--- a/notebooks/src/all_models.py\n+++ b/notebooks/src/all_models.py\n@@ -372,7 +372,9 @@\n # %%\n from qpdk.models.couplers import cpw_cpw_coupling_capacitance\n \n-cpw_cpw_coupling_capacitance(TEST_FREQUENCY, 100, 100, \"cpw\")\n+cpw_cpw_coupling_capacitance(\n+    f=TEST_FREQUENCY, length=100, gap=100, cross_section=\"cpw\"\n+)\n \n # %%\n from qpdk.models.couplers import coupler_straight\n"}]}]

Summary by Sourcery

Improve lint suppression placement and code readability in the all_models notebook and its Python source.

Enhancements:

  • Move the Ruff E402 suppression comment to directly precede the late jax.numpy import in the all_models source and regenerated notebook.
  • Replace inline walrus operator assignments for capacitance and inductance with separate variable declarations before capacitor/inductor calls.
  • Use explicit keyword arguments for the cpw_cpw_coupling_capacitance example to clarify parameter meaning in the notebook and source.

Copilot AI changed the title [WIP] Fix ruff disable comment positioning and improve readability Fix all_models notebook lint suppression placement and readability issues Jul 1, 2026
Copilot AI requested a review from nikosavola July 1, 2026 08:05
@nikosavola nikosavola marked this pull request as ready for review July 1, 2026 08:07
@nikosavola nikosavola enabled auto-merge July 1, 2026 08:07
@sourcery-ai

sourcery-ai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates the all_models notebook source and synced .ipynb to improve lint correctness and readability by relocating the Ruff E402 suppression, replacing walrus-operator inline assignments with explicit variables, and converting ambiguous positional arguments to named keyword arguments in a coupler example.

Flow diagram for updated import and Ruff suppression placement in all_models notebook

flowchart TB
    ruff_disable[Ruff disable E402 comment]
    import_jnp[Import jax.numpy as jnp]
    import_plt[Import matplotlib.pyplot as plt]
    import_PDK[Import PDK from qpdk]
    activate_PDK[Call PDK.activate]

    ruff_disable --> import_jnp --> import_plt --> import_PDK --> activate_PDK
Loading

File-Level Changes

Change Details Files
Relocate Ruff E402 suppression comment to correctly cover late imports.
  • Move the # ruff: disable[E402] comment into the cell immediately before the late jax.numpy import.
  • Remove the previous # ruff: disable[E402] comment that appeared after PDK.activate() so suppression is scoped only to the intended imports.
notebooks/src/all_models.py
notebooks/all_models.ipynb
Replace walrus-operator inline assignments with explicit variable declarations for capacitance and inductance examples.
  • Introduce a standalone capacitance = 100e-15 assignment before the capacitor(...) call and pass the variable by name.
  • Introduce a standalone inductance = 1e-9 assignment before the inductor(...) call and pass the variable by name.
  • Regenerate the notebook cell sources so the .ipynb reflects the updated explicit assignments.
notebooks/src/all_models.py
notebooks/all_models.ipynb
Use named keyword arguments for the CPW coupling capacitance example to clarify call semantics.
  • Rewrite the cpw_cpw_coupling_capacitance(...) invocation to use f=TEST_FREQUENCY, length=100, gap=100, cross_section="cpw" instead of positional literals.
  • Sync the updated call signature into the corresponding cell in the Jupyter notebook file.
notebooks/src/all_models.py
notebooks/all_models.ipynb

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@github-actions github-actions Bot added python Pull requests that update python code notebooks Related to Jupyter Notebooks labels Jul 1, 2026
@nikosavola nikosavola added this pull request to the merge queue Jul 1, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 1, 2026
Co-authored-by: nikosavola <7860886+nikosavola@users.noreply.github.com>
@nikosavola nikosavola force-pushed the copilot/move-ruff-disable-comment branch from a35e5f4 to aa7da10 Compare July 1, 2026 10:08
@nikosavola nikosavola enabled auto-merge July 1, 2026 10:08
@nikosavola nikosavola added this pull request to the merge queue Jul 1, 2026
Merged via the queue into main with commit 93c9e7d Jul 1, 2026
28 checks passed
@nikosavola nikosavola deleted the copilot/move-ruff-disable-comment branch July 1, 2026 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notebooks Related to Jupyter Notebooks python Pull requests that update python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants