Skip to content

Commit

Permalink
Fix tweedledum runtime detection in BooleanExpression.from_dimacs_file (
Browse files Browse the repository at this point in the history
#10132) (#10137)

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.

(cherry picked from commit 9f647c7)

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
  • Loading branch information
mergify[bot] and mtreinish authored May 22, 2023
1 parent c896ebf commit ab40959
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions qiskit/circuit/classicalfunction/boolean_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/Qiskit/qiskit-terra/issues/10079>`__

0 comments on commit ab40959

Please sign in to comment.