Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for suppressing warnings in NoiseModel.from_backend() #792

Merged
merged 4 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions qiskit/providers/aer/noise/device/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def basic_device_gate_errors(properties,
gate_lengths=None,
gate_length_units='ns',
temperature=0,
standard_gates=True):
standard_gates=True,
warnings=True):
"""
Return QuantumErrors derived from a devices BackendProperties.

Expand All @@ -82,6 +83,7 @@ def basic_device_gate_errors(properties,
standard_gates (bool): If true return errors as standard
qobj gates. If false return as unitary
qobj instructions (Default: True).
warnings (bool): Display warnings (Default: True).

Returns:
list: A list of tuples ``(label, qubits, QuantumError)``, for gates
Expand Down Expand Up @@ -134,7 +136,7 @@ def basic_device_gate_errors(properties,
# Get depolarizing error channel
if gate_error:
depol_error = _device_depolarizing_error(
qubits, error_param, relax_error, standard_gates)
qubits, error_param, relax_error, standard_gates, warnings=warnings)

# Combine errors
if depol_error is None and relax_error is None:
Expand All @@ -157,7 +159,8 @@ def basic_device_gate_errors(properties,
def _device_depolarizing_error(qubits,
error_param,
relax_error=None,
standard_gates=True):
standard_gates=True,
warnings=True):
"""Construct a depolarizing_error for device"""

# We now deduce the depolarizing channel error parameter in the
Expand Down Expand Up @@ -191,21 +194,23 @@ 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:
logger.warning(
'Device reported a gate error parameter greater'
' than maximum allowed value (%f > %f). Truncating to'
' maximum value.', 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)
dim = 2 ** num_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:
logger.warning(
'Device model returned a depolarizing error parameter greater'
' than maximum allowed value (%f > %f). Truncating to'
' maximum value.', 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)
Expand Down
11 changes: 7 additions & 4 deletions qiskit/providers/aer/noise/noise_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ def from_backend(cls, backend,
temperature=0,
gate_lengths=None,
gate_length_units='ns',
standard_gates=True):
standard_gates=True,
warnings=True):
"""Return a noise model derived from a devices backend properties.

This function generates a noise model based on:
Expand Down Expand Up @@ -259,6 +260,7 @@ def from_backend(cls, backend,
standard_gates (bool): If true return errors as standard
qobj gates. If false return as unitary
qobj instructions (Default: True)
warnings (bool): Display warnings (Default: True).

Returns:
NoiseModel: An approximate noise model for the device backend.
Expand All @@ -281,7 +283,7 @@ def from_backend(cls, backend,
# Add single-qubit readout errors
if readout_error:
for qubits, error in basic_device_readout_errors(properties):
noise_model.add_readout_error(error, qubits)
noise_model.add_readout_error(error, qubits, warnings=warnings)

# Add gate errors
gate_errors = basic_device_gate_errors(
Expand All @@ -291,9 +293,10 @@ def from_backend(cls, backend,
gate_lengths=gate_lengths,
gate_length_units=gate_length_units,
temperature=temperature,
standard_gates=standard_gates)
standard_gates=standard_gates,
warnings=warnings)
for name, qubits, error in gate_errors:
noise_model.add_quantum_error(error, name, qubits)
noise_model.add_quantum_error(error, name, qubits, warnings=warnings)
return noise_model

def __repr__(self):
Expand Down