Skip to content

Commit

Permalink
add SamplerResult / EstimatorResult serialization (#1074)
Browse files Browse the repository at this point in the history
* add SamplerResult serialization

Signed-off-by: Akihiko Kuroda <[email protected]>

* add EstimatorResult serialization

---------

Signed-off-by: Akihiko Kuroda <[email protected]>
  • Loading branch information
akihikokuroda authored Nov 3, 2023
1 parent c5fab28 commit b2a28c8
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion client/quantum_serverless/serializers/program_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import json
import os
from typing import Any, Dict

from qiskit.primitives import SamplerResult, EstimatorResult
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime.utils.json import RuntimeDecoder, RuntimeEncoder

Expand All @@ -45,6 +45,16 @@ def default(self, obj: Any) -> Any:
"__type__": "QiskitRuntimeService",
"__value__": obj.active_account(),
}
if isinstance(obj, SamplerResult):
return {
"__type__": "SamplerResult",
"__value__": {"quasi_dists": obj.quasi_dists, "metadata": obj.metadata},
}
if isinstance(obj, EstimatorResult):
return {
"__type__": "EstimatorResult",
"__value__": {"values": obj.values, "metadata": obj.metadata},
}
return super().default(obj)


Expand All @@ -57,6 +67,10 @@ def object_hook(self, obj: Any) -> Any:

if obj_type == "QiskitRuntimeService":
return QiskitRuntimeService(**obj["__value__"])
if obj_type == "SamplerResult":
return SamplerResult(**obj["__value__"])
if obj_type == "EstimatorResult":
return EstimatorResult(**obj["__value__"])
return super().object_hook(obj)
return obj

Expand Down

0 comments on commit b2a28c8

Please sign in to comment.