Skip to content

Commit

Permalink
tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
rileyjmurray committed May 23, 2024
1 parent b932571 commit 4f47d1f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
5 changes: 3 additions & 2 deletions pygsti/models/fogistore.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ def opcoeffs_to_fogiv_components_array(self, op_coeffs):
errorgen_vec = _np.zeros(self.errorgen_space_dim, 'd')
for i, (op_label, elem_lbl) in enumerate(self.errorgen_space_op_elem_labels):
errorgen_vec[i] += op_coeffs[op_label].get(elem_lbl, 0.0)
return self.errorgen_vec_to_fogi_components_array(errorgen_vec), \
self.errorgen_vec_to_fogv_components_array(errorgen_vec)
out1 = self.errorgen_vec_to_fogi_components_array(errorgen_vec)
out2 = self.errorgen_vec_to_fogv_components_array(errorgen_vec)
return out1, out2

def fogi_components_array_to_errorgen_vec(self, fogi_components):
assert(self._dependent_fogi_action == 'drop'), \
Expand Down
29 changes: 13 additions & 16 deletions pygsti/tools/matrixtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ def nullspace_qr(m, tol=1e-7):
return q[:, rank:]


#TODO: remove the orthogonalize argument (requires changing functions that call this one)
def nice_nullspace(m, tol=1e-7, orthogonalize=False):
"""
Computes the nullspace of a matrix, and tries to return a "nice" basis for it.
Expand All @@ -229,21 +228,19 @@ def nice_nullspace(m, tol=1e-7, orthogonalize=False):
-------
An matrix of shape (M,K) whose columns contain nullspace basis vectors.
"""

#
# nullsp = nullspace(m, tol)
# dim_ker = nullsp.shape[1]
# _, _, p = _spl.qr(nullsp.T.conj(), mode='raw', pivoting=True)
# ret = nullsp @ (nullsp.T[:, p[dim_ker]]).conj()
#
## ^ Equivalent to, but faster than the following
##
## nullsp_projector = nullsp @ nullsp.T.conj()
## ret = nullsp_projector[:, p[:dim_ker]]
##
#

ret = nullspace(m, tol)
nullsp = nullspace(m, tol)
dim_ker = nullsp.shape[1]
if dim_ker == 0:
return nullsp # empty 0-by-N array
_, _, p = _spl.qr(nullsp.T.conj(), mode='raw', pivoting=True)
ret = nullsp @ (nullsp.T[:, p[:dim_ker]]).conj()
# ^ That's equivalent to, but faster than:
# nullsp_projector = nullsp @ nullsp.T.conj()
# _, _, p = _spl.qr(nullsp_projector mode='raw', pivoting=True)
# ret = nullsp_projector[:, p[:dim_ker]]

if orthogonalize:
ret, _ = _spl.qr(ret, mode='economic')
for j in range(ret.shape[1]): # normalize columns so largest element is +1.0
imax = _np.argmax(_np.abs(ret[:, j]))
if abs(ret[imax, j]) > 1e-6:
Expand Down
4 changes: 2 additions & 2 deletions test/unit/objects/test_fogi.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ def test_cloud_crosstalk_fogi(self):
nprefix = mdl.num_params - nfogi # reparameterization *prefixes* FOGI params with "unused" params

self.assertEqual(nprefix, 0) # because include_spam=True above
self.assertArraysAlmostEqual(mdl.fogi_errorgen_components_array(include_fogv=False, normalized_elem_gens=True),
mdl.to_vector()[nprefix:])
temp = mdl.fogi_errorgen_components_array(include_fogv=False, normalized_elem_gens=True)
self.assertArraysAlmostEqual(temp, mdl.to_vector()[nprefix:])

v = mdl.to_vector() # just test this works

Expand Down

0 comments on commit 4f47d1f

Please sign in to comment.