diff --git a/qiskit/circuit/annotated_operation.py b/qiskit/circuit/annotated_operation.py index 6006e68f58d..c1093d8fc5b 100644 --- a/qiskit/circuit/annotated_operation.py +++ b/qiskit/circuit/annotated_operation.py @@ -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).""" diff --git a/qiskit/primitives/backend_estimator.py b/qiskit/primitives/backend_estimator.py index f6a53c02ea9..722ee900cee 100644 --- a/qiskit/primitives/backend_estimator.py +++ b/qiskit/primitives/backend_estimator.py @@ -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 @@ -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 diff --git a/qiskit/primitives/backend_sampler.py b/qiskit/primitives/backend_sampler.py index 213b9701a55..905fa237154 100644 --- a/qiskit/primitives/backend_sampler.py +++ b/qiskit/primitives/backend_sampler.py @@ -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 diff --git a/qiskit/primitives/estimator.py b/qiskit/primitives/estimator.py index 1ca1529852c..6ae50ee7f0f 100644 --- a/qiskit/primitives/estimator.py +++ b/qiskit/primitives/estimator.py @@ -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, @@ -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: diff --git a/qiskit/primitives/sampler.py b/qiskit/primitives/sampler.py index d93db4f0411..9155e50ad2c 100644 --- a/qiskit/primitives/sampler.py +++ b/qiskit/primitives/sampler.py @@ -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, @@ -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: diff --git a/test/python/circuit/test_annotated_operation.py b/test/python/circuit/test_annotated_operation.py index e2ca9f4af9a..375c19fcf3a 100644 --- a/test/python/circuit/test_annotated_operation.py +++ b/test/python/circuit/test_annotated_operation.py @@ -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()