Skip to content

Commit 0d859ce

Browse files
authored
Merge pull request #519 from sandialabs/fix-test-packages-failures
Fix test_packages failures
2 parents c74fcb2 + 6d4379a commit 0d859ce

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

pygsti/data/dataset.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,6 +1730,14 @@ def _add_raw_arrays(self, circuit, oli_array, time_array, rep_array,
17301730
# so we need to build this up for all existings sequences:
17311731
self._add_explicit_repetition_counts()
17321732

1733+
if rep_array is not None:
1734+
# Check for entries that are numerically equal to zero. For any such entries,
1735+
# so them to _exactly_ zero in preparation for floating-point equality checks
1736+
# with zero below, and in unit tests.
1737+
dtype_info = _np.finfo(rep_array.dtype)
1738+
near_zero = rep_array < 10**(-1.5*dtype_info.precision)
1739+
rep_array[near_zero] = 0
1740+
17331741
if not record_zero_counts:
17341742
# Go through repArray and remove any zeros, along with
17351743
# corresponding elements of oliArray and timeArray

test/test_packages/drivers/test_timedep.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,20 @@ def test_time_dependent_datagen(self):
6868
ds = pygsti.data.simulate_data(mdl, circuits, num_samples=100,
6969
sample_error='none', seed=1234, times=[0,0.1,0.2])
7070

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

7576
# sparse data
7677
ds2 = pygsti.data.simulate_data(mdl, circuits, num_samples=100,
7778
sample_error='none', seed=1234, times=[0,0.1,0.2],
7879
record_zero_counts=False)
79-
self.assertArraysEqual(ds2[Circuit([Label('Gi',0)], line_labels=(0,))].time, np.array([0., 0.1, 0.1, 0.2, 0.2]))
80-
self.assertArraysEqual(ds2[Circuit([Label('Gi',0)], line_labels=(0,))].reps, np.array([100., 95., 5., 90., 10.]))
81-
self.assertArraysEqual(ds2[Circuit([Label('Gi',0)], line_labels=(0,))].outcomes, [('0',), ('0',), ('1',), ('0',), ('1',)])
80+
ds2r = ds2[Circuit([Label('Gi',0)], line_labels=(0,))]
81+
self.assertArraysEqual(ds2r.time, np.array([0., 0.1, 0.1, 0.2, 0.2]))
82+
self.assertArraysEqual(ds2r.reps, np.array([100., 95., 5., 90., 10.]))
83+
self.assertArraysEqual(ds2r.outcomes, [('0',), ('0',), ('1',), ('0',), ('1',)])
84+
return
8285

8386
def test_time_dependent_gst_staticdata(self):
8487

test/unit/util.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,11 @@ def __getattr__(self, name):
219219
except AttributeError as err:
220220
if name in self.__ns_props__:
221221
return self.__ns_props__[name](self)
222-
else:
223-
raise err
222+
# else:
223+
# raise err
224+
return None
225+
# ^ necessary to avoid cursed issues that can arise when a call to pyest.main(...)
226+
# ends up triggering a test which needs the Namespace class.
224227

225228
def property(self, fn):
226229
"""Dynamic namespace property"""

0 commit comments

Comments
 (0)