diff --git a/docs/api/migration-guides/local-simulators.mdx b/docs/api/migration-guides/local-simulators.mdx index 21eb9ab11c4..b99ed0becb4 100644 --- a/docs/api/migration-guides/local-simulators.mdx +++ b/docs/api/migration-guides/local-simulators.mdx @@ -5,7 +5,7 @@ description: Migrate from using the IBM Quantum cloud simulators to using Qiskit # Migrate from cloud simulators to local simulators -In quantum computing, the choice between using simulators and quantum hardware is crucial for making progress in the field. While simulators are useful for testing and debugging, in this era of quantum utility, quantum development and industry advancement requires actual hardware. As part of the move to quantum utility, IBM Quantum™ will retire its cloud simulators on 15 May 2024. This guide explains in more detail why this is happening, and how to migrate from [cloud based simulators](/verify/cloud-based-simulators), such as `ibmq_qasm_simulator`, to local simulators. +In quantum computing, the choice between using simulators and quantum hardware is crucial for making progress in the field. While simulators are useful for testing and debugging, in this era of quantum utility, quantum development and industry advancement requires actual hardware. As part of the move to quantum utility, IBM Quantum™ cloud simulators were retired on 15 May 2024. This guide explains the retirement in more detail, and how to migrate from cloud-based simulators, such as `ibmq_qasm_simulator`, to local simulators. ## Why are the cloud simulators being retired? diff --git a/docs/api/migration-guides/qiskit-algorithms-module.mdx b/docs/api/migration-guides/qiskit-algorithms-module.mdx index 8ed24f8e037..08cac1da759 100644 --- a/docs/api/migration-guides/qiskit-algorithms-module.mdx +++ b/docs/api/migration-guides/qiskit-algorithms-module.mdx @@ -6,23 +6,23 @@ description: How to update your code to use the new interface for `qiskit.algori # Algorithms migration guide In Qiskit 0.44 and later releases, the `qiskit.algorithms` module has been superseded by a new standalone library, `qiskit_algorithms`, - available on [GitHub](https://github.com/qiskit-community/qiskit-algorithms) and + available on [GitHub](https://github.com/qiskit-community/qiskit-algorithms) and [PyPi](https://pypi.org/project/qiskit-algorithms). The `qiskit.algorithms` module was migrated to a separate package in order to clarify the purpose of Qiskit and make a distinction between the tools and libraries built on top of it. If your code used `qiskit.algorithms`, follow these steps: 1. Check your code for any uses of the `qiskit.algorithms` module. If you are, follow this guide to migrate to the primitives-based implementation. - 2. After updating your code, run `pip install qiskit-algorithms` and update your imports from + 2. After updating your code, run `pip install qiskit-algorithms` and update your imports from `qiskit.algorithms` to `qiskit_algorithms`. - + ## Background The [`qiskit.algorithms`](../qiskit/0.46/algorithms) module was originally built on top of the [`qiskit.opflow`](../qiskit/0.46/opflow) library and the [`qiskit.utils.QuantumInstance`](../qiskit/0.46/qiskit.utils.QuantumInstance) utility. The development of the [`qiskit.primitives`](../qiskit/primitives) -introduced a higher-level execution paradigm, with the `Estimator` for computing expectation values for observables, and `Sampler` for executing circuits and returning probability distributions. These tools allowed the [`qiskit.algorithms`](../qiskit/0.46/algorithms) module to be refactored, after which, +introduced a higher-level execution paradigm, with the `Estimator` for computing expectation values for observables, and `Sampler` for executing circuits and returning probability distributions. These tools allowed the [`qiskit.algorithms`](../qiskit/0.46/algorithms) module to be refactored, after which, [`qiskit.opflow`](../qiskit/0.46/opflow) and [`qiskit.utils.QuantumInstance`](../qiskit/0.46/qiskit.utils.QuantumInstance) were deprecated. @@ -65,7 +65,7 @@ There have been three types of refactoring: - [Phase Estimators](#phase-estimators) 3. Algorithms that were deprecated and are now removed entirely from [`qiskit.algorithms`](../qiskit/0.46/algorithms). These are algorithms that do not serve - as building blocks for applications and are only valuable for education, as described in the following tutorials: + as building blocks for applications and are only valuable for education, as described in the following tutorials: - [Linear Solvers (HHL)](https://github.com/Qiskit/textbook/blob/main/notebooks/ch-applications/hhl_tutorial.ipynb) , - [Factorizers (Shor)](https://github.com/Qiskit/textbook/blob/main/notebooks/ch-algorithms/shor.ipynb) @@ -157,7 +157,7 @@ estimator = Estimator() ## Minimum Eigensolvers -The minimum eigensolver algorithms were refactored in a new location. +The minimum eigensolver algorithms were refactored in a new location. Instead of a [`qiskit.utils.QuantumInstance`](../qiskit/0.46/qiskit.utils.QuantumInstance), [`qiskit.algorithms.minimum_eigensolvers`](../qiskit/0.46/qiskit.algorithms.minimum_eigensolvers) are now initialized by using an instance of the [`qiskit.primitives.Sampler`](../qiskit/qiskit.primitives.Sampler) or [`qiskit.primitives.Estimator`](../qiskit/qiskit.primitives.Estimator) primitive, depending on the algorithm. The legacy classes can still be found in `qiskit.algorithms.minimum_eigen_solvers`. @@ -332,7 +332,7 @@ For complete code examples, see the following updated tutorials: ### QAOA -The new QAOA only supports diagonal operators. This is because the legacy `qiskit.algorithms.minimum_eigen_solvers.QAOA` class extended +The new QAOA only supports diagonal operators. This is because the legacy `qiskit.algorithms.minimum_eigen_solvers.QAOA` class extended `qiskit.algorithms.minimum_eigen_solvers.VQE`, but now, [`qiskit.algorithms.minimum_eigensolvers.QAOA`](../qiskit/0.46/qiskit.algorithms.minimum_eigensolvers.QAOA) extends [`qiskit.algorithms.minimum_eigensolvers.SamplingVQE`](../qiskit/0.46/qiskit.algorithms.minimum_eigensolvers.SamplingVQE). @@ -471,7 +471,7 @@ For complete code examples, see the updated [VQE, callback, gradients, initial p ## Eigensolvers -The eigensolver algorithms were refactored in a new location. Instead of using +The eigensolver algorithms were refactored in a new location. Instead of using [`qiskit.utils.QuantumInstance`](../qiskit/0.46/qiskit.utils.QuantumInstance), [`qiskit.algorithms.eigensolvers`](../qiskit/0.46/qiskit.algorithms.eigensolvers) are now initialized using an instance of the [`qiskit.primitives.Sampler`](../qiskit/qiskit.primitives.Sampler) or [`qiskit.primitives.Estimator`](../qiskit/qiskit.primitives.Estimator) primitive, or a primitive-based subroutine, depending on the algorithm. The legacy classes can still be found @@ -559,9 +559,9 @@ ansatz = TwoLocal(3, rotation_blocks=["ry", "rz"], entanglement_blocks="cz", rep optimizer = SLSQP(maxiter=10) hamiltonian = SparsePauliOp.from_list([("XXZ", 1), ("XYI", 1)]) -# example executing in cloud simulator +# example executing on a physical system service = QiskitRuntimeService(channel="ibm_quantum") -backend = service.backend("ibmq_qasm_simulator") +backend = service.backend("ibm_sherbrooke") with Session(service=service, backend=backend) as session: estimator = Estimator() @@ -633,7 +633,7 @@ Instead of using a [`qiskit.utils.QuantumInstance`](../qiskit/0.46/qiskit.utils. using a [`qiskit.primitives.Estimator`](../qiskit/qiskit.primitives.Estimator) primitive instance. The legacy classes can still be found in `qiskit.algorithms.evolvers`. -In addition to the migration, the module has been substantially expanded to include Variational Quantum Time Evolution +In addition to the migration, the module has been substantially expanded to include Variational Quantum Time Evolution (`qiskit.algorithms.time_evolvers.VarQTE`) solvers. ### TrotterQRTE @@ -724,12 +724,12 @@ q: ┤ exp(it X) ├┤ exp(it Z) ├ ## Amplitude amplifiers -The amplitude amplifier algorithms were refactored in-place. +The amplitude amplifier algorithms were refactored in-place. Instead of a [`qiskit.utils.QuantumInstance`](../qiskit/0.46/qiskit.utils.QuantumInstance), `qiskit.algorithms.amplitude_amplifiers` are now initialized using an instance of any `Sampler` primitive. That is, [`qiskit.primitives.Sampler`](../qiskit/qiskit.primitives.Sampler). - The full `qiskit.algorithms.amplitude_amplifiers` module has been refactored in place. Therefore, you don't need to + The full `qiskit.algorithms.amplitude_amplifiers` module has been refactored in place. Therefore, you don't need to change import paths. @@ -763,12 +763,12 @@ For complete code examples, see the following updated tutorials: ## Amplitude estimators -Similarly to the amplitude amplifiers, the amplitude estimators were refactored in-place. +Similarly to the amplitude amplifiers, the amplitude estimators were refactored in-place. Instead of a [`qiskit.utils.QuantumInstance`](../qiskit/0.46/qiskit.utils.QuantumInstance), `qiskit.algorithms.amplitude_estimators` are now initialized using an instance of any `Sampler` primitive. That is, [`qiskit.primitives.Sampler`](../qiskit/qiskit.primitives.Sampler). - The full `qiskit.algorithms.amplitude_estimators` module has been refactored in place. You do not need to + The full `qiskit.algorithms.amplitude_estimators` module has been refactored in place. You do not need to change import paths. @@ -807,7 +807,7 @@ For a complete code example, see the updated [Amplitude Estimation tutorial.](ht ## Phase estimators The phase estimators were refactored in-place. -Instead of a [`qiskit.utils.QuantumInstance`](../qiskit/0.46/qiskit.utils.QuantumInstance), `qiskit.algorithms.phase_estimators` are now initialized by +Instead of a [`qiskit.utils.QuantumInstance`](../qiskit/0.46/qiskit.utils.QuantumInstance), `qiskit.algorithms.phase_estimators` are now initialized by using an instance of any `Sampler` primitive. That is, [`qiskit.primitives.Sampler`](../qiskit/qiskit.primitives.Sampler). diff --git a/docs/api/migration-guides/qiskit-runtime-examples.mdx b/docs/api/migration-guides/qiskit-runtime-examples.mdx index 166d2e16c99..5a35dfab840 100644 --- a/docs/api/migration-guides/qiskit-runtime-examples.mdx +++ b/docs/api/migration-guides/qiskit-runtime-examples.mdx @@ -506,6 +506,5 @@ to the following: - [Primitive execution options API reference](../qiskit-ibm-runtime/qiskit_ibm_runtime.options.Options) - [How to run a session](../../run/run-jobs-in-session) - [Qiskit Runtime local testing mode](../../verify/local-testing-mode) -- [Noisy simulators in Qiskit Runtime](../../verify/using-ibm-quantum-simulators) diff --git a/docs/verify/_toc.json b/docs/verify/_toc.json index 67fb5946f7b..3b91ad58202 100644 --- a/docs/verify/_toc.json +++ b/docs/verify/_toc.json @@ -29,19 +29,6 @@ { "title": "Efficient simulation of stabilizer circuits with Qiskit Aer primitives", "url": "/verify/stabilizer-circuit-simulation" - }, - { - "title": "IBM Quantum cloud-based simulators", - "children": [ - { - "title": "Using IBM Quantum cloud-based simulators", - "url": "/verify/using-ibm-quantum-simulators" - }, - { - "title": "Available IBM Quantum simulators", - "url": "/verify/cloud-based-simulators" - } - ] } ] } \ No newline at end of file diff --git a/docs/verify/cloud-based-simulators.mdx b/docs/verify/cloud-based-simulators.mdx deleted file mode 100644 index 3b075019d30..00000000000 --- a/docs/verify/cloud-based-simulators.mdx +++ /dev/null @@ -1,175 +0,0 @@ ---- -title: Available IBM Quantum simulators -description: Overview of available IBM Quantum cloud-based simulators ---- -# Available IBM Quantum simulators - - -IBM Quantum™ will retire its cloud simulators on 15 May 2024. Instead, you can use local simulators through [Qiskit Runtime primitives](local-testing-mode), [Qiskit Aer primitives](simulate-with-qiskit-aer), or [Qiskit reference primitives](simulate-with-qiskit-primitives). See [Migrate to local simulators](/api/migration-guides/local-simulators) for full details. - - -IBM Quantum features a collection of high-performance simulators for prototyping quantum circuits and algorithms. - -To view available simulators, on the upper right corner of the screen, click the Application switcher ( ![Application switcher icon](/images/migration/switcher-small2.png) ), select **Compute resources** to view the [Compute resources page,](https://quantum.ibm.com/services/resources?services=simulators) then click All simulators. - -The following simulation methods support a maximum of 300 circuits and 8192 shots per job. Find more information on each simulator below, including its type, a description, the number of qubits it simulates, whether it includes noise modeling, a list of supported gates, and how to call it using Qiskit Runtime. The `simulator_statevector` is a good default choice since it is a general-purpose solution method. - - - To prevent the simulators from processing jobs that would otherwise not finish processing in a reasonable amount of time, jobs sent to the simulators are limited to run times under 10,000 seconds (\~2.75 hours). - - -## Statevector simulator - -**Type:** Schrödinger wavefunction - -**Name:** simulator\_statevector - -Simulates a quantum circuit by computing the wavefunction of the qubit’s statevector as gates and instructions are applied. Supports general noise modeling. - -**Qubits:** 32 - -**Noise modeling:** Yes - -**Supported gates / instructions** - -```python -['u1', 'u2', 'u3', 'u', 'p', 'r', 'rx', 'ry', 'rz', 'id', -'x', 'y', 'z', 'h', 's', 'sdg', 'sx', 't', 'tdg', 'swap', -'cx', 'cy', 'cz', 'csx', 'cp', 'cu1', 'cu2', 'cu3', 'rxx', -'ryy', 'rzz', 'rzx', 'ccx', 'cswap', 'mcx', 'mcy', 'mcz', -'mcsx', 'mcp', 'mcu1', 'mcu2', 'mcu3', 'mcrx', 'mcry', -'mcrz', 'mcr', 'mcswap', 'unitary', 'diagonal', -'multiplexer', 'initialize', 'kraus', 'roerror', 'delay'] -``` - -**Code example** - -```python -from qiskit_ibm_runtime import QiskitRuntimeService -service = QiskitRuntimeService() -backend = service.get_backend("simulator_statevector") -``` - -## Stabilizer simulator - -**Type:** Clifford - -**Name:** simulator\_stabilizer - -An efficient simulator of Clifford circuits. Can simulate noisy evolution if the noise operators are also Clifford gates. - -**Qubits:** 5000 - -**Noise modeling:** Yes (Clifford only) - -**Supported gates / instructions** - -```python -['cx', 'cy', 'cz', 'id', 'x', 'y', 'z', 'h', -'s', 'sdg', 'sx', 'swap', 'delay', 'roerror'] -``` - -**Code example** - -```python -from qiskit_ibm_runtime import QiskitRuntimeService -service = QiskitRuntimeService() -backend = service.get_backend("simulator_stabilizer") -``` - -## Extended stabilizer simulator - -**Type:** Extended Clifford (e.g., Clifford+T) - -**Name:** simulator\_extended\_stabilizer - -Approximates the action of a quantum circuit using a ranked-stabilizer decomposition. The number of non-Clifford gates determines the number of stabilizer terms. - -**Qubits:** 63 - -**Noise modeling:** No - -**Supported gates / instructions** - -```python -['u0', 'u1', 'cx', 'cz', 'id', 'x', 'y', 'z', 'h', -'t', 'tdg', 's', 'sdg', 'sx', 'swap', 'p', 'ccx', 'ccz', -'delay', 'roerror'] -``` - -**Code example** - -```python -from qiskit_ibm_runtime import QiskitRuntimeService -service = QiskitRuntimeService() -backend = service.get_backend("simulator_extended_stabilizer") -``` - -## MPS simulator - -**Type:** Matrix Product State - -**Name:** simulator\_mps - -A tensor-network simulator that uses a Matrix Product State (MPS) representation for states. This representation is often more efficient for states with weak entanglement. - -**Qubits:** 100 - -**Noise modeling:** No - -**Supported gates / instructions** - -```python -['unitary', 't', 'tdg', 'id', 'cp', 'u1', 'u2', 'u3', 'u', -'cx', 'cz', 'x', 'y', 'z', 'h', 's', 'sdg', 'sx', 'swap', -'p', 'ccx', 'delay', 'roerror'] -``` - -**Code example** - -```python -from qiskit_ibm_runtime import QiskitRuntimeService -service = QiskitRuntimeService() -backend = service.get_backend("simulator_mps") -``` - -## QASM simulator - -**Type:** General, context-aware - -**Name:** ibmq\_qasm\_simulator - -A general-purpose simulator for simulating quantum circuits both ideally and subject to noise modeling. The simulation method is automatically selected based on the input circuits and parameters. - -**Qubits:** 32 - -**Noise modeling:** Yes - -**Supported gates / instructions** - -```python -['u1', 'u2', 'u3', 'u', 'p', 'r', 'rx', 'ry', 'rz', 'id', -'x', 'y', 'z', 'h', 's', 'sdg', 'sx', 't', 'tdg', 'swap', -'cx', 'cy', 'cz', 'csx', 'cp', 'cu1', 'cu2', 'cu3', 'rxx', -'ryy', 'rzz', 'rzx', 'ccx', 'cswap', 'mcx', 'mcy', 'mcz', -'mcsx', 'mcp', 'mcu1', 'mcu2', 'mcu3', 'mcrx', 'mcry', -'mcrz', 'mcr', 'mcswap', 'unitary', 'diagonal', -'multiplexer', 'initialize', 'kraus', 'roerror', 'delay'] -``` - -**Code example** - -```python -from qiskit_ibm_runtime import QiskitRuntimeService -service = QiskitRuntimeService() -backend = service.get_backend("ibmq_qasm_simulator") -``` - - Qiskit built-in simulator, see the [Python-based simulators API](/api/qiskit/providers_basic_provider) reference. - - ## Next steps - - - - Learn about simulators built into Qiskit in the [Python-based simulators API](/api/qiskit/providers_basic_provider) reference. - - Discover available systems in the [System information](../run/system-information) topic. - \ No newline at end of file diff --git a/docs/verify/using-ibm-quantum-simulators.mdx b/docs/verify/using-ibm-quantum-simulators.mdx deleted file mode 100644 index bb10be678f3..00000000000 --- a/docs/verify/using-ibm-quantum-simulators.mdx +++ /dev/null @@ -1,327 +0,0 @@ ---- -title: Using IBM Quantum cloud-based simulators -description: Set up ibmq_qasm_simulator and map a basic noise model for an IBM Quantum hardware device in Qiskit Runtime. - ---- - -# Using IBM Quantum cloud-based simulators - -Set up ``ibmq_qasm_simulator`` and map a basic noise model for an IBM Quantum™ hardware device in Qiskit Runtime, then use this noise model to perform noisy simulations of ``QuantumCircuits`` by using ``Sampler`` and ``Estimator`` to study the effects of errors that occur on real devices. - - -IBM Quantum™ will retire its cloud simulators on 15 May 2024. Instead, you can use local simulators through [Qiskit Runtime primitives](local-testing-mode), [Qiskit Aer primitives](simulate-with-qiskit-aer), or [Qiskit reference primitives](simulate-with-qiskit-primitives). See [Migrate to local simulators](/api/migration-guides/local-simulators) for full details. - - -## Set up your local development environment - -If you haven’t already set up a Qiskit Runtime service instance, follow the steps in [Install and set up](../start/install) to do so. - -``` python -# load necessary Runtime libraries -from qiskit_ibm_runtime import QiskitRuntimeService, Sampler, Estimator, Session, Options - -service = QiskitRuntimeService() -``` - -## Prepare the environment - -First, we run an example routine. One of the major benefits of using primitives is simplification of binding multiple parameters in parameterized circuits. To illustrate this, we start with is an example circuit with a controlled [P-gate](/api/qiskit/qiskit.circuit.library.PhaseGate) as implemented in the following code. Here, we parameterize the ``P-gate`` with a rotation parameter ``theta``. - -``` python -from qiskit.circuit import Parameter -from qiskit import QuantumCircuit - -theta = Parameter('theta') - -qc = QuantumCircuit(2,1) -qc.x(1) -qc.h(0) -qc.cp(theta,0,1) -qc.h(0) -qc.measure(0,0) - -qc.draw('mpl', style="iqp") -``` - -![](/images/qiskit-ibm-runtime/noisy-sim-circuit.png) - -The circuit shown previously is parameterized and the eigenvalue is put back into qubit 0 to be measured. The eigenvalue's rotation is determined by the parameter theta. Next, we define the circuit's parameters as a list. The parameters in this example range from $0$ to $2\pi$, divided over 50 evenly spaced points. - -``` python -import numpy as np - -phases = np.linspace(0, 2*np.pi, 50) - -# phases need to be expressed as a list of lists -individual_phases = [[phase] for phase in phases] -``` -## Running on the ideal simulator - -### Set the backend and options to use - - -Our first run assumes an ideal case, without any ``noise_model``, ``optimization_level`` or ``resilience_level`` for both Sampler and Estimator. We will define the options in the following code: - -``` python -backend = "ibmq_qasm_simulator" # use the simulator -``` - -``` python -options = Options() -options.simulator.seed_simulator = 42 -options.execution.shots = 1000 -options.optimization_level = 0 # no optimization -options.resilience_level = 0 # no error mitigation -``` -### Run the circuits on Sampler - -Next, we use the Sampler primitive to sample the circuit and get the resultant quasi-probability distribution. Visit the [Get started with Sampler](../run/primitives-get-started#get-started-with-sampler) section for more information about the Sampler primitive. - -``` python -sampler = Sampler(options=options, backend=backend) -job = sampler.run( - circuits=[qc]*len(phases), - parameter_values=individual_phases -) -result = job.result() -``` - -``` python -import matplotlib.pyplot as plt - -# the probablity of being in the 1 state for each of these values -prob_values = [dist.get(1, 0) for dist in result.quasi_dists] - -plt.plot(phases, prob_values, 'o', label='Simulator') -plt.plot(phases, np.sin(phases/2,)**2, label='Theory') -plt.xlabel('Phase') -plt.ylabel('Probability') -plt.legend() -``` - -``` - -``` - -![This image shows that the value found by the simulator is very close to the theoretical value.](/images/qiskit-ibm-runtime/noisy-sim-sampler-ideal.png "Simulated versus theoretical value") - -### Run the circuits on Estimator - -Visit the [Get started with Estimator](../run/primitives-get-started#get-started-with-estimator) section for more information on the Estimator primitive. - -The Estimator binds single-qubit rotations to get Hamiltonians before it returns expectation values of quantum operators. Therefore, the circuit doesn’t require any measurements. Currently the circuit ``qc`` has measurements, so we will remove these with ``remove_final_measurements``. - -``` python -qc_no_meas = qc.remove_final_measurements(inplace=False) -qc_no_meas.draw('mpl', style="iqp") -``` - -![](/images/qiskit-ibm-runtime/noisy-sim-estimator-circuit.png) - -``` python - -from qiskit.quantum_info import SparsePauliOp - -ZZ = SparsePauliOp.from_list([("ZZ", 1)]) -print(f" > Observable: {ZZ.paulis}") -``` - -``` -> Observable: ['ZZ'] -``` - -With this observable, the expectation value is calculated by the -following equation. - -$$ \langle ZZ\rangle =\langle \psi | ZZ | \psi\rangle=\langle \psi|(|0\rangle\langle 0| -|1\rangle\langle 1|)\otimes(|0\rangle\langle 0| - |1\rangle\langle 1|) |\psi\rangle =|\langle 00|\psi\rangle|^2 - |\langle 01 | \psi\rangle|^2 - |\langle 10 | \psi\rangle|^2 + |\langle 11|\psi\rangle|^2$$ - -The following code implements the expectation value equation. - -``` python -with Session(service=service, backend=backend): - estimator = Estimator(options=options) - job = estimator.run( - circuits=[qc_no_meas]*len(phases), - parameter_values=individual_phases, - observables=[ZZ]*len(phases) - ) - result = job.result() -``` -``` python -exp_values = result.values - -plt.plot(phases, exp_values, 'o', label='Simulator') -plt.plot(phases, 2*np.sin(phases/2)**2-1, label='Theory') -plt.xlabel('Phase') -plt.ylabel('Expectation') -plt.legend() -``` - - - -``` - -``` - -![This image shows that the value found by the simulator is very close to the theoretical value.](/images/qiskit-ibm-runtime/noisy-sim-estimator-ideal.png "Simulated versus theoretical values") - -## Running a noisy simulation - -Now we’ll set up our simulator to run a noisy simulation rather than the ideal one. We can pass a custom ``noise_model`` to the Qiskit Runtime simulator by specifying it in the ``Options`` parameter. Here we will try to mimic a real backend by using the ``noise_model`` from a ``FakeBackend`` class. The noise model can be extracted from the ``FakeBackend`` and passed as a ``simulator`` parameter in options. For more details, visit the [Fake Provider](/api/qiskit/providers_fake_provider) documentation in the Qiskit Terra API reference. - -Since we are trying to mimic a real backend, we can also pass in the backend topology's ``coupling_map`` and its supported ``basis_gates`` to have a more realistic noisy simulation. - -``` python -from qiskit.providers.fake_provider import FakeManila -from qiskit_aer.noise import NoiseModel - -# Make a noise model -fake_backend = FakeManila() -noise_model = NoiseModel.from_backend(fake_backend) - -# Set options to include the noise model -options = Options() -options.simulator = { - "noise_model": noise_model, - "basis_gates": fake_backend.configuration().basis_gates, - "coupling_map": fake_backend.configuration().coupling_map, - "seed_simulator": 42 -} - -# Set number of shots, optimization_level and resilience_level -options.execution.shots = 1000 -options.optimization_level = 0 -options.resilience_level = 0 -``` - -The ``ibmq_qasm_simulator`` allows for the activation of the ``resilience_levels`` offered by the Qiskit Runtime service, and use of these levels on simulators is best demonstrated using the noisy simulation as we have described previously. - -To illustrate the comparison, we will define two set of ``Options``. Here, ``options`` is set to ``resilience level = 0`` to represent a normal run without error mitigation, and ``options with em`` is set to ``resilience level = 1`` to represent a run with error mitigation enabled. - -``` python -# Set options to include the noise model with error mitigation -options_with_em = Options() -options_with_em.simulator = { - "noise_model": noise_model, - "basis_gates": fake_backend.configuration().basis_gates, - "coupling_map": fake_backend.configuration().coupling_map, - "seed_simulator": 42 -} - -# Set number of shots, optimization_level and resilience_level -options_with_em.execution.shots = 1000 -options_with_em.optimization_level = 0 # no optimization -options_with_em.resilience_level = 1 # M3 for Sampler and T-REx for Estimator -``` - -When you set the ``resilience_level`` to 1, M3 is activated in Sampler. -All available resilience level configurations are described on the [Configure error mitigation](../run/configure-error-mitigation) page. - -``` python -with Session(service=service, backend=backend): - # include the noise model without M3 - sampler = Sampler(options=options) - job = sampler.run( - circuits=[qc]*len(phases), - parameter_values=individual_phases - ) - result = job.result() - prob_values = [1-dist[0] for dist in result.quasi_dists] - - # include the noise model with M3 - sampler = Sampler(options=options_with_em) - job = sampler.run( - circuits=[qc]*len(phases), - parameter_values=individual_phases - ) - result = job.result() - prob_values_with_em = [1-dist[0] for dist in result.quasi_dists] -``` -``` python -plt.plot(phases, prob_values, 'o', label='Noisy') -plt.plot(phases, prob_values_with_em, 'o', label='Mitigated') -plt.plot(phases, np.sin(phases/2,)**2, label='Theory') -plt.xlabel('Phase') -plt.ylabel('Probability') -plt.legend() -``` - -``` - -``` - -![This image shows that the value found by a "noisy" simulator is not very close to the theoretical value, but the approximation is better when mitigated by using M3.](/images/qiskit-ibm-runtime/noisy-sim-sampler-noisy.png "Noisy and mitigated (M3) values versus theoretical values") - -``T-REx`` is triggered in Estimator when the resilience level is set to -1. - -``` python -with Session(service=service, backend=backend): - # include the noise model without T-REx - estimator = Estimator(options=options) - job = estimator.run( - circuits=[qc_no_meas]*len(phases), - parameter_values=individual_phases, - observables=[ZZ]*len(phases) - ) - result = job.result() - exp_values = result.values - - # include the noise model with T-REx - estimator = Estimator(options=options_with_em) - job = estimator.run( - circuits=[qc_no_meas]*len(phases), - parameter_values=individual_phases, - observables=[ZZ]*len(phases)) - result = job.result() - exp_values_with_em = result.values -``` -``` python -plt.plot(phases, exp_values, 'o', label='Noisy') -plt.plot(phases, exp_values_with_em, 'o', label='Mitigated') -plt.plot(phases, 2*np.sin(phases/2)**2-1, label='Theory') -plt.xlabel('Phase') -plt.ylabel('Expectation') -plt.legend() -``` - - - -``` - -``` - - - -![This image shows that the value found by a "noisy" simulator is not very close to the theoretical value, but the approximation is better when mitigated by using T-REX.](/images/qiskit-ibm-runtime/noisy-sim-estimator-noisy.png "Noisy and mitigated (T-REX) values versus theoretical values") - -Resilience levels are currently in beta so sampling overhead and -solution quality will vary from circuit to circuit. New features, -advanced options, and management tools will be released on a rolling -basis. You can also test out higher levels of resilience and -explore the additional options they offer. For more information -about activating features like `Digital-ZNE` and `PEC`, in addition to `M3` and `T-REx` as shown in the previous examples, see the [Error suppression and error mitigation with Qiskit Runtime](https://learning.quantum.ibm.com/tutorial/error-suppression-and-error-mitigation-with-qiskit-runtime) tutorial. - -``` python -import qiskit_ibm_runtime -qiskit_ibm_runtime.version.get_version_info() -``` - - - -``` -'0.8.0' -``` - - -``` python -from qiskit.tools.jupyter import * -%qiskit_version_table -``` - -## Next steps - - - - Learn about Qiskit Runtime error mitigation in [Exact and noisy simulation with Qiskit Aer primitives](../run/configure-error-mitigation). - - Explore error mitigation options in the [Cost Functions](https://learning.quantum.ibm.com/course/variational-algorithm-design/cost-functions) course. - \ No newline at end of file diff --git a/qiskit_bot.yaml b/qiskit_bot.yaml index e6644fe2b0e..0101f80a3f1 100644 --- a/qiskit_bot.yaml +++ b/qiskit_bot.yaml @@ -137,9 +137,6 @@ notifications: - "`@kevinsung`" "docs/verify/stabilizer-circuit-simulation": - "`@kevinsung`" - "docs/verify/cloud-based-simulators": - - "@abbycross" - - "@beckykd" # run "docs/run/index": - "@javabster"