-
Notifications
You must be signed in to change notification settings - Fork 222
Python api performance improvement #1615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Iroy30
wants to merge
22
commits into
NVIDIA:main
Choose a base branch
from
Iroy30:python_api_performance
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
429d93e
Improve repeated-solve Python API performance
Iroy30 6834882
Optimize repeated Python model updates
2b42019
Delete script_perf_eval.py
Iroy30 a2ac39a
Merge branch 'main' into python_api_performance
Iroy30 b8049b8
fix pre-existing bug
0c6da6c
Skip stale tracking on solution attribute writes
acaf5b0
Merge remote-tracking branch 'iroy30/python_api_performance' into pyt…
Iroy30 8a01887
Merge branch 'main' into python_api_performance
Iroy30 744065d
Fix Q lifetime and MIPStart clear on warm updates.
98cda41
Merge branch 'main' into python_api_performance
Iroy30 5826f3b
formatting
Iroy30 6d4d4ed
fix conflict
Iroy30 0974eb9
address reviews
Iroy30 52b4f0b
Merge branch 'main' into python_api_performance
Iroy30 7f45787
move slack computation to cython
Iroy30 66b2f0b
fix read to add quadratic constraints and cache
Iroy30 634c910
Merge branch 'main' into python_api_performance
Iroy30 7e522fa
Update solution.py
Iroy30 089566b
Merge branch 'main' into python_api_performance
Iroy30 c3a64fd
Merge branch 'main' into python_api_performance
Iroy30 dd8d449
Merge branch 'main' into python_api_performance
Iroy30 670e5bf
fix formatting and row senses
Iroy30 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: NVIDIA/cuopt
Length of output: 50368
🏁 Script executed:
Repository: NVIDIA/cuopt
Length of output: 18011
🏁 Script executed:
Repository: NVIDIA/cuopt
Length of output: 2916
🌐 Web query:
Cython cppclass omitted default constructor new Foo() exception handling except + implicit constructor declaration💡 Result:
In Cython, when using a C++ class that has no explicitly declared constructor, Cython does not automatically assume a default constructor exists for the purposes of code generation, often leading to compilation errors or crashes if you attempt to instantiate the class [1][2]. If a class has only one constructor and it is a nullary (default) constructor, Cython may allow it without explicit declaration, but it is best practice to declare it [3][4]. Regarding exception handling: 1. Constructor Exception Handling: If your C++ constructor can throw an exception, you must explicitly declare it with
except +[3][4]. If you omit this, C++ exceptions thrown during construction will not be caught or translated into Python exceptions, which can lead to undefined behavior or process termination [3][4][5]. 2. Heap Allocation (new Foo()): When you usenew Foo()in Cython, the generated C++ code performs a raw call to thenewoperator. If you have not declared the constructor withexcept +, any exception raised during the execution of that constructor (or the allocation itself) will not be handled by Cython [5]. Even if the constructor logic is simple, declaring the constructor asFoo() except +is recommended to ensure that memory allocation failures or constructor-internal exceptions are safely translated into Python exceptions (e.g.,MemoryErroror others based on the C++ exception type) [3][4][5]. 3. Implicit Constructor Declarations: Because Cython requires explicit declarations for exception propagation, relying on "implicit" declarations is discouraged [5]. If a class lacks a nullary constructor, Cython will fail to stack-allocate it [6][7]. Developers working with such classes often use workarounds such as: - Defining a static factory function that returns the object and declaring it withexcept +[8]. - Usingstd::shared_ptrorstd::unique_ptrto manage the object on the heap, avoiding the need for a stack-allocated default constructor [9]. In summary, you should explicitly declare your constructors and useexcept +whenever the C++ code has the potential to raise an exception, including during memory allocation or object initialization, to ensure robust Python-C++ exception bridging [3][4][5].Citations:
Declare
data_model_view_t()withexcept +indata_model.pxd.The
new data_model_view_t[int, double]()call can otherwise let C++ allocation or construction failures escape the Python boundary.🤖 Prompt for AI Agents
Source: Path instructions