Skip to content

Commit

Permalink
fix: failed importlib import (#254)
Browse files Browse the repository at this point in the history
For some reason this failed in python310 with error
```
AttributeError: module 'importlib' has no attribute 'resources'
```

This fix _seems_ to work, although I'm not sure why it didn't work on
the first place...
  • Loading branch information
aborgna-q authored Nov 21, 2023
1 parent 97e2e0a commit b077660
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions tket2-py/tket2/passes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path
from typing import Optional
import importlib
from importlib import resources

from pytket import Circuit
from pytket.passes import CustomPass
Expand Down Expand Up @@ -33,7 +33,7 @@ def badger_pass(
The arguments `max_threads`, `timeout`, `log_dir` and `rebase` are optional
and will be passed on to the Badger optimiser if provided."""
if rewriter is None:
rewriter = Path(importlib.resources.files("tket2").joinpath("data/nam_6_3.rwr"))
rewriter = Path(resources.files("tket2").joinpath("data/nam_6_3.rwr"))
opt = optimiser.BadgerOptimiser.load_precompiled(rewriter)

def apply(circuit: Circuit) -> Circuit:
Expand Down
4 changes: 2 additions & 2 deletions tket2-py/tket2/rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .tket2 import _rewrite

from pathlib import Path
import importlib
from importlib import resources

__all__ = [
"default_ecc_rewriter",
Expand All @@ -14,5 +14,5 @@
def default_ecc_rewriter() -> _rewrite.ECCRewriter:
"""Load the default ecc rewriter."""
# TODO: Cite, explain what this is
rewriter = Path(importlib.resources.files("tket2").joinpath("data/nam_6_3.rwr"))
rewriter = Path(resources.files("tket2").joinpath("data/nam_6_3.rwr"))
return _rewrite.ECCRewriter.load_precompiled(rewriter)

0 comments on commit b077660

Please sign in to comment.