Skip to content

Commit

Permalink
Merge branch 'main' into avoid-operation-creation
Browse files Browse the repository at this point in the history
  • Loading branch information
mtreinish authored Jul 31, 2024
2 parents ea676ca + 919cfd3 commit cb1ecf5
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 20 deletions.
2 changes: 1 addition & 1 deletion qiskit/circuit/annotated_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def __eq__(self, other) -> bool:

def copy(self) -> "AnnotatedOperation":
"""Return a copy of the :class:`~.AnnotatedOperation`."""
return AnnotatedOperation(base_op=self.base_op, modifiers=self.modifiers.copy())
return AnnotatedOperation(base_op=self.base_op.copy(), modifiers=self.modifiers.copy())

def to_matrix(self):
"""Return a matrix representation (allowing to construct Operator)."""
Expand Down
15 changes: 8 additions & 7 deletions qiskit/primitives/backend_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
)
from qiskit.utils.deprecation import deprecate_func

from .base import BaseEstimatorV1, EstimatorResult
from .base import BaseEstimator, EstimatorResult
from .primitive_job import PrimitiveJob
from .utils import _circuit_key, _observable_key, init_observable

Expand Down Expand Up @@ -88,17 +88,18 @@ def _prepare_counts(results: list[Result]):
return counts


class BackendEstimator(BaseEstimatorV1[PrimitiveJob[EstimatorResult]]):
class BackendEstimator(BaseEstimator[PrimitiveJob[EstimatorResult]]):
"""Evaluates expectation value using Pauli rotation gates.
The :class:`~.BackendEstimator` class is a generic implementation of the
:class:`~.BaseEstimatorV1` interface that is used to wrap a :class:`~.BackendV2`
(or :class:`~.BackendV1`) object in the :class:`~.BaseEstimatorV1` API. It
:class:`~.BaseEstimator` (V1) interface that is used to wrap a :class:`~.BackendV2`
(or :class:`~.BackendV1`) object in the :class:`~.BaseEstimator` V1 API. It
facilitates using backends that do not provide a native
:class:`~.BaseEstimatorV1` implementation in places that work with
:class:`~.BaseEstimatorV1`.
:class:`~.BaseEstimator` V1 implementation in places that work with
:class:`~.BaseEstimator` V1.
However, if you're using a provider that has a native implementation of
:class:`~.BaseEstimatorV1` or :class:`~.BaseEstimatorV2`, it is a better
:class:`~.BaseEstimatorV1` ( :class:`~.BaseEstimator`) or
:class:`~.BaseEstimatorV2`, it is a better
choice to leverage that native implementation as it will likely include
additional optimizations and be a more efficient implementation.
The generic nature of this class precludes doing any provider- or
Expand Down
13 changes: 7 additions & 6 deletions qiskit/primitives/backend_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,23 @@
from qiskit.utils.deprecation import deprecate_func

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


class BackendSampler(BaseSamplerV1[PrimitiveJob[SamplerResult]]):
"""A :class:`~.BaseSamplerV1` implementation that provides a wrapper for
class BackendSampler(BaseSampler[PrimitiveJob[SamplerResult]]):
"""A :class:`~.BaseSampler` (V1) implementation that provides a wrapper for
leveraging the Sampler V1 interface from any backend.
This class provides a sampler interface from any backend and doesn't do
any measurement mitigation, it just computes the probability distribution
from the counts. It facilitates using backends that do not provide a
native :class:`~.BaseSamplerV1` implementation in places that work with
:class:`~.BaseSamplerV1`.
native :class:`~.BaseSampler` V1 implementation in places that work with
:class:`~.BaseSampler` V1.
However, if you're using a provider that has a native implementation of
:class:`~.BaseSamplerV1` or :class:`~.BaseESamplerV2`, it is a better
:class:`~.BaseSamplerV1` ( :class:`~.BaseSampler`) or
:class:`~.BaseESamplerV2`, it is a better
choice to leverage that native implementation as it will likely include
additional optimizations and be a more efficient implementation.
The generic nature of this class precludes doing any provider- or
Expand Down
6 changes: 3 additions & 3 deletions qiskit/primitives/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from qiskit.quantum_info.operators.base_operator import BaseOperator
from qiskit.utils.deprecation import deprecate_func

from .base import BaseEstimatorV1, EstimatorResult
from .base import BaseEstimator, EstimatorResult
from .primitive_job import PrimitiveJob
from .utils import (
_circuit_key,
Expand All @@ -36,9 +36,9 @@
)


class Estimator(BaseEstimatorV1[PrimitiveJob[EstimatorResult]]):
class Estimator(BaseEstimator[PrimitiveJob[EstimatorResult]]):
"""
Reference implementation of :class:`BaseEstimatorV1`.
Reference implementation of :class:`BaseEstimator` (V1).
:Run Options:
Expand Down
6 changes: 3 additions & 3 deletions qiskit/primitives/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from qiskit.result import QuasiDistribution
from qiskit.utils.deprecation import deprecate_func

from .base import BaseSamplerV1, SamplerResult
from .base import BaseSampler, SamplerResult
from .primitive_job import PrimitiveJob
from .utils import (
_circuit_key,
Expand All @@ -36,11 +36,11 @@
)


class Sampler(BaseSamplerV1[PrimitiveJob[SamplerResult]]):
class Sampler(BaseSampler[PrimitiveJob[SamplerResult]]):
"""
Sampler V1 class.
:class:`~Sampler` is a reference implementation of :class:`~BaseSamplerV1`.
:class:`~Sampler` is a reference implementation of :class:`~BaseSampler` (V1).
:Run Options:
Expand Down
11 changes: 11 additions & 0 deletions test/python/circuit/test_annotated_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,17 @@ def test_invalid_params_access(self):
with self.assertRaises(AttributeError):
_ = annotated.validate_parameter(1.2)

def test_invariant_under_assign(self):
"""Test the annotated operation is not changed by assigning."""
p = Parameter("p")
annotated = RXGate(p).control(2, annotated=True)
circuit = QuantumCircuit(annotated.num_qubits)
circuit.append(annotated, circuit.qubits)
bound = circuit.assign_parameters([1.23])

self.assertEqual(list(circuit.parameters), [p])
self.assertEqual(len(bound.parameters), 0)


if __name__ == "__main__":
unittest.main()

0 comments on commit cb1ecf5

Please # to comment.