Skip to content

Commit f549099

Browse files
committed
fix: type errors
1 parent 1942d78 commit f549099

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

mpqp/core/instruction/measurement/expectation_value.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class to define your observable, and a :class:`ExpectationMeasure` to perform
1212

1313
import numpy as np
1414
import numpy.typing as npt
15+
from typeguard import typechecked
16+
1517
from mpqp.core.instruction.gates.native_gates import SWAP
1618
from mpqp.core.instruction.measurement.measure import Measure
1719
from mpqp.core.instruction.measurement.pauli_string import (
@@ -23,7 +25,6 @@ class to define your observable, and a :class:`ExpectationMeasure` to perform
2325
from mpqp.tools.errors import NumberQubitsError
2426
from mpqp.tools.generics import Matrix, OneOrMany
2527
from mpqp.tools.maths import is_diagonal, is_hermitian, is_power_of_two
26-
from typeguard import typechecked
2728

2829
if TYPE_CHECKING:
2930
from braket.circuits.observables import Hermitian
@@ -126,7 +127,7 @@ def matrix(self) -> Matrix:
126127
"""The matrix representation of the observable."""
127128
if self._matrix is None:
128129
if self.is_diagonal and self._diag_elements is not None:
129-
self._matrix = np.diag(self._diag_elements)
130+
self._matrix = np.diag(np.array(self._diag_elements, dtype=np.float64))
130131
else:
131132
self._matrix = self.pauli_string.to_matrix()
132133
matrix = copy.deepcopy(self._matrix).astype(np.complex64)
@@ -138,7 +139,7 @@ def pauli_string(self) -> PauliString:
138139
if self._pauli_string is None:
139140
if self.is_diagonal:
140141
self._pauli_string = PauliString.from_diagonal_elements(
141-
self.diagonal_elements
142+
np.array(self.diagonal_elements, dtype=np.float64)
142143
)
143144
else:
144145
self._pauli_string = PauliString.from_matrix(self.matrix)
@@ -150,7 +151,7 @@ def diagonal_elements(self) -> npt.NDArray[np.float32]:
150151
"""The diagonal elements of the matrix representing the observable (diagonal or not)."""
151152
if self._diag_elements is None:
152153
self._diag_elements = np.diagonal(self.matrix)
153-
return copy.deepcopy(self._diag_elements).real
154+
return copy.deepcopy(np.array(self._diag_elements, dtype=np.float32)).real
154155

155156
@matrix.setter
156157
def matrix(self, matrix: Matrix):

mpqp/tools/obs_decomposition.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ def generate_and_explore_node_diagonal_case(
404404

405405
@typechecked
406406
def decompose_diagonal_observable_ptdr(
407-
diag_elements: list[Real] | npt.NDArray[np.float32], print_progression: bool = False
407+
diag_elements: list[Real] | npt.NDArray[np.float64], print_progression: bool = False
408408
) -> PauliString:
409409
"""Decomposes a diagonal observable into a Pauli string representation.
410410
@@ -505,7 +505,7 @@ def compute_coefficients_walsh(
505505

506506
@typechecked
507507
def decompose_diagonal_observable_walsh_hadamard(
508-
diag_elements: list[Real] | npt.NDArray[np.float32],
508+
diag_elements: list[Real] | npt.NDArray[np.float64],
509509
) -> PauliString:
510510
"""Decomposes the observable represented by the diagonal elements into a
511511
Pauli string using the Walsh-Hadamard transform.

0 commit comments

Comments
 (0)