Skip to content

Conversation

@MarkDana
Copy link
Collaborator

@MarkDana MarkDana commented Apr 13, 2023

Updated files:

  • causallearn/graph/Endpoint.py: reload __eq__.
  • causallearn/graph/Edge.py;Edges.py and causallearn/utils/GraphUtils.py: replace all the "is Endpoint" with "== Endpoint", since identity comparison is unsafe.

Reproduce the issue (as of 446b9a2):

>>> from causallearn.graph import Endpoint
>>> arr1 = Endpoint.Endpoint.ARROW
>>>
>>> # module reload sometimes happens unknowingly; e.g., during discovery algorithms in causallearn
>>> import importlib; importlib.reload(Endpoint)
>>> arr2 = Endpoint.Endpoint.ARROW
>>>
>>> print(arr1, arr2, type(arr1), type(arr2), id(arr1), id(arr2))
ARROW ARROW <enum 'Endpoint'> <enum 'Endpoint'> 4302557296 4302743968
>>> arr1 == arr2 # oh no..
False

According to Python doc, equality comparisons for Enum are defined by identity comparison (i.e., is). Here we need to explicitly reimplement __eq__ for attributed value comparison. See stackoverflow 1 2.

Incorrect SHD caused:

I experienced an incorrect SHD result due to this bug. The truth contains X1 --> X2 and the estimation contains X2 --> X1 (given by GES), but the returned SHD is 0, because this line is evaluated as False (i.e., ARROW != ARROW).

Potentially there might be more bugs related:

Might be a fatal bug:

Endpoint comparisons are in the basic building blocks, while they're not used uniformly:

Let's take care of this if there will be a graph class refactoring.

Merge plan

I'm not sure whether this pr should be merged right away. On the one hand, we need to ensure that the users receive accurate results (especially SHDs for evaluation in papers). On the other hand, we need to regenerate all the test benchmarks (which takes time) so that all the tests can pass. What do you think? @kunwuz @tofuwen

Signed-off-by: Haoyue Dai <hyda@cmu.edu>
@MarkDana MarkDana force-pushed the fix-endpoint-comparison-bug branch from 37dd5cf to 4de754d Compare April 13, 2023 09:18
Signed-off-by: Haoyue Dai <hyda@cmu.edu>
Signed-off-by: Haoyue Dai <hyda@cmu.edu>
@MarkDana MarkDana force-pushed the fix-endpoint-comparison-bug branch from 44ebf20 to b3beba7 Compare April 13, 2023 11:24
@tofuwen
Copy link
Contributor

tofuwen commented Apr 13, 2023

Thanks for identifying this bug! This is a really fatal bug! This is a great great finding!

Now I am really worried about the correctness of some of our algorithms, and very surprised why we didn't identify this bug before. Let's have a joint meeting to discuss next steps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants