Qiskit Runtime local testing mode
このページはまだ翻訳されていません。英語の原文を表示しています。
Package versions
The code on this page was developed using the following requirements. We recommend using these versions or newer.
qiskit[all]~=2.3.0
qiskit-ibm-runtime~=0.43.1
qiskit-aer~=0.17
Use local testing mode (available with qiskit-ibm-runtime v0.22.0 or later) to test programs before fine-tuning them and sending them to real quantum hardware. After using local testing mode to verify your program, all you need to change is the backend name to run it on a QPU.
To use local testing mode, specify one of the fake backends from qiskit_ibm_runtime.fake_provider or specify a Qiskit Aer backend when instantiating a Qiskit Runtime primitive or a session.
-
Fake backends: The fake backends in
qiskit_ibm_runtime.fake_providermimic the behaviors of IBM® QPUs by using QPU snapshots. The QPU snapshots contain important information about the QPU, such as the coupling map, basis gates, and qubit properties, which are useful for testing the transpiler and performing noisy simulations of the QPU. The noise model from the snapshot is automatically applied during simulation. -
Aer simulator: Simulators from Qiskit Aer provide higher-performance simulation that can handle larger circuits and custom noise models. A list of simulation method options are available when you use
AerSimulatorin local testing mode. See the Clifford simulation mode example, which demonstrates how to efficiently simulate Clifford circuits with a large number of qubits.List of simulation methods available from Qiskit Aer
See the
AerSimulatordocumentation for more information.-
"automatic": Default simulation method. Select the simulation method automatically, based on the circuit and noise model. -
"statevector": A dense statevector simulation that can sample measurement outcomes from ideal circuits with all measurements at the end of the circuit. For noisy simulations, each shot samples a randomly sampled noisy circuit from the noise model. -
"density_matrix": A density matrix simulation that can sample measurement outcomes from noisy circuits with all measurements at the end of the circuit. -
"stabilizer": An efficient Clifford stabilizer state simulator that can simulate noisy Clifford circuits if all errors in the noise model are also Clifford errors. -
"extended_stabilizer": An approximate simulator for Clifford + T circuits based on decomposing the state into a ranked-stabilizer state. The number of terms grows with the number of non-Clifford (T) gates. -
"matrix_product_state": A tensor-network statevector simulator that uses a Matrix Product State (MPS) representation for the state. This can be done with or without truncating the MPS bond dimensions, depending on the simulator options. The default behavior is no truncation. -
"unitary": A dense unitary matrix simulation of an ideal circuit. This simulates the unitary matrix of the circuit itself, rather than the evolution of an initial quantum state. This method can only simulate gates; it does not support measurement, reset, or noise. -
"superop": A dense superoperator matrix simulation of an ideal or noisy circuit. This simulates the superoperator matrix of the circuit itself, rather than the evolution of an initial quantum state. This method can simulate ideal and noisy gates and resets, but it does not support measurements. -
"tensor_network": A tensor-network-based simulation that supports both statevector and density matrix. Currently this is only available for GPU and is accelerated by using cuQuantumcuTensorNetAPIs.
-
- You can specify all Qiskit Runtime options in local testing mode. However, all options except shots are ignored when run on a local simulator.
- It is recommended that you install Qiskit Aer before using fake backends or Aer simulators by running
pip install qiskit-aer. The fake backends use Aer simulators under the cover if available, to take advantage of their performance.
Fake backends example
from qiskit.circuit import QuantumCircuit
from qiskit.transpiler import generate_preset_pass_manager
from qiskit_ibm_runtime import SamplerV2 as Sampler
from qiskit_ibm_runtime.fake_provider import FakeManilaV2
# Bell Circuit
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.measure_all()
# Run the sampler job locally using FakeManilaV2
fake_manila = FakeManilaV2()
pm = generate_preset_pass_manager(backend=fake_manila, optimization_level=1)
isa_qc = pm.run(qc)
# You can use a fixed seed to get fixed results.
options = {"simulator": {"seed_simulator": 42}}
sampler = Sampler(mode=fake_manila, options=options)
result = sampler.run([isa_qc]).result()