Source code for pytket.extensions.qiskit.backends.ibmq_emulator
# Copyright Quantinuum## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.fromcollections.abcimportSequencefromtypingimport(TYPE_CHECKING,Optional,)fromqiskit_aer.noise.noise_modelimportNoiseModel# type: ignorefrompytket.backends.backendimportBackendfrompytket.backends.backendinfoimportBackendInfofrompytket.backends.backendresultimportBackendResultfrompytket.backends.resulthandleimportResultHandle,_ResultIdTuplefrompytket.backends.statusimportCircuitStatusfrompytket.circuitimportCircuitfrompytket.passesimportBasePassfrompytket.predicatesimportPredicatefrompytket.utils.resultsimportKwargTypesfrom.aerimportAerBackendfrom.ibmimportIBMQBackendifTYPE_CHECKING:fromcollectionsimportCounterfromqiskit_ibm_runtimeimportQiskitRuntimeService# type: ignore
[docs]classIBMQEmulatorBackend(Backend):"""A backend which uses the AerBackend to loaclly emulate the behaviour of IBMQBackend. Identical to :py:class:`IBMQBackend` except there is no `monitor` parameter. Performs the same compilation and predicate checks as IBMQBackend. Requires a valid IBM account. """_supports_shots=False_supports_counts=True_supports_contextual_optimisation=True_persistent_handles=False_supports_expectation=False
[docs]def__init__(self,backend_name:str,instance:Optional[str]=None,service:Optional["QiskitRuntimeService"]=None,token:Optional[str]=None,use_fractional_gates:bool=False,):super().__init__()self._ibmq=IBMQBackend(backend_name=backend_name,instance=instance,service=service,token=token,use_fractional_gates=use_fractional_gates,)# Get noise model:self._noise_model=NoiseModel.from_backend(self._ibmq._backend)# Construct AerBackend based on noise model:self._aer=AerBackend(noise_model=self._noise_model)# cache of results keyed by job id and circuit indexself._ibm_res_cache:dict[tuple[str,int],Counter]=dict()
[docs]defdefault_compilation_pass(self,optimisation_level:int=2,)->BasePass:""" See documentation for :py:meth:`IBMQBackend.default_compilation_pass`. """returnself._ibmq.default_compilation_pass(optimisation_level=optimisation_level)