Skip to content

Commit 3a1b860

Browse files
committed
reduce test_reports tols where possible
1 parent 951850b commit 3a1b860

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

tests/integration-e2e/test_reports.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,17 @@ def test_reports_compartment_vs_summation_reference_compartment_set(create_tmp_s
224224
reference_dir = V5_SONATA / "reference" / "reports" if is_v5_sonata else RINGTEST_DIR / "reference" / "reports"
225225

226226
nd.run()
227+
loose_tols = {"rtol": 1e-6, "atol": 1e-6}
227228

228229
# compartment vs summation
229230
for var in ["v", "i_membrane", "pas"]:
230231
r_compartment = ReportReader(output_dir / f"compartment_{var}.h5")
231232
r_summation = ReportReader(output_dir / f"summation_{var}.h5")
232233

233234
r_compartment.convert_to_summation()
234-
assert r_compartment == r_summation, f"The summation-converted-compartment:\n{r_compartment}\ndiffers from the summation one:\n{r_summation}"
235+
# summation after report printing loses accuracy due to truncation
236+
# We use the loose tols in that case
237+
assert r_compartment.allclose(r_summation, **loose_tols), f"The summation-converted-compartment:\n{r_compartment}\ndiffers from the summation one:\n{r_summation}"
235238

236239
# summation vs summation. Variable reordering
237240
r_summation_i_membrane_IClamp = ReportReader(output_dir / f"summation_i_membrane_IClamp.h5")
@@ -244,15 +247,18 @@ def test_reports_compartment_vs_summation_reference_compartment_set(create_tmp_s
244247
r_summation_IClamp = ReportReader(output_dir / f"summation_IClamp.h5")
245248
r_compartment_i_membrane = ReportReader(output_dir / f"compartment_i_membrane.h5")
246249
r_summation_i_membrane_IClamp_manual = r_compartment_i_membrane+ r_summation_IClamp
247-
assert r_summation_i_membrane_IClamp == r_summation_i_membrane_IClamp_manual, "Summation report does not match manual addition of compartment_i_membrane and summation_IClamp reports."
250+
# summation after report printing loses accuracy due to truncation
251+
# We use the loose tols in that case
252+
assert r_summation_i_membrane_IClamp.allclose(r_summation_i_membrane_IClamp_manual, **loose_tols), "Summation report does not match manual addition of compartment_i_membrane and summation_IClamp reports."
248253

249254
# Compare files to reference. Since the reference is fixed, this is also a comparison neuron vs coreneuron
250255
for ref_file in reference_dir.glob("*.h5"):
251256
r_reference = ReportReader(ref_file)
252257
file = output_dir / ref_file.name
253258
r = ReportReader(file)
254259

255-
assert r == r_reference, f"The reports differ:\n{file}\n{ref_file}"
260+
# coreneuron does not have exactly the same results, we use the loose tols in that case
261+
assert r.allclose(r_reference, **(loose_tols if SimConfig.use_coreneuron else {})), f"The reports differ:\n{file}\n{ref_file}"
256262

257263
# compartment vs compartment_set
258264
# magic list of positions in the full compartment list. It was done by hand because there isn't a clear cut way

tests/utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,14 @@ def __init__(self, file: str):
443443
self.populations[name] = (node_ids, df)
444444

445445
def __eq__(self, other: object) -> bool:
446+
return self.allclose(other)
447+
448+
def allclose(self, other: object, rtol=1e-16, atol=1e-16) -> bool:
449+
"""
450+
Compare two ReportReader instances for approximate equality.
451+
452+
Rtol and atol are the relative and absolute tolerances. The default values are
453+
the standards for numpy.allclose."""
446454
if not isinstance(other, ReportReader):
447455
return NotImplemented
448456

@@ -458,7 +466,7 @@ def __eq__(self, other: object) -> bool:
458466

459467
# coreneuron has sometimes garbage for the first line
460468
# erro thresholds as for old bb5 itegration report tests
461-
if not np.allclose(df1.values[1:], df2.values[1:], rtol=1e-6, atol=1e-6):
469+
if not np.allclose(df1.values[1:], df2.values[1:], rtol=rtol, atol=atol):
462470
return False
463471

464472
return True

0 commit comments

Comments
 (0)