Skip to content

Migrate to pydantic 2; read GDS files with gdstk; require Python 3.11 - #15

Draft
sequoiap wants to merge 2 commits into
masterfrom
feat/pydantic-2
Draft

sequoiap wants to merge 2 commits into
masterfrom
feat/pydantic-2

Conversation

@sequoiap

@sequoiap sequoiap commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Draft: depends on a PyroLab release. This needs a PyroLab release that includes BYUCamachoLab/pyrolab#96 (PyroLab's own move to pydantic 2). Until that release exists, pyproject.toml pulls pyrolab from git through [tool.uv.sources]. That only affects development installs, not what PyPI users get. Before releasing AutoGator, delete that section and change the pyrolab[rto] dependency to require the new release.

Why

gdsfactory<7 held AutoGator on pydantic 1, and PyroLab is moving to pydantic 2. Newer gdsfactory doesn't help: 7.x requires pydantic 2 but pins an old gdstk, and 8+ is built on KLayout. AutoGator only used gdsfactory to read a GDS file's top cell and its polygons. gdstk, which gdsfactory 6 used underneath, does that directly.

Changes

  • GDS loading (circuits.py): uses gdstk.read_gds(...).top_level() instead of gf.import_gds. If a file has more than one top-level cell, it now raises an error that names them. gdsfactory is no longer a dependency, so 17 fewer packages get installed.
  • pydantic 2:
    • model_dump_json / model_validate_json replace json / parse_file, so existing profile JSON files load unchanged.
    • ConfigDict(extra="forbid").
    • Stage axes are explicitly Optional[...] = None.
  • Keyboard bindings (controllers.py) use pydantic-settings and read environment variables with the prefixes AUTOGATOR_KEYBOARD_ and AUTOGATOR_GUI_.
    • This fixes a bug: with no prefix, the HOME binding picked up the shell's HOME variable (e.g. /home/user).
    • ⚠️ Anyone who overrode a binding with an unprefixed environment variable must add the prefix.
  • Python 3.11+, matching PyroLab.

Verification

AutoGator has no test CI and only stub tests, so I checked these by hand:

  • Every module imports on Python 3.11 and 3.13.
  • A profile JSON written in the old format loads and round-trips, and unknown keys are rejected.
  • The environment prefixes work, and HOME no longer leaks into the bindings.
  • I compared loadGDS on master (gdsfactory 6, pydantic 1) with this branch on the same synthetic chips. The polygon counts and polygon hashes matched, and so did the outcome.
    • My synthetic layouts don't contain any recognizable circuits, so both versions failed the same way.
    • Please also check it on a real chip GDS before merging.

🤖 Generated with Claude Code

sequoiap and others added 2 commits October 5, 2026 09:44
gdsfactory<7 pinned AutoGator to pydantic 1. It was only used to read a
GDS file's top cell and its polygons, which gdstk (what gdsfactory 6 used
underneath) does directly, with identical results.

- pydantic 2 and pydantic-settings 2 replace pydantic 1's BaseSettings.
- The keyboard bindings read environment variables with the prefixes
  AUTOGATOR_KEYBOARD_ and AUTOGATOR_GUI_. Without a prefix, the HOME
  binding picked up the HOME environment variable.
- Stage axes are explicitly Optional (pydantic 2 no longer infers it).
- loadGDS raises a clear error if the file has more than one top cell.
- Python 3.11+, as PyroLab requires.

pyrolab is temporarily sourced from git (development installs only) until
a release with pydantic 2 support exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant