diff --git a/qiskit/transpiler/exceptions.py b/qiskit/transpiler/exceptions.py index 53dc051e1c..f170985d5b 100644 --- a/qiskit/transpiler/exceptions.py +++ b/qiskit/transpiler/exceptions.py @@ -15,16 +15,25 @@ """ Exception for errors raised by the transpiler. """ +import warnings from qiskit.exceptions import QiskitError -class TranspilerError(QiskitError): - """Exceptions raised during transpilation""" - - class TranspilerAccessError(QiskitError): """Exception of access error in the transpiler passes.""" + def __init__(self, *message): + """Set the error message.""" + super().__init__(' '.join(message)) + warnings.warn('The exception TranspilerAccessError is deprecated as of 0.11.0 ' + 'and will be removed no earlier than 3 months after that release ' + 'date. You should use the exception TranspilerError instead.', + DeprecationWarning, stacklevel=2) + + +class TranspilerError(TranspilerAccessError): + """Exceptions raised during transpilation.""" + class CouplingError(QiskitError): """Base class for errors raised by the coupling graph object.""" diff --git a/qiskit/transpiler/fencedobjs.py b/qiskit/transpiler/fencedobjs.py index f2c9952529..ecea347b50 100644 --- a/qiskit/transpiler/fencedobjs.py +++ b/qiskit/transpiler/fencedobjs.py @@ -12,13 +12,13 @@ # copyright notice, and modified files need to carry a notice indicating # that they have been altered from the originals. -""" Fenced objects are wraps for raising TranspilerAccessError when they are modified.""" +""" Fenced objects are wraps for raising TranspilerError when they are modified.""" -from .exceptions import TranspilerAccessError +from .exceptions import TranspilerError class FencedObject(): - """ Given an instance and a list of attributes to fence, raises a TranspilerAccessError when one + """ Given an instance and a list of attributes to fence, raises a TranspilerError when one of these attributes is accessed.""" def __init__(self, instance, attributes_to_fence): @@ -40,17 +40,17 @@ class FencedObject(): def _check_if_fenced(self, name): """ Checks if the attribute name is in the list of attributes to protect. If so, raises - TranspilerAccessError. + TranspilerError. Args: name (string): the attribute name to check Raises: - TranspilerAccessError: when name is the list of attributes to protect. + TranspilerError: when name is the list of attributes to protect. """ if name in object.__getattribute__(self, '_attributes_to_fence'): - raise TranspilerAccessError("The fenced %s has the property %s protected" % - (type(object.__getattribute__(self, '_wrapped')), name)) + raise TranspilerError("The fenced %s has the property %s protected" % + (type(object.__getattribute__(self, '_wrapped')), name)) class FencedPropertySet(FencedObject): diff --git a/releasenotes/notes/remove-TranspilerAccessError-af8b91abfb7ba920.yaml b/releasenotes/notes/remove-TranspilerAccessError-af8b91abfb7ba920.yaml new file mode 100644 index 0000000000..22b0e79271 --- /dev/null +++ b/releasenotes/notes/remove-TranspilerAccessError-af8b91abfb7ba920.yaml @@ -0,0 +1,7 @@ +--- +deprecations: + - | + The Exception ``TranspilerAccessError´´ has been deprecated. An + alternative function ``TranspilerError´´ can be used instead to provide + the same functionality. This alternative function provides the exact same + functionality but with greater generality. \ No newline at end of file diff --git a/test/python/transpiler/test_pass_scheduler.py b/test/python/transpiler/test_pass_scheduler.py index dc79a12f14..a49650b577 100644 --- a/test/python/transpiler/test_pass_scheduler.py +++ b/test/python/transpiler/test_pass_scheduler.py @@ -22,7 +22,7 @@ import unittest.mock import sys from qiskit import QuantumRegister, QuantumCircuit -from qiskit.transpiler import PassManager, TranspilerAccessError, TranspilerError +from qiskit.transpiler import PassManager, TranspilerError from qiskit.compiler import transpile from qiskit.transpiler.runningpassmanager import DoWhileController, ConditionalController, \ FlowController @@ -282,7 +282,7 @@ class TestUseCases(SchedulerTestCase): self.passmanager.append(PassH_Bad_TP()) self.assertSchedulerRaises(self.circuit, self.passmanager, ['run transformation pass PassH_Bad_TP'], - TranspilerAccessError) + TranspilerError) def test_fenced_dag(self): """Analysis passes are not allowed to modified the DAG.""" @@ -297,7 +297,7 @@ class TestUseCases(SchedulerTestCase): self.assertSchedulerRaises(circ, self.passmanager, ['run analysis pass PassI_Bad_AP', 'cx_runs: {(5, 6, 7, 8)}'], - TranspilerAccessError) + TranspilerError) def test_analysis_pass_is_idempotent(self): """Analysis passes are idempotent."""