Skip to content

Commit

Permalink
Switched np.sqrt to math.sqrt for documentation generation purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
mtweiden committed Aug 28, 2024
1 parent 70059ff commit ef862cd
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions bqskit/ir/gates/constant/h.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
"""This module implements the HGate."""
from __future__ import annotations

import numpy as np
from math import sqrt

from numpy import array
from numpy import complex128
from numpy import exp
from numpy import pi
from numpy import zeros

from bqskit.ir.gates.constantgate import ConstantGate
from bqskit.ir.gates.quditgate import QuditGate
Expand Down Expand Up @@ -67,22 +73,22 @@ def __init__(self, radix: int = 2) -> None:

# Calculate unitary
if radix == 2:
matrix = np.array(
matrix = array(
[
[np.sqrt(2) / 2, np.sqrt(2) / 2],
[np.sqrt(2) / 2, -np.sqrt(2) / 2],
[sqrt(2) / 2, sqrt(2) / 2],
[sqrt(2) / 2, -sqrt(2) / 2],
],
dtype=np.complex128,
dtype=complex128,
)
self._utry = UnitaryMatrix(matrix)

else:
matrix = np.zeros([radix] * 2, dtype=np.complex128)
omega = np.exp(2j * np.pi / radix)
matrix = zeros([radix] * 2, dtype=complex128)
omega = exp(2j * pi / radix)
for i in range(radix):
for j in range(i, radix):
val = omega ** (i * j)
matrix[i, j] = val
matrix[j, i] = val
matrix *= 1 / np.sqrt(radix)
matrix *= 1 / sqrt(radix)
self._utry = UnitaryMatrix(matrix, self.radixes)

0 comments on commit ef862cd

Please sign in to comment.