Skip to content

Add Python API for Resizer (rsz)#9693

Open
rohithsiddi wants to merge 3 commits intoThe-OpenROAD-Project:masterfrom
rohithsiddi:add-rsz-python-wrapper
Open

Add Python API for Resizer (rsz)#9693
rohithsiddi wants to merge 3 commits intoThe-OpenROAD-Project:masterfrom
rohithsiddi:add-rsz-python-wrapper

Conversation

@rohithsiddi
Copy link

Summary

Adds a Python API for the Resizer (rsz) tool so that flows can use rsz_aux and the rsz module instead of Tcl for buffer_ports, repair_design, repair_timing, and related commands.

Motivation

The Resizer had no Python bindings; Python flows had to call Tcl commands via evalTclString. This change brings rsz in line with other tools (e.g. grt, cts, drt, pdn) that expose a Python API.

Changes

  • Build: New rsz_py SWIG module in src/rsz/src/CMakeLists.txt using Resizer-py.i; linked in src/CMakeLists.txt; rsz added to Python module load list in src/Main.cc.
  • Bindings: Resizer-py.i exposes snake_case wrappers for Resizer commands (opaque STA types; no Tcl-specific code).
  • Wrapper: src/rsz/test/rsz_aux.py with full command coverage, docstrings, and correct unit conversions (microns↔metres, ns↔seconds, percent↔fraction).
  • Tests: helpers.py and gcd_resize.py mirroring the existing Tcl test; run via CTest as rsz.gcd_resize.py.
  • Docs: New "Using the Python interface to rsz" section in src/rsz/README.md.

Testing

  • ctest -R "rsz.gcd_resize.py" — pass
  • ctest -R "rsz" — all RSZ tests (Tcl + Python) pass

Copy link
Contributor

@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 introduces a Python API for the Resizer (rsz) tool, which is a great step towards unifying the scripting interface across OpenROAD tools. The changes are well-structured, including build system updates, SWIG bindings, a Pythonic wrapper, tests, and documentation.

My review focuses on correctness and memory safety. I've found a few areas in the SWIG interface file (Resizer-py.i) where using smart pointers (std::unique_ptr) would improve exception safety and prevent potential memory leaks. These are detailed in the specific comments.

Overall, this is a solid contribution that significantly improves the usability of the Resizer from Python-based flows.

Note: Security Review is unavailable for this PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

clang-tidy review says "All clean, LGTM! 👍"

@maliberty
Copy link
Member

We should have a python API for rsz. This PR however tries to impose an interface the mirrors tcl which is not desirable. In Python we intend to expose an object-oriented API rather than a command oriented API. Please look at other modules for examples.

@rohithsiddi
Copy link
Author

Thanks for the feedback — understood. I’ll pivot the architecture to follow the object-oriented Python API pattern used in the other modules instead of the Tcl-like command wrappers.

I'll study the preferred modules to align with your exact design patterns and push an updated structure to this branch shortly.

- Add rsz_py SWIG module (Resizer-py.i) and wire into build/Main.cc
- Add rsz_aux.py Python wrapper with unit conversions and docstrings
- Add helpers.py and gcd_resize.py test mirroring gcd_resize.tcl
- All RSZ commands exposed: dont_use, buffer_ports, repair_design,
  repair_timing, reporting, eliminate_dead_logic, etc.

Signed-off-by: rohithsiddi <rohithsiddi7@gmail.com>
Signed-off-by: rohithsiddi <rohithsiddi7@gmail.com>
Signed-off-by: rohithsiddi <rohithsiddi7@gmail.com>
@rohithsiddi rohithsiddi force-pushed the add-rsz-python-wrapper branch from 3bc3a95 to 3f83a1f Compare March 9, 2026 18:00
@rohithsiddi
Copy link
Author

rohithsiddi commented Mar 9, 2026

@maliberty I've addressed the review comments. Summary of the changes below.

What I updated

  • Kept the RSZ Python interface object-oriented (design.getResizer().<method>), aligned with other tool bindings.
  • Simplified Resizer-py.i style to match existing *-py.i files (minimal comments, no behavior change).
  • Refined rsz_aux.py interface details:
    • removed unused verbose argument from report_floating_nets
    • clarified Python-facing error messages (removed Tcl-style flag prefixes)
  • Updated gcd_resize.py call site accordingly (report_floating_nets(design)).

Validation

  • Rebuilt successfully.
  • RSZ Python test passes:
    • ctest --output-on-failure -R "rsz.gcd_resize.py"

%include <std_string.i>
%include <std_vector.i>

%ignore rsz::Resizer::Resizer;
Copy link
Member

Choose a reason for hiding this comment

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

Why are there so many %ignore ?

Copy link
Author

Choose a reason for hiding this comment

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

The higher %ignore count in Resizer-py.i compared to GRT/CTS is because
Resizer.hh is deeply integrated with OpenSTA internals:

  • ~21 methods return/take STA collection types (NetSeq*, PinSet*, vector)
    that have no Python SWIG typemaps — these are either ignored or replaced with
    %extend wrappers (e.g. findFloatingNetsCount(), string-based repairSetup).
  • ~5 methods use output-by-reference params (Delay&, Slew&, map<Pin*, float>&)
    not cleanly expressible in Python.
  • Internal/GUI hooks (postReadLiberty, setDebugGraphics, lib_data_) follow
    the same pattern as GRT's init/initGui/setRenderer ignores.

GlobalRouter gets away with only 5 %ignores because its API mostly uses
odb::db* types already registered by the odb SWIG module.

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.

2 participants