Skip to content

Commit

Permalink
Fixed undefined symbol in optools.fidelity, plus linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
robpkelly committed Oct 23, 2019
1 parent 9fa2b4a commit 3ea46e3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/pygsti/construction/circuitconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def tolabel(x): return x if isinstance(x, _Lbl) else _Lbl(x)

line_labels = prepStrs[0].line_labels if len(prepStrs) > 0 else 'auto'
if line_labels is None or len(line_labels) == 0: line_labels = ('*',)
singleOps = [_cir.Circuit((gl,), line_labels=line_labels)**1 for gl in opLabels] # **1 adds parens to stringrep
singleOps = [_cir.Circuit((gl,), line_labels=line_labels)**1 for gl in opLabels] # **1 adds parens to stringrep
ret = create_circuit_list('eStr', 'prepStr', 'prepStr+eStr', 'prepStr+g+eStr',
eStr=effectStrs, prepStr=prepStrs, g=singleOps,
order=['g', 'prepStr', 'eStr']) # LEXICOGRAPHICAL VS MATRIX ORDER
Expand Down
7 changes: 4 additions & 3 deletions packages/pygsti/tools/optools.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ def fidelity(A, B):

#if _np.array_equal(A, B): return 1.0 # HACK - some cases when A and B are perfecty equal sqrtm(A) fails...
sqrtA = _hack_sqrtm(A) # _spl.sqrtm(A)
#assert(_np.linalg.norm(_np.dot(sqrtA, sqrtA) - A) < 1e-8) # test the scipy sqrtm function - sometimes fails when rank defficient
# test the scipy sqrtm function - sometimes fails when rank defficient
#assert(_np.linalg.norm(_np.dot(sqrtA, sqrtA) - A) < 1e-8)
if _np.linalg.norm(_np.dot(sqrtA, sqrtA) - A) > 1e-8:
evals = _np.linalg.eigvals(A)
_warning.warn(("sqrtm(A) failure when computing fidelity - beware result. "
"Maybe due to rank defficiency - eigenvalues of A are: %s") % evals)
_warnings.warn(("sqrtm(A) failure when computing fidelity - beware result. "
"Maybe due to rank defficiency - eigenvalues of A are: %s") % evals)
F = (_mt.trace(_hack_sqrtm(_np.dot(sqrtA, _np.dot(B, sqrtA)))).real)**2 # Tr( sqrt{ sqrt(A) * B * sqrt(A) } )^2
return float(F)

Expand Down

0 comments on commit 3ea46e3

Please sign in to comment.