Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test_packages failures #519

Merged
merged 8 commits into from
Jan 17, 2025
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
Loading