Source code for qiskit_experiments.library.randomized_benchmarking.rb_utils
# This code is part of Qiskit.## (C) Copyright IBM 2019-2021.## 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.## 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."""RB Helper functions"""importnumpyasnp
[docs]classRBUtils:"""A collection of utility functions for computing additional data from randomized benchmarking experiments"""
[docs]@staticmethoddefcoherence_limit(nQ=2,T1_list=None,T2_list=None,gatelen=0.1):""" The error per gate (1-average_gate_fidelity) given by the T1,T2 limit. Args: nQ (int): Number of qubits (1 and 2 supported). T1_list (list): List of T1's (Q1,...,Qn). T2_list (list): List of T2's (as measured, not Tphi). If not given assume T2=2*T1 . gatelen (float): Length of the gate. Returns: float: coherence limited error per gate. Raises: ValueError: If there are invalid inputs """# pylint: disable = invalid-nameT1=np.array(T1_list)ifT2_listisNone:T2=2*T1else:T2=np.array(T2_list)iflen(T1)!=nQorlen(T2)!=nQ:raiseValueError("T1 and/or T2 not the right length")coherence_limit_err=0ifnQ==1:coherence_limit_err=0.5*(1.0-2.0/3.0*np.exp(-gatelen/T2[0])-1.0/3.0*np.exp(-gatelen/T1[0]))elifnQ==2:T1factor=0T2factor=0foriinrange(2):T1factor+=1.0/15.0*np.exp(-gatelen/T1[i])T2factor+=(2.0/15.0*(np.exp(-gatelen/T2[i])+np.exp(-gatelen*(1.0/T2[i]+1.0/T1[1-i]))))T1factor+=1.0/15.0*np.exp(-gatelen*np.sum(1/T1))T2factor+=4.0/15.0*np.exp(-gatelen*np.sum(1/T2))coherence_limit_err=0.75*(1.0-T1factor-T2factor)else:raiseValueError("Not a valid number of qubits")returncoherence_limit_err