Skip to content

Commit

Permalink
Update fake backend and fake provider to use versioned interface (#6286)
Browse files Browse the repository at this point in the history
* Update fake backend and fake provider to use versioned interface

As was reported in #6280 the algorithms path doesn't work on minimal
examples of the Backend and Jobs interface and instead only works in
practice on ibmq, aer, or basic aer backends. Part of the reason for
this was that all the testing of algorithms is done exclusively on those
providers and there wasn't a minimal example to test against that
doesn't have legacy overhead (like qobj, etc). This commit updates the
fake providers and fake backends to use the latest version of the
provider, backend, and job interfaces and to be strictly compatible (ie
no qobj support). Besides exercising the new interface version it also
enables us to test the eventual fix for #6280 when it's available.

* Fix lint

* Add legacy fake backends using BaseBackend
  • Loading branch information
mtreinish authored Apr 29, 2021
1 parent dd718f9 commit 6f9784c
Show file tree
Hide file tree
Showing 77 changed files with 1,135 additions and 135 deletions.
6 changes: 3 additions & 3 deletions qiskit/test/mock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
The mock devices are mainly for testing the compiler.
"""

from .fake_provider import FakeProvider
from .fake_provider import FakeProvider, FakeLegacyProvider
from .fake_provider import FakeProviderFactory
from .fake_backend import FakeBackend
from .fake_job import FakeJob
from .fake_backend import FakeBackend, FakeLegacyBackend
from .fake_job import FakeJob, FakeLegacyJob
from .fake_qobj import FakeQobj

from .backends import *
Expand Down
36 changes: 36 additions & 0 deletions qiskit/test/mock/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
Mocked versions of real quantum backends.
"""

# BackendV1 Backends
from .almaden import FakeAlmaden
from .armonk import FakeArmonk
from .athens import FakeAthens
Expand Down Expand Up @@ -50,3 +51,38 @@
from .valencia import FakeValencia
from .vigo import FakeVigo
from .yorktown import FakeYorktown
# Legacy Backends
from .almaden import FakeLegacyAlmaden
from .armonk import FakeLegacyArmonk
from .athens import FakeLegacyAthens
from .belem import FakeLegacyBelem
from .boeblingen import FakeLegacyBoeblingen
from .bogota import FakeLegacyBogota
from .burlington import FakeLegacyBurlington
from .cambridge import FakeLegacyCambridge
from .cambridge import FakeLegacyCambridgeAlternativeBasis
from .casablanca import FakeLegacyCasablanca
from .essex import FakeLegacyEssex
from .johannesburg import FakeLegacyJohannesburg
from .lima import FakeLegacyLima
from .london import FakeLegacyLondon
from .manhattan import FakeLegacyManhattan
from .melbourne import FakeLegacyMelbourne
from .montreal import FakeLegacyMontreal
from .mumbai import FakeLegacyMumbai
from .ourense import FakeLegacyOurense
from .paris import FakeLegacyParis
from .poughkeepsie import FakeLegacyPoughkeepsie
from .quito import FakeLegacyQuito
from .rochester import FakeLegacyRochester
from .rome import FakeLegacyRome
from .rueschlikon import FakeLegacyRueschlikon
from .santiago import FakeLegacySantiago
from .singapore import FakeLegacySingapore
from .sydney import FakeLegacySydney
from .tenerife import FakeLegacyTenerife
from .tokyo import FakeLegacyTokyo
from .toronto import FakeLegacyToronto
from .valencia import FakeLegacyValencia
from .vigo import FakeLegacyVigo
from .yorktown import FakeLegacyYorktown
1 change: 1 addition & 0 deletions qiskit/test/mock/backends/almaden/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
"""Mock almaden backend"""

from .fake_almaden import FakeAlmaden
from .fake_almaden import FakeLegacyAlmaden
23 changes: 21 additions & 2 deletions qiskit/test/mock/backends/almaden/fake_almaden.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,29 @@
"""

import os
from qiskit.test.mock.fake_pulse_backend import FakePulseBackend
from qiskit.test.mock import fake_pulse_backend


class FakeAlmaden(FakePulseBackend):
class FakeAlmaden(fake_pulse_backend.FakePulseBackend):
"""A fake Almaden backend.
00 ↔ 01 ↔ 02 ↔ 03 ↔ 04
↕ ↕
05 ↔ 06 ↔ 07 ↔ 08 ↔ 09
↕ ↕ ↕
10 ↔ 11 ↔ 12 ↔ 13 ↔ 14
↕ ↕
15 ↔ 16 ↔ 17 ↔ 18 ↔ 19
"""

dirname = os.path.dirname(__file__)
conf_filename = "conf_almaden.json"
props_filename = "props_almaden.json"
defs_filename = "defs_almaden.json"
backend_name = "fake_almaden"


class FakeLegacyAlmaden(fake_pulse_backend.FakePulseLegacyBackend):
"""A fake Almaden backend.
00 ↔ 01 ↔ 02 ↔ 03 ↔ 04
Expand Down
1 change: 1 addition & 0 deletions qiskit/test/mock/backends/armonk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
"""Mock armonk backend"""

from .fake_armonk import FakeArmonk
from .fake_armonk import FakeLegacyArmonk
17 changes: 15 additions & 2 deletions qiskit/test/mock/backends/armonk/fake_armonk.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,23 @@
"""

import os
from qiskit.test.mock.fake_pulse_backend import FakePulseBackend
from qiskit.test.mock import fake_pulse_backend


class FakeArmonk(FakePulseBackend):
class FakeArmonk(fake_pulse_backend.FakePulseBackend):
"""A fake 1 qubit backend.
0
"""

dirname = os.path.dirname(__file__)
conf_filename = "conf_armonk.json"
props_filename = "props_armonk.json"
defs_filename = "defs_armonk.json"
backend_name = "fake_armonk"


class FakeLegacyArmonk(fake_pulse_backend.FakePulseLegacyBackend):
"""A fake 1 qubit backend.
0
Expand Down
1 change: 1 addition & 0 deletions qiskit/test/mock/backends/athens/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
"""Mock athens backend"""

from .fake_athens import FakeAthens
from .fake_athens import FakeLegacyAthens
14 changes: 12 additions & 2 deletions qiskit/test/mock/backends/athens/fake_athens.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@
"""

import os
from qiskit.test.mock.fake_pulse_backend import FakePulseBackend
from qiskit.test.mock import fake_pulse_backend


class FakeAthens(FakePulseBackend):
class FakeAthens(fake_pulse_backend.FakePulseBackend):
"""A fake 5 qubit backend."""

dirname = os.path.dirname(__file__)
conf_filename = "conf_athens.json"
props_filename = "props_athens.json"
defs_filename = "defs_athens.json"
backend_name = "fake_athens"


class FakeLegacyAthens(fake_pulse_backend.FakePulseLegacyBackend):
"""A fake 5 qubit backend."""

dirname = os.path.dirname(__file__)
Expand Down
1 change: 1 addition & 0 deletions qiskit/test/mock/backends/belem/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
"""Mock belem backend"""

from .fake_belem import FakeBelem
from .fake_belem import FakeLegacyBelem
14 changes: 12 additions & 2 deletions qiskit/test/mock/backends/belem/fake_belem.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@
"""

import os
from qiskit.test.mock.fake_pulse_backend import FakePulseBackend
from qiskit.test.mock import fake_pulse_backend


class FakeBelem(FakePulseBackend):
class FakeBelem(fake_pulse_backend.FakePulseBackend):
"""A fake 5 qubit backend."""

dirname = os.path.dirname(__file__)
conf_filename = "conf_belem.json"
props_filename = "props_belem.json"
defs_filename = "defs_belem.json"
backend_name = "fake_belem"


class FakeLegacyBelem(fake_pulse_backend.FakePulseLegacyBackend):
"""A fake 5 qubit backend."""

dirname = os.path.dirname(__file__)
Expand Down
1 change: 1 addition & 0 deletions qiskit/test/mock/backends/boeblingen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
"""Mock boeblingen backend"""

from .fake_boeblingen import FakeBoeblingen
from .fake_boeblingen import FakeLegacyBoeblingen
23 changes: 21 additions & 2 deletions qiskit/test/mock/backends/boeblingen/fake_boeblingen.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,29 @@
"""

import os
from qiskit.test.mock.fake_pulse_backend import FakePulseBackend
from qiskit.test.mock import fake_pulse_backend


class FakeBoeblingen(FakePulseBackend):
class FakeBoeblingen(fake_pulse_backend.FakePulseBackend):
"""A fake Boeblingen backend.
00 ↔ 01 ↔ 02 ↔ 03 ↔ 04
↕ ↕
05 ↔ 06 ↔ 07 ↔ 08 ↔ 09
↕ ↕ ↕
10 ↔ 11 ↔ 12 ↔ 13 ↔ 14
↕ ↕
15 ↔ 16 ↔ 17 ↔ 18 ↔ 19
"""

dirname = os.path.dirname(__file__)
conf_filename = "conf_boeblingen.json"
props_filename = "props_boeblingen.json"
defs_filename = "defs_boeblingen.json"
backend_name = "fake_boeblingen"


class FakeLegacyBoeblingen(fake_pulse_backend.FakePulseLegacyBackend):
"""A fake Boeblingen backend.
00 ↔ 01 ↔ 02 ↔ 03 ↔ 04
Expand Down
1 change: 1 addition & 0 deletions qiskit/test/mock/backends/bogota/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
"""Mock bogota backend"""

from .fake_bogota import FakeBogota
from .fake_bogota import FakeLegacyBogota
40 changes: 15 additions & 25 deletions qiskit/test/mock/backends/bogota/fake_bogota.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,23 @@
"""

import os
import json

from qiskit.providers.models import QasmBackendConfiguration, BackendProperties
from qiskit.test.mock.fake_backend import FakeBackend
from qiskit.test.mock import fake_qasm_backend


class FakeBogota(FakeBackend):
class FakeBogota(fake_qasm_backend.FakeQasmBackend):
"""A fake 5 qubit backend."""

def __init__(self):
dirname = os.path.dirname(__file__)
filename = "conf_bogota.json"
with open(os.path.join(dirname, filename)) as f_conf:
conf = json.load(f_conf)

configuration = QasmBackendConfiguration.from_dict(conf)
configuration.backend_name = 'fake_bogota'
self._defaults = None
self._properties = None
super().__init__(configuration)

def properties(self):
"""Returns a snapshot of device properties"""
if not self._properties:
dirname = os.path.dirname(__file__)
filename = "props_bogota.json"
with open(os.path.join(dirname, filename)) as f_prop:
props = json.load(f_prop)
self._properties = BackendProperties.from_dict(props)
return self._properties
dirname = os.path.dirname(__file__)
conf_filename = "conf_bogota.json"
props_filename = "props_bogota.json"
backend_name = "fake_bogota"


class FakeLegacyBogota(fake_qasm_backend.FakeQasmLegacyBackend):
"""A fake 5 qubit backend."""

dirname = os.path.dirname(__file__)
conf_filename = "conf_bogota.json"
props_filename = "props_bogota.json"
backend_name = "fake_bogota"
1 change: 1 addition & 0 deletions qiskit/test/mock/backends/burlington/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
"""Mock burlington backend"""

from .fake_burlington import FakeBurlington
from .fake_burlington import FakeLegacyBurlington
18 changes: 16 additions & 2 deletions qiskit/test/mock/backends/burlington/fake_burlington.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,24 @@
"""

import os
from qiskit.test.mock.fake_qasm_backend import FakeQasmBackend
from qiskit.test.mock import fake_qasm_backend


class FakeBurlington(FakeQasmBackend):
class FakeBurlington(fake_qasm_backend.FakeQasmBackend):
"""A fake 5 qubit backend.
0 ↔ 1 ↔ 3 ↔ 4
2
"""

dirname = os.path.dirname(__file__)
conf_filename = "conf_burlington.json"
props_filename = "props_burlington.json"
backend_name = "fake_burlington"


class FakeLegacyBurlington(fake_qasm_backend.FakeQasmLegacyBackend):
"""A fake 5 qubit backend.
0 ↔ 1 ↔ 3 ↔ 4
Expand Down
2 changes: 2 additions & 0 deletions qiskit/test/mock/backends/cambridge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@

from .fake_cambridge import FakeCambridge
from .fake_cambridge import FakeCambridgeAlternativeBasis
from .fake_cambridge import FakeLegacyCambridge
from .fake_cambridge import FakeLegacyCambridgeAlternativeBasis
34 changes: 32 additions & 2 deletions qiskit/test/mock/backends/cambridge/fake_cambridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"""

import os
from qiskit.test.mock.fake_qasm_backend import FakeQasmBackend
from qiskit.test.mock import fake_qasm_backend


class FakeCambridge(FakeQasmBackend):
class FakeCambridge(fake_qasm_backend.FakeQasmBackend):
"""A fake Cambridge backend.
00 ↔ 01 ↔ 02 ↔ 03 ↔ 04
Expand Down Expand Up @@ -46,3 +46,33 @@ class FakeCambridgeAlternativeBasis(FakeCambridge):
def __init__(self):
super().__init__()
self._configuration.basis_gates = ['u', 'sx', 'p', 'cx', 'id']


class FakeLegacyCambridge(fake_qasm_backend.FakeQasmLegacyBackend):
"""A fake Cambridge backend.
00 ↔ 01 ↔ 02 ↔ 03 ↔ 04
↕ ↕
05 06
↕ ↕
07 ↔ 08 ↔ 09 ↔ 10 ↔ 11 ↔ 12 ↔ 13 ↔ 14 ↔ 15
↕ ↕ ↕
16 17 18
↕ ↕ ↕
19 ↔ 20 ↔ 21 ↔ 22 ↔ 23 ↔ 24 ↔ 25 ↔ 26 ↔ 27
"""

dirname = os.path.dirname(__file__)
conf_filename = "conf_cambridge.json"
props_filename = "props_cambridge.json"
backend_name = "fake_cambridge"


class FakeLegacyCambridgeAlternativeBasis(FakeLegacyCambridge):
"""A fake Cambridge backend with alternate 1q basis gates."""

props_filename = "props_cambridge_alt.json"

def __init__(self):
super().__init__()
self._configuration.basis_gates = ['u', 'sx', 'p', 'cx', 'id']
1 change: 1 addition & 0 deletions qiskit/test/mock/backends/casablanca/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
"""Mock casablanca backend"""

from .fake_casablanca import FakeCasablanca
from .fake_casablanca import FakeLegacyCasablanca
14 changes: 12 additions & 2 deletions qiskit/test/mock/backends/casablanca/fake_casablanca.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,20 @@
"""

import os
from qiskit.test.mock.fake_pulse_backend import FakePulseBackend
from qiskit.test.mock import fake_pulse_backend


class FakeCasablanca(FakePulseBackend):
class FakeCasablanca(fake_pulse_backend.FakePulseBackend):
"""A fake 7 qubit backend."""

dirname = os.path.dirname(__file__)
conf_filename = "conf_casablanca.json"
props_filename = "props_casablanca.json"
defs_filename = "defs_casablanca.json"
backend_name = "fake_casablanca"


class FakeLegacyCasablanca(fake_pulse_backend.FakePulseLegacyBackend):
"""A fake 7 qubit backend."""

dirname = os.path.dirname(__file__)
Expand Down
1 change: 1 addition & 0 deletions qiskit/test/mock/backends/essex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
"""Mock essex backend"""

from .fake_essex import FakeEssex
from .fake_essex import FakeLegacyEssex
Loading

0 comments on commit 6f9784c

Please sign in to comment.