12
12
13
13
"""Estimator result decoder."""
14
14
15
- from typing import Dict
15
+ from typing import Dict , Union
16
16
import numpy as np
17
17
18
18
from qiskit .primitives import EstimatorResult
19
- from qiskit .primitives .containers import PrimitiveResult , make_data_bin , PubResult
19
+ from qiskit .primitives .containers import PrimitiveResult
20
20
21
21
from .result_decoder import ResultDecoder
22
22
@@ -26,24 +26,14 @@ class EstimatorResultDecoder(ResultDecoder):
26
26
27
27
@classmethod
28
28
def decode ( # type: ignore # pylint: disable=arguments-differ
29
- cls , raw_result : str , version : int
30
- ) -> EstimatorResult :
29
+ cls , raw_result : str
30
+ ) -> Union [ EstimatorResult , PrimitiveResult ] :
31
31
"""Convert the result to EstimatorResult."""
32
32
decoded : Dict = super ().decode (raw_result )
33
- if version == 2 :
34
- out_results = []
35
- for val , meta in zip (decoded ["values" ], decoded ["metadata" ]):
36
- if not isinstance (val , np .ndarray ):
37
- val = np .asarray (val )
38
- data_bin_cls = make_data_bin (
39
- [("evs" , np .ndarray ), ("stds" , np .ndarray )], shape = val .shape
40
- )
41
- out_results .append (
42
- PubResult (data = data_bin_cls (val , meta .pop ("standard_error" )), metadata = meta )
43
- )
44
- # TODO what metadata should be passed in to PrimitiveResult?
45
- return PrimitiveResult (out_results , metadata = decoded ["metadata" ])
46
- return EstimatorResult (
47
- values = np .asarray (decoded ["values" ]),
48
- metadata = decoded ["metadata" ],
49
- )
33
+ if isinstance (decoded , PrimitiveResult ):
34
+ return decoded
35
+ else :
36
+ return EstimatorResult (
37
+ values = np .asarray (decoded ["values" ]),
38
+ metadata = decoded ["metadata" ],
39
+ )
0 commit comments