Skip to content

Commit

Permalink
Update v2 sampler decoder (#1429)
Browse files Browse the repository at this point in the history
* v2 sampler decoder

* reenable qctrl check
  • Loading branch information
jyu00 authored Feb 28, 2024
1 parent 7b303aa commit 93ddd8d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 2 additions & 4 deletions qiskit_ibm_runtime/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,8 @@ def __init__(
Sampler.__init__(self)
BasePrimitiveV2.__init__(self, backend=backend, session=session, options=options)

raise NotImplementedError("SamplerV2 is not currently supported.")

# if self._service._channel_strategy == "q-ctrl":
# raise NotImplementedError("SamplerV2 is not supported with q-ctrl channel strategy.")
if self._service._channel_strategy == "q-ctrl":
raise NotImplementedError("SamplerV2 is not supported with q-ctrl channel strategy.")

def run(self, pubs: Iterable[SamplerPubLike], *, shots: int | None = None) -> RuntimeJob:
"""Submit a request to the estimator primitive.
Expand Down
12 changes: 10 additions & 2 deletions qiskit_ibm_runtime/utils/sampler_result_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@

"""Sampler result decoder."""

from typing import Dict
from typing import Dict, Union
from math import sqrt

from qiskit.result import QuasiDistribution
from qiskit.primitives import SamplerResult
from qiskit.primitives import PrimitiveResult

from .result_decoder import ResultDecoder

Expand All @@ -25,9 +26,16 @@ class SamplerResultDecoder(ResultDecoder):
"""Class used to decode sampler results."""

@classmethod
def decode(cls, raw_result: str) -> SamplerResult:
def decode(cls, raw_result: str) -> Union[SamplerResult, PrimitiveResult]:
"""Convert the result to SamplerResult."""
decoded: Dict = super().decode(raw_result)

if isinstance(decoded, PrimitiveResult):
return decoded

# TODO: Handle V2 result that is returned in dict format

# V1 result
quasi_dists = []
for quasi, meta in zip(decoded["quasi_dists"], decoded["metadata"]):
shots = meta.get("shots", float("inf"))
Expand Down

0 comments on commit 93ddd8d

Please sign in to comment.