2019-04-30 02:56:51 +08:00
|
|
|
# This code is part of Qiskit.
|
|
|
|
#
|
2019-05-01 04:25:19 +08:00
|
|
|
# (C) Copyright IBM 2018, 2019.
|
2019-04-30 02:56:51 +08:00
|
|
|
#
|
|
|
|
# This code is licensed under the Apache License, Version 2.0. You may
|
|
|
|
# obtain a copy of this license in the LICENSE.txt file in the root directory
|
|
|
|
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
|
2018-12-12 03:49:21 +08:00
|
|
|
#
|
2019-04-30 02:56:51 +08:00
|
|
|
# Any modifications or derivative works of this code must retain this
|
|
|
|
# copyright notice, and modified files need to carry a notice indicating
|
|
|
|
# that they have been altered from the originals.
|
2018-12-12 03:49:21 +08:00
|
|
|
|
|
|
|
"""
|
|
|
|
Functions to extract device error parameters from backend properties.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from numpy import inf
|
|
|
|
|
2018-12-14 05:14:31 +08:00
|
|
|
# Time and frequency unit conversions
|
|
|
|
_NANOSECOND_UNITS = {"s": 1e9, "ms": 1e6, "µs": 1e3, "us": 1e3, "ns": 1}
|
|
|
|
_GHZ_UNITS = {"Hz": 1e-9, "KHz": 1e-6, "MHz": 1e-3, "GHz": 1, "THz": 1e3}
|
|
|
|
|
2018-12-12 03:49:21 +08:00
|
|
|
|
2018-12-15 04:54:43 +08:00
|
|
|
def gate_param_values(properties):
|
2019-11-13 03:25:35 +08:00
|
|
|
"""
|
|
|
|
Return parameter error values from a devices BackendProperties.
|
2018-12-15 04:54:43 +08:00
|
|
|
|
|
|
|
Args:
|
|
|
|
properties (BackendProperties): device backend properties
|
|
|
|
|
|
|
|
Returns:
|
2019-11-13 03:25:35 +08:00
|
|
|
list: A list of tuples ``(name, qubits, time, error)``. If gate
|
|
|
|
error or gate_length information is not available ``None``
|
|
|
|
will be returned for value.
|
2018-12-15 04:54:43 +08:00
|
|
|
"""
|
|
|
|
values = []
|
|
|
|
for gate in properties.gates:
|
|
|
|
name = gate.gate
|
|
|
|
qubits = gate.qubits
|
|
|
|
# Check for gate time information
|
2019-09-23 18:22:40 +08:00
|
|
|
gate_length = None # default value
|
|
|
|
time_param = _check_for_item(gate.parameters, "gate_length")
|
2018-12-15 04:54:43 +08:00
|
|
|
if hasattr(time_param, "value"):
|
2019-09-23 18:22:40 +08:00
|
|
|
gate_length = time_param.value
|
2018-12-15 04:54:43 +08:00
|
|
|
if hasattr(time_param, "unit"):
|
|
|
|
# Convert gate time to ns
|
2019-09-23 18:22:40 +08:00
|
|
|
gate_length *= _NANOSECOND_UNITS.get(time_param.unit, 1)
|
2018-12-15 04:54:43 +08:00
|
|
|
# Check for gate error information
|
|
|
|
gate_error = None # default value
|
|
|
|
error_param = _check_for_item(gate.parameters, "gate_error")
|
|
|
|
if hasattr(error_param, "value"):
|
|
|
|
gate_error = error_param.value
|
2019-09-23 18:22:40 +08:00
|
|
|
values.append((name, qubits, gate_length, gate_error))
|
2018-12-15 04:54:43 +08:00
|
|
|
|
|
|
|
return values
|
|
|
|
|
|
|
|
|
2018-12-12 03:49:21 +08:00
|
|
|
def gate_error_values(properties):
|
2019-11-13 03:25:35 +08:00
|
|
|
"""
|
|
|
|
Return gate error values from a devices BackendProperties.
|
2018-12-12 03:49:21 +08:00
|
|
|
|
|
|
|
Args:
|
|
|
|
properties (BackendProperties): device backend properties
|
|
|
|
|
|
|
|
Returns:
|
2019-11-13 03:25:35 +08:00
|
|
|
list: A list of tuples ``(name, qubits, value)``. If gate
|
|
|
|
error information is not available ``None`` will be returned
|
|
|
|
for value.
|
2018-12-12 03:49:21 +08:00
|
|
|
"""
|
|
|
|
values = []
|
|
|
|
for gate in properties.gates:
|
|
|
|
name = gate.gate
|
|
|
|
qubits = gate.qubits
|
2018-12-14 05:14:31 +08:00
|
|
|
value = None # default value
|
|
|
|
params = _check_for_item(gate.parameters, "gate_error")
|
|
|
|
if hasattr(params, "value"):
|
|
|
|
value = params.value
|
2018-12-12 03:49:21 +08:00
|
|
|
values.append((name, qubits, value))
|
|
|
|
return values
|
|
|
|
|
|
|
|
|
2019-09-23 18:22:40 +08:00
|
|
|
def gate_length_values(properties):
|
2019-11-13 03:25:35 +08:00
|
|
|
"""
|
|
|
|
Return gate length values from a devices BackendProperties.
|
2018-12-14 05:14:31 +08:00
|
|
|
|
2018-12-12 03:49:21 +08:00
|
|
|
Args:
|
|
|
|
properties (BackendProperties): device backend properties
|
|
|
|
|
|
|
|
Returns:
|
2019-11-13 03:25:35 +08:00
|
|
|
list: A list of tuples ``(name, qubits, value)``. If gate length
|
|
|
|
information is not available ``None`` will be returned for value.
|
|
|
|
|
|
|
|
Additional Information:
|
|
|
|
Gate length values are returned in nanosecond (ns) units.
|
2018-12-12 03:49:21 +08:00
|
|
|
"""
|
|
|
|
values = []
|
|
|
|
for gate in properties.gates:
|
|
|
|
name = gate.gate
|
|
|
|
qubits = gate.qubits
|
2018-12-14 05:14:31 +08:00
|
|
|
value = None # default value
|
2019-09-23 18:22:40 +08:00
|
|
|
params = _check_for_item(gate.parameters, "gate_length")
|
2018-12-14 05:14:31 +08:00
|
|
|
if hasattr(params, "value"):
|
|
|
|
value = params.value
|
|
|
|
if hasattr(params, "unit"):
|
|
|
|
# Convert gate time to ns
|
|
|
|
value *= _NANOSECOND_UNITS.get(params.unit, 1)
|
2018-12-12 03:49:21 +08:00
|
|
|
values.append((name, qubits, value))
|
|
|
|
return values
|
|
|
|
|
|
|
|
|
|
|
|
def readout_error_values(properties):
|
2019-11-13 03:25:35 +08:00
|
|
|
"""
|
|
|
|
Return readout error values from a devices BackendProperties.
|
2018-12-12 03:49:21 +08:00
|
|
|
|
|
|
|
Args:
|
|
|
|
properties (BackendProperties): device backend properties
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
list: A list of readout error values for qubits. If readout
|
2019-11-13 03:25:35 +08:00
|
|
|
error information is not available None will be returned
|
|
|
|
for value.
|
2018-12-12 03:49:21 +08:00
|
|
|
"""
|
|
|
|
values = []
|
2019-06-06 22:13:55 +08:00
|
|
|
for qubit_props in properties.qubits:
|
2018-12-14 05:14:31 +08:00
|
|
|
value = None # default value
|
2019-10-01 01:13:07 +08:00
|
|
|
|
|
|
|
params_roerror = _check_for_item(qubit_props, "readout_error")
|
|
|
|
params_m1p0 = _check_for_item(qubit_props, "prob_meas1_prep0")
|
|
|
|
params_m0p1 = _check_for_item(qubit_props, "prob_meas0_prep1")
|
|
|
|
|
|
|
|
if hasattr(params_m1p0, "value") and hasattr(params_m0p1, "value"):
|
|
|
|
value = [params_m1p0.value, params_m0p1.value]
|
|
|
|
elif hasattr(params_roerror, "value"):
|
|
|
|
value = [params_roerror.value, params_roerror.value]
|
2018-12-12 03:49:21 +08:00
|
|
|
values.append(value)
|
|
|
|
return values
|
|
|
|
|
|
|
|
|
|
|
|
def thermal_relaxation_values(properties):
|
2019-11-13 03:25:35 +08:00
|
|
|
"""
|
|
|
|
Return T1, T2 and frequency values from a devices BackendProperties.
|
2018-12-14 05:14:31 +08:00
|
|
|
|
2018-12-12 03:49:21 +08:00
|
|
|
Args:
|
|
|
|
properties (BackendProperties): device backend properties
|
|
|
|
|
|
|
|
Returns:
|
2019-11-13 03:25:35 +08:00
|
|
|
list: A list of tuples ``(T1, T2, freq)`` for each qubit in the device.
|
|
|
|
If :math:`T_1`, :math:`T_2`, or frequency cannot be found for qubit a
|
|
|
|
value of ``Numpy.inf`` will be used.
|
|
|
|
|
|
|
|
Additional Information:
|
2022-03-29 16:22:51 +08:00
|
|
|
:math:`T_1` and :math:`T_2` values are returned in nanosecond
|
|
|
|
(ns) units and frequency is returned in gigahertz (GHz) units
|
|
|
|
if ``unit`` for each ``value`` is provided in ``properties``.
|
|
|
|
Otherwise, the raw values (in unknown original units) are returned.
|
2018-12-12 03:49:21 +08:00
|
|
|
"""
|
|
|
|
values = []
|
2019-06-06 22:13:55 +08:00
|
|
|
for qubit_props in properties.qubits:
|
|
|
|
# pylint: disable=invalid-name
|
2018-12-14 05:14:31 +08:00
|
|
|
# Default values
|
|
|
|
t1, t2, freq = inf, inf, inf
|
|
|
|
|
2018-12-12 03:49:21 +08:00
|
|
|
# Get the readout error value
|
2018-12-14 05:14:31 +08:00
|
|
|
t1_params = _check_for_item(qubit_props, "T1")
|
|
|
|
t2_params = _check_for_item(qubit_props, "T2")
|
|
|
|
freq_params = _check_for_item(qubit_props, "frequency")
|
|
|
|
|
|
|
|
# Load values from parameters
|
|
|
|
if hasattr(t1_params, "value"):
|
|
|
|
t1 = t1_params.value
|
|
|
|
if hasattr(t1_params, "unit"):
|
2020-04-20 22:02:55 +08:00
|
|
|
# Convert to nanoseconds
|
|
|
|
t1 *= _NANOSECOND_UNITS.get(t1_params.unit, 1)
|
2018-12-14 05:14:31 +08:00
|
|
|
if hasattr(t2_params, "value"):
|
|
|
|
t2 = t2_params.value
|
|
|
|
if hasattr(t2_params, "unit"):
|
2020-04-20 22:02:55 +08:00
|
|
|
# Convert to nanoseconds
|
|
|
|
t2 *= _NANOSECOND_UNITS.get(t2_params.unit, 1)
|
2020-09-21 14:41:41 +08:00
|
|
|
if hasattr(freq_params, "value"):
|
2018-12-14 05:14:31 +08:00
|
|
|
freq = freq_params.value
|
|
|
|
if hasattr(freq_params, "unit"):
|
|
|
|
# Convert to Gigahertz
|
|
|
|
freq *= _GHZ_UNITS.get(freq_params.unit, 1)
|
|
|
|
|
2018-12-12 03:49:21 +08:00
|
|
|
values.append((t1, t2, freq))
|
|
|
|
return values
|
|
|
|
|
|
|
|
|
|
|
|
def _check_for_item(lst, name):
|
|
|
|
"""Search list for item with given name."""
|
2018-12-14 05:14:31 +08:00
|
|
|
filtered = [item for item in lst if item.name == name]
|
2019-06-06 22:13:55 +08:00
|
|
|
if not filtered:
|
2018-12-12 03:49:21 +08:00
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return filtered[0]
|