Skip to content

Add jupytext sync for notebook diffs#135

Merged
vvahidd merged 4 commits into
mainfrom
add-jupytext-sync
May 14, 2026
Merged

Add jupytext sync for notebook diffs#135
vvahidd merged 4 commits into
mainfrom
add-jupytext-sync

Conversation

@joamatab
Copy link
Copy Markdown
Contributor

@joamatab joamatab commented May 12, 2026

Summary

  • Adds a jupytext --sync pre-commit hook so every .ipynb in nbs/ is automatically paired with a .py percent-script file
  • Paired .py files are tracked in git, giving clean line-by-line diffs for notebook changes instead of opaque JSON blobs
  • Configures [tool.jupytext] in pyproject.toml with format nbs///ipynb,nbs///py:percent
  • Includes the initial sync output for all 22 existing notebooks

Fixes prs with notebooks hard to review

image

Test plan

  • Verify uv run jupytext --sync nbs/*.ipynb runs without errors
  • Edit a notebook, run pre-commit run jupytext --all-files, confirm the .py file updates
  • Confirm git diff on a notebook change shows a readable diff via the .py file

Notebooks are hard to diff in git. This adds jupytext --sync as a
pre-commit hook so every .ipynb in nbs/ is paired with a .py
percent-script file that produces clean, reviewable diffs.

- Add jupytext pre-commit hook (--sync)
- Add [tool.jupytext] config in pyproject.toml (nbs///ipynb,nbs///py:percent)
- Add jupytext to lint dependency group
- Un-ignore nbs/*.py so paired scripts are tracked in git
- Initial sync: generate .py files for all 22 existing notebooks
@github-actions github-actions Bot added the enhancement New feature or request label May 12, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request integrates Jupytext into the project to enable synchronization between Jupyter notebooks and Python scripts. The changes include updating the pre-commit configuration, adding Jupytext to the project dependencies, and introducing numerous Python scripts representing various MEEP and Palace simulation examples. The reviewer identified a typo in the Jupytext format specification within pyproject.toml, where a triple slash was used instead of the standard double slash separator.

Comment thread pyproject.toml
convention = "google"

[tool.jupytext]
formats = "nbs///ipynb,nbs///py:percent"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The Jupytext format specification nbs///ipynb,nbs///py:percent contains a triple slash (///), which appears to be a typo. Jupytext uses a double slash (//) as a separator to indicate that paired files should be located in the same directory relative to the path prefix. Using /// may cause Jupytext to misinterpret the directory structure or the file extensions.

Suggested change
formats = "nbs///ipynb,nbs///py:percent"
formats = "nbs//ipynb,nbs//py:percent"

Copy link
Copy Markdown
Member

@nikosavola nikosavola left a comment

Choose a reason for hiding this comment

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

Hooks are now failing likely due to the .py files being under linting and formatting now whereas the ipynbs weren't

vvahidd added 3 commits May 13, 2026 16:31
- pyproject.toml: widen nbs/*.py ruff per-file-ignores to mirror *.ipynb
  (notebook-inherent noise like E501/E402/B018/B905/etc.) and exclude
  nbs/**/* from interrogate.
- .pre-commit-config.yaml: bump jupytext hook to v1.19.2 (matches local),
  scope it to nbs/*.{ipynb,py}, and exclude nbs/docs/tests from interrogate.
- src/gsim/palace/driven.py and eigenmode.py: add @overload signatures so
  sim.run() narrows to SParams (driven) or dict[str, Path] (eigenmode)
  when wait=True (default), eliminating SParams|str union access errors
  in notebooks.
- palace_branch_line_coupler.py: inline tline1 + branch_line_coupler PCells
  (removed from ihp.cells when IHP migrated schematic metadata).
- meep notebooks: move num_freqs out of ModeSource (no such field) onto
  Simulation where it belongs.
- palace notebooks: assert port.name is not None before add_port,
  switch wait_for_results(job_ids) to wait_for_results(*job_ids),
  fix mesh(air_above=...) -> set_stack(air_above=...) in mach_zehnder,
  type-annotate _VIA_RULES so mixed-type values don't break arithmetic.
# Conflicts:
#	nbs/palace_branch_line_coupler.ipynb
#	nbs/palace_cpw_lumped.ipynb
#	nbs/palace_microstrip.ipynb
#	nbs/palace_width_sweep.ipynb
Exclude nbs/** from the ty pre-commit hook so customer notebooks
(read by physicists, not SWEs) don't accumulate type-checker
appeasements. Removes the resulting noise:

- nbs: drop `assert port.name is not None` before add_port in
  palace_branch_line_coupler, palace_microstrip, palace_width_sweep.
- nbs/palace_cpw_via: revert `_VIA_RULES` to plain dict literal and
  drop the `from typing import Any` import.
- nbs/palace_width_sweep: revert `wait_for_results(*job_ids)` to
  `wait_for_results(job_ids)` (both forms are documented).
- src/gsim/palace/{driven,eigenmode}.py: remove the @overload pair
  on `run()` and the `# ty: ignore[invalid-method-override]` they
  required. The runtime return type (`SParams | str` / `dict | str`)
  is unchanged.

Real runtime fixes from cae514d (num_freqs move, mesh→set_stack
air_above, inlined branch_line_coupler PCells) are kept.
@nikosavola nikosavola self-requested a review May 14, 2026 06:50
@vvahidd vvahidd merged commit 7d9ef0b into main May 14, 2026
8 checks passed
@vvahidd vvahidd deleted the add-jupytext-sync branch May 14, 2026 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants