Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix serialization of primitives (backport #9076) #9152

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions qiskit/primitives/backend_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ def __new__( # pylint: disable=signature-differs
self = super().__new__(cls)
return self

def __getnewargs__(self):
return (self._backend,)

@property
def transpile_options(self) -> Options:
"""Return the transpiler options for transpiling the circuits."""
Expand Down
5 changes: 4 additions & 1 deletion qiskit/primitives/backend_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
from qiskit.result import QuasiDistribution, Result
from qiskit.transpiler.passmanager import PassManager

from .backend_estimator import _prepare_counts, _run_circuits
from .base import BaseSampler, SamplerResult
from .primitive_job import PrimitiveJob
from .utils import _circuit_key
from .backend_estimator import _run_circuits, _prepare_counts


class BackendSampler(BaseSampler):
Expand Down Expand Up @@ -83,6 +83,9 @@ def __new__( # pylint: disable=signature-differs
self = super().__new__(cls)
return self

def __getnewargs__(self):
return (self._backend,)

@property
def preprocessed_circuits(self) -> list[QuantumCircuit]:
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
fixes:
- |
Fixed an issue with the primitive classes, :class:`~.BackendSampler` and :class:`~.BackendEstimator`,
where instances were not able to be serialized with ``pickle``. In general these classes are not guaranteed
to be serializable as :class:`~.BackendV2` and :class:`~.BackendV1` instances are not required to be
serializable (and often are not), but the class definitions of :class:`~.BackendSampler` and
:class:`~.BackendEstimator` no longer prevent the use of ``pickle``.
2 changes: 1 addition & 1 deletion test/python/primitives/test_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"""Tests for Estimator."""

import unittest
from ddt import ddt, data, unpack

import numpy as np
from ddt import data, ddt, unpack

from qiskit.circuit import Parameter, QuantumCircuit
from qiskit.circuit.library import RealAmplitudes
Expand Down