Add Python API for Resizer (rsz)#9693
Add Python API for Resizer (rsz)#9693rohithsiddi wants to merge 4 commits intoThe-OpenROAD-Project:masterfrom
Conversation
There was a problem hiding this comment.
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.
|
clang-tidy review says "All clean, LGTM! 👍" |
|
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. |
|
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. |
3bc3a95 to
3f83a1f
Compare
|
@maliberty I've addressed the review comments. Summary of the changes below. What I updated
Validation
|
| %include <std_string.i> | ||
| %include <std_vector.i> | ||
|
|
||
| %ignore rsz::Resizer::Resizer; |
There was a problem hiding this comment.
Why are there so many %ignore ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Look at odb where we have
void getGridPatternX(int i, int& origin_x, int& line_count, int& step);
and map it with
%apply int& OUTPUT { int& origin_x, int& origin_y, int& line_count, int& step };
There was a problem hiding this comment.
@maliberty Thanks for the feedback — I updated Resizer-py.i accordingly.
Resizer-py.i: replaced %ignore with %apply OUTPUT where applicable
For bufferWireDelay, I removed %ignore and added:
%apply float& OUTPUT { sta::Delay& delay, sta::Slew& slew };sta::Delay and sta::Slew are aliases of float, so this follows SWIG's standard float& OUTPUT mapping pattern (same style as in odb/src/swig/common/dbtypes_common.i). From Python, bufferWireDelay(...) now returns (delay, slew).
I also removed %ignore from methods that SWIG can wrap directly without extra typemaps:
parseMove(static, returnsMoveType)repairSetup(const sta::Pin*)(single-pin testing overload)resetInputSlews(no args)getSlewRCFactor(returnsfloat)
Why the remaining %ignore entries stay
The remaining %ignore methods are cases where %apply is not applicable:
- Return STA container/internal types (
sta::NetSeq,sta::PinSet,sta::VertexSeq,std::optional<sta::Slack>) that are not directly wrapped in this module - Use C-style fixed-size output arrays (e.g.
ArcDelay[2]) —%applyworks on scalarT&, notT[N] - Use
std::map<const Pin*, float>&output params - Require
sta::Scene*inputs, which are internal STA context objects not available from Python - Internal lifecycle/GUI hooks (
init, constructor,postReadLiberty,setDebugGraphics), consistent with other tool bindings
For findFloatingNets, findFloatingPins, findOverdrivenNets, and repairSetup(vector<MoveType>), %ignore is paired with %extend wrappers that expose Python-usable alternatives (count helpers and string-based sequence input).
- 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>
Replace %ignore rsz::Resizer::bufferWireDelay with
%apply float& OUTPUT { sta::Delay& delay, sta::Slew& slew }
so the output-by-reference params are mapped to a Python return tuple,
following the same pattern used in odb's dbtypes_common.i.
Also remove unnecessary %ignore directives for methods that SWIG can
wrap directly: parseMove (static, returns MoveType enum),
repairSetup(const sta::Pin*) (single-pin testing overload),
resetInputSlews (void, no args), getSlewRCFactor (returns float).
Signed-off-by: rohithsiddi <rohithsiddi7@gmail.com>
3f83a1f to
237255d
Compare
Summary
Adds a Python API for the Resizer (rsz) tool so that flows can use
rsz_auxand therszmodule 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
rsz_pySWIG module insrc/rsz/src/CMakeLists.txtusingResizer-py.i; linked insrc/CMakeLists.txt;rszadded to Python module load list insrc/Main.cc.Resizer-py.iexposes snake_case wrappers for Resizer commands (opaque STA types; no Tcl-specific code).src/rsz/test/rsz_aux.pywith full command coverage, docstrings, and correct unit conversions (microns↔metres, ns↔seconds, percent↔fraction).helpers.pyandgcd_resize.pymirroring the existing Tcl test; run via CTest asrsz.gcd_resize.py.src/rsz/README.md.Testing
ctest -R "rsz.gcd_resize.py"— passctest -R "rsz"— all RSZ tests (Tcl + Python) pass