Skip to content

Commit

Permalink
reduce number of options available in non-LS gauge optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
rileyjmurray committed Nov 21, 2024
1 parent f916247 commit a138b7b
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions pygsti/algorithms/gaugeopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,9 +587,23 @@ def _mock_objective_fn(v):
else:
# non-least-squares case where objective function returns a single float
# and (currently) there's no analytic jacobian
dim = int(_np.sqrt(mxBasis.dim))
if n_leak > 0:
dim = int(_np.sqrt(mxBasis.dim))
B = _tools.leading_dxd_submatrix_basis_vectors(dim - n_leak, dim, mxBasis)
"""
^ Need to do something else.
In a leakage-friendly basis the operation matrices can be partitioned as
[comp , semileak1]
[semileak2, fulleak ].
Instead of projecting only on to comp, we want to keep everything
except fullleak. ... But I don't think we can implement that just by
pre-multiplying by a projector.
I think this distinction might not be significant under certain idealized
assumptions, but small deviations from those conditions (which are certain
to happen in practice) might make it matter.
"""
P = B @ B.T.conj()
if _np.linalg.norm(P.imag) > 1e-12:
raise ValueError()
Expand All @@ -601,10 +615,11 @@ def _mock_objective_fn(v):
# the second element of the tuple, but those aren't implemented yet so
# for now I'm setting the second entry to None. -- Riley
else:
transform_mx_arg = None
transform_mx_arg = (_np.eye(mxBasis.dim), None)

assert gates_metric != "frobeniustt"
assert spam_metric != "frobeniustt"
# assert spam_metric == gates_metric
# ^ Erik and Corey said these are rarely used. I've removed support for
# them in this codepath (non-LS optimizer) in order to make it easier to
# read my updated code for leakage-aware metrics. It wouldn't be hard to
Expand All @@ -625,18 +640,32 @@ def _objective_fn(gauge_group_el, oob_check):
ret += _np.sum(spamPenaltyVec)

if target_model is not None:
# Leakage-aware metric supported, per implementation in mdl.frobeniusdist.
# Refer to how mdl.frobeniusdist handles the case when transform_mx_arg
# is a tuple in order to understand how the leakage-aware metric is defined.
"""
Leakage-aware metric supported, per implementation in mdl.frobeniusdist.
Refer to how mdl.frobeniusdist handles the case when transform_mx_arg
is a tuple in order to understand how the leakage-aware metric is defined.
Idea: raise an error if mxBasis isn't leakage-friendly.
PROBLEM: if we're deep in the code then we end up needing to be
working in a basis that has the identity matrix as its
first element. The leakage-friendly basis doesn't even
have the identity matrix as an element, let alone the first element
TODO: dig into function calls below and see where we can
access the mxBasis object. (I'm sure we can.)
Looks like it isn't accessible within ExplicitOpModelCalc objects.
It's most definitely available in ExplicitOpModel.
"""
if "frobenius" in gates_metric:
if spam_metric == gates_metric:
val = mdl.frobeniusdist(target_model, transform_mx_arg, item_weights)
else:
wts = item_weights.copy(); wts['spam'] = 0.0
wts = item_weights.copy()
wts['spam'] = 0.0
for k in wts:
if k in mdl.preps or \
k in mdl.povms: wts[k] = 0.0
val = mdl.frobeniusdist(target_model, transform_mx_arg, wts)
if k in mdl.preps or k in mdl.povms:
wts[k] = 0.0
val = mdl.frobeniusdist(target_model, transform_mx_arg, wts, n_leak)
if "squared" in gates_metric:
val = val ** 2
ret += val
Expand Down

0 comments on commit a138b7b

Please sign in to comment.