From b0442b2c9d0261cca223284f72edfc1136b9a659 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Fri, 19 May 2023 17:39:58 -0400 Subject: [PATCH] Fix tweedledum runtime detection in BooleanExpression.from_dimacs_file This commit fixes an oversight in the 0.24.0 release that caused an accidental change in the exception raised when attempting to use BooleanExpression.from_dimacs_file without having tweedledum installed. In #9754 the detection of tweedledum was updated to avoid import time detection so that the module can be imported even if tweedledum isn't installed. This was done through the use of the optionals decorators so that tweedledum is only attempted to be imported when the classicalfunction modules is used. However, the decorators don't wrap classmethod constructors by default and this caused the incorrect exception type to be raised. This commit fixes this by doing the runtime checking manually inside the from_dimacs_file constructor. --- qiskit/circuit/classicalfunction/boolean_expression.py | 1 + .../fix-exception-from_dimacs_file-b9338f3c913a9bff.yaml | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 releasenotes/notes/fix-exception-from_dimacs_file-b9338f3c913a9bff.yaml diff --git a/qiskit/circuit/classicalfunction/boolean_expression.py b/qiskit/circuit/classicalfunction/boolean_expression.py index 1ed820058b18..0f4a53494af4 100644 --- a/qiskit/circuit/classicalfunction/boolean_expression.py +++ b/qiskit/circuit/classicalfunction/boolean_expression.py @@ -110,6 +110,7 @@ def from_dimacs_file(cls, filename: str): Raises: FileNotFoundError: If filename is not found. """ + HAS_TWEEDLEDUM.require_now("BooleanExpression") from tweedledum import BoolFunction # pylint: disable=import-error diff --git a/releasenotes/notes/fix-exception-from_dimacs_file-b9338f3c913a9bff.yaml b/releasenotes/notes/fix-exception-from_dimacs_file-b9338f3c913a9bff.yaml new file mode 100644 index 000000000000..b7f2d34d5cda --- /dev/null +++ b/releasenotes/notes/fix-exception-from_dimacs_file-b9338f3c913a9bff.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + Fixed an issue with the :meth:`.BooleanExpression.from_dimacs_file` + constructor method where the exception type raised when tweedledum wasn't + installed was not the expected :class:`~.MissingOptionalLibrary`. + Fixed `#10079 `__