def test_expval_pauli(self, pauli): """Test expectation_value method for Pauli op""" seed = 1020 op = Pauli(pauli) state = random_statevector(2**op.num_qubits, seed=seed) target = state.expectation_value(op.to_matrix()) expval = state.expectation_value(op) self.assertAlmostEqual(expval, target)
def test_expval_pauli_c_contiguous(self, pauli): """Test expectation_value method for Pauli op""" seed = 1020 op = Pauli(pauli) rho = random_density_matrix(2**op.num_qubits, seed=seed) rho._data = np.reshape(rho.data.flatten(order="C"), rho.data.shape, order="C") target = rho.expectation_value(op.to_matrix()) expval = rho.expectation_value(op) self.assertAlmostEqual(expval, target)