mirror of https://github.com/Qiskit/qiskit.git
TranspilerAccessError is deprecated in favor of TranspilerError (#3222)
* deprecated TranspilerAccessError in favour of TranspilerError * changed version for deprecation * fixed linting errors * fixed unused import * added changelog and fixed deprecation
This commit is contained in:
parent
77662d1e7a
commit
1e3c165611
|
@ -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."""
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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.
|
|
@ -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."""
|
||||
|
|
Loading…
Reference in New Issue