Skip to content

Commit

Permalink
Merge pull request #267 from BQSKit/overflow-fix
Browse files Browse the repository at this point in the history
Fixed overflow in Unitary.dim
  • Loading branch information
edyounis authored Aug 6, 2024
2 parents 200e799 + 70cca15 commit f8263b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion bqskit/qis/unitary/unitary.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ def dim(self) -> int:
if hasattr(self, '_dim'):
return self._dim

return int(np.prod(self.radixes))
# return int(np.prod(self.radixes))
# Above line removed due to failure to handle overflow and
# underflows for large dimensions.

acm = 1
for radix in self.radixes:
acm *= int(radix)
return acm

@abc.abstractmethod
def get_unitary(self, params: RealVector = []) -> UnitaryMatrix:
Expand Down
8 changes: 8 additions & 0 deletions tests/qis/unitary/test_props.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from __future__ import annotations

from bqskit.ir.circuit import Circuit


def test_circuit_dim_overflow() -> None:
c = Circuit(1024)
assert c.dim != 0

0 comments on commit f8263b9

Please sign in to comment.