forked from Qiskit/rustworkx
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix memory allocation issues in binomial graph generators
This commit fixes issues with the allocation of memory in the binomial graph generators. Previously there were 2 issues in the binomial graph generator functions when it came to allocating memory. The first was a temporary Vec was used to store all the node indices in the graph which would eat num_nodes * sizeof(usize) bytes of memory. This Vec isn't actually needed as the NodeIndex is just a usize integer wrapper and we know the indices of the nodes. This commit removes this and just iterates over the range of nodes instead of creating a Vec reducing the amoount of memory required. The second issue was that it was easily possible to overflow the max Vec size (either inside the graph objects or from the Vec previously created to store the node indices) by using an order where 2**order > isize::MAX or if order > 64 causing an overflow of a 64bit usize which would result in a panic. This fixes this issue by checking the input of order and seeing if it will overflow or exceed the max Vec size and raise an OverflowError. Fixes Qiskit#457
- Loading branch information
Showing
3 changed files
with
90 additions
and
92 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
releasenotes/notes/binomial-tree-alloc-fix-c24c8c4f3c27d489.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
fixes: | ||
- | | ||
Fixed an issue with the :func:`~retworkx.generators.binomial_tree_graph` | ||
and :func:`~retworkx.generators.directed_binomial_tree_graph` generator | ||
functions in :mod:`retworkx.generators` where passing an ``order`` value | ||
>= 60 would cause an overflow and raise a ``PanicException`` caused by the | ||
internal Rust panic when overflowing or exceeding the max Vec size. Instead | ||
the function will raise an ``OverflowError` and indicate the specified | ||
order is too large. | ||
Fixed `#457 <https://github.com/Qiskit/retworkx/issues/457?>`__ |
This file contains 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
This file contains 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