Repository: Qiskit/qiskit

Issue:
TranspilerAccessError should be deprecated in favor of TranspilerError
Following the suggestion in https://github.com/Qiskit/qiskit-terra/issues/601#issuecomment-471257119


Discussion:

Resolving patch:
diff --git a/qiskit/transpiler/exceptions.py b/qiskit/transpiler/exceptions.py
--- 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
--- 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 @@ def __setitem__(self, key, value):
     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):


Test patch:
diff --git a/test/python/transpiler/test_pass_scheduler.py b/test/python/transpiler/test_pass_scheduler.py
--- a/test/python/transpiler/test_pass_scheduler.py
+++ b/test/python/transpiler/test_pass_scheduler.py
@@ -22,7 +22,7 @@
 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 @@ def test_fenced_property_set(self):
         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 @@ def test_fenced_dag(self):
         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."""