From be9b0da397d3a800a8996697710bb2cd399a361e Mon Sep 17 00:00:00 2001 From: Ali Javadi-Abhari Date: Wed, 28 Aug 2019 08:35:57 -0400 Subject: [PATCH] Split mock backends and add new ones (#3050) * split files for backend mock utilities * fix coupling maps of new devices * copyright year * fake qobj docstring * graphs with direction * ourense * FakePoughkeepsie * asciiart --- qiskit/test/mock.py | 519 ----------------------- qiskit/test/mock/__init__.py | 43 ++ qiskit/test/mock/fake_backend.py | 112 +++++ qiskit/test/mock/fake_boeblingen.py | 60 +++ qiskit/test/mock/fake_job.py | 86 ++++ qiskit/test/mock/fake_melbourne.py | 51 +++ qiskit/test/mock/fake_openpulse_2q.py | 101 +++++ qiskit/test/mock/fake_ourense.py | 49 +++ qiskit/test/mock/fake_poughkeepsie.py | 58 +++ qiskit/test/mock/fake_provider.py | 71 ++++ qiskit/test/mock/fake_qasm_simulator.py | 44 ++ qiskit/test/mock/fake_qobj.py | 39 ++ qiskit/test/mock/fake_rueschlikon.py | 52 +++ qiskit/test/mock/fake_tenerife.py | 51 +++ qiskit/test/mock/fake_tokyo.py | 64 +++ qiskit/test/mock/fake_valencia.py | 49 +++ qiskit/test/mock/fake_vigo.py | 49 +++ qiskit/test/mock/fake_yorktown.py | 51 +++ test/python/providers/test_jobmethods.py | 6 +- 19 files changed, 1033 insertions(+), 522 deletions(-) delete mode 100644 qiskit/test/mock.py create mode 100644 qiskit/test/mock/__init__.py create mode 100644 qiskit/test/mock/fake_backend.py create mode 100644 qiskit/test/mock/fake_boeblingen.py create mode 100644 qiskit/test/mock/fake_job.py create mode 100644 qiskit/test/mock/fake_melbourne.py create mode 100644 qiskit/test/mock/fake_openpulse_2q.py create mode 100644 qiskit/test/mock/fake_ourense.py create mode 100644 qiskit/test/mock/fake_poughkeepsie.py create mode 100644 qiskit/test/mock/fake_provider.py create mode 100644 qiskit/test/mock/fake_qasm_simulator.py create mode 100644 qiskit/test/mock/fake_qobj.py create mode 100644 qiskit/test/mock/fake_rueschlikon.py create mode 100644 qiskit/test/mock/fake_tenerife.py create mode 100644 qiskit/test/mock/fake_tokyo.py create mode 100644 qiskit/test/mock/fake_valencia.py create mode 100644 qiskit/test/mock/fake_vigo.py create mode 100644 qiskit/test/mock/fake_yorktown.py diff --git a/qiskit/test/mock.py b/qiskit/test/mock.py deleted file mode 100644 index 6a895c5eb5..0000000000 --- a/qiskit/test/mock.py +++ /dev/null @@ -1,519 +0,0 @@ -# -*- coding: utf-8 -*- - -# This code is part of Qiskit. -# -# (C) Copyright IBM 2017, 2018. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. - -# pylint: disable=missing-docstring - -""" -Utilities for mocking the IBMQ provider, including job responses and backends. - -The module includes dummy provider, backends, and jobs. The purpose of -these classes is to trick backends for testing purposes: -testing local timeouts, arbitrary responses or behavior, etc. - -The mock devices are mainly for testing the compiler. -""" - -import uuid -from concurrent import futures -import time - -from qiskit.result import Result -from qiskit.providers import BaseBackend, BaseJob -from qiskit.providers.models import (BackendProperties, GateConfig, - QasmBackendConfiguration, PulseBackendConfiguration, - PulseDefaults, Command, UchannelLO) -from qiskit.qobj import (QasmQobj, QobjExperimentHeader, QobjHeader, - QasmQobjInstruction, QasmQobjExperimentConfig, - QasmQobjExperiment, QasmQobjConfig, PulseLibraryItem, - PulseQobjInstruction) -from qiskit.providers.jobstatus import JobStatus -from qiskit.providers.baseprovider import BaseProvider -from qiskit.providers.exceptions import QiskitBackendNotFoundError - - -class FakeProvider(BaseProvider): - """Dummy provider just for testing purposes. - - Only filtering backends by name is implemented. - """ - - def get_backend(self, name=None, **kwargs): - backend = self._backends[0] - if name: - filtered_backends = [backend for backend in self._backends - if backend.name() == name] - if not filtered_backends: - raise QiskitBackendNotFoundError() - - backend = filtered_backends[0] - - return backend - - def backends(self, name=None, **kwargs): - return self._backends - - def __init__(self): - self._backends = [FakeQasmSimulator(), - FakeTenerife(), - FakeMelbourne(), - FakeRueschlikon(), - FakeTokyo(), - FakeOpenPulse2Q()] - super().__init__() - - -class FakeBackend(BaseBackend): - """This is a dummy backend just for testing purposes.""" - - def __init__(self, configuration, time_alive=10): - """ - Args: - configuration (BackendConfiguration): backend configuration - time_alive (int): time to wait before returning result - """ - super().__init__(configuration) - self.time_alive = time_alive - - def properties(self): - """Return backend properties""" - - coupling_map = self.configuration().coupling_map - unique_qubits = list(set().union(*coupling_map)) - - properties = { - 'backend_name': self.name(), - 'backend_version': self.configuration().backend_version, - 'last_update_date': '2000-01-01 00:00:00Z', - 'qubits': [ - [ - { - "date": "2000-01-01 00:00:00Z", - "name": "T1", - "unit": "\u00b5s", - "value": 0.0 - }, - { - "date": "2000-01-01 00:00:00Z", - "name": "T2", - "unit": "\u00b5s", - "value": 0.0 - }, - { - "date": "2000-01-01 00:00:00Z", - "name": "frequency", - "unit": "GHz", - "value": 0.0 - }, - { - "date": "2000-01-01 00:00:00Z", - "name": "readout_error", - "unit": "", - "value": 0.0 - } - ] for _ in range(len(unique_qubits)) - ], - 'gates': [{ - "gate": "cx", - "name": "CX" + str(pair[0]) + "_" + str(pair[1]), - "parameters": [ - { - "date": "2000-01-01 00:00:00Z", - "name": "gate_error", - "unit": "", - "value": 0.0 - } - ], - "qubits": [ - pair[0], - pair[1] - ] - } for pair in coupling_map], - 'general': [] - } - - return BackendProperties.from_dict(properties) - - def run(self, qobj): - job_id = str(uuid.uuid4()) - job = FakeJob(self, job_id, self.run_job, qobj) - job.submit() - return job - - def run_job(self, job_id, qobj): - """Main dummy run loop""" - del qobj # unused - time.sleep(self.time_alive) - - return Result.from_dict( - {'job_id': job_id, 'result': [], 'status': 'COMPLETED'}) - - -class FakeQasmSimulator(FakeBackend): - """A fake simulator backend.""" - - def __init__(self): - configuration = QasmBackendConfiguration( - backend_name='fake_qasm_simulator', - backend_version='0.0.0', - n_qubits=5, - basis_gates=['u1', 'u2', 'u3', 'cx', 'cz', 'id', 'x', 'y', 'z', - 'h', 's', 'sdg', 't', 'tdg', 'ccx', 'swap', - 'snapshot', 'unitary'], - coupling_map=None, - simulator=True, - local=True, - conditional=True, - open_pulse=False, - memory=True, - max_shots=65536, - gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')] - ) - - super().__init__(configuration) - - -class FakeOpenPulse2Q(FakeBackend): - """A fake 2 qubit backend for pulse test.""" - - def __init__(self): - configuration = PulseBackendConfiguration( - backend_name='fake_openpulse_2q', - backend_version='0.0.0', - n_qubits=2, - meas_levels=[0, 1, 2], - basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], - simulator=False, - local=True, - conditional=True, - open_pulse=True, - memory=False, - max_shots=65536, - gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], - coupling_map=[[1, 0]], - n_registers=2, - n_uchannels=2, - u_channel_lo=[ - [UchannelLO(q=0, scale=1. + 0.j)], - [UchannelLO(q=0, scale=-1. + 0.j), UchannelLO(q=1, scale=1. + 0.j)] - ], - meas_level=[1, 2], - qubit_lo_range=[[4.5, 5.5], [4.5, 5.5]], - meas_lo_range=[[6.0, 7.0], [6.0, 7.0]], - dt=1.3333, - dtm=10.5, - rep_times=[100, 250, 500, 1000], - meas_map=[[0, 1]], - channel_bandwidth=[ - [-0.2, 0.4], [-0.3, 0.3], [-0.3, 0.3], - [-0.02, 0.02], [-0.02, 0.02], [-0.02, 0.02] - ], - meas_kernels=['kernel1'], - discriminators=['max_1Q_fidelity'], - acquisition_latency=[[100, 100], [100, 100]], - conditional_latency=[ - [100, 1000], [1000, 100], [100, 1000], - [1000, 100], [100, 1000], [1000, 100] - ] - ) - - self._defaults = PulseDefaults( - qubit_freq_est=[4.9, 5.0], - meas_freq_est=[6.5, 6.6], - buffer=10, - pulse_library=[PulseLibraryItem(name='test_pulse_1', samples=[0.j, 0.1j]), - PulseLibraryItem(name='test_pulse_2', samples=[0.j, 0.1j, 1j]), - PulseLibraryItem(name='test_pulse_3', - samples=[0.j, 0.1j, 1j, 0.5 + 0j])], - cmd_def=[Command(name='u1', qubits=[0], - sequence=[PulseQobjInstruction(name='fc', ch='d0', - t0=0, phase='-P1*np.pi')]), - Command(name='u3', qubits=[0], - sequence=[PulseQobjInstruction(name='test_pulse_1', ch='d0', t0=0)]), - Command(name='u3', qubits=[1], - sequence=[PulseQobjInstruction(name='test_pulse_3', ch='d1', t0=0)]), - Command(name='cx', qubits=[0, 1], - sequence=[PulseQobjInstruction(name='test_pulse_1', ch='d0', t0=0), - PulseQobjInstruction(name='test_pulse_2', ch='u0', t0=10), - PulseQobjInstruction(name='pv', ch='d1', - t0=2, val='cos(P2)'), - PulseQobjInstruction(name='test_pulse_1', ch='d1', t0=20), - PulseQobjInstruction(name='fc', ch='d1', - t0=20, phase=2.1)]), - Command(name='measure', qubits=[0], - sequence=[PulseQobjInstruction(name='test_pulse_1', ch='m0', t0=0), - PulseQobjInstruction(name='acquire', duration=10, t0=0, - qubits=[0], memory_slot=[0])])] - ) - - super().__init__(configuration) - - def defaults(self): - return self._defaults - - -class FakeTenerife(FakeBackend): - """A fake 5 qubit backend.""" - - def __init__(self): - """ - 1 - / | - 0 - 2 - 3 - | / - 4 - """ - cmap = [[1, 0], [2, 0], [2, 1], [3, 2], [3, 4], [4, 2]] - - configuration = QasmBackendConfiguration( - backend_name='fake_tenerife', - backend_version='0.0.0', - n_qubits=5, - basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], - simulator=False, - local=True, - conditional=False, - open_pulse=False, - memory=False, - max_shots=65536, - gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], - coupling_map=cmap, - ) - - super().__init__(configuration) - - -class FakeMelbourne(FakeBackend): - """A fake 14 qubit backend.""" - - def __init__(self): - """ - 0 - 1 - 2 - 3 - 4 - 5 - 6 - - | | | | | | - - 13 - 12 - 11 - 10 - 9 - 8 - 7 - """ - cmap = [[1, 0], [1, 2], [2, 3], [4, 3], [4, 10], [5, 4], - [5, 6], [5, 9], [6, 8], [7, 8], [9, 8], [9, 10], - [11, 3], [11, 10], [11, 12], [12, 2], [13, 1], [13, 12]] - - configuration = QasmBackendConfiguration( - backend_name='fake_melbourne', - backend_version='0.0.0', - n_qubits=14, - basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], - simulator=False, - local=True, - conditional=False, - open_pulse=False, - memory=False, - max_shots=65536, - gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], - coupling_map=cmap, - ) - - super().__init__(configuration) - - -class FakeRueschlikon(FakeBackend): - """A fake 16 qubit backend.""" - - def __init__(self): - """ - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - - | | | | | | | | - - 0 - 15 - 14 - 13 - 12 - 11 - 10 - 9 - """ - cmap = [[1, 0], [1, 2], [2, 3], [3, 4], [3, 14], [5, 4], [6, 5], - [6, 7], [6, 11], [7, 10], [8, 7], [9, 8], [9, 10], - [11, 10], [12, 5], [12, 11], [12, 13], [13, 4], - [13, 14], [15, 0], [15, 2], [15, 14]] - - configuration = QasmBackendConfiguration( - backend_name='fake_rueschlikon', - backend_version='0.0.0', - n_qubits=16, - basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], - simulator=False, - local=True, - conditional=False, - open_pulse=False, - memory=False, - max_shots=65536, - gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], - coupling_map=cmap, - ) - - super().__init__(configuration) - - -class FakeTokyo(FakeBackend): - """A fake 20 qubit backend.""" - - def __init__(self): - """ - 0 = 1 = 2 = 3 4 - - || || || || X || - - 5 = 6 = 7 = 8 = 9 - - || X || || X || - - 10 = 11 = 12 = 13 = 14 - - || || X || X || - - 15 = 16 = 17 18 19 - """ - cmap = [[0, 1], [0, 5], [1, 0], [1, 2], [1, 6], [2, 1], - [2, 3], [2, 6], [3, 2], [3, 8], [3, 9], [4, 8], [4, 9], - [5, 0], [5, 6], [5, 10], [5, 11], [6, 1], [6, 2], [6, 5], - [6, 7], [6, 10], [6, 11], [7, 1], [7, 6], [7, 8], [7, 12], - [7, 13], [8, 3], [8, 4], [8, 7], [8, 9], [8, 12], [8, 13], - [9, 3], [9, 4], [9, 8], [10, 5], [10, 6], [10, 11], [10, 15], - [11, 5], [11, 6], [11, 10], [11, 12], [11, 16], [11, 17], - [12, 7], [12, 8], [12, 11], [12, 13], [12, 16], [13, 7], - [13, 8], [13, 12], [13, 14], [13, 18], [13, 19], [14, 13], - [14, 18], [14, 19], [15, 10], [15, 16], [16, 11], [16, 12], - [16, 15], [16, 17], [17, 11], [17, 16], [18, 13], [18, 14], - [19, 13], [19, 14]] - - configuration = QasmBackendConfiguration( - backend_name='fake_tokyo', - backend_version='0.0.0', - n_qubits=20, - basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], - simulator=False, - local=True, - conditional=False, - open_pulse=False, - memory=False, - max_shots=65536, - gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], - coupling_map=cmap, - ) - - super().__init__(configuration) - - -class FakePoughkeepsie(FakeBackend): - """A fake Poughkeepsie backend.""" - - def __init__(self): - cmap = [[0, 1], [0, 5], [1, 0], [1, 2], [2, 1], [2, 3], [3, 2], [3, 4], [4, 3], [4, 9], - [5, 0], [5, 6], [5, 10], [6, 5], [6, 7], [7, 6], [7, 8], [7, 12], [8, 7], [8, 9], - [9, 4], [9, 8], [9, 14], [10, 5], [10, 11], [10, 15], [11, 10], [11, 12], [12, 7], - [12, 11], [12, 13], [13, 12], [13, 14], [14, 9], [14, 13], [14, 19], [15, 10], - [15, 16], [16, 15], [16, 17], [17, 16], [17, 18], [18, 17], [18, 19], [19, 14], - [19, 18]] - - configuration = QasmBackendConfiguration( - backend_name='fake_poughkeepsie', - backend_version='0.0.0', - n_qubits=20, - basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], - simulator=False, - local=True, - conditional=False, - open_pulse=False, - memory=True, - max_shots=8192, - gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], - coupling_map=cmap, - ) - - super().__init__(configuration) - - -class FakeJob(BaseJob): - """Fake simulator job""" - _executor = futures.ProcessPoolExecutor() - - def __init__(self, backend, job_id, fn, qobj): - super().__init__(backend, job_id) - self._backend = backend - self._job_id = job_id - self._qobj = qobj - self._future = None - self._future_callback = fn - - def submit(self): - self._future = self._executor.submit(self._future_callback, self._qobj) - - def result(self, timeout=None): - # pylint: disable=arguments-differ - return self._future.result(timeout=timeout) - - def cancel(self): - return self._future.cancel() - - def status(self): - if self._running: - _status = JobStatus.RUNNING - elif not self._done: - _status = JobStatus.QUEUED - elif self._cancelled: - _status = JobStatus.CANCELLED - elif self._done: - _status = JobStatus.DONE - elif self._error: - _status = JobStatus.ERROR - else: - raise Exception('Unexpected state of {0}'.format( - self.__class__.__name__)) - _status_msg = None - return {'status': _status, - 'status_msg': _status_msg} - - def job_id(self): - return self._job_id - - def backend(self): - return self._backend - - @property - def _cancelled(self): - return self._future.cancelled() - - @property - def _done(self): - return self._future.done() - - @property - def _running(self): - return self._future.running() - - @property - def _error(self): - return self._future.exception(timeout=0) - - -def new_fake_qobj(): - """Create fake `Qobj` and backend instances.""" - backend = FakeQasmSimulator() - return QasmQobj( - qobj_id='test-id', - config=QasmQobjConfig(shots=1024, memory_slots=1, max_credits=100), - header=QobjHeader(backend_name=backend.name()), - experiments=[QasmQobjExperiment( - instructions=[ - QasmQobjInstruction(name='barrier', qubits=[1]) - ], - header=QobjExperimentHeader(), - config=QasmQobjExperimentConfig(seed=123456) - )] - ) diff --git a/qiskit/test/mock/__init__.py b/qiskit/test/mock/__init__.py new file mode 100644 index 0000000000..29a68f9a5e --- /dev/null +++ b/qiskit/test/mock/__init__.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- + +# This code is part of Qiskit. +# +# (C) Copyright IBM 2019. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +""" +Utilities for mocking the IBMQ provider, including job responses and backends. + +The module includes dummy provider, backends, and jobs. +The purpose of these classes is to fake backends for testing purposes: +testing local timeouts, arbitrary responses or behavior, etc. + +The mock devices are mainly for testing the compiler. +""" + +from .fake_provider import FakeProvider +from .fake_backend import FakeBackend +from .fake_job import FakeJob +from .fake_qobj import FakeQobj + +from .fake_qasm_simulator import FakeQasmSimulator + +from .fake_yorktown import FakeYorktown +from .fake_tenerife import FakeTenerife +from .fake_ourense import FakeOurense +from .fake_valencia import FakeValencia +from .fake_vigo import FakeVigo +from .fake_melbourne import FakeMelbourne +from .fake_rueschlikon import FakeRueschlikon +from .fake_tokyo import FakeTokyo +from .fake_poughkeepsie import FakePoughkeepsie +from .fake_boeblingen import FakeBoeblingen + +from .fake_openpulse_2q import FakeOpenPulse2Q diff --git a/qiskit/test/mock/fake_backend.py b/qiskit/test/mock/fake_backend.py new file mode 100644 index 0000000000..bc712f09c8 --- /dev/null +++ b/qiskit/test/mock/fake_backend.py @@ -0,0 +1,112 @@ +# -*- coding: utf-8 -*- + +# This code is part of Qiskit. +# +# (C) Copyright IBM 2019. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +""" +Base class for dummy backends. +""" + + +import uuid +import time + +from qiskit.providers.models import BackendProperties +from qiskit.providers import BaseBackend +from qiskit.result import Result +from .fake_job import FakeJob + + +class FakeBackend(BaseBackend): + """This is a dummy backend just for testing purposes.""" + + def __init__(self, configuration, time_alive=10): + """ + Args: + configuration (BackendConfiguration): backend configuration + time_alive (int): time to wait before returning result + """ + super().__init__(configuration) + self.time_alive = time_alive + + def properties(self): + """Return backend properties""" + + coupling_map = self.configuration().coupling_map + unique_qubits = list(set().union(*coupling_map)) + + properties = { + 'backend_name': self.name(), + 'backend_version': self.configuration().backend_version, + 'last_update_date': '2000-01-01 00:00:00Z', + 'qubits': [ + [ + { + "date": "2000-01-01 00:00:00Z", + "name": "T1", + "unit": "\u00b5s", + "value": 0.0 + }, + { + "date": "2000-01-01 00:00:00Z", + "name": "T2", + "unit": "\u00b5s", + "value": 0.0 + }, + { + "date": "2000-01-01 00:00:00Z", + "name": "frequency", + "unit": "GHz", + "value": 0.0 + }, + { + "date": "2000-01-01 00:00:00Z", + "name": "readout_error", + "unit": "", + "value": 0.0 + } + ] for _ in range(len(unique_qubits)) + ], + 'gates': [{ + "gate": "cx", + "name": "CX" + str(pair[0]) + "_" + str(pair[1]), + "parameters": [ + { + "date": "2000-01-01 00:00:00Z", + "name": "gate_error", + "unit": "", + "value": 0.0 + } + ], + "qubits": [ + pair[0], + pair[1] + ] + } for pair in coupling_map], + 'general': [] + } + + return BackendProperties.from_dict(properties) + + def run(self, qobj): + job_id = str(uuid.uuid4()) + job = FakeJob(self, job_id, self.run_job, qobj) + job.submit() + return job + + def run_job(self, job_id, qobj): + """Main dummy run loop""" + del qobj # unused + time.sleep(self.time_alive) + + return Result.from_dict( + {'job_id': job_id, 'result': [], 'status': 'COMPLETED'}) diff --git a/qiskit/test/mock/fake_boeblingen.py b/qiskit/test/mock/fake_boeblingen.py new file mode 100644 index 0000000000..17677e2d3f --- /dev/null +++ b/qiskit/test/mock/fake_boeblingen.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- + +# This code is part of Qiskit. +# +# (C) Copyright IBM 2019. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +""" +Fake Boeblingen device (20 qubit). +""" + +from qiskit.providers.models import GateConfig, QasmBackendConfiguration +from .fake_backend import FakeBackend + + +class FakeBoeblingen(FakeBackend): + """A fake Boeblingen backend.""" + + def __init__(self): + """ + 00 ↔ 01 ↔ 02 ↔ 03 ↔ 04 + ↕ ↕ + 05 ↔ 06 ↔ 07 ↔ 08 ↔ 09 + ↕ ↕ ↕ + 10 ↔ 11 ↔ 12 ↔ 13 ↔ 14 + ↕ ↕ + 15 ↔ 16 ↔ 17 ↔ 18 ↔ 19 + """ + cmap = [[0, 1], [1, 0], [1, 2], [1, 6], [2, 1], [2, 3], [3, 2], + [3, 4], [3, 8], [4, 3], [5, 6], [5, 10], [6, 1], [6, 5], + [6, 7], [7, 6], [7, 8], [7, 12], [8, 3], [8, 7], [8, 9], + [9, 8], [9, 14], [10, 5], [10, 11], [11, 10], [11, 12], + [11, 16], [12, 7], [12, 11], [12, 13], [13, 12], [13, 14], + [13, 18], [14, 9], [14, 13], [15, 16], [16, 11], [16, 15], + [16, 17], [17, 16], [17, 18], [18, 13], [18, 17], [18, 19], + [19, 18]] + + configuration = QasmBackendConfiguration( + backend_name='fake_boeblingen', + backend_version='0.0.0', + n_qubits=20, + basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], + simulator=False, + local=True, + conditional=False, + open_pulse=False, + memory=True, + max_shots=8192, + gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], + coupling_map=cmap, + ) + + super().__init__(configuration) diff --git a/qiskit/test/mock/fake_job.py b/qiskit/test/mock/fake_job.py new file mode 100644 index 0000000000..85c7cced82 --- /dev/null +++ b/qiskit/test/mock/fake_job.py @@ -0,0 +1,86 @@ +# -*- coding: utf-8 -*- + +# This code is part of Qiskit. +# +# (C) Copyright IBM 2019. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +""" +Base class for dummy jobs. +""" + + +from concurrent import futures + +from qiskit.providers import BaseJob +from qiskit.providers.jobstatus import JobStatus + + +class FakeJob(BaseJob): + """Fake simulator job""" + _executor = futures.ProcessPoolExecutor() + + def __init__(self, backend, job_id, fn, qobj): + super().__init__(backend, job_id) + self._backend = backend + self._job_id = job_id + self._qobj = qobj + self._future = None + self._future_callback = fn + + def submit(self): + self._future = self._executor.submit(self._future_callback, self._qobj) + + def result(self, timeout=None): + # pylint: disable=arguments-differ + return self._future.result(timeout=timeout) + + def cancel(self): + return self._future.cancel() + + def status(self): + if self._running: + _status = JobStatus.RUNNING + elif not self._done: + _status = JobStatus.QUEUED + elif self._cancelled: + _status = JobStatus.CANCELLED + elif self._done: + _status = JobStatus.DONE + elif self._error: + _status = JobStatus.ERROR + else: + raise Exception('Unexpected state of {0}'.format( + self.__class__.__name__)) + _status_msg = None + return {'status': _status, + 'status_msg': _status_msg} + + def job_id(self): + return self._job_id + + def backend(self): + return self._backend + + @property + def _cancelled(self): + return self._future.cancelled() + + @property + def _done(self): + return self._future.done() + + @property + def _running(self): + return self._future.running() + + @property + def _error(self): + return self._future.exception(timeout=0) diff --git a/qiskit/test/mock/fake_melbourne.py b/qiskit/test/mock/fake_melbourne.py new file mode 100644 index 0000000000..208248ff3f --- /dev/null +++ b/qiskit/test/mock/fake_melbourne.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- + +# This code is part of Qiskit. +# +# (C) Copyright IBM 2019. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +""" +Fake Melbourne device (14 qubit). +""" + +from qiskit.providers.models import GateConfig, QasmBackendConfiguration +from .fake_backend import FakeBackend + + +class FakeMelbourne(FakeBackend): + """A fake 14 qubit backend.""" + + def __init__(self): + """ + 0 ← 1 → 2 → 3 ← 4 ← 5 → 6 + ↑ ↑ ↑ ↓ ↓ ↓ + 13 → 12 ← 11 → 10 ← 9 → 8 ← 7 + """ + cmap = [[1, 0], [1, 2], [2, 3], [4, 3], [4, 10], [5, 4], + [5, 6], [5, 9], [6, 8], [7, 8], [9, 8], [9, 10], + [11, 3], [11, 10], [11, 12], [12, 2], [13, 1], [13, 12]] + + configuration = QasmBackendConfiguration( + backend_name='fake_melbourne', + backend_version='0.0.0', + n_qubits=14, + basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], + simulator=False, + local=True, + conditional=False, + open_pulse=False, + memory=False, + max_shots=65536, + gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], + coupling_map=cmap, + ) + + super().__init__(configuration) diff --git a/qiskit/test/mock/fake_openpulse_2q.py b/qiskit/test/mock/fake_openpulse_2q.py new file mode 100644 index 0000000000..a812f3d04c --- /dev/null +++ b/qiskit/test/mock/fake_openpulse_2q.py @@ -0,0 +1,101 @@ +# -*- coding: utf-8 -*- + +# This code is part of Qiskit. +# +# (C) Copyright IBM 2019. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +""" +Fake backend supporting OpenPulse. +""" + +from qiskit.providers.models import (GateConfig, PulseBackendConfiguration, + PulseDefaults, Command, UchannelLO) +from qiskit.qobj import PulseLibraryItem, PulseQobjInstruction +from .fake_backend import FakeBackend + + +class FakeOpenPulse2Q(FakeBackend): + """A fake 2 qubit backend for pulse test.""" + + def __init__(self): + configuration = PulseBackendConfiguration( + backend_name='fake_openpulse_2q', + backend_version='0.0.0', + n_qubits=2, + meas_levels=[0, 1, 2], + basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], + simulator=False, + local=True, + conditional=True, + open_pulse=True, + memory=False, + max_shots=65536, + gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], + coupling_map=[[1, 0]], + n_registers=2, + n_uchannels=2, + u_channel_lo=[ + [UchannelLO(q=0, scale=1. + 0.j)], + [UchannelLO(q=0, scale=-1. + 0.j), UchannelLO(q=1, scale=1. + 0.j)] + ], + meas_level=[1, 2], + qubit_lo_range=[[4.5, 5.5], [4.5, 5.5]], + meas_lo_range=[[6.0, 7.0], [6.0, 7.0]], + dt=1.3333, + dtm=10.5, + rep_times=[100, 250, 500, 1000], + meas_map=[[0, 1]], + channel_bandwidth=[ + [-0.2, 0.4], [-0.3, 0.3], [-0.3, 0.3], + [-0.02, 0.02], [-0.02, 0.02], [-0.02, 0.02] + ], + meas_kernels=['kernel1'], + discriminators=['max_1Q_fidelity'], + acquisition_latency=[[100, 100], [100, 100]], + conditional_latency=[ + [100, 1000], [1000, 100], [100, 1000], + [1000, 100], [100, 1000], [1000, 100] + ] + ) + + self._defaults = PulseDefaults( + qubit_freq_est=[4.9, 5.0], + meas_freq_est=[6.5, 6.6], + buffer=10, + pulse_library=[PulseLibraryItem(name='test_pulse_1', samples=[0.j, 0.1j]), + PulseLibraryItem(name='test_pulse_2', samples=[0.j, 0.1j, 1j]), + PulseLibraryItem(name='test_pulse_3', + samples=[0.j, 0.1j, 1j, 0.5 + 0j])], + cmd_def=[Command(name='u1', qubits=[0], + sequence=[PulseQobjInstruction(name='fc', ch='d0', + t0=0, phase='-P1*np.pi')]), + Command(name='u3', qubits=[0], + sequence=[PulseQobjInstruction(name='test_pulse_1', ch='d0', t0=0)]), + Command(name='u3', qubits=[1], + sequence=[PulseQobjInstruction(name='test_pulse_3', ch='d1', t0=0)]), + Command(name='cx', qubits=[0, 1], + sequence=[PulseQobjInstruction(name='test_pulse_1', ch='d0', t0=0), + PulseQobjInstruction(name='test_pulse_2', ch='u0', t0=10), + PulseQobjInstruction(name='pv', ch='d1', + t0=2, val='cos(P2)'), + PulseQobjInstruction(name='test_pulse_1', ch='d1', t0=20), + PulseQobjInstruction(name='fc', ch='d1', + t0=20, phase=2.1)]), + Command(name='measure', qubits=[0], + sequence=[PulseQobjInstruction(name='test_pulse_1', ch='m0', t0=0), + PulseQobjInstruction(name='acquire', duration=10, t0=0, + qubits=[0], memory_slot=[0])])] + ) + + super().__init__(configuration) + + def defaults(self): # pylint: disable=missing-docstring + return self._defaults diff --git a/qiskit/test/mock/fake_ourense.py b/qiskit/test/mock/fake_ourense.py new file mode 100644 index 0000000000..2663ec774e --- /dev/null +++ b/qiskit/test/mock/fake_ourense.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- + +# This code is part of Qiskit. +# +# (C) Copyright IBM 2019. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +""" +Fake Ourense device (5 qubit). +""" + +from qiskit.providers.models import GateConfig, QasmBackendConfiguration +from .fake_backend import FakeBackend + + +class FakeOurense(FakeBackend): + """A fake 5 qubit backend.""" + + def __init__(self): + """ + 0 ↔ 1 ↔ 3 ↔ 4 + ↕ + 2 + """ + cmap = [[0, 1], [1, 0], [1, 2], [1, 3], [2, 1], [3, 1], [3, 4], [4, 3]] + + configuration = QasmBackendConfiguration( + backend_name='fake_ourense', + backend_version='0.0.0', + n_qubits=5, + basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], + simulator=False, + local=True, + conditional=False, + open_pulse=False, + memory=False, + max_shots=65536, + gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], + coupling_map=cmap, + ) + + super().__init__(configuration) diff --git a/qiskit/test/mock/fake_poughkeepsie.py b/qiskit/test/mock/fake_poughkeepsie.py new file mode 100644 index 0000000000..ca6e62e45c --- /dev/null +++ b/qiskit/test/mock/fake_poughkeepsie.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- + +# This code is part of Qiskit. +# +# (C) Copyright IBM 2019. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +""" +Fake Poughkeepsie device (20 qubit). +""" + +from qiskit.providers.models import GateConfig, QasmBackendConfiguration +from .fake_backend import FakeBackend + + +class FakePoughkeepsie(FakeBackend): + """A fake Poughkeepsie backend.""" + + def __init__(self): + """ + 00 ↔ 01 ↔ 02 ↔ 03 ↔ 04 + ↕ ↕ + 05 ↔ 06 ↔ 07 ↔ 08 ↔ 09 + ↕ ↕ ↕ + 10 ↔ 11 ↔ 12 ↔ 13 ↔ 14 + ↕ ↕ + 15 ↔ 16 ↔ 17 ↔ 18 ↔ 19 + """ + cmap = [[0, 1], [0, 5], [1, 0], [1, 2], [2, 1], [2, 3], [3, 2], [3, 4], [4, 3], [4, 9], + [5, 0], [5, 6], [5, 10], [6, 5], [6, 7], [7, 6], [7, 8], [7, 12], [8, 7], [8, 9], + [9, 4], [9, 8], [9, 14], [10, 5], [10, 11], [10, 15], [11, 10], [11, 12], [12, 7], + [12, 11], [12, 13], [13, 12], [13, 14], [14, 9], [14, 13], [14, 19], [15, 10], + [15, 16], [16, 15], [16, 17], [17, 16], [17, 18], [18, 17], [18, 19], [19, 14], + [19, 18]] + + configuration = QasmBackendConfiguration( + backend_name='fake_poughkeepsie', + backend_version='0.0.0', + n_qubits=20, + basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], + simulator=False, + local=True, + conditional=False, + open_pulse=False, + memory=True, + max_shots=8192, + gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], + coupling_map=cmap, + ) + + super().__init__(configuration) diff --git a/qiskit/test/mock/fake_provider.py b/qiskit/test/mock/fake_provider.py new file mode 100644 index 0000000000..4707bf8580 --- /dev/null +++ b/qiskit/test/mock/fake_provider.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- + +# This code is part of Qiskit. +# +# (C) Copyright IBM 2019. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +""" +Fake provider class that provides access to fake backends. +""" + +from qiskit.providers.baseprovider import BaseProvider +from qiskit.providers.exceptions import QiskitBackendNotFoundError + +from .fake_qasm_simulator import FakeQasmSimulator +from .fake_yorktown import FakeYorktown +from .fake_tenerife import FakeTenerife +from .fake_ourense import FakeOurense +from .fake_valencia import FakeValencia +from .fake_vigo import FakeVigo +from .fake_melbourne import FakeMelbourne +from .fake_rueschlikon import FakeRueschlikon +from .fake_tokyo import FakeTokyo +from .fake_poughkeepsie import FakePoughkeepsie +from .fake_boeblingen import FakeBoeblingen +from .fake_openpulse_2q import FakeOpenPulse2Q + + +class FakeProvider(BaseProvider): + """Dummy provider just for testing purposes. + + Only filtering backends by name is implemented. + """ + + def get_backend(self, name=None, **kwargs): + backend = self._backends[0] + if name: + filtered_backends = [backend for backend in self._backends + if backend.name() == name] + if not filtered_backends: + raise QiskitBackendNotFoundError() + + backend = filtered_backends[0] + + return backend + + def backends(self, name=None, **kwargs): + return self._backends + + def __init__(self): + self._backends = [FakeQasmSimulator(), + FakeOpenPulse2Q(), + FakeYorktown(), + FakeTenerife(), + FakeOurense(), + FakeValencia(), + FakeVigo(), + FakeMelbourne(), + FakeRueschlikon(), + FakeTokyo(), + FakePoughkeepsie(), + FakeBoeblingen()] + + super().__init__() diff --git a/qiskit/test/mock/fake_qasm_simulator.py b/qiskit/test/mock/fake_qasm_simulator.py new file mode 100644 index 0000000000..f791526919 --- /dev/null +++ b/qiskit/test/mock/fake_qasm_simulator.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- + +# This code is part of Qiskit. +# +# (C) Copyright IBM 2019. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +""" +Fake qasm simulator. +""" + +from qiskit.providers.models import GateConfig, QasmBackendConfiguration +from .fake_backend import FakeBackend + + +class FakeQasmSimulator(FakeBackend): + """A fake simulator backend.""" + + def __init__(self): + configuration = QasmBackendConfiguration( + backend_name='fake_qasm_simulator', + backend_version='0.0.0', + n_qubits=5, + basis_gates=['u1', 'u2', 'u3', 'cx', 'cz', 'id', 'x', 'y', 'z', + 'h', 's', 'sdg', 't', 'tdg', 'ccx', 'swap', + 'snapshot', 'unitary'], + coupling_map=None, + simulator=True, + local=True, + conditional=True, + open_pulse=False, + memory=True, + max_shots=65536, + gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')] + ) + + super().__init__(configuration) diff --git a/qiskit/test/mock/fake_qobj.py b/qiskit/test/mock/fake_qobj.py new file mode 100644 index 0000000000..b3c84a39c8 --- /dev/null +++ b/qiskit/test/mock/fake_qobj.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- + +# This code is part of Qiskit. +# +# (C) Copyright IBM 2019. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +""" +Base Fake Qobj. +""" + +from qiskit.qobj import (QasmQobj, QobjExperimentHeader, QobjHeader, + QasmQobjInstruction, QasmQobjExperimentConfig, + QasmQobjExperiment, QasmQobjConfig) +from .fake_qasm_simulator import FakeQasmSimulator + + +class FakeQobj(QasmQobj): + """A fake `Qobj` instance.""" + def __init__(self): + qobj_id = 'test_id' + config = QasmQobjConfig(shots=1024, memory_slots=1, max_credits=100) + header = QobjHeader(backend_name=FakeQasmSimulator().name()) + experiments = [QasmQobjExperiment( + instructions=[ + QasmQobjInstruction(name='barrier', qubits=[1]) + ], + header=QobjExperimentHeader(), + config=QasmQobjExperimentConfig(seed=123456) + )] + super().__init__(qobj_id=qobj_id, config=config, + experiments=experiments, header=header) diff --git a/qiskit/test/mock/fake_rueschlikon.py b/qiskit/test/mock/fake_rueschlikon.py new file mode 100644 index 0000000000..f827ef141c --- /dev/null +++ b/qiskit/test/mock/fake_rueschlikon.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- + +# This code is part of Qiskit. +# +# (C) Copyright IBM 2019. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +""" +Fake Reuschlikon device (16 qubit). +""" + +from qiskit.providers.models import GateConfig, QasmBackendConfiguration +from .fake_backend import FakeBackend + + +class FakeRueschlikon(FakeBackend): + """A fake 16 qubit backend.""" + + def __init__(self): + """ + 1 → 2 → 3 → 4 ← 5 ← 6 → 7 ← 8 + ↓ ↑ ↓ ↓ ↑ ↓ ↓ ↑ + 0 ← 15 → 14 ← 13 ← 12 → 11 → 10 ← 9 + """ + cmap = [[1, 0], [1, 2], [2, 3], [3, 4], [3, 14], [5, 4], [6, 5], + [6, 7], [6, 11], [7, 10], [8, 7], [9, 8], [9, 10], + [11, 10], [12, 5], [12, 11], [12, 13], [13, 4], + [13, 14], [15, 0], [15, 2], [15, 14]] + + configuration = QasmBackendConfiguration( + backend_name='fake_rueschlikon', + backend_version='0.0.0', + n_qubits=16, + basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], + simulator=False, + local=True, + conditional=False, + open_pulse=False, + memory=False, + max_shots=65536, + gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], + coupling_map=cmap, + ) + + super().__init__(configuration) diff --git a/qiskit/test/mock/fake_tenerife.py b/qiskit/test/mock/fake_tenerife.py new file mode 100644 index 0000000000..bcc5951422 --- /dev/null +++ b/qiskit/test/mock/fake_tenerife.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- + +# This code is part of Qiskit. +# +# (C) Copyright IBM 2019. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +""" +Fake Tenerife device (5 qubit). +""" + +from qiskit.providers.models import GateConfig, QasmBackendConfiguration +from .fake_backend import FakeBackend + + +class FakeTenerife(FakeBackend): + """A fake 5 qubit backend.""" + + def __init__(self): + """ + 1 + ↙ ↑ + 0 ← 2 ← 3 + ↑ ↙ + 4 + """ + cmap = [[1, 0], [2, 0], [2, 1], [3, 2], [3, 4], [4, 2]] + + configuration = QasmBackendConfiguration( + backend_name='fake_tenerife', + backend_version='0.0.0', + n_qubits=5, + basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], + simulator=False, + local=True, + conditional=False, + open_pulse=False, + memory=False, + max_shots=65536, + gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], + coupling_map=cmap, + ) + + super().__init__(configuration) diff --git a/qiskit/test/mock/fake_tokyo.py b/qiskit/test/mock/fake_tokyo.py new file mode 100644 index 0000000000..65db6bd4c8 --- /dev/null +++ b/qiskit/test/mock/fake_tokyo.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- + +# This code is part of Qiskit. +# +# (C) Copyright IBM 2019. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +""" +Fake Tokyo device (20 qubit). +""" + +from qiskit.providers.models import GateConfig, QasmBackendConfiguration +from .fake_backend import FakeBackend + + +class FakeTokyo(FakeBackend): + """A fake 20 qubit backend.""" + + def __init__(self): + """ + 00 ↔ 01 ↔ 02 ↔ 03 ↔ 04 + ↕ ↕ ↕ ↕ ⤫ ↕ + 05 ↔ 06 ↔ 07 ↔ 08 ↔ 09 + ↕ ⤫ ↕ ↕ ⤫ ↕ + 10 ↔ 11 ↔ 12 ↔ 13 ↔ 14 + ↕ ↕ ⤫ ↕ ⤫ ↕ + 15 ↔ 16 ↔ 17 18 19 + """ + cmap = [[0, 1], [0, 5], [1, 0], [1, 2], [1, 6], [2, 1], + [2, 3], [2, 6], [3, 2], [3, 8], [3, 9], [4, 8], [4, 9], + [5, 0], [5, 6], [5, 10], [5, 11], [6, 1], [6, 2], [6, 5], + [6, 7], [6, 10], [6, 11], [7, 1], [7, 6], [7, 8], [7, 12], + [7, 13], [8, 3], [8, 4], [8, 7], [8, 9], [8, 12], [8, 13], + [9, 3], [9, 4], [9, 8], [10, 5], [10, 6], [10, 11], [10, 15], + [11, 5], [11, 6], [11, 10], [11, 12], [11, 16], [11, 17], + [12, 7], [12, 8], [12, 11], [12, 13], [12, 16], [13, 7], + [13, 8], [13, 12], [13, 14], [13, 18], [13, 19], [14, 13], + [14, 18], [14, 19], [15, 10], [15, 16], [16, 11], [16, 12], + [16, 15], [16, 17], [17, 11], [17, 16], [18, 13], [18, 14], + [19, 13], [19, 14]] + + configuration = QasmBackendConfiguration( + backend_name='fake_tokyo', + backend_version='0.0.0', + n_qubits=20, + basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], + simulator=False, + local=True, + conditional=False, + open_pulse=False, + memory=False, + max_shots=65536, + gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], + coupling_map=cmap, + ) + + super().__init__(configuration) diff --git a/qiskit/test/mock/fake_valencia.py b/qiskit/test/mock/fake_valencia.py new file mode 100644 index 0000000000..479ab02577 --- /dev/null +++ b/qiskit/test/mock/fake_valencia.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- + +# This code is part of Qiskit. +# +# (C) Copyright IBM 2019. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +""" +Fake Valencia device (5 qubit). +""" + +from qiskit.providers.models import GateConfig, QasmBackendConfiguration +from .fake_backend import FakeBackend + + +class FakeValencia(FakeBackend): + """A fake 5 qubit backend.""" + + def __init__(self): + """ + 0 ↔ 1 ↔ 3 ↔ 4 + ↕ + 2 + """ + cmap = [[0, 1], [1, 0], [1, 2], [1, 3], [2, 1], [3, 1], [3, 4], [4, 3]] + + configuration = QasmBackendConfiguration( + backend_name='fake_valencia', + backend_version='0.0.0', + n_qubits=5, + basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], + simulator=False, + local=True, + conditional=False, + open_pulse=False, + memory=False, + max_shots=65536, + gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], + coupling_map=cmap, + ) + + super().__init__(configuration) diff --git a/qiskit/test/mock/fake_vigo.py b/qiskit/test/mock/fake_vigo.py new file mode 100644 index 0000000000..25184440a6 --- /dev/null +++ b/qiskit/test/mock/fake_vigo.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- + +# This code is part of Qiskit. +# +# (C) Copyright IBM 2019. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +""" +Fake Vigo device (5 qubit). +""" + +from qiskit.providers.models import GateConfig, QasmBackendConfiguration +from .fake_backend import FakeBackend + + +class FakeVigo(FakeBackend): + """A fake 5 qubit backend.""" + + def __init__(self): + """ + 0 ↔ 1 ↔ 3 ↔ 4 + ↕ + 2 + """ + cmap = [[0, 1], [1, 0], [1, 2], [1, 3], [2, 1], [3, 1], [3, 4], [4, 3]] + + configuration = QasmBackendConfiguration( + backend_name='fake_vigo', + backend_version='0.0.0', + n_qubits=5, + basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], + simulator=False, + local=True, + conditional=False, + open_pulse=False, + memory=False, + max_shots=65536, + gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], + coupling_map=cmap, + ) + + super().__init__(configuration) diff --git a/qiskit/test/mock/fake_yorktown.py b/qiskit/test/mock/fake_yorktown.py new file mode 100644 index 0000000000..c4f8075dfe --- /dev/null +++ b/qiskit/test/mock/fake_yorktown.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- + +# This code is part of Qiskit. +# +# (C) Copyright IBM 2019. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +""" +Fake Yorktown device (5 qubit). +""" + +from qiskit.providers.models import GateConfig, QasmBackendConfiguration +from .fake_backend import FakeBackend + + +class FakeYorktown(FakeBackend): + """A fake 5 qubit backend.""" + + def __init__(self): + """ + 1 + / | + 0 - 2 - 3 + | / + 4 + """ + cmap = [[0, 1], [0, 2], [1, 2], [3, 2], [3, 4], [4, 2]] + + configuration = QasmBackendConfiguration( + backend_name='fake_yorktown', + backend_version='0.0.0', + n_qubits=5, + basis_gates=['u1', 'u2', 'u3', 'cx', 'id'], + simulator=False, + local=True, + conditional=False, + open_pulse=False, + memory=False, + max_shots=65536, + gates=[GateConfig(name='TODO', parameters=[], qasm_def='TODO')], + coupling_map=cmap, + ) + + super().__init__(configuration) diff --git a/test/python/providers/test_jobmethods.py b/test/python/providers/test_jobmethods.py index 0a11d27832..8ac47199b0 100644 --- a/test/python/providers/test_jobmethods.py +++ b/test/python/providers/test_jobmethods.py @@ -23,7 +23,7 @@ import unittest from unittest.mock import patch from qiskit.test import QiskitTestCase -from qiskit.test.mock import new_fake_qobj, FakeRueschlikon +from qiskit.test.mock import FakeQobj, FakeRueschlikon class TestSimulatorsJob(QiskitTestCase): @@ -41,7 +41,7 @@ class TestSimulatorsJob(QiskitTestCase): backend = FakeRueschlikon() with mocked_executor() as (SimulatorJob, executor): for index in range(taskcount): - job = SimulatorJob(backend, job_id, target_tasks[index], new_fake_qobj()) + job = SimulatorJob(backend, job_id, target_tasks[index], FakeQobj()) job.submit() self.assertEqual(executor.submit.call_count, taskcount) @@ -59,7 +59,7 @@ class TestSimulatorsJob(QiskitTestCase): job_id = str(uuid.uuid4()) backend = FakeRueschlikon() with mocked_executor() as (BasicAerJob, executor): - job = BasicAerJob(backend, job_id, lambda: None, new_fake_qobj()) + job = BasicAerJob(backend, job_id, lambda: None, FakeQobj()) job.submit() job.cancel()