Skip to content

Commit

Permalink
v2 result
Browse files Browse the repository at this point in the history
  • Loading branch information
jyu00 committed Nov 24, 2023
1 parent 85b4192 commit 14112fe
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions qiskit_ibm_runtime/base_primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _run(self, tasks: Union[list[EstimatorTask], list[SamplerTask]]) -> RuntimeJ
inputs=primitive_inputs,
options=runtime_options,
callback=options_dict.get("environment", {}).get("callback", None),
result_decoder=DEFAULT_DECODERS.get(self._program_id()),
result_decoder=DEFAULT_DECODERS.get((self._program_id(), self.version)),
)

if self._backend:
Expand All @@ -158,7 +158,7 @@ def _run(self, tasks: Union[list[EstimatorTask], list[SamplerTask]]) -> RuntimeJ
options=runtime_options,
inputs=primitive_inputs,
callback=options_dict.get("environment", {}).get("callback", None),
result_decoder=DEFAULT_DECODERS.get(self._program_id()),
result_decoder=DEFAULT_DECODERS.get((self._program_id(), self.version)),
)

@property
Expand Down
2 changes: 2 additions & 0 deletions qiskit_ibm_runtime/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@
"estimator": [ResultDecoder, EstimatorResultDecoder],
"circuit-runner": RunnerResult,
"qasm3-runner": RunnerResult,
("sampler", 2): [ResultDecoder, SamplerResultDecoder],
("estimator", 2): [ResultDecoder, EstimatorResultDecoder],
}
16 changes: 15 additions & 1 deletion qiskit_ibm_runtime/utils/estimator_result_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@

"""Estimator result decoder."""

from typing import Dict
from typing import Dict, List
import numpy as np

from qiskit.primitives import EstimatorResult

from ..program.result_decoder import ResultDecoder
from ..qiskit.primitives.task_result import TaskResult


class EstimatorResultDecoder(ResultDecoder):
Expand All @@ -31,3 +32,16 @@ def decode(cls, raw_result: str) -> EstimatorResult:
values=np.asarray(decoded["values"]),
metadata=decoded["metadata"],
)


class EstimatorV2ResultDecoder(ResultDecoder):
"""Class used to decode v2 estimator results"""

@classmethod
def decode(cls, raw_result: str) -> List[TaskResult]:
"""Convert the result to a list of TaskResult."""
decoded: Dict = super().decode(raw_result)
return EstimatorResult(
values=np.asarray(decoded["values"]),
metadata=decoded["metadata"],
)

0 comments on commit 14112fe

Please sign in to comment.