Skip to content

Commit 5eebdc0

Browse files
author
Corey Ostrove
committed
Add in missing return_basis implementation
Patch in support for the missing support for the return_basis of EmbeddedErrorgen and EmbeddedOp.
1 parent 3944ca5 commit 5eebdc0

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

pygsti/modelmembers/operations/embeddederrorgen.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,26 @@ def coefficients(self, return_basis=False, logscale_nonham=False, label_type='gl
139139
Where `termType` is `"H"` (Hamiltonian), `"S"` (Stochastic),
140140
`"C"`(Correlation) or `"A"` (Affine). Hamiltonian and S terms always have a
141141
single basis label while 'C' and 'A' terms have two.
142-
"""
143-
coeffs_to_embed = self.embedded_op.coefficients(return_basis, logscale_nonham, label_type)
144142
143+
basis : `Basis` (if return_basis==True)
144+
A Basis mapping the basis labels used in the keys of basis-labels of the
145+
underlying (pre-embedding) error generator coeffs to basis matrices.
146+
"""
147+
if return_basis:
148+
coeffs_to_embed, basis = self.embedded_op.coefficients(return_basis, logscale_nonham, label_type)
149+
else:
150+
coeffs_to_embed = self.embedded_op.coefficients(return_basis, logscale_nonham, label_type)
151+
145152
if coeffs_to_embed:
146153
embedded_labels = self.coefficient_labels(label_type=label_type, identity_label=identity_label)
147154
embedded_coeffs = {lbl:val for lbl, val in zip(embedded_labels, coeffs_to_embed.values())}
148155
else:
149156
embedded_coeffs = dict()
150157

151-
return embedded_coeffs
158+
if return_basis:
159+
return embedded_coeffs, basis
160+
else:
161+
return embedded_coeffs
152162

153163
def coefficient_labels(self, label_type='global', identity_label='I'):
154164
"""

pygsti/modelmembers/operations/embeddedop.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,17 +600,27 @@ def errorgen_coefficients(self, return_basis=False, logscale_nonham=False, label
600600
Where `termType` is `"H"` (Hamiltonian), `"S"` (Stochastic),
601601
`"C"`(Correlation) or `"A"` (Affine). Hamiltonian and S terms always have a
602602
single basis label while 'C' and 'A' terms have two.
603+
604+
basis : `Basis` (if return_basis==True)
605+
A Basis mapping the basis labels used in the keys of basis-labels of the
606+
underlying (pre-embedding) error generator coeffs to basis matrices.
603607
"""
604608
#*** Note: this function is nearly identical to EmbeddedErrorgen.coefficients() ***
605-
coeffs_to_embed = self.embedded_op.errorgen_coefficients(return_basis, logscale_nonham, label_type)
606-
609+
if return_basis:
610+
coeffs_to_embed, basis = self.embedded_op.errorgen_coefficients(return_basis, logscale_nonham, label_type)
611+
else:
612+
coeffs_to_embed, basis = self.embedded_op.errorgen_coefficients(return_basis, logscale_nonham, label_type)
613+
607614
if coeffs_to_embed:
608615
embedded_labels = self.errorgen_coefficient_labels(label_type=label_type, identity_label=identity_label)
609616
embedded_coeffs = {lbl:val for lbl, val in zip(embedded_labels, coeffs_to_embed.values())}
610617
else:
611618
embedded_coeffs = dict()
612619

613-
return embedded_coeffs
620+
if return_basis:
621+
return embedded_coeffs, basis
622+
else:
623+
return embedded_coeffs
614624

615625
def errorgen_coefficient_labels(self, label_type='global', identity_label='I'):
616626
"""

0 commit comments

Comments
 (0)