Skip to content

Commit

Permalink
Numpy 2 anticipatory fixes (#1312)
Browse files Browse the repository at this point in the history
Numpy 2 support
  • Loading branch information
mpharrigan authored Aug 20, 2024
1 parent 8ba3644 commit 7823bdb
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions qualtran/bloqs/basic_gates/su2_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def signature(self) -> Signature:
return Signature.build(q=1)

@cached_property
def rotation_matrix(self) -> NDArray[np.complex_]:
def rotation_matrix(self) -> NDArray[np.complex128]:
if isinstance(self.lambd, sympy.Expr):
raise ValueError(f'Symbolic lambda not allowed: {self.lambd}')
if isinstance(self.phi, sympy.Expr):
Expand All @@ -89,7 +89,7 @@ def rotation_matrix(self) -> NDArray[np.complex_]:
)

@staticmethod
def from_matrix(mat: NDArray[np.complex_]) -> 'SU2RotationGate':
def from_matrix(mat: NDArray[np.complex128]) -> 'SU2RotationGate':
theta = np.arctan2(np.abs(mat[1, 0]), np.abs(mat[0, 0]))
if np.isclose(np.cos(theta), 0):
alpha = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def degree(self) -> SymbolicInt:
return degree_jacobi_anger_approximation(self.t * self.alpha, precision=self.precision)

@cached_property
def approx_cos(self) -> Union[NDArray[np.complex_], Shaped]:
def approx_cos(self) -> Union[NDArray[np.complex128], Shaped]:
r"""polynomial approximation for $$e^{i\theta} \mapsto e^{it\cos(\theta)}$$"""
if self.is_symbolic():
return Shaped((2 * self.degree + 1,))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_generalized_qsp_with_exp_cos_approx_on_random_unitaries(


def verify_hamiltonian_simulation_by_gqsp(
W: QubitizationWalkOperator, H: NDArray[np.complex_], *, t: float, precision: float
W: QubitizationWalkOperator, H: NDArray[np.complex128], *, t: float, precision: float
):
N = H.shape[0]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def from_coefficient_map(
@classmethod
def from_sparse_array(
cls,
coeffs: Union[Sequence[complex], NDArray[np.complex_], 'scipy.sparse.sparray'],
coeffs: Union[Sequence[complex], NDArray[np.complex128], 'scipy.sparse.sparray'],
phase_bitsize: SymbolicInt,
):
"""Factory to construct sparse state given the coefficients.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_examples(bloq_autotester):
bloq_autotester(_sparse_state_prep_via_rotations)


def get_prepared_state_vector(bloq: SparseStatePreparationViaRotations) -> NDArray[np.complex_]:
def get_prepared_state_vector(bloq: SparseStatePreparationViaRotations) -> NDArray[np.complex128]:
bb = BloqBuilder()
state = bb.add(IntState(0, bloq.target_bitsize))
phase_gradient = bb.add(PhaseGradientState(bloq.phase_bitsize))
Expand Down
4 changes: 2 additions & 2 deletions qualtran/linalg/polynomial/jacobi_anger_approximations.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def term_too_small(n: int) -> bool:
return d


def approx_exp_cos_by_jacobi_anger(t: float, *, degree: int) -> NDArray[np.complex_]:
def approx_exp_cos_by_jacobi_anger(t: float, *, degree: int) -> NDArray[np.complex128]:
r"""Laurent Polynomial approximation for $e^{i\theta} \mapsto e^{it\cos\theta}$.
The approximation is given by
Expand All @@ -82,7 +82,7 @@ def approx_exp_cos_by_jacobi_anger(t: float, *, degree: int) -> NDArray[np.compl
return 1j**coeff_indices * scipy.special.jv(coeff_indices, t)


def approx_exp_sin_by_jacobi_anger(t: float, *, degree: int) -> NDArray[np.complex_]:
def approx_exp_sin_by_jacobi_anger(t: float, *, degree: int) -> NDArray[np.complex128]:
r"""Laurent Polynomial approximation for $e^{i\theta} \mapsto e^{it\cos\theta}$.
The approximation is given by
Expand Down
2 changes: 1 addition & 1 deletion qualtran/linalg/polynomial/qsp_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _polynomial_max_abs_value_on_unit_circle(

def scale_down_to_qsp_polynomial(
P: Sequence[complex], *, n_points: int = 2**17
) -> NDArray[np.complex_]:
) -> NDArray[np.complex128]:
r"""Scale down the polynomial to be a valid QSP Polynomial
$P$ is a QSP polynomial if $|P(e^{i\theta})| \le 1$ for every $\theta \in [0, 2\pi]$.
Expand Down

0 comments on commit 7823bdb

Please sign in to comment.