qiboteam / qibo

A full-stack framework for quantum computing.
https://qibo.science
Apache License 2.0
294 stars 60 forks source link

Testing different backends #1374

Open stavros11 opened 4 months ago

stavros11 commented 4 months ago

Currently some tests are executing circuits using the circuit.execute()/circuit() interface, instead of backend.execute_circuit. This invokes the GlobalBackend which is set to an arbitrary value, potentially from a previous test, unless set_backend is used. More details in https://github.com/qiboteam/qibo/pull/1272#discussion_r1655006022.

A potential solution is to never use circuit() in tests and replace by backend.execute_circuit, except from very few tests that test the circuit() interface itself.

Another solution is to switch the global backend within the backend fixture, using for example something like

@pytest.fixture
def backend(backend_name):
    original_backend = qibo.get_backend()
    qibo.set_backend(backend_name)
    yield
    qibo.set_backend(original_backend)

List of tests that execute circuits using the circuit.execute interface (which invokes the GlobalBackend()), found by inserting an assert False in circuit.execute: