diff --git a/qiskit/extensions/__init__.py b/qiskit/extensions/__init__.py index d0685f0a0d03..38d3c5c9a296 100644 --- a/qiskit/extensions/__init__.py +++ b/qiskit/extensions/__init__.py @@ -50,7 +50,6 @@ from qiskit.circuit.library.generalized_gates import UnitaryGate from qiskit.circuit.barrier import Barrier -from .exceptions import ExtensionError from .quantum_initializer import ( Initialize, SingleQubitUnitary, @@ -59,7 +58,6 @@ UCRYGate, UCRZGate, ) -from .simulator import Snapshot warnings.warn( diff --git a/qiskit/extensions/exceptions.py b/qiskit/extensions/exceptions.py deleted file mode 100644 index 7a3f052e19f1..000000000000 --- a/qiskit/extensions/exceptions.py +++ /dev/null @@ -1,31 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2017. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. - -""" -Exception for errors raised by extensions module. -""" -from qiskit.exceptions import QiskitError -from qiskit.utils.deprecation import deprecate_func - - -class ExtensionError(QiskitError): - """Base class for errors raised by extensions module.""" - - @deprecate_func(since="0.45.0", pending=True) - def __init__(self, *message): - """Set the error message.""" - super().__init__(*message) - self.message = " ".join(message) - - def __str__(self): - """Return the message.""" - return repr(self.message) diff --git a/qiskit/extensions/simulator/__init__.py b/qiskit/extensions/simulator/__init__.py index 069ec393979e..0d00459713b2 100644 --- a/qiskit/extensions/simulator/__init__.py +++ b/qiskit/extensions/simulator/__init__.py @@ -11,5 +11,3 @@ # that they have been altered from the originals. """Instructions usable by simulator backends.""" - -from .snapshot import Snapshot diff --git a/qiskit/extensions/simulator/snapshot.py b/qiskit/extensions/simulator/snapshot.py deleted file mode 100644 index ca45e56354ac..000000000000 --- a/qiskit/extensions/simulator/snapshot.py +++ /dev/null @@ -1,70 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2017. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. -""" -Simulator command to snapshot internal simulator representation. -""" - -from qiskit.circuit.instruction import Instruction -from qiskit.extensions.exceptions import QiskitError, ExtensionError - -from qiskit.utils.deprecation import deprecate_func - - -class Snapshot(Instruction): - """Simulator snapshot instruction.""" - - _directive = True - - @deprecate_func( - since="0.45.0", - additional_msg="The Snapshot instruction has been superseded by Qiskit Aer's save " - "instructions, see " - "https://qiskit.org/ecosystem/aer/apidocs/aer_library.html#saving-simulator-data.", - ) - def __init__(self, label, snapshot_type="statevector", num_qubits=0, num_clbits=0, params=None): - """Create new snapshot instruction. - - Args: - label (str): the snapshot label for result data. - snapshot_type (str): the type of the snapshot. - num_qubits (int): the number of qubits for the snapshot type [Default: 0]. - num_clbits (int): the number of classical bits for the snapshot type - [Default: 0]. - params (list or None): the parameters for snapshot_type [Default: None]. - - Raises: - ExtensionError: if snapshot label is invalid. - """ - if not isinstance(label, str): - raise ExtensionError("Snapshot label must be a string.") - self._snapshot_type = snapshot_type - if params is None: - params = [] - super().__init__("snapshot", num_qubits, num_clbits, params, label=label) - - def assemble(self): - """Assemble a QasmQobjInstruction""" - instruction = super().assemble() - instruction.snapshot_type = self._snapshot_type - return instruction - - def inverse(self): - """Special case. Return self.""" - return Snapshot(self.num_qubits, self.num_clbits, self.params[0], self.params[1]) - - @property - def snapshot_type(self): - """Return snapshot type""" - return self._snapshot_type - - def c_if(self, classical, val): - raise QiskitError("Snapshots are simulator directives and cannot be conditional.") diff --git a/releasenotes/notes/remove-deprecated-extensions-fca165125c534de5.yaml b/releasenotes/notes/remove-deprecated-extensions-fca165125c534de5.yaml new file mode 100644 index 000000000000..ebc6ce7877eb --- /dev/null +++ b/releasenotes/notes/remove-deprecated-extensions-fca165125c534de5.yaml @@ -0,0 +1,11 @@ +--- +upgrade: + - | + Remove features deprecated in 0.45 for `qiskit/extensions`: + + * `exceptions`, No alternative will be provided + * `squ`, Instead, use QuantumCircuit unitary + * `snapshot`, + + The Snapshot instruction has been superseded by Qiskit Aer's save instructions, + see: https://qiskit.org/ecosystem/aer/apidocs/aer_library.html#saving-simulator-data diff --git a/test/python/circuit/test_circuit_properties.py b/test/python/circuit/test_circuit_properties.py index f2531954676e..78b7c41e1e88 100644 --- a/test/python/circuit/test_circuit_properties.py +++ b/test/python/circuit/test_circuit_properties.py @@ -14,12 +14,12 @@ import unittest import numpy as np +from qiskit_aer.library import SaveState from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, pulse from qiskit.circuit import Clbit from qiskit.circuit.library import RXGate, RYGate from qiskit.test import QiskitTestCase from qiskit.circuit.exceptions import CircuitError -from qiskit.extensions.simulator import Snapshot class TestCircuitProperties(QiskitTestCase): @@ -578,8 +578,8 @@ def test_circuit_depth_snap1(self): circ = QuantumCircuit(q, c) circ.h(0) circ.cx(0, 1) - with self.assertWarns(DeprecationWarning): - circ.append(Snapshot("snap", num_qubits=4), [0, 1, 2, 3]) + circ.append(SaveState(4, "snap"), [0, 1, 2, 3]) + circ.h(2) circ.cx(2, 3) self.assertEqual(circ.depth(), 4) @@ -600,14 +600,11 @@ def test_circuit_depth_snap2(self): c = ClassicalRegister(4, "c") circ = QuantumCircuit(q, c) circ.h(0) - with self.assertWarns(DeprecationWarning): - circ.append(Snapshot("snap0", num_qubits=4), [0, 1, 2, 3]) + circ.append(SaveState(4, "snap0"), [0, 1, 2, 3]) circ.cx(0, 1) - with self.assertWarns(DeprecationWarning): - circ.append(Snapshot("snap1", num_qubits=4), [0, 1, 2, 3]) + circ.append(SaveState(4, "snap1"), [0, 1, 2, 3]) circ.h(2) - with self.assertWarns(DeprecationWarning): - circ.append(Snapshot("snap2", num_qubits=4), [0, 1, 2, 3]) + circ.append(SaveState(4, "snap3"), [0, 1, 2, 3]) circ.cx(2, 3) self.assertEqual(circ.depth(), 4) @@ -628,9 +625,8 @@ def test_circuit_depth_snap3(self): circ = QuantumCircuit(q, c) circ.h(0) circ.cx(0, 1) - with self.assertWarns(DeprecationWarning): - circ.append(Snapshot("snap0", num_qubits=4), [0, 1, 2, 3]) - circ.append(Snapshot("snap1", num_qubits=4), [0, 1, 2, 3]) + circ.append(SaveState(4, "snap0"), [0, 1, 2, 3]) + circ.append(SaveState(4, "snap1"), [0, 1, 2, 3]) circ.h(2) circ.cx(2, 3) self.assertEqual(circ.depth(), 4) @@ -756,8 +752,7 @@ def test_circuit_size_ignores_barriers_snapshots(self): self.assertEqual(qc.size(), 2) qc.barrier(q) self.assertEqual(qc.size(), 2) - with self.assertWarns(DeprecationWarning): - qc.append(Snapshot("snapshot_label", num_qubits=4), [0, 1, 2, 3]) + qc.append(SaveState(4, "snapshot_label"), [0, 1, 2, 3]) self.assertEqual(qc.size(), 2) def test_circuit_count_ops(self): diff --git a/test/python/transpiler/test_unroller.py b/test/python/transpiler/test_unroller.py index a69d7667ef2b..1f5ca078cf73 100644 --- a/test/python/transpiler/test_unroller.py +++ b/test/python/transpiler/test_unroller.py @@ -15,8 +15,8 @@ from numpy import pi +from qiskit_aer.library import SaveState from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit -from qiskit.extensions.simulator import Snapshot from qiskit.transpiler.passes import Unroller from qiskit.converters import circuit_to_dag, dag_to_circuit from qiskit.quantum_info import Operator @@ -777,8 +777,7 @@ def test_unroll_z(self): def test_unroll_snapshot(self): """test unroll snapshot""" num_qubits = self.circuit.num_qubits - with self.assertWarns(DeprecationWarning): - instr = Snapshot("0", num_qubits=num_qubits) + instr = SaveState(num_qubits, "0") self.circuit.append(instr, range(num_qubits)) self.ref_circuit.append(instr, range(num_qubits)) self.compare_dags()