Skip to content

Commit

Permalink
test: Design a test to load a backend without Qibojit
Browse files Browse the repository at this point in the history
Since qibojit is always installed in the CI, we have to temporarily
remove it manually, and restore after the test.
  • Loading branch information
alecandido committed Aug 21, 2024
1 parent 386fe25 commit 01bcd4f
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion tests/test_backends.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import importlib
import platform
import shutil
import sys
from pathlib import Path
from tempfile import TemporaryDirectory

import numpy as np
import pytest
import qibojit

from qibo import construct_backend, gates, list_available_backends, set_backend
from qibo.backends import MetaBackend
from qibo.backends import GlobalBackend, MetaBackend, get_backend

####################### Test `matrix` #######################
GATES = [
Expand Down Expand Up @@ -112,6 +117,28 @@ def test_construct_backend(backend):
)


@pytest.fixture
def uninstall_qibojit():
p = Path(qibojit.__file__).parent
modules = list(sys.modules.keys())
for mod in modules:
if mod.startswith("qibojit"):
del sys.modules[mod]
with TemporaryDirectory() as tdir:
shutil.move(p, tdir)
yield
shutil.move(Path(tdir) / p.name, p)
importlib.import_module("qibojit")


def test_default_backend(uninstall_qibojit):
"""Reproducing https://github.com/qiboteam/qibo/issues/1424."""
# reset global backend
GlobalBackend._instance = None
# attempt loading
default_backend = get_backend()


def test_list_available_backends():
tensorflow = False if platform.system() == "Windows" else True
qulacs = (
Expand Down

0 comments on commit 01bcd4f

Please sign in to comment.