mirror of https://github.com/Qiskit/qiskit-aer.git
Remove verbose warnings on parameter truncations when creating noise model from backend (#1639)
This commit removes warnings about a noise model from a backend to report un-physical device parameters (such as T2 > 2*T1 due to statistical errors in their estimation). These warnings are not actionable (so useless) for users in the sense that there are no means other than truncating them to the theoretical bounds as done within noise.device module. * Fix 1631 by removing warnings on parameter truncations * Add release note * Remove one more case printing useless warnings Co-authored-by: Hiroshi Horii <hhorii@users.noreply.github.com>
This commit is contained in:
parent
d13c2a516e
commit
d304233f58
|
@ -141,7 +141,7 @@ def basic_device_gate_errors(properties,
|
|||
warnings = True
|
||||
|
||||
if target is not None:
|
||||
if not standard_gates or not warnings:
|
||||
if standard_gates is not None or not warnings:
|
||||
warn("When `target` is supplied, `standard_gates` and `warnings` are ignored,"
|
||||
" and they are always set to true.", UserWarning)
|
||||
|
||||
|
@ -208,7 +208,7 @@ def basic_device_gate_errors(properties,
|
|||
module="qiskit_aer.noise.errors.errorutils"
|
||||
)
|
||||
depol_error = _device_depolarizing_error(
|
||||
qubits, error_param, relax_error, standard_gates, warnings=warnings)
|
||||
qubits, error_param, relax_error, standard_gates)
|
||||
|
||||
# Combine errors
|
||||
combined_error = _combine_depol_and_relax_error(depol_error, relax_error)
|
||||
|
@ -272,9 +272,9 @@ def _basic_device_target_gate_errors(target,
|
|||
def _device_depolarizing_error(qubits,
|
||||
error_param,
|
||||
relax_error=None,
|
||||
standard_gates=True,
|
||||
warnings=True):
|
||||
"""Construct a depolarizing_error for device"""
|
||||
standard_gates=True):
|
||||
"""Construct a depolarizing_error for device.
|
||||
If un-physical parameters are supplied, they are truncated to the theoretical bound values."""
|
||||
|
||||
# We now deduce the depolarizing channel error parameter in the
|
||||
# presence of T1/T2 thermal relaxation. We assume the gate error
|
||||
|
@ -307,11 +307,6 @@ def _device_depolarizing_error(qubits,
|
|||
# The minimum average gate fidelity is F_min = 1 / (dim + 1)
|
||||
# So the maximum gate error is 1 - F_min = dim / (dim + 1)
|
||||
if error_param > error_max:
|
||||
if warnings:
|
||||
logger.warning(
|
||||
'Device reported a gate error parameter greater'
|
||||
' than maximum allowed value (%f > %f). Truncating to'
|
||||
' maximum value.', error_param, error_max)
|
||||
error_param = error_max
|
||||
# Model gate error entirely as depolarizing error
|
||||
num_qubits = len(qubits)
|
||||
|
@ -319,11 +314,6 @@ def _device_depolarizing_error(qubits,
|
|||
depol_param = dim * (error_param - relax_infid) / (dim * relax_fid - 1)
|
||||
max_param = 4**num_qubits / (4**num_qubits - 1)
|
||||
if depol_param > max_param:
|
||||
if warnings:
|
||||
logger.warning(
|
||||
'Device model returned a depolarizing error parameter greater'
|
||||
' than maximum allowed value (%f > %f). Truncating to'
|
||||
' maximum value.', depol_param, max_param)
|
||||
depol_param = min(depol_param, max_param)
|
||||
return depolarizing_error(
|
||||
depol_param, num_qubits, standard_gates=standard_gates)
|
||||
|
@ -362,9 +352,6 @@ def _truncate_t2_value(t1, t2):
|
|||
new_t2 = t2
|
||||
if t2 > 2 * t1:
|
||||
new_t2 = 2 * t1
|
||||
warn("Device model returned an invalid T_2 relaxation time greater than"
|
||||
f" the theoretical maximum value 2 * T_1 ({t2} > 2 * {t1})."
|
||||
" Truncating to maximum value.", UserWarning)
|
||||
return new_t2
|
||||
|
||||
|
||||
|
|
|
@ -227,11 +227,15 @@ class NoiseModel:
|
|||
|
||||
* Single qubit :class:`ReadoutError` on all measurements.
|
||||
|
||||
The Error error parameters are tuned for each individual qubit based on
|
||||
The error (noise) parameters are tuned for each individual qubit based on
|
||||
the :math:`T_1`, :math:`T_2`, frequency and readout error parameters for
|
||||
each qubit, and the gate error and gate time parameters for each gate
|
||||
obtained from the device backend properties.
|
||||
|
||||
Note that if un-physical parameters are supplied, they are internally truncated to
|
||||
the theoretical bound values. For example, if :math:`T_2 > 2 T_1`, :math:`T_2`
|
||||
parameter will be truncated to :math:`2 T_1`.
|
||||
|
||||
**Additional Information**
|
||||
|
||||
The noise model includes the following errors:
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
fixes:
|
||||
- |
|
||||
Fixes a bug where ``NoiseModel.from_backend()`` prints verbose warnings when
|
||||
supplying a backend that reports un-physical device parameters such as T2 > 2 * T1
|
||||
due to statistical errors in their estimation.
|
||||
This commit removes such warnings because they are not actionable for users in the sense
|
||||
that there are no means other than truncating them to the theoretical bounds as
|
||||
done within ``noise.device`` module.
|
||||
See `Issue 1631 <https://github.com/Qiskit/qiskit-aer/issues/1631>`__
|
||||
for details of the fixed bug.
|
|
@ -15,6 +15,7 @@ NoiseModel class integration tests
|
|||
"""
|
||||
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
import numpy as np
|
||||
from qiskit_aer.backends import AerSimulator
|
||||
|
@ -33,7 +34,7 @@ from qiskit.circuit.library.generalized_gates import PauliGate
|
|||
from qiskit.circuit.library.standard_gates import IGate, XGate
|
||||
from qiskit.compiler import transpile
|
||||
from qiskit.providers.fake_provider import (
|
||||
FakeBackend, FakeAlmaden, FakeLagos, FakeSingapore, FakeMumbai,
|
||||
FakeBackend, FakeAlmaden, FakeLagos, FakeSingapore, FakeMumbai, FakeKolkata,
|
||||
FakeBackendV2, FakeLagosV2
|
||||
)
|
||||
from test.terra.common import QiskitAerTestCase
|
||||
|
@ -244,7 +245,7 @@ class TestNoiseModel(QiskitAerTestCase):
|
|||
|
||||
backend = FakeBackendV2()
|
||||
noise_model = NoiseModel.from_backend(backend)
|
||||
self.assertEquals([0, 1], noise_model.noise_qubits)
|
||||
self.assertEqual([0, 1], noise_model.noise_qubits)
|
||||
circ = transpile(circ, backend, optimization_level=0)
|
||||
result = AerSimulator().run(circ, noise_model=noise_model).result()
|
||||
self.assertTrue(result.success)
|
||||
|
@ -257,13 +258,13 @@ class TestNoiseModel(QiskitAerTestCase):
|
|||
|
||||
backend = FakeLagosV2()
|
||||
noise_model = NoiseModel.from_backend(backend)
|
||||
self.assertEquals([0, 1, 2, 3, 4, 5, 6], noise_model.noise_qubits)
|
||||
self.assertEqual([0, 1, 2, 3, 4, 5, 6], noise_model.noise_qubits)
|
||||
circ = transpile(circ, backend, optimization_level=0)
|
||||
result = AerSimulator().run(circ, noise_model=noise_model).result()
|
||||
self.assertTrue(result.success)
|
||||
|
||||
def test_noise_model_from_invalid_t2_backend(self):
|
||||
"""Test if issue user warning when creating a noise model from invalid t2 backend"""
|
||||
"""Test if silently truncate invalid T2 values when creating a noise model from backend"""
|
||||
from qiskit.providers.models.backendproperties import BackendProperties, Gate, Nduv
|
||||
import datetime
|
||||
|
||||
|
@ -312,7 +313,6 @@ class TestNoiseModel(QiskitAerTestCase):
|
|||
return self._configuration
|
||||
|
||||
backend = InvalidT2Fake1Q()
|
||||
with self.assertWarns(UserWarning):
|
||||
noise_model = NoiseModel.from_backend(backend, gate_error=False)
|
||||
expected = thermal_relaxation_error(
|
||||
t1=t1_ns,
|
||||
|
@ -322,6 +322,15 @@ class TestNoiseModel(QiskitAerTestCase):
|
|||
)
|
||||
self.assertEqual(expected, noise_model._local_quantum_errors["u3"][(0, )])
|
||||
|
||||
def test_create_noise_model_without_user_warnings(self):
|
||||
"""Test if never issue user warnings when creating a noise model from backend.
|
||||
See issue#1631 for the details."""
|
||||
# FakeKolkata has a qubit with T_2 > 2 * T_1
|
||||
with warnings.catch_warnings(record=True) as warns:
|
||||
NoiseModel.from_backend(FakeKolkata())
|
||||
user_warnings = [w for w in warns if issubclass(w.category, UserWarning)]
|
||||
self.assertEqual(len(user_warnings), 0)
|
||||
|
||||
def test_transform_noise(self):
|
||||
org_error = reset_error(0.2)
|
||||
new_error = pauli_error([("I", 0.5), ("Z", 0.5)])
|
||||
|
|
Loading…
Reference in New Issue