Repository: Qiskit/qiskit

Issue:
Handle Aer deprecation on AerPauliExpectation
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues -->

### Information

- **Qiskit Terra version**:
- **Python version**:
- **Operating system**:

### What is the current behavior?
AerPauliExpectation shows the following deprecate msg:
```
PendingDeprecationWarning: The `SnapshotExpectationValue` instruction will be deprecated in the future. It has been superseded by the `SaveExpectationValue` and `SaveExpectationValueVariance` instructions.
```


### Steps to reproduce the problem



### What is the expected behavior?
SaveExpectationValue / SaveExpectationValueVariance should be used instead.


### Suggested solutions





Discussion:
@ikkoham Any chance you could take a look at this please.
Got it
@ikkoham Here is Aer PR for changing these pending warnings to actual deprecation warnings: https://github.com/Qiskit/qiskit-aer/pull/1270
@chriseclectic Thanks you so much. 

Resolving patch:
diff --git a/qiskit/opflow/converters/circuit_sampler.py b/qiskit/opflow/converters/circuit_sampler.py
--- a/qiskit/opflow/converters/circuit_sampler.py
+++ b/qiskit/opflow/converters/circuit_sampler.py
@@ -346,15 +346,8 @@ def sample_circuits(
                 circ_index = (i * reps) + j
                 circ_results = results.data(circ_index)
 
-                if "expval_measurement" in circ_results.get("snapshots", {}).get(
-                    "expectation_value", {}
-                ):
-                    snapshot_data = results.data(circ_index)["snapshots"]
-                    avg = snapshot_data["expectation_value"]["expval_measurement"][0]["value"]
-                    if isinstance(avg, (list, tuple)):
-                        # Aer versions before 0.4 use a list snapshot format
-                        # which must be converted to a complex value.
-                        avg = avg[0] + 1j * avg[1]
+                if "expval_measurement" in circ_results:
+                    avg = circ_results["expval_measurement"]
                     # Will be replaced with just avg when eval is called later
                     num_qubits = circuit_sfns[0].num_qubits
                     result_sfn = DictStateFn(
diff --git a/qiskit/opflow/expectations/aer_pauli_expectation.py b/qiskit/opflow/expectations/aer_pauli_expectation.py
--- a/qiskit/opflow/expectations/aer_pauli_expectation.py
+++ b/qiskit/opflow/expectations/aer_pauli_expectation.py
@@ -13,6 +13,8 @@
 """ AerPauliExpectation Class """
 
 import logging
+from functools import reduce
+from operator import add
 from typing import Union
 
 from qiskit.exceptions import MissingOptionalLibraryError
@@ -25,6 +27,7 @@
 from qiskit.opflow.primitive_ops.pauli_sum_op import PauliSumOp
 from qiskit.opflow.state_fns.circuit_state_fn import CircuitStateFn
 from qiskit.opflow.state_fns.operator_state_fn import OperatorStateFn
+from qiskit.quantum_info import SparsePauliOp
 
 logger = logging.getLogger(__name__)
 
@@ -55,14 +58,14 @@ def convert(self, operator: OperatorBase) -> OperatorBase:
     @classmethod
     def _replace_pauli_sums(cls, operator):
         try:
-            from qiskit.providers.aer.extensions import SnapshotExpectationValue
+            from qiskit.providers.aer.library import SaveExpectationValue
         except ImportError as ex:
             raise MissingOptionalLibraryError(
                 libname="qiskit-aer",
                 name="AerPauliExpectation",
                 pip_install="pip install qiskit-aer",
             ) from ex
-        # The 'expval_measurement' label on the snapshot instruction is special - the
+        # The 'expval_measurement' label on the save instruction is special - the
         # CircuitSampler will look for it to know that the circuit is a Expectation
         # measurement, and not simply a
         # circuit to replace with a DictStateFn
@@ -70,10 +73,9 @@ def _replace_pauli_sums(cls, operator):
             return operator.traverse(cls._replace_pauli_sums)
 
         if isinstance(operator, PauliSumOp):
-            paulis = [(meas[1], meas[0]) for meas in operator.primitive.to_list()]
-            snapshot_instruction = SnapshotExpectationValue("expval_measurement", paulis)
+            save_instruction = SaveExpectationValue(operator.primitive, "expval_measurement")
             return CircuitStateFn(
-                snapshot_instruction, coeff=operator.coeff, is_measurement=True, from_operator=True
+                save_instruction, coeff=operator.coeff, is_measurement=True, from_operator=True
             )
 
         # Change to Pauli representation if necessary
@@ -87,13 +89,18 @@ def _replace_pauli_sums(cls, operator):
             operator = operator.to_pauli_op(massive=False)
 
         if isinstance(operator, SummedOp):
-            paulis = [[meas.coeff, meas.primitive] for meas in operator.oplist]
-            snapshot_instruction = SnapshotExpectationValue("expval_measurement", paulis)
-            return CircuitStateFn(snapshot_instruction, is_measurement=True, from_operator=True)
+            sparse_pauli = reduce(
+                add, (meas.coeff * SparsePauliOp(meas.primitive) for meas in operator.oplist)
+            )
+            save_instruction = SaveExpectationValue(sparse_pauli, "expval_measurement")
+            return CircuitStateFn(
+                save_instruction, coeff=operator.coeff, is_measurement=True, from_operator=True
+            )
+
         if isinstance(operator, PauliOp):
-            paulis = [[operator.coeff, operator.primitive]]
-            snapshot_instruction = SnapshotExpectationValue("expval_measurement", paulis)
-            return CircuitStateFn(snapshot_instruction, is_measurement=True, from_operator=True)
+            sparse_pauli = operator.coeff * SparsePauliOp(operator.primitive)
+            save_instruction = SaveExpectationValue(sparse_pauli, "expval_measurement")
+            return CircuitStateFn(save_instruction, is_measurement=True, from_operator=True)
 
         raise TypeError(
             f"Conversion of OperatorStateFn of {operator.__class__.__name__} is not defined."


Test patch:
diff --git a/test/python/opflow/test_aer_pauli_expectation.py b/test/python/opflow/test_aer_pauli_expectation.py
--- a/test/python/opflow/test_aer_pauli_expectation.py
+++ b/test/python/opflow/test_aer_pauli_expectation.py
@@ -250,11 +250,6 @@ def test_list_pauli_sum(self):
         self.assertIsInstance(observable[0], CircuitStateFn)
         self.assertTrue(observable[0].is_measurement)
 
-    def test_pauli_expectation_non_hermite_op(self):
-        """Test PauliExpectation for non hermitian operator"""
-        exp = ~StateFn(1j * Z) @ One
-        self.assertEqual(self.sampler.convert(self.expect.convert(exp)).eval(), 1j)
-
     def test_expectation_with_coeff(self):
         """Test AerPauliExpectation with coefficients."""
         with self.subTest("integer coefficients"):