@@ -12,6 +12,8 @@ class to define your observable, and a :class:`ExpectationMeasure` to perform
12
12
13
13
import numpy as np
14
14
import numpy .typing as npt
15
+ from typeguard import typechecked
16
+
15
17
from mpqp .core .instruction .gates .native_gates import SWAP
16
18
from mpqp .core .instruction .measurement .measure import Measure
17
19
from mpqp .core .instruction .measurement .pauli_string import (
@@ -23,7 +25,6 @@ class to define your observable, and a :class:`ExpectationMeasure` to perform
23
25
from mpqp .tools .errors import NumberQubitsError
24
26
from mpqp .tools .generics import Matrix , OneOrMany
25
27
from mpqp .tools .maths import is_diagonal , is_hermitian , is_power_of_two
26
- from typeguard import typechecked
27
28
28
29
if TYPE_CHECKING :
29
30
from braket .circuits .observables import Hermitian
@@ -126,7 +127,7 @@ def matrix(self) -> Matrix:
126
127
"""The matrix representation of the observable."""
127
128
if self ._matrix is None :
128
129
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 ) )
130
131
else :
131
132
self ._matrix = self .pauli_string .to_matrix ()
132
133
matrix = copy .deepcopy (self ._matrix ).astype (np .complex64 )
@@ -138,7 +139,7 @@ def pauli_string(self) -> PauliString:
138
139
if self ._pauli_string is None :
139
140
if self .is_diagonal :
140
141
self ._pauli_string = PauliString .from_diagonal_elements (
141
- self .diagonal_elements
142
+ np . array ( self .diagonal_elements , dtype = np . float64 )
142
143
)
143
144
else :
144
145
self ._pauli_string = PauliString .from_matrix (self .matrix )
@@ -150,7 +151,7 @@ def diagonal_elements(self) -> npt.NDArray[np.float32]:
150
151
"""The diagonal elements of the matrix representing the observable (diagonal or not)."""
151
152
if self ._diag_elements is None :
152
153
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
154
155
155
156
@matrix .setter
156
157
def matrix (self , matrix : Matrix ):
0 commit comments