Source files: 10
Click here to show/hide file namesSource files:
tools/rpetools.py,
tools/rbtools.py,
tools/basistools.py,
tools/chi2fns.py,
tools/__init__.py,
tools/gatetools.py,
tools/likelihoodfns.py,
tools/matrixtools.py,
tools/jamiolkowski.py,
tools/listtools.py
Clones detected: 23
236 of 1224 lines are duplicates (19.28%)
Parameters
clustering_threshold = 10
distance_threshold = 5
size_threshold = 5
hashing_depth = 1
clusterize_using_hash = False
clusterize_using_dcup = False
Clone # 1
Distance between two fragments = 3
Clone size = 12
Source file "tools/basistools.py" The first line is 602 | Source file "tools/basistools.py" The first line is 805 | |
def gm_to_std_transform_matrix(dimOrBlockDims): _, gateDim, blockDims = _processBlockDims(dimOrBlockDims) gmToStd = _np.zeros((gateDim, gateDim), 'complex') start = 0 for blockDim in blockDims: mxs = gm_matrices(blockDim) assert len(mxs) == (blockDim) ** (2) for j, mx in enumerate(mxs): gmToStd[start:(start) + ((blockDim) ** (2)),(start) + (j)] = mx.flatten() start += (blockDim) ** (2) assert start == gateDim return gmToStd |
def pp_to_std_transform_matrix(dimOrBlockDims): _, gateDim, blockDims = _processBlockDims(dimOrBlockDims) ppToStd = _np.zeros((gateDim, gateDim), 'complex') start = 0 for blockDim in blockDims: mxs = pp_matrices(blockDim) assert len(mxs) == (blockDim) ** (2) for j, mx in enumerate(mxs): ppToStd[start:(start) + ((blockDim) ** (2)),(start) + (j)] = mx.flatten() start += (blockDim) ** (2) assert start == gateDim return ppToStd |
Clone # 2
Distance between two fragments = 4
Clone size = 11
Source file "tools/basistools.py" The first line is 931 | Source file "tools/basistools.py" The first line is 724 | |
if dimOrBlockDims is None: dimOrBlockDims = int(round(_np.sqrt(mxInPauliProdBasis.shape[0]))) assert (dimOrBlockDims) ** (2) == mxInPauliProdBasis.shape[0] |
if dimOrBlockDims is None: dimOrBlockDims = int(round(_np.sqrt(mxInGellMannBasis.shape[0]))) assert (dimOrBlockDims) ** (2) == mxInGellMannBasis.shape[0] |
|
ppToStd = pp_to_std_transform_matrix(dimOrBlockDims) | gmToStd = gm_to_std_transform_matrix(dimOrBlockDims) | |
stdToPP = _np.linalg.inv(ppToStd) | stdToGM = _np.linalg.inv(gmToStd) | |
if (len(mxInPauliProdBasis.shape) == 2) and (mxInPauliProdBasis.shape[0] == mxInPauliProdBasis.shape[1]): return _np.dot(ppToStd, _np.dot(mxInPauliProdBasis, stdToPP)) elif (len(mxInPauliProdBasis.shape) == 1) or ((len(mxInPauliProdBasis.shape) == 2) and (mxInPauliProdBasis.shape[1] == 1)): return _np.dot(ppToStd, mxInPauliProdBasis) else: raise ValueError('Invalid dimension of object - must be 1 or 2, i.e. a vector or matrix') |
if (len(mxInGellMannBasis.shape) == 2) and (mxInGellMannBasis.shape[0] == mxInGellMannBasis.shape[1]): return _np.dot(gmToStd, _np.dot(mxInGellMannBasis, stdToGM)) elif (len(mxInGellMannBasis.shape) == 1) or ((len(mxInGellMannBasis.shape) == 2) and (mxInGellMannBasis.shape[1] == 1)): return _np.dot(gmToStd, mxInGellMannBasis) else: raise ValueError('Invalid dimension of object - must be 1 or 2, i.e. a vector or matrix') |
Clone # 3
Distance between two fragments = 4
Clone size = 11
Source file "tools/basistools.py" The first line is 434 | Source file "tools/basistools.py" The first line is 385 | |
indxMap = [] | indxMap = [] | |
start = 0 | start = 0 | |
for blockDim in blockDims: for i in range(start, (start) + (blockDim)): for j in range(start, (start) + (blockDim)): indxMap.append(((dmDim) * (i)) + (j)) start += blockDim |
for blockDim in blockDims: for i in range(start, (start) + (blockDim)): for j in range(start, (start) + (blockDim)): indxMap.append(((dmDim) * (i)) + (j)) start += blockDim |
|
for i, fi in enumerate(indxMap): for j, fj in enumerate(indxMap): mx[i,j] = mxInStdBasis[fi,fj] |
for i, fi in enumerate(indxMap): for j, fj in enumerate(indxMap): mx[fi,fj] = mxInStdBasis[i,j] |
|
return mx | return mx |
Clone # 4
Distance between two fragments = 1
Clone size = 10
Source file "tools/jamiolkowski.py" The first line is 102 | Source file "tools/jamiolkowski.py" The first line is 161 | |
N = gateMxInStdBasis.shape[0] | N = choiMx.shape[0] | |
dmDim = int(round(_np.sqrt(N))) | dmDim = int(round(_np.sqrt(N))) | |
if choiMxBasis == 'gm': BVec = _bt.gm_matrices(dmDim) elif choiMxBasis == 'std': BVec = _bt.std_matrices(dmDim) elif choiMxBasis == 'pp': BVec = _bt.pp_matrices(dmDim) else: raise ValueError(('Invalid choiMxBasis: %s') % (choiMxBasis)) |
if choiMxBasis == 'gm': BVec = _bt.gm_matrices(dmDim) elif choiMxBasis == 'std': BVec = _bt.std_matrices(dmDim) elif choiMxBasis == 'pp': BVec = _bt.pp_matrices(dmDim) else: raise ValueError(('Invalid choiMxBasis: %s') % (choiMxBasis)) |
|
assert len(BVec) == N | assert len(BVec) == N |
Clone # 5
Distance between two fragments = 1
Clone size = 9
Source file "tools/basistools.py" The first line is 288 | Source file "tools/basistools.py" The first line is 777 | |
def is_integer(x): return bool(abs((x) - (round(x))) < 1e-06) |
def is_integer(x): return bool(abs((x) - (round(x))) < 1e-06) |
|
if type(dimOrBlockDims) != int: if (type(dimOrBlockDims) in (list, tuple)) and (len(dimOrBlockDims) == 1): dimOrBlockDims = dimOrBlockDims[0] else: raise ValueError('Dimension for Pauli tensor product matrices must be an *integer* power of 2') |
if type(dim) != int: if (type(dim) in (list, tuple)) and (len(dim) == 1): dim = dim[0] else: raise ValueError('Dimension for Pauli tensor product matrices must be an *integer* power of 2') |
|
nQubits = _np.log2(dimOrBlockDims) | nQubits = _np.log2(dim) | |
if not is_integer(nQubits): raise ValueError('Dimension for Pauli tensor product matrices must be an integer *power of 2*') |
if not is_integer(nQubits): raise ValueError('Dimension for Pauli tensor product matrices must be an integer *power of 2*') |
Clone # 6
Distance between two fragments = 4
Clone size = 8
Source file "tools/basistools.py" The first line is 1193 | Source file "tools/basistools.py" The first line is 1219 | |
def stdmx_to_ppvec(m): assert (len(m.shape) == 2) and (m.shape[0] == m.shape[1]) dim = m.shape[0] ppMxs = pp_matrices(dim) v = _np.empty(((dim) ** (2), 1)) for i, ppMx in enumerate(ppMxs): v[i,0] = _np.real(_mt.trace(_np.dot(ppMx, m))) return v |
def stdmx_to_gmvec(m): assert (len(m.shape) == 2) and (m.shape[0] == m.shape[1]) dim = m.shape[0] gmMxs = gm_matrices(dim) v = _np.empty(((dim) ** (2), 1)) for i, gmMx in enumerate(gmMxs): v[i,0] = _np.real(_mt.trace(_np.dot(gmMx, m))) return v |
Clone # 7
Distance between two fragments = 4
Clone size = 8
Source file "tools/basistools.py" The first line is 1219 | Source file "tools/basistools.py" The first line is 1246 | |
def stdmx_to_gmvec(m): assert (len(m.shape) == 2) and (m.shape[0] == m.shape[1]) dim = m.shape[0] gmMxs = gm_matrices(dim) v = _np.empty(((dim) ** (2), 1)) for i, gmMx in enumerate(gmMxs): v[i,0] = _np.real(_mt.trace(_np.dot(gmMx, m))) return v |
def stdmx_to_stdvec(m): assert (len(m.shape) == 2) and (m.shape[0] == m.shape[1]) dim = m.shape[0] stdMxs = std_matrices(dim) v = _np.empty(((dim) ** (2), 1)) for i, stdMx in enumerate(stdMxs): v[i,0] = _np.real(_mt.trace(_np.dot(stdMx, m))) return v |
Clone # 8
Distance between two fragments = 4
Clone size = 8
Source file "tools/basistools.py" The first line is 1193 | Source file "tools/basistools.py" The first line is 1246 | |
def stdmx_to_ppvec(m): assert (len(m.shape) == 2) and (m.shape[0] == m.shape[1]) dim = m.shape[0] ppMxs = pp_matrices(dim) v = _np.empty(((dim) ** (2), 1)) for i, ppMx in enumerate(ppMxs): v[i,0] = _np.real(_mt.trace(_np.dot(ppMx, m))) return v |
def stdmx_to_stdvec(m): assert (len(m.shape) == 2) and (m.shape[0] == m.shape[1]) dim = m.shape[0] stdMxs = std_matrices(dim) v = _np.empty(((dim) ** (2), 1)) for i, stdMx in enumerate(stdMxs): v[i,0] = _np.real(_mt.trace(_np.dot(stdMx, m))) return v |
Clone # 9
Distance between two fragments = 4
Clone size = 7
Source file "tools/basistools.py" The first line is 1117 | Source file "tools/basistools.py" The first line is 1143 | |
def ppvec_to_stdmx(v): dim = int(_np.sqrt(len(v))) ppMxs = pp_matrices(dim) ret = _np.zeros((dim, dim), 'complex') for i, ppMx in enumerate(ppMxs): ret += (float(v[i])) * (ppMx) return ret |
def gmvec_to_stdmx(v): dim = int(_np.sqrt(len(v))) gmMxs = gm_matrices(dim) ret = _np.zeros((dim, dim), 'complex') for i, gmMx in enumerate(gmMxs): ret += (float(v[i])) * (gmMx) return ret |
Clone # 10
Distance between two fragments = 4
Clone size = 7
Source file "tools/basistools.py" The first line is 1143 | Source file "tools/basistools.py" The first line is 1167 | |
def gmvec_to_stdmx(v): dim = int(_np.sqrt(len(v))) gmMxs = gm_matrices(dim) ret = _np.zeros((dim, dim), 'complex') for i, gmMx in enumerate(gmMxs): ret += (float(v[i])) * (gmMx) return ret |
def stdvec_to_stdmx(v): dim = int(_np.sqrt(len(v))) stdMxs = std_matrices(dim) ret = _np.zeros((dim, dim), 'complex') for i, stdMx in enumerate(stdMxs): ret += (float(v[i])) * (stdMx) return ret |
Clone # 11
Distance between two fragments = 4
Clone size = 7
Source file "tools/basistools.py" The first line is 1117 | Source file "tools/basistools.py" The first line is 1167 | |
def ppvec_to_stdmx(v): dim = int(_np.sqrt(len(v))) ppMxs = pp_matrices(dim) ret = _np.zeros((dim, dim), 'complex') for i, ppMx in enumerate(ppMxs): ret += (float(v[i])) * (ppMx) return ret |
def stdvec_to_stdmx(v): dim = int(_np.sqrt(len(v))) stdMxs = std_matrices(dim) ret = _np.zeros((dim, dim), 'complex') for i, stdMx in enumerate(stdMxs): ret += (float(v[i])) * (stdMx) return ret |
Clone # 12
Distance between two fragments = 4
Clone size = 6
Source file "tools/rpetools.py" The first line is 320 | Source file "tools/rpetools.py" The first line is 316 | |
try: epsilonTrue = trueGateset.epsilonTrue except: epsilonTrue = extract_epsilon(trueGateset) |
try: alphaTrue = trueGateset.alphaTrue except: alphaTrue = extract_alpha(trueGateset) |
|
try: thetaTrue = trueGateset.thetaTrue except: thetaTrue = extract_theta(trueGateset) |
try: epsilonTrue = trueGateset.epsilonTrue except: epsilonTrue = extract_epsilon(trueGateset) |
Clone # 13
Distance between two fragments = 0
Clone size = 6
Source file "tools/likelihoodfns.py" The first line is 257 | Source file "tools/likelihoodfns.py" The first line is 378 | |
S = ((countVecMx) / (min_p)) - (totalCntVec[None,None:None]) | S = ((countVecMx) / (min_p)) - (totalCntVec[None,None:None]) | |
S2 = ((-0.5) * (countVecMx)) / ((min_p) ** (2)) | S2 = ((-0.5) * (countVecMx)) / ((min_p) ** (2)) | |
v = ((countVecMx) * (_np.log(pos_probs))) - ((totalCntVec[None,None:None]) * (pos_probs)) | v = ((countVecMx) * (_np.log(pos_probs))) - ((totalCntVec[None,None:None]) * (pos_probs)) | |
v = _np.minimum(v, 0) | v = _np.minimum(v, 0) | |
v = _np.where(probs < min_p, ((v) + ((S) * ((probs) - (min_p)))) + ((S2) * (((probs) - (min_p)) ** (2))), v) | v = _np.where(probs < min_p, ((v) + ((S) * ((probs) - (min_p)))) + ((S2) * (((probs) - (min_p)) ** (2))), v) | |
v = _np.where(countVecMx == 0, (-totalCntVec[None,None:None]) * (_np.where(probs >= a, probs, ((((-1.0) / ((3) * ((a) ** (2)))) * ((probs) ** (3))) + (((probs) ** (2)) / (a))) + ((a) / (3.0)))), v) | v = _np.where(countVecMx == 0, (-totalCntVec[None,None:None]) * (_np.where(probs >= a, probs, ((((-1.0) / ((3) * ((a) ** (2)))) * ((probs) ** (3))) + (((probs) ** (2)) / (a))) + ((a) / (3.0)))), v) |
Clone # 14
Distance between two fragments = 0
Clone size = 6
Source file "tools/likelihoodfns.py" The first line is 266 | Source file "tools/likelihoodfns.py" The first line is 395 | |
S = (countVecMx) / (min_p) | S = (countVecMx) / (min_p) | |
S2 = ((-0.5) * (countVecMx)) / ((min_p) ** (2)) | S2 = ((-0.5) * (countVecMx)) / ((min_p) ** (2)) | |
v = (countVecMx) * (_np.log(pos_probs)) | v = (countVecMx) * (_np.log(pos_probs)) | |
v = _np.minimum(v, 0) | v = _np.minimum(v, 0) | |
v = _np.where(probs < min_p, ((v) + ((S) * ((probs) - (min_p)))) + ((S2) * (((probs) - (min_p)) ** (2))), v) | v = _np.where(probs < min_p, ((v) + ((S) * ((probs) - (min_p)))) + ((S2) * (((probs) - (min_p)) ** (2))), v) | |
v = _np.where(countVecMx == 0, 0.0, v) | v = _np.where(countVecMx == 0, 0.0, v) |
Clone # 15
Distance between two fragments = 2
Clone size = 6
Source file "tools/gatetools.py" The first line is 44 | Source file "tools/gatetools.py" The first line is 51 | |
evals, U = _np.linalg.eig(A) | evals, U = _np.linalg.eig(B) | |
if len([ev for ev in evals if abs(ev) > 1e-08]) == 1: ivec = _np.argmax(evals) vec = U[None:None,ivec:(ivec) + (1)] F = _np.dot(_np.conjugate(_np.transpose(vec)), _np.dot(B, vec)).real return F |
if len([ev for ev in evals if abs(ev) > 1e-08]) == 1: ivec = _np.argmax(evals) vec = U[None:None,ivec:(ivec) + (1)] F = _np.dot(_np.conjugate(_np.transpose(vec)), _np.dot(A, vec)).real return F |
Clone # 16
Distance between two fragments = 3
Clone size = 5
Source file "tools/basistools.py" The first line is 875 | Source file "tools/basistools.py" The first line is 669 | |
if dimOrBlockDims is None: dimOrBlockDims = int(round(_np.sqrt(mxInStdBasis.shape[0]))) assert (dimOrBlockDims) ** (2) == mxInStdBasis.shape[0] |
if dimOrBlockDims is None: dimOrBlockDims = int(round(_np.sqrt(mxInStdBasis.shape[0]))) assert (dimOrBlockDims) ** (2) == mxInStdBasis.shape[0] |
|
ppToStd = pp_to_std_transform_matrix(dimOrBlockDims) | gmToStd = gm_to_std_transform_matrix(dimOrBlockDims) | |
stdToPP = _np.linalg.inv(ppToStd) | stdToGM = _np.linalg.inv(gmToStd) |
Clone # 17
Distance between two fragments = 1
Clone size = 5
Source file "tools/basistools.py" The first line is 875 | Source file "tools/basistools.py" The first line is 931 | |
if dimOrBlockDims is None: dimOrBlockDims = int(round(_np.sqrt(mxInStdBasis.shape[0]))) assert (dimOrBlockDims) ** (2) == mxInStdBasis.shape[0] |
if dimOrBlockDims is None: dimOrBlockDims = int(round(_np.sqrt(mxInPauliProdBasis.shape[0]))) assert (dimOrBlockDims) ** (2) == mxInPauliProdBasis.shape[0] |
|
ppToStd = pp_to_std_transform_matrix(dimOrBlockDims) | ppToStd = pp_to_std_transform_matrix(dimOrBlockDims) | |
stdToPP = _np.linalg.inv(ppToStd) | stdToPP = _np.linalg.inv(ppToStd) |
Clone # 18
Distance between two fragments = 4
Clone size = 5
Source file "tools/basistools.py" The first line is 875 | Source file "tools/basistools.py" The first line is 724 | |
if dimOrBlockDims is None: dimOrBlockDims = int(round(_np.sqrt(mxInStdBasis.shape[0]))) assert (dimOrBlockDims) ** (2) == mxInStdBasis.shape[0] |
if dimOrBlockDims is None: dimOrBlockDims = int(round(_np.sqrt(mxInGellMannBasis.shape[0]))) assert (dimOrBlockDims) ** (2) == mxInGellMannBasis.shape[0] |
|
ppToStd = pp_to_std_transform_matrix(dimOrBlockDims) | gmToStd = gm_to_std_transform_matrix(dimOrBlockDims) | |
stdToPP = _np.linalg.inv(ppToStd) | stdToGM = _np.linalg.inv(gmToStd) |
Clone # 19
Distance between two fragments = 4
Clone size = 5
Source file "tools/basistools.py" The first line is 669 | Source file "tools/basistools.py" The first line is 931 | |
if dimOrBlockDims is None: dimOrBlockDims = int(round(_np.sqrt(mxInStdBasis.shape[0]))) assert (dimOrBlockDims) ** (2) == mxInStdBasis.shape[0] |
if dimOrBlockDims is None: dimOrBlockDims = int(round(_np.sqrt(mxInPauliProdBasis.shape[0]))) assert (dimOrBlockDims) ** (2) == mxInPauliProdBasis.shape[0] |
|
gmToStd = gm_to_std_transform_matrix(dimOrBlockDims) | ppToStd = pp_to_std_transform_matrix(dimOrBlockDims) | |
stdToGM = _np.linalg.inv(gmToStd) | stdToPP = _np.linalg.inv(ppToStd) |
Clone # 20
Distance between two fragments = 1
Clone size = 5
Source file "tools/basistools.py" The first line is 669 | Source file "tools/basistools.py" The first line is 724 | |
if dimOrBlockDims is None: dimOrBlockDims = int(round(_np.sqrt(mxInStdBasis.shape[0]))) assert (dimOrBlockDims) ** (2) == mxInStdBasis.shape[0] |
if dimOrBlockDims is None: dimOrBlockDims = int(round(_np.sqrt(mxInGellMannBasis.shape[0]))) assert (dimOrBlockDims) ** (2) == mxInGellMannBasis.shape[0] |
|
gmToStd = gm_to_std_transform_matrix(dimOrBlockDims) | gmToStd = gm_to_std_transform_matrix(dimOrBlockDims) | |
stdToGM = _np.linalg.inv(gmToStd) | stdToGM = _np.linalg.inv(gmToStd) |
Clone # 21
Distance between two fragments = 0
Clone size = 5
Source file "tools/likelihoodfns.py" The first line is 240 | Source file "tools/likelihoodfns.py" The first line is 358 | |
totalCntVec = _np.sum(countVecMx, axis=0) | totalCntVec = _np.sum(countVecMx, axis=0) | |
a = radius | a = radius | |
min_p = minProbClip | min_p = minProbClip | |
if evalTree is None: evalTree = gateset.bulk_evaltree(gatestring_list) |
if evalTree is None: evalTree = gateset.bulk_evaltree(gatestring_list) |
Clone # 22
Distance between two fragments = 3
Clone size = 5
Source file "tools/basistools.py" The first line is 895 | Source file "tools/basistools.py" The first line is 689 | |
pp = _np.dot(stdToPP, mxInStdBasis) | gm = _np.dot(stdToGM, mxInStdBasis) | |
if _np.linalg.norm(_np.imag(pp)) > 1e-08: raise ValueError(('Pauil-product vector has non-zero imaginary part (%g)!') % (_np.linalg.norm(_np.imag(pp)))) |
if _np.linalg.norm(_np.imag(gm)) > 1e-08: raise ValueError(('Gell-Mann vector has non-zero imaginary part (%g)!') % (_np.linalg.norm(_np.imag(gm)))) |
|
return _np.real(pp) | return _np.real(gm) |
Clone # 23
Distance between two fragments = 4
Clone size = 5
Source file "tools/basistools.py" The first line is 883 | Source file "tools/basistools.py" The first line is 677 | |
pp = _np.dot(stdToPP, _np.dot(mxInStdBasis, ppToStd)) | gm = _np.dot(stdToGM, _np.dot(mxInStdBasis, gmToStd)) | |
if _np.linalg.norm(_np.imag(pp)) > 1e-08: raise ValueError(('Pauil-product matrix has non-zero imaginary part (%g)!') % (_np.linalg.norm(_np.imag(pp)))) |
if _np.linalg.norm(_np.imag(gm)) > 1e-08: raise ValueError(('Gell-Mann matrix has non-zero imaginary part (%g)!') % (_np.linalg.norm(_np.imag(gm)))) |
|
return _np.real(pp) | return _np.real(gm) |