@@ -174,21 +174,17 @@ def _eval_aux_operators(
174
174
if operator is None :
175
175
continue
176
176
value = 0.0
177
- if isinstance (operator , PauliSumOp ):
178
- if operator .coeff != 0 :
179
- mat = operator .to_spmatrix ()
180
- # Terra doesn't support sparse yet, so do the matmul directly if so
181
- # This is necessary for the particle_hole and other chemistry tests because the
182
- # pauli conversions are 2^12th large and will OOM error if not sparse.
183
- if isinstance (mat , scisparse .spmatrix ):
184
- value = mat .dot (wavefn ).dot (np .conj (wavefn ))
185
- else :
186
- value = (
187
- Statevector (wavefn ).expectation_value (operator .primitive )
188
- * operator .coeff
189
- )
190
- else :
177
+ if isinstance (operator , Operator ):
191
178
value = Statevector (wavefn ).expectation_value (operator )
179
+ else :
180
+ if isinstance (operator , PauliSumOp ):
181
+ if operator .coeff != 0 :
182
+ op_matrix = operator .to_spmatrix ()
183
+ value = op_matrix .dot (wavefn ).dot (np .conj (wavefn ))
184
+ else :
185
+ op_matrix = operator .to_matrix (sparse = True )
186
+ value = op_matrix .dot (wavefn ).dot (np .conj (wavefn ))
187
+
192
188
value = value if np .abs (value ) > threshold else 0.0
193
189
# The value gets wrapped into a tuple: (mean, metadata).
194
190
# The metadata includes variance (and, for other eigensolvers, shots).
0 commit comments