Skip to content

Commit

Permalink
Merge pull request #336 from pyGSTio/bugfix-tppovm-pickle-gpindices
Browse files Browse the repository at this point in the history
Fixes gpindices initialization issue in TPPOVM.
  • Loading branch information
sserita authored Aug 10, 2023
2 parents 040acad + be43ae2 commit 2dbf24f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
7 changes: 5 additions & 2 deletions pygsti/modelmembers/povms/basepovm.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ def __init__(self, effects, evotype=None, state_space=None, preserve_sum=False,
paramlbls = []
for k, v in items:
if k == self.complement_label: continue
if isinstance(v, _POVMEffect):
if called_from_reduce: # __reduce__ should always initialize w/POVMEffects except for ...
assert isinstance(v, _POVMEffect) # complement (which hits continue above)
effect = v # don't copy as we want to preserve the gpindices in effects
elif isinstance(v, _POVMEffect):
effect = v if (not preserve_sum) else v.copy() # .copy() just to de-allocate parameters
else:
assert(evotype is not None), "Must specify `evotype` when effect vectors are not POVMEffect objects!"
Expand Down Expand Up @@ -108,7 +111,7 @@ def __init__(self, effects, evotype=None, state_space=None, preserve_sum=False,
identity_for_complement = _np.array(sum([v.to_dense().reshape(comp_val.shape) for v in non_comp_effects])
+ comp_val, 'd') # ensure shapes match before summing
complement_effect = _ComplementPOVMEffect(
identity_for_complement, non_comp_effects)
identity_for_complement, non_comp_effects, called_from_reduce)
items.append((self.complement_label, complement_effect))

super(_BasePOVM, self).__init__(state_space, evotype, None, items)
Expand Down
9 changes: 6 additions & 3 deletions pygsti/modelmembers/povms/complementeffect.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ComplementPOVMEffect(_ConjugatedStatePOVMEffect):
"complement" POVM effect vector.
"""

def __init__(self, identity, other_effects):
def __init__(self, identity, other_effects, called_from_reduce=False):
evotype = other_effects[0]._evotype
state_space = other_effects[0].state_space

Expand All @@ -62,8 +62,11 @@ def __init__(self, identity, other_effects):
# 2) set the gpindices of the elements of other_spamvecs so
# that they index into our local parameter vector.

_ConjugatedStatePOVMEffect.__init__(self, self.identity.copy())
self.init_gpindices() # initialize our gpindices based on sub-members
_ConjugatedStatePOVMEffect.__init__(self, self.identity.copy(), called_from_reduce)
if not called_from_reduce:
self.init_gpindices() # initialize our gpindices based on sub-members
else:
self.allocate_gpindices(10000, None, submembers_already_allocated=True)
self._construct_vector() # reset's self.base

def _construct_vector(self):
Expand Down
7 changes: 5 additions & 2 deletions pygsti/modelmembers/povms/conjugatedeffect.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,15 @@ class ConjugatedStatePOVMEffect(DenseEffectInterface, _POVMEffect):
i.e, a (dim,1)-shaped array.
"""

def __init__(self, state):
def __init__(self, state, called_from_reduce=False):
self.state = state
evotype = state._evotype
rep = evotype.create_conjugatedstate_effect_rep(state._rep)
_POVMEffect.__init__(self, rep, evotype)
self.init_gpindices() # initialize our gpindices based on sub-members
if not called_from_reduce:
self.init_gpindices() # initialize our gpindices based on sub-members
else:
self.allocate_gpindices(10000, None, submembers_already_allocated=True)

@property
def _basis(self):
Expand Down

0 comments on commit 2dbf24f

Please sign in to comment.