vector icon indicating copy to clipboard operation
vector copied to clipboard

Structural v/s symbolic equality for SymPy tests

Open Saransh-cpp opened this issue 7 months ago • 1 comments

#581 raises the question of structural (x == y) v/s symbolic (simplify(x - y) == 0 or Eq(x, y)) equality. Even though symbolic equality would be easier to maintain in the longer run, it would be better to use the structural equality wherever possible to be more strict as -

  • we test (or at least, aim to test when we drop Python 3.8 support (uncompyle6 does not support Python 3.9+)) the ability of vector's compute functions to operate only on data containers using the SymPy tests - https://github.com/scikit-hep/vector/blob/main/tests/test_compute_features.py
  • the SymPy tests don't fail often, so the maintainability is not that big of a problem

Originally posted by @Saransh-cpp in https://github.com/scikit-hep/vector/pull/581#pullrequestreview-2806944886

Tests failing without being mathematically wrong is bad IMO, since they will sooner or later fail with sympy updates (as is the case now from 1.13.1 -> 1.14.0). Hence I prefer symbolic comparison.

In fact it is quite similar to checking floating points by an epsilon range, since the backend computation can change, but the result is still right (wrt. the scope).

Originally posted by @APN-Pucky in https://github.com/scikit-hep/vector/issues/581#issuecomment-2863341676

Thanks! My comment behind using structural equality was because the "symbolic" nature of our compute functions will solely be tested by SymPy once Python 3.8 is removed from GH Actions; hence, we would want these tests to be strict (unless we find another way - #531). But at the same time, I don't think this strictness is actually adding anything to the test suite - the symbolic equality will test the exact same thing but in a more flexible way.

Given that we use structural equality everywhere in the tests, I have reverted to keep using that for now. However, I will open an issue to discuss this further (and possibly change all equalities in the tests in the future).

Originally posted by @Saransh-cpp in https://github.com/scikit-hep/vector/issues/581#issuecomment-2927882803

Saransh-cpp avatar Jun 01 '25 20:06 Saransh-cpp

One argument in favor of structural tests could also be that you want to be sure that you get optimized (simplified) results, i.e. without any x + ... - x.

APN-Pucky avatar Jun 03 '25 13:06 APN-Pucky