Skip to content

Commit

Permalink
Merge pull request #519 from sandialabs/fix-test-packages-failures
Browse files Browse the repository at this point in the history
Fix test_packages failures
  • Loading branch information
sserita authored Jan 17, 2025
2 parents c74fcb2 + 6d4379a commit 0d859ce
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
8 changes: 8 additions & 0 deletions pygsti/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,14 @@ def _add_raw_arrays(self, circuit, oli_array, time_array, rep_array,
# so we need to build this up for all existings sequences:
self._add_explicit_repetition_counts()

if rep_array is not None:
# Check for entries that are numerically equal to zero. For any such entries,
# so them to _exactly_ zero in preparation for floating-point equality checks
# with zero below, and in unit tests.
dtype_info = _np.finfo(rep_array.dtype)
near_zero = rep_array < 10**(-1.5*dtype_info.precision)
rep_array[near_zero] = 0

if not record_zero_counts:
# Go through repArray and remove any zeros, along with
# corresponding elements of oliArray and timeArray
Expand Down
15 changes: 9 additions & 6 deletions test/test_packages/drivers/test_timedep.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,20 @@ def test_time_dependent_datagen(self):
ds = pygsti.data.simulate_data(mdl, circuits, num_samples=100,
sample_error='none', seed=1234, times=[0,0.1,0.2])

self.assertArraysEqual(ds[Circuit([Label('Gi',0)], line_labels=(0,))].time, np.array([0., 0., 0.1, 0.1, 0.2, 0.2]))
self.assertArraysEqual(ds[Circuit([Label('Gi',0)], line_labels=(0,))].reps, np.array([100., 0., 95., 5., 90., 10.]))
self.assertArraysEqual(ds[Circuit([Label('Gi',0)], line_labels=(0,))].outcomes, [('0',), ('1',), ('0',), ('1',), ('0',), ('1',)])
dsr = ds[Circuit([Label('Gi',0)], line_labels=(0,))]
self.assertArraysEqual(dsr.time, np.array([0., 0., 0.1, 0.1, 0.2, 0.2]))
self.assertArraysEqual(dsr.reps, np.array([100., 0., 95., 5., 90., 10.]))
self.assertArraysEqual(dsr.outcomes, [('0',), ('1',), ('0',), ('1',), ('0',), ('1',)])

# sparse data
ds2 = pygsti.data.simulate_data(mdl, circuits, num_samples=100,
sample_error='none', seed=1234, times=[0,0.1,0.2],
record_zero_counts=False)
self.assertArraysEqual(ds2[Circuit([Label('Gi',0)], line_labels=(0,))].time, np.array([0., 0.1, 0.1, 0.2, 0.2]))
self.assertArraysEqual(ds2[Circuit([Label('Gi',0)], line_labels=(0,))].reps, np.array([100., 95., 5., 90., 10.]))
self.assertArraysEqual(ds2[Circuit([Label('Gi',0)], line_labels=(0,))].outcomes, [('0',), ('0',), ('1',), ('0',), ('1',)])
ds2r = ds2[Circuit([Label('Gi',0)], line_labels=(0,))]
self.assertArraysEqual(ds2r.time, np.array([0., 0.1, 0.1, 0.2, 0.2]))
self.assertArraysEqual(ds2r.reps, np.array([100., 95., 5., 90., 10.]))
self.assertArraysEqual(ds2r.outcomes, [('0',), ('0',), ('1',), ('0',), ('1',)])
return

def test_time_dependent_gst_staticdata(self):

Expand Down
7 changes: 5 additions & 2 deletions test/unit/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,11 @@ def __getattr__(self, name):
except AttributeError as err:
if name in self.__ns_props__:
return self.__ns_props__[name](self)
else:
raise err
# else:
# raise err
return None
# ^ necessary to avoid cursed issues that can arise when a call to pyest.main(...)
# ends up triggering a test which needs the Namespace class.

def property(self, fn):
"""Dynamic namespace property"""
Expand Down

0 comments on commit 0d859ce

Please sign in to comment.