Skip to content

Commit de0dc51

Browse files
authored
Fix regression in scars tutorial: properly use noiseless backend when NO_NOISE=True (#2982)
* Fix regression in scars tutorial: properly use noiseless backend when NO_NOISE=True The ibmq_executor_full function was always using the noisy backend, ignoring the NO_NOISE flag. When NO_NOISE=True, the ideal Trotter curve should be computed on backend_noiseless, not backend. Also add warnings.filterwarnings to suppress UserWarnings that appear during execution on the stable docs page. Fixes #2973 * Simplify: use exec_backend instead of inline conditional Resolves review comment by natestemen
1 parent 154bf1b commit de0dc51

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

docs/source/examples/quantum_simulation_scars_ibmq.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ kernelspec:
1414
```{tags} qiskit, zne, advanced
1515
```
1616

17+
```{code-cell} ipython3
18+
import warnings
19+
warnings.filterwarnings("ignore", category=UserWarning)
20+
```
21+
1722
```{code-cell} ipython3
1823
import qiskit
1924
from qiskit import QuantumCircuit
@@ -188,9 +193,12 @@ def ibmq_executor_full(circuit: qiskit.QuantumCircuit,
188193
shots: Number of times to execute the circuit to compute
189194
the expectation value.
190195
"""
196+
# Select the appropriate backend based on noise flag
197+
exec_backend = backend_noiseless if NO_NOISE else backend
198+
191199
# Transpile the circuit so it can be properly run
192200
pm = generate_preset_pass_manager(
193-
backend=backend,
201+
backend=exec_backend,
194202
optimization_level=0,
195203
basis_gates=noise_model.basis_gates if noise_model else None,
196204
)
@@ -200,8 +208,8 @@ def ibmq_executor_full(circuit: qiskit.QuantumCircuit,
200208
if not isinstance(exec_circuit, list):
201209
exec_circuit = [exec_circuit]
202210
203-
# Run the circuit
204-
sampler = Sampler(backend)
211+
# Run the circuit on the selected backend
212+
sampler = Sampler(exec_backend)
205213
job = sampler.run(exec_circuit, shots=shots)
206214
207215
# Convert from raw measurement counts to the expectation value

0 commit comments

Comments
 (0)