diff --git a/requirements.txt b/requirements.txt index 6474ff4b..78cae132 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -qiskit>=0.43,<1 +qiskit qiskit-aer>=0.11.0 qiskit_ibm_provider>=0.5.0 pybind11<=2.9.1 @@ -6,6 +6,7 @@ PyMatching>=0.6.0,!=2.0.0 rustworkx>=0.12.0 networkx>=2.6.3 sympy>=1.9 +testtools numpy>=1.21.0 ipython ipywidgets>=8.0.5 diff --git a/src/qiskit_qec/__init__.py b/src/qiskit_qec/__init__.py index 31b2ad0b..3d8f6a4e 100644 --- a/src/qiskit_qec/__init__.py +++ b/src/qiskit_qec/__init__.py @@ -24,6 +24,7 @@ linear, operators, structures, + test, utils, ) diff --git a/src/qiskit_qec/circuits/repetition_code.py b/src/qiskit_qec/circuits/repetition_code.py index e80931da..4efda151 100644 --- a/src/qiskit_qec/circuits/repetition_code.py +++ b/src/qiskit_qec/circuits/repetition_code.py @@ -23,11 +23,6 @@ import networkx as nx from qiskit import ClassicalRegister, QuantumCircuit, QuantumRegister, transpile -from qiskit.circuit.library import XGate, RZGate -from qiskit.transpiler import PassManager, InstructionDurations -from qiskit_ibm_provider.transpiler.passes.scheduling import DynamicCircuitInstructionDurations -from qiskit_ibm_provider.transpiler.passes.scheduling import PadDynamicalDecoupling -from qiskit_ibm_provider.transpiler.passes.scheduling import ALAPScheduleAnalysis from qiskit_qec.circuits.code_circuit import CodeCircuit from qiskit_qec.utils import DecodingGraphEdge, DecodingGraphNode @@ -979,6 +974,7 @@ def _process_string(self, string): q_l = self.num_qubits[1] - 1 - j qubit_l = self.links[q_l][1] # the first results are themselves the changes + change = None if t == 0: change = syndrome_list[-1][j] != "0" # if the link was involved in a just finished 202... @@ -1222,19 +1218,16 @@ def is_cluster_neutral(self, nodes: dict): self._linear, ) - def transpile(self, backend, echo=("X", "X"), echo_num=(2, 0)): + def transpile(self, backend, scheduling_method="alap"): """ Args: backend (qiskit.providers.ibmq.IBMQBackend): Backend to transpile and schedule the circuits for. The numbering of the qubits in this backend should correspond to the numbering used in `self.links`. - echo (tuple): List of gate sequences (expressed as strings) to be used on code qubits and - link qubits, respectively. Valid strings are `'X'` and `'XZX'`. - echo_num (tuple): Number of times to repeat the sequences for code qubits and - link qubits, respectively. + scheduling_method (str): Name of scheduling pass. Arguemnt passed to `qiskit.transpile`. Returns: - transpiled_circuit: As `self.circuit`, but with the circuits scheduled, transpiled and - with dynamical decoupling added. + transpiled_circuit: As `self.circuit`, but with the circuits scheduled and remapped + to the device connectivity. """ bases = list(self.circuit.keys()) @@ -1248,51 +1241,9 @@ def transpile(self, backend, echo=("X", "X"), echo_num=(2, 0)): ] # transpile to backend - circuits = transpile(circuits, backend, initial_layout=initial_layout) - - # then dynamical decoupling if needed - if any(echo_num): - if self.run_202: - durations = DynamicCircuitInstructionDurations().from_backend(backend) - else: - durations = InstructionDurations().from_backend(backend) - - # set up the dd sequences - dd_sequences = [] - spacings = [] - for j in range(2): - if echo[j] == "X": - dd_sequences.append([XGate()] * echo_num[j]) - spacings.append(None) - elif echo[j] == "XZX": - dd_sequences.append([XGate(), RZGate(np.pi), XGate()] * echo_num[j]) - d = 1.0 / (2 * echo_num[j] - 1 + 1) - spacing = [d / 2] + ([0, d, d] * echo_num[j])[:-1] + [d / 2] - for _ in range(2): - spacing[0] += 1 - sum(spacing) - spacings.append(spacing) - else: - dd_sequences.append(None) - spacings.append(None) - - # add in the dd sequences - for j, dd_sequence in enumerate(dd_sequences): - if dd_sequence: - if echo_num[j]: - qubits = self.qubits[j] - else: - qubits = None - pm = PassManager( - [ - ALAPScheduleAnalysis(durations), - PadDynamicalDecoupling( - durations, dd_sequence, qubits=qubits, spacings=spacings[j] - ), - ] - ) - circuits = pm.run(circuits) - if not isinstance(circuits, list): - circuits = [circuits] + circuits = transpile( + circuits, backend, initial_layout=initial_layout, scheduling_method=scheduling_method + ) return {basis: circuits[j] for j, basis in enumerate(bases)} diff --git a/src/qiskit_qec/test/__init__.py b/src/qiskit_qec/test/__init__.py new file mode 100644 index 00000000..5548ec37 --- /dev/null +++ b/src/qiskit_qec/test/__init__.py @@ -0,0 +1,27 @@ +# 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. + +"""Functionality and helpers for testing Qiskit.""" + +import warnings +from .base import QiskitTestCase +from .decorators import requires_aer_provider, online_test, slow_test +from .reference_circuits import ReferenceCircuits +from .utils import Path + +warnings.warn( + "The `qiskit.test` module is deprecated since Qiskit 0.46, and will be removed in Qiskit 1.0." + " This module was internal to Qiskit's test suite; if you absolutely require any of its" + " functionality, consider vendoring the code into your own project.", + DeprecationWarning, + stacklevel=2, +) diff --git a/src/qiskit_qec/test/_canonical.py b/src/qiskit_qec/test/_canonical.py new file mode 100644 index 00000000..367281f5 --- /dev/null +++ b/src/qiskit_qec/test/_canonical.py @@ -0,0 +1,125 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Utility methods for canonicalising various Qiskit objects, to help with testing.""" + +import threading + +from qiskit.circuit import ( + BreakLoopOp, + CircuitInstruction, + ContinueLoopOp, + ControlFlowOp, + ForLoopOp, + Parameter, + QuantumCircuit, +) + + +class _CanonicalParametersIterator: + """An object that, when iterated through, will produce the same sequence of parameters as every + other instance of this iterator.""" + + __parameters = [] + __mutex = threading.Lock() + + def __init__(self): + self._counter = 0 + + def __iter__(self): + return self + + def __next__(self): + with self.__mutex: + if len(self.__parameters) >= self._counter: + param = Parameter(f"_canonicalization_loop_{self._counter}") + self.__parameters.append(param) + out = self.__parameters[self._counter] + self._counter += 1 + return out + + +def canonicalize_control_flow(circuit: QuantumCircuit) -> QuantumCircuit: + """Canonicalize all control-flow operations in a circuit. + + This is not an efficient operation, and does not affect any properties of the circuit. Its + intent is to normalise parts of circuits that have a non-deterministic construction. These are + the ordering of bit arguments in control-flow blocks output by the builder interface, and + automatically generated ``for``-loop variables. + + The canonical form sorts the bits in the arguments of these operations so that they always + appear in the order they were originally added to the outer-most circuit. For-loop variables + are re-bound into new, cached auto-generated ones.""" + params = iter(_CanonicalParametersIterator()) + base_bit_order = {bit: i for i, bit in enumerate(circuit.qubits)} + base_bit_order.update((bit, i) for i, bit in enumerate(circuit.clbits)) + + def worker(circuit, bit_map=None): + if bit_map is None: + bit_map = {bit: bit for bits in (circuit.qubits, circuit.clbits) for bit in bits} + + def bit_key(bit): + return base_bit_order[bit_map[bit]] + + # This isn't quite QuantumCircuit.copy_empty_like because of the bit reordering. + out = QuantumCircuit( + sorted(circuit.qubits, key=bit_key), + sorted(circuit.clbits, key=bit_key), + *circuit.qregs, + *circuit.cregs, + name=circuit.name, + global_phase=circuit.global_phase, + metadata=circuit.metadata, + ) + for instruction in circuit.data: + new_instruction = instruction + # Control-flow operations associated bits in the instruction arguments with bits in the + # circuit blocks just by sequencing. All blocks must have the same width. + if isinstance(new_instruction.operation, ControlFlowOp): + op = new_instruction.operation + first_block = op.blocks[0] + inner_bit_map = dict( + zip(first_block.qubits, (bit_map[bit] for bit in new_instruction.qubits)) + ) + inner_bit_map.update( + zip(first_block.clbits, (bit_map[bit] for bit in new_instruction.clbits)) + ) + new_instruction = CircuitInstruction( + operation=op.replace_blocks( + [worker(block, inner_bit_map) for block in op.blocks] + ), + qubits=sorted(new_instruction.qubits, key=bit_key), + clbits=sorted(new_instruction.clbits, key=bit_key), + ) + elif isinstance(new_instruction.operation, (BreakLoopOp, ContinueLoopOp)): + new_instruction = new_instruction.replace( + qubits=sorted(new_instruction.qubits, key=bit_key), + clbits=sorted(new_instruction.clbits, key=bit_key), + ) + # For for loops specifically, the control-flow builders generate a loop parameter if one + # is needed but not explicitly supplied. We want the parameters to compare equal, so we + # replace them with those from a shared list. + if isinstance(new_instruction.operation, ForLoopOp): + old_op = new_instruction.operation + indexset, loop_param, body = old_op.params + if loop_param is not None: + new_loop_param = next(params) + new_op = ForLoopOp( + indexset, + new_loop_param, + body.assign_parameters({loop_param: new_loop_param}), + ) + new_instruction = new_instruction.replace(operation=new_op) + out._append(new_instruction) + return out + + return worker(circuit) diff --git a/src/qiskit_qec/test/base.py b/src/qiskit_qec/test/base.py new file mode 100644 index 00000000..f33179a1 --- /dev/null +++ b/src/qiskit_qec/test/base.py @@ -0,0 +1,318 @@ +# 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=invalid-name +# pylint: disable=consider-using-f-string + + +"""Base TestCases for the unit tests. + +Implementors of unit tests for Terra are encouraged to subclass +``QiskitTestCase`` in order to take advantage of utility functions (for example, +the environment variables for customizing different options), and the +decorators in the ``decorators`` package. +""" + +import inspect +import logging +import os +import sys +import warnings +import unittest +from unittest.util import safe_repr +import testtools + +from qiskit.utils.parallel import get_platform_parallel_default +from qiskit.utils import optionals as _optionals +from qiskit.circuit import QuantumCircuit +from .decorators import enforce_subclasses_call +from .utils import Path, setup_test_logging + + +__unittest = True # Allows shorter stack trace for .assertDictAlmostEqual + + +# Use testtools as a (mostly) drop in replacement for +# unittest's TestCase. This will enable the fixtures used for capturing stdout +# stderr, and pylogging to attach the output to stestr's result stream. +class BaseTestCase(testtools.TestCase): + """Base test class.""" + + # testtools maintains their own version of assert functions which mostly + # behave as value adds to the std unittest assertion methods. However, + # for assertEquals and assertRaises modern unittest has diverged from + # the forks in testtools and offer more (or different) options that are + # incompatible testtools versions. Just use the stdlib versions so that + # our tests work as expected. + assertRaises = unittest.TestCase.assertRaises + assertEqual = unittest.TestCase.assertEqual + + +@enforce_subclasses_call(["setUp", "setUpClass", "tearDown", "tearDownClass"]) +class BaseQiskitTestCase(BaseTestCase): + """Additions for test cases for all Qiskit-family packages. + + The additions here are intended for all packages, not just Terra. Terra-specific logic should + be in the Terra-specific classes.""" + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.__setup_called = False + self.__teardown_called = False + + def setUp(self): + super().setUp() + self.addTypeEqualityFunc(QuantumCircuit, self.assertQuantumCircuitEqual) + if self.__setup_called: + raise ValueError( + "In File: %s\n" + "TestCase.setUp was already called. Do not explicitly call " + "setUp from your tests. In your own setUp, use super to call " + "the base setUp." % (sys.modules[self.__class__.__module__].__file__,) + ) + self.__setup_called = True + + def tearDown(self): + super().tearDown() + if self.__teardown_called: + raise ValueError( + "In File: %s\n" + "TestCase.tearDown was already called. Do not explicitly call " + "tearDown from your tests. In your own tearDown, use super to " + "call the base tearDown." % (sys.modules[self.__class__.__module__].__file__,) + ) + self.__teardown_called = True + + @staticmethod + def _get_resource_path(filename, path=Path.TEST): + """Get the absolute path to a resource. + + Args: + filename (string): filename or relative path to the resource. + path (Path): path used as relative to the filename. + + Returns: + str: the absolute path to the resource. + """ + return os.path.normpath(os.path.join(path.value, filename)) + + def assertQuantumCircuitEqual(self, qc1, qc2, msg=None): + """Extra assertion method to give a better error message when two circuits are unequal.""" + if qc1 == qc2: + return + if msg is None: + msg = "The two circuits are not equal." + msg += f""" +Left circuit: +{qc1} + +Right circuit: +{qc2}""" + raise self.failureException(msg) + + def assertDictAlmostEqual( + self, dict1, dict2, delta=None, msg=None, places=None, default_value=0 + ): + """Assert two dictionaries with numeric values are almost equal. + + Fail if the two dictionaries are unequal as determined by + comparing that the difference between values with the same key are + not greater than delta (default 1e-8), or that difference rounded + to the given number of decimal places is not zero. If a key in one + dictionary is not in the other the default_value keyword argument + will be used for the missing value (default 0). If the two objects + compare equal then they will automatically compare almost equal. + + Args: + dict1 (dict): a dictionary. + dict2 (dict): a dictionary. + delta (number): threshold for comparison (defaults to 1e-8). + msg (str): return a custom message on failure. + places (int): number of decimal places for comparison. + default_value (number): default value for missing keys. + + Raises: + TypeError: if the arguments are not valid (both `delta` and + `places` are specified). + AssertionError: if the dictionaries are not almost equal. + """ + + error_msg = dicts_almost_equal(dict1, dict2, delta, places, default_value) + + if error_msg: + msg = self._formatMessage(msg, error_msg) + raise self.failureException(msg) + + def enable_parallel_processing(self): + """ + Enables parallel processing, for the duration of a test, on platforms + that support it. This is done by temporarily overriding the value of + the QISKIT_PARALLEL environment variable with the platform specific default. + """ + parallel_default = str(get_platform_parallel_default()).upper() + + def set_parallel_env(name, value): + os.environ[name] = value + + self.addCleanup( + lambda value: set_parallel_env("QISKIT_PARALLEL", value), + os.getenv("QISKIT_PARALLEL", parallel_default), + ) + + os.environ["QISKIT_PARALLEL"] = parallel_default + + +class QiskitTestCase(BaseQiskitTestCase): + """Terra-specific extra functionality for test cases.""" + + def tearDown(self): + super().tearDown() + # Reset the default providers, as in practice they acts as a singleton + # due to importing the instances from the top-level qiskit namespace. + from qiskit.providers.basic_provider import BasicProvider + + with self.assertWarns(DeprecationWarning): + BasicProvider()._backends = BasicProvider()._verify_backends() + + @classmethod + def setUpClass(cls): + super().setUpClass() + # Determines if the TestCase is using IBMQ credentials. + cls.using_ibmq_credentials = False + # Set logging to file and stdout if the LOG_LEVEL envar is set. + cls.log = logging.getLogger(cls.__name__) + if os.getenv("LOG_LEVEL"): + filename = "%s.log" % os.path.splitext(inspect.getfile(cls))[0] + setup_test_logging(cls.log, os.getenv("LOG_LEVEL"), filename) + + warnings.filterwarnings("error", category=DeprecationWarning) + allow_DeprecationWarning_modules = [ + "test.python.pulse.test_parameters", + "test.python.pulse.test_transforms", + "test.python.circuit.test_gate_power", + "test.python.pulse.test_builder", + "test.python.pulse.test_block", + "test.python.quantum_info.operators.symplectic.test_legacy_pauli", + "qiskit.quantum_info.operators.pauli", + "pybobyqa", + "numba", + "qiskit.utils.measurement_error_mitigation", + "qiskit.circuit.library.standard_gates.x", + "qiskit.pulse.schedule", + "qiskit.pulse.instructions.instruction", + "qiskit.pulse.instructions.play", + "qiskit.pulse.library.parametric_pulses", + "qiskit.quantum_info.operators.symplectic.pauli", + "test.python.dagcircuit.test_dagcircuit", + "importlib_metadata", + ] + for mod in allow_DeprecationWarning_modules: + warnings.filterwarnings("default", category=DeprecationWarning, module=mod) + allow_DeprecationWarning_message = [ + r"elementwise comparison failed.*", + r"The jsonschema validation included in qiskit-terra.*", + r"The DerivativeBase.parameter_expression_grad method.*", + r"The property ``qiskit\.circuit\.bit\.Bit\.(register|index)`` is deprecated.*", + r"The CXDirection pass has been deprecated", + # Caused by internal scikit-learn scipy usage + r"The 'sym_pos' keyword is deprecated and should be replaced by using", + # jupyter_client 7.4.8 uses deprecated shims in pyzmq that raise warnings with pyzmq 25. + # These are due to be fixed by jupyter_client 8, see: + # - https://github.com/jupyter/jupyter_client/issues/913 + # - https://github.com/jupyter/jupyter_client/pull/842 + r"zmq\.eventloop\.ioloop is deprecated in pyzmq .*", + ] + for msg in allow_DeprecationWarning_message: + warnings.filterwarnings("default", category=DeprecationWarning, message=msg) + allow_aer_DeprecationWarning_message = [ + # This warning should be fixed once Qiskit/qiskit-aer#1761 is in a release version of Aer. + "Setting metadata to None.*", + # and this one once Qiskit/qiskit-aer#1945 is merged and released. + r"The method ``qiskit\.circuit\.quantumcircuit\.QuantumCircuit\.i\(\)`` is " + r"deprecated as of qiskit 0\.45\.0\. It will be removed" + r" in the Qiskit 1\.0\.0 release\. Use QuantumCircuit\.id as direct replacement\.", + # This warning will be fixed once Qiskit/qiskit-aer#2023 is released. + "The qiskit.extensions module is deprecated since Qiskit 0.46.0. It will be removed " + "in the Qiskit 1.0 release.", + ] + for msg in allow_aer_DeprecationWarning_message: + warnings.filterwarnings( + "default", category=DeprecationWarning, module="qiskit_aer.*", message=msg + ) + # Ignore fake backend deprecation warnings to avoid over-crowding the test log + ignore_fake_backend_message = r".*have been migrated to the `qiskit_ibm_runtime` package.*" + warnings.filterwarnings( + "ignore", category=DeprecationWarning, message=ignore_fake_backend_message + ) + + +def dicts_almost_equal(dict1, dict2, delta=None, places=None, default_value=0): + """Test if two dictionaries with numeric values are almost equal. + + Fail if the two dictionaries are unequal as determined by + comparing that the difference between values with the same key are + not greater than delta (default 1e-8), or that difference rounded + to the given number of decimal places is not zero. If a key in one + dictionary is not in the other the default_value keyword argument + will be used for the missing value (default 0). If the two objects + compare equal then they will automatically compare almost equal. + + Args: + dict1 (dict): a dictionary. + dict2 (dict): a dictionary. + delta (number): threshold for comparison (defaults to 1e-8). + places (int): number of decimal places for comparison. + default_value (number): default value for missing keys. + + Raises: + TypeError: if the arguments are not valid (both `delta` and + `places` are specified). + + Returns: + String: Empty string if dictionaries are almost equal. A description + of their difference if they are deemed not almost equal. + """ + + def valid_comparison(value): + """compare value to delta, within places accuracy""" + if places is not None: + return round(value, places) == 0 + else: + return value < delta + + # Check arguments. + if dict1 == dict2: + return "" + if places is not None: + if delta is not None: + raise TypeError("specify delta or places not both") + msg_suffix = " within %s places" % places + else: + delta = delta or 1e-8 + msg_suffix = " within %s delta" % delta + + # Compare all keys in both dicts, populating error_msg. + error_msg = "" + for key in set(dict1.keys()) | set(dict2.keys()): + val1 = dict1.get(key, default_value) + val2 = dict2.get(key, default_value) + if not valid_comparison(abs(val1 - val2)): + error_msg += f"({safe_repr(key)}: {safe_repr(val1)} != {safe_repr(val2)}), " + + if error_msg: + return error_msg[:-2] + msg_suffix + else: + return "" + + +# Maintain naming backwards compatibility for downstream packages. +BasicQiskitTestCase = QiskitTestCase diff --git a/src/qiskit_qec/test/decorators.py b/src/qiskit_qec/test/decorators.py new file mode 100644 index 00000000..2f1ed064 --- /dev/null +++ b/src/qiskit_qec/test/decorators.py @@ -0,0 +1,300 @@ +# 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. + + +"""Decorator for using with Qiskit unit tests.""" + +import collections.abc +import functools +import os +import socket +from typing import Union, Callable, Type, Iterable +import unittest + +from qiskit.utils import wrap_method, optionals +from .testing_options import get_test_options + +HAS_NET_CONNECTION = None + + +def _has_connection(hostname, port): + """Checks if internet connection exists to host via specified port. + + If any exception is raised while trying to open a socket this will return + false. + + Args: + hostname (str): Hostname to connect to. + port (int): Port to connect to + + Returns: + bool: Has connection or not + + """ + try: + host = socket.gethostbyname(hostname) + socket.create_connection((host, port), 2).close() + return True + except Exception: # pylint: disable=broad-except + return False + + +def is_aer_provider_available(): + """Check if the C++ simulator can be instantiated. + + Returns: + bool: True if simulator executable is available + """ + return bool(optionals.HAS_AER) + + +def requires_aer_provider(test_item): + """Decorator that skips test if qiskit aer provider is not available + + Args: + test_item (callable): function or class to be decorated. + + Returns: + callable: the decorated function. + """ + reason = "Aer provider not found, skipping test" + return unittest.skipIf(not is_aer_provider_available(), reason)(test_item) + + +def slow_test(func): + """Decorator that signals that the test takes minutes to run. + + Args: + func (callable): test function to be decorated. + + Returns: + callable: the decorated function. + """ + + @functools.wraps(func) + def _wrapper(*args, **kwargs): + skip_slow = not TEST_OPTIONS["run_slow"] + if skip_slow: + raise unittest.SkipTest("Skipping slow tests") + + return func(*args, **kwargs) + + return _wrapper + + +def _get_credentials(): + """Finds the credentials for a specific test and options. + + Returns: + Credentials: set of credentials + + Raises: + SkipTest: when credentials can't be found + """ + try: + from qiskit.providers.ibmq.credentials import Credentials, discover_credentials + except ImportError as ex: + raise unittest.SkipTest( + "qiskit-ibmq-provider could not be found, " + "and is required for executing online tests. " + 'To install, run "pip install qiskit-ibmq-provider" ' + "or check your installation." + ) from ex + + if os.getenv("IBMQ_TOKEN") and os.getenv("IBMQ_URL"): + return Credentials(os.getenv("IBMQ_TOKEN"), os.getenv("IBMQ_URL")) + elif os.getenv("QISKIT_TESTS_USE_CREDENTIALS_FILE"): + # Attempt to read the standard credentials. + discovered_credentials = discover_credentials() + + if discovered_credentials: + # Decide which credentials to use for testing. + if len(discovered_credentials) > 1: + raise unittest.SkipTest( + "More than 1 credential set found, use: " + "IBMQ_TOKEN and IBMQ_URL env variables to " + "set credentials explicitly" + ) + + # Use the first available credentials. + return list(discovered_credentials.values())[0] + raise unittest.SkipTest( + "No IBMQ credentials found for running the test. This is required for running online tests." + ) + + +def online_test(func): + """Decorator that signals that the test uses the network (and the online API): + + It involves: + * determines if the test should be skipped by checking environment + variables. + * if the `USE_ALTERNATE_ENV_CREDENTIALS` environment variable is + set, it reads the credentials from an alternative set of environment + variables. + * if the test is not skipped, it reads `qe_token` and `qe_url` from + `Qconfig.py`, environment variables or qiskitrc. + * if the test is not skipped, it appends `qe_token` and `qe_url` as + arguments to the test function. + + Args: + func (callable): test function to be decorated. + + Returns: + callable: the decorated function. + """ + + @functools.wraps(func) + def _wrapper(self, *args, **kwargs): + # To avoid checking the connection in each test + global HAS_NET_CONNECTION # pylint: disable=global-statement + + if TEST_OPTIONS["skip_online"]: + raise unittest.SkipTest("Skipping online tests") + + if HAS_NET_CONNECTION is None: + HAS_NET_CONNECTION = _has_connection("qiskit.org", 443) + + if not HAS_NET_CONNECTION: + raise unittest.SkipTest("Test requires internet connection.") + + credentials = _get_credentials() + self.using_ibmq_credentials = credentials.is_ibmq() + kwargs.update({"qe_token": credentials.token, "qe_url": credentials.url}) + + return func(self, *args, **kwargs) + + return _wrapper + + +def enforce_subclasses_call( + methods: Union[str, Iterable[str]], attr: str = "_enforce_subclasses_call_cache" +) -> Callable[[Type], Type]: + """Class decorator which enforces that if any subclasses define on of the ``methods``, they must + call ``super().()`` or face a ``ValueError`` at runtime. + + This is unlikely to be useful for concrete test classes, who are not normally subclassed. It + should not be used on user-facing code, because it prevents subclasses from being free to + override parent-class behavior, even when the parent-class behavior is not needed. + + This adds behavior to the ``__init__`` and ``__init_subclass__`` methods of the class, in + addition to the named methods of this class and all subclasses. The checks could be averted in + grandchildren if a child class overrides ``__init_subclass__`` without up-calling the decorated + class's method, though this would typically break inheritance principles. + + Arguments: + methods: + Names of the methods to add the enforcement to. These do not necessarily need to be + defined in the class body, provided they are somewhere in the method-resolution tree. + + attr: + The attribute which will be added to all instances of this class and subclasses, in + order to manage the call enforcement. This can be changed to avoid clashes. + + Returns: + A decorator, which returns its input class with the class with the relevant methods modified + to include checks, and injection code in the ``__init_subclass__`` method. + """ + + methods = {methods} if isinstance(methods, str) else set(methods) + + def initialize_call_memory(self, *_args, **_kwargs): + """Add the extra attribute used for tracking the method calls.""" + setattr(self, attr, set()) + + def save_call_status(name): + """Decorator, whose return saves the fact that the top-level method call occurred.""" + + def out(self, *_args, **_kwargs): + getattr(self, attr).add(name) + + return out + + def clear_call_status(name): + """Decorator, whose return clears the call status of the method ``name``. This prepares the + call tracking for the child class's method call.""" + + def out(self, *_args, **_kwargs): + getattr(self, attr).discard(name) + + return out + + def enforce_call_occurred(name): + """Decorator, whose return checks that the top-level method call occurred, and raises + ``ValueError`` if not. Concretely, this is an assertion that ``save_call_status`` ran.""" + + def out(self, *_args, **_kwargs): + cache = getattr(self, attr) + if name not in cache: + classname = self.__name__ if isinstance(self, type) else type(self).__name__ + raise ValueError( + f"Parent '{name}' method was not called by '{classname}.{name}'." + f" Ensure you have put in calls to 'super().{name}()'." + ) + + return out + + def wrap_subclass_methods(cls): + """Wrap all the ``methods`` of ``cls`` with the call-tracking assertions that the top-level + versions of the methods were called (likely via ``super()``).""" + # Only wrap methods who are directly defined in this class; if we're resolving to a method + # higher up the food chain, then it will already have been wrapped. + for name in set(cls.__dict__) & methods: + wrap_method( + cls, + name, + before=clear_call_status(name), + after=enforce_call_occurred(name), + ) + + def decorator(cls): + # Add a class-level memory on, so class methods will work as well. Instances will override + # this on instantiation, to keep the "namespace" of class- and instance-methods separate. + initialize_call_memory(cls) + # Do the extra bits after the main body of __init__ so we can check we're not overwriting + # anything, and after __init_subclass__ in case the decorated class wants to influence the + # creation of the subclass's methods before we get to them. + wrap_method(cls, "__init__", after=initialize_call_memory) + for name in methods: + wrap_method(cls, name, before=save_call_status(name)) + wrap_method(cls, "__init_subclass__", after=wrap_subclass_methods) + return cls + + return decorator + + +class _TestOptions(collections.abc.Mapping): + """Lazy-loading view onto the test options retrieved from the environment.""" + + __slots__ = ("_options",) + + def __init__(self): + self._options = None + + def _load(self): + if self._options is None: + self._options = get_test_options() + + def __getitem__(self, key): + self._load() + return self._options[key] + + def __iter__(self): + self._load() + return iter(self._options) + + def __len__(self): + self._load() + return len(self._options) + + +TEST_OPTIONS = _TestOptions() diff --git a/src/qiskit_qec/test/ibmq_mock.py b/src/qiskit_qec/test/ibmq_mock.py new file mode 100644 index 00000000..73b30f4f --- /dev/null +++ b/src/qiskit_qec/test/ibmq_mock.py @@ -0,0 +1,45 @@ +# 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. + +"""Mock functions for qiskit.IBMQ.""" + +from unittest.mock import MagicMock +import qiskit +from qiskit.providers import fake_provider as backend_mocks + + +def mock_get_backend(backend): + """Replace qiskit.IBMQ with a mock that returns a single backend. + + Note this will set the value of qiskit.IBMQ to a MagicMock object. It is + intended to be run as part of docstrings with jupyter-example in a hidden + cell so that later examples which rely on ibmq devices so that the docs can + be built without requiring configured credentials. If used outside of this + context be aware that you will have to manually restore qiskit.IBMQ the + value to qiskit.providers.ibmq.IBMQ after you finish using your mock. + + Args: + backend (str): The class name as a string for the fake device to + return from the mock IBMQ object. For example, FakeVigo. + Raises: + NameError: If the specified value of backend + """ + mock_ibmq = MagicMock() + mock_provider = MagicMock() + if not hasattr(backend_mocks, backend): + raise NameError( + "The specified backend name is not a valid mock from qiskit.providers.fake_provider." + ) + fake_backend = getattr(backend_mocks, backend)() + mock_provider.get_backend.return_value = fake_backend + mock_ibmq.get_provider.return_value = mock_provider + qiskit.IBMQ = mock_ibmq diff --git a/src/qiskit_qec/test/mock/__init__.py b/src/qiskit_qec/test/mock/__init__.py new file mode 100644 index 00000000..41cca129 --- /dev/null +++ b/src/qiskit_qec/test/mock/__init__.py @@ -0,0 +1,40 @@ +# 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. +""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed in Qiskit 1.0. " + "Instead, you should import the desired object directly 'qiskit.providers.fake_provider'.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/__init__.py b/src/qiskit_qec/test/mock/backends/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/almaden/__init__.py b/src/qiskit_qec/test/mock/backends/almaden/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/almaden/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/armonk/__init__.py b/src/qiskit_qec/test/mock/backends/armonk/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/armonk/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/athens/__init__.py b/src/qiskit_qec/test/mock/backends/athens/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/athens/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/belem/__init__.py b/src/qiskit_qec/test/mock/backends/belem/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/belem/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/boeblingen/__init__.py b/src/qiskit_qec/test/mock/backends/boeblingen/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/boeblingen/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/bogota/__init__.py b/src/qiskit_qec/test/mock/backends/bogota/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/bogota/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/brooklyn/__init__.py b/src/qiskit_qec/test/mock/backends/brooklyn/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/brooklyn/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/burlington/__init__.py b/src/qiskit_qec/test/mock/backends/burlington/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/burlington/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/cairo/__init__.py b/src/qiskit_qec/test/mock/backends/cairo/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/cairo/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/cambridge/__init__.py b/src/qiskit_qec/test/mock/backends/cambridge/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/cambridge/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/casablanca/__init__.py b/src/qiskit_qec/test/mock/backends/casablanca/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/casablanca/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/essex/__init__.py b/src/qiskit_qec/test/mock/backends/essex/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/essex/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/guadalupe/__init__.py b/src/qiskit_qec/test/mock/backends/guadalupe/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/guadalupe/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/hanoi/__init__.py b/src/qiskit_qec/test/mock/backends/hanoi/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/hanoi/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/jakarta/__init__.py b/src/qiskit_qec/test/mock/backends/jakarta/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/jakarta/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/johannesburg/__init__.py b/src/qiskit_qec/test/mock/backends/johannesburg/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/johannesburg/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/kolkata/__init__.py b/src/qiskit_qec/test/mock/backends/kolkata/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/kolkata/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/lagos/__init__.py b/src/qiskit_qec/test/mock/backends/lagos/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/lagos/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/lima/__init__.py b/src/qiskit_qec/test/mock/backends/lima/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/lima/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/london/__init__.py b/src/qiskit_qec/test/mock/backends/london/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/london/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/manhattan/__init__.py b/src/qiskit_qec/test/mock/backends/manhattan/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/manhattan/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/manila/__init__.py b/src/qiskit_qec/test/mock/backends/manila/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/manila/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/melbourne/__init__.py b/src/qiskit_qec/test/mock/backends/melbourne/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/melbourne/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/montreal/__init__.py b/src/qiskit_qec/test/mock/backends/montreal/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/montreal/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/mumbai/__init__.py b/src/qiskit_qec/test/mock/backends/mumbai/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/mumbai/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/nairobi/__init__.py b/src/qiskit_qec/test/mock/backends/nairobi/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/nairobi/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/ourense/__init__.py b/src/qiskit_qec/test/mock/backends/ourense/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/ourense/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/paris/__init__.py b/src/qiskit_qec/test/mock/backends/paris/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/paris/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/poughkeepsie/__init__.py b/src/qiskit_qec/test/mock/backends/poughkeepsie/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/poughkeepsie/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/quito/__init__.py b/src/qiskit_qec/test/mock/backends/quito/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/quito/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/rochester/__init__.py b/src/qiskit_qec/test/mock/backends/rochester/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/rochester/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/rome/__init__.py b/src/qiskit_qec/test/mock/backends/rome/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/rome/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/rueschlikon/__init__.py b/src/qiskit_qec/test/mock/backends/rueschlikon/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/rueschlikon/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/santiago/__init__.py b/src/qiskit_qec/test/mock/backends/santiago/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/santiago/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/singapore/__init__.py b/src/qiskit_qec/test/mock/backends/singapore/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/singapore/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/sydney/__init__.py b/src/qiskit_qec/test/mock/backends/sydney/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/sydney/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/tenerife/__init__.py b/src/qiskit_qec/test/mock/backends/tenerife/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/tenerife/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/tokyo/__init__.py b/src/qiskit_qec/test/mock/backends/tokyo/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/tokyo/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/toronto/__init__.py b/src/qiskit_qec/test/mock/backends/toronto/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/toronto/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/valencia/__init__.py b/src/qiskit_qec/test/mock/backends/valencia/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/valencia/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/vigo/__init__.py b/src/qiskit_qec/test/mock/backends/vigo/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/vigo/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/washington/__init__.py b/src/qiskit_qec/test/mock/backends/washington/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/washington/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/mock/backends/yorktown/__init__.py b/src/qiskit_qec/test/mock/backends/yorktown/__init__.py new file mode 100644 index 00000000..7682c117 --- /dev/null +++ b/src/qiskit_qec/test/mock/backends/yorktown/__init__.py @@ -0,0 +1,32 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2022. +# +# 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. + +"""Deprecation warnings for moved functionality.""" + +import warnings + +import qiskit.providers.fake_provider + + +def __getattr__(name): + if name.startswith("_"): + # Some Python components (including tests) do funny things with dunders. + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + warnings.warn( + f"The module '{__name__}' is deprecated since " + "Qiskit Terra 0.21.0, and will be removed 3 months or more later. " + "Instead, you should import from `qiskit.providers.fake_provider` directly.", + category=DeprecationWarning, + stacklevel=2, + ) + return getattr(qiskit.providers.fake_provider, name) diff --git a/src/qiskit_qec/test/providers/__init__.py b/src/qiskit_qec/test/providers/__init__.py new file mode 100644 index 00000000..73c3a1da --- /dev/null +++ b/src/qiskit_qec/test/providers/__init__.py @@ -0,0 +1,16 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2017, 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 TestCases for provider and backends.""" + +from .backend import BackendTestCase +from .provider import ProviderTestCase diff --git a/src/qiskit_qec/test/providers/backend.py b/src/qiskit_qec/test/providers/backend.py new file mode 100644 index 00000000..b836339a --- /dev/null +++ b/src/qiskit_qec/test/providers/backend.py @@ -0,0 +1,80 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2017, 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 TestCase for testing backends.""" + +import warnings +from unittest import SkipTest + +from qiskit import transpile +from ..base import QiskitTestCase +from ..reference_circuits import ReferenceCircuits + + +class BackendTestCase(QiskitTestCase): + """Test case for backends. + + Implementers of backends are encouraged to subclass and customize this + TestCase, as it contains a "canonical" series of tests in order to ensure + the backend functionality matches the specifications. + + Members: + backend_cls (BaseBackend): backend to be used in this test case. Its + instantiation can be further customized by overriding the + ``_get_backend`` function. + circuit (QuantumCircuit): circuit to be used for the tests. + """ + + backend_cls = None + circuit = ReferenceCircuits.bell() + + def setUp(self): + super().setUp() + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=DeprecationWarning, message=r".*basicaer.*") + self.backend = self._get_backend() + + @classmethod + def setUpClass(cls): + if cls is BackendTestCase: + raise SkipTest("Skipping base class tests") + super().setUpClass() + + def _get_backend(self): + """Return an instance of a Provider.""" + return self.backend_cls() # pylint: disable=not-callable + + def test_configuration(self): + """Test backend.configuration().""" + configuration = self.backend.configuration() + return configuration + + def test_properties(self): + """Test backend.properties().""" + properties = self.backend.properties() + if self.backend.configuration().simulator: + self.assertEqual(properties, None) + return properties + + def test_status(self): + """Test backend.status().""" + status = self.backend.status() + return status + + def test_run_circuit(self): + """Test running a single circuit.""" + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=DeprecationWarning, message=r".*basicaer.*") + job = self.backend.run(transpile(self.circuit, self.backend)) + result = job.result() + self.assertEqual(result.success, True) + return result diff --git a/src/qiskit_qec/test/providers/provider.py b/src/qiskit_qec/test/providers/provider.py new file mode 100644 index 00000000..1f1cb0ed --- /dev/null +++ b/src/qiskit_qec/test/providers/provider.py @@ -0,0 +1,61 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2017, 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 TestCase for testing Providers.""" +import warnings +from unittest import SkipTest + +from ..base import QiskitTestCase + + +class ProviderTestCase(QiskitTestCase): + """Test case for Providers. + + Implementers of providers are encouraged to subclass and customize this + TestCase, as it contains a "canonical" series of tests in order to ensure + the provider functionality matches the specifications. + + Members: + provider_cls (BaseProvider): provider to be used in this test case. Its + instantiation can be further customized by overriding the + ``_get_provider`` function. + backend_name (str): name of a backend provided by the provider. + """ + + provider_cls = None + backend_name = "" + + def setUp(self): + super().setUp() + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=DeprecationWarning, message=r".*BasicAer.*") + self.provider = self._get_provider() + + @classmethod + def setUpClass(cls): + if cls is ProviderTestCase: + raise SkipTest("Skipping base class tests") + super().setUpClass() + + def _get_provider(self): + """Return an instance of a Provider.""" + return self.provider_cls() # pylint: disable=not-callable + + def test_backends(self): + """Test the provider has backends.""" + backends = self.provider.backends() + self.assertTrue(len(backends) > 0) + + def test_get_backend(self): + """Test getting a backend from the provider.""" + backend = self.provider.get_backend(name=self.backend_name) + self.assertEqual(backend.name(), self.backend_name) diff --git a/src/qiskit_qec/test/reference_circuits.py b/src/qiskit_qec/test/reference_circuits.py new file mode 100644 index 00000000..8b94dfa8 --- /dev/null +++ b/src/qiskit_qec/test/reference_circuits.py @@ -0,0 +1,41 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2017, 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. + +"""Reference circuits used by the tests.""" + +from qiskit.circuit import QuantumCircuit, QuantumRegister, ClassicalRegister + + +class ReferenceCircuits: + """Container for reference circuits used by the tests.""" + + @staticmethod + def bell(): + """Return a Bell circuit.""" + qr = QuantumRegister(2, name="qr") + cr = ClassicalRegister(2, name="qc") + qc = QuantumCircuit(qr, cr, name="bell") + qc.h(qr[0]) + qc.cx(qr[0], qr[1]) + qc.measure(qr, cr) + + return qc + + @staticmethod + def bell_no_measure(): + """Return a Bell circuit.""" + qr = QuantumRegister(2, name="qr") + qc = QuantumCircuit(qr, name="bell_no_measure") + qc.h(qr[0]) + qc.cx(qr[0], qr[1]) + + return qc diff --git a/src/qiskit_qec/test/testing_options.py b/src/qiskit_qec/test/testing_options.py new file mode 100644 index 00000000..0ecd8bee --- /dev/null +++ b/src/qiskit_qec/test/testing_options.py @@ -0,0 +1,93 @@ +# 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. + +"""Obtain and set the options in QISKIT_TESTS, used for running the tests.""" + +import os +import logging + +logger = logging.getLogger(__name__) + + +def get_test_options(option_var="QISKIT_TESTS"): + """Read option_var from env and returns a dict in which the test options are set. + + Args: + option_var (str): The env var to read. Default: 'QISKIT_TESTS' + + Returns: + dict: A dictionary with the format {