Skip to content

Commit

Permalink
implement changes discussed in 12/17 dev meeting
Browse files Browse the repository at this point in the history
  • Loading branch information
rileyjmurray committed Dec 17, 2024
1 parent 5959a53 commit 19316be
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pygsti/objectivefns/objectivefns.py
Original file line number Diff line number Diff line change
Expand Up @@ -4440,7 +4440,7 @@ def set_penalties(self, regularize_factor=0, cptp_penalty_factor=0, spam_penalty

return ex

def terms(self, paramvec=None, profiler_str="TERMS OBJECTIVE"):
def terms(self, paramvec=None, oob_check=False, profiler_str="TERMS OBJECTIVE"):
"""
Compute the terms of the objective function.
Expand Down Expand Up @@ -4471,6 +4471,11 @@ def terms(self, paramvec=None, profiler_str="TERMS OBJECTIVE"):
with self.resource_alloc.temporarily_track_memory(self.nelements): # 'e' (terms)
self.model.sim.bulk_fill_probs(self.probs, self.layout)
self._clip_probs()

if oob_check: # Only used for termgap cases
if not self.model.sim.bulk_test_if_paths_are_sufficient(self.layout, self.probs, verbosity=1):
raise ValueError("Out of bounds!") # signals LM optimizer

if shared_mem_leader:
terms_no_penalty = self.raw_objfn.terms(self.probs, self.counts, self.total_counts, self.freqs)
terms[:self.nelements] = terms_no_penalty
Expand Down Expand Up @@ -4566,8 +4571,8 @@ def lsvec(self, paramvec=None, oob_check=False):
numpy.ndarray
An array of shape `(nElements,)` where `nElements = self.nelements + self.ex_local`.
"""
lsvec = self.terms(paramvec, "LS OBJECTIVE")
if oob_check and _np.any(lsvec < 0):
lsvec = self.terms(paramvec, oob_check, "LS OBJECTIVE")
if _np.any(lsvec < 0):
bad_locs = _np.where(lsvec < 0)[0]
msg = f"""
lsvec is only defined when terms is elementwise nonnegative.
Expand Down

0 comments on commit 19316be

Please sign in to comment.