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

Edge equality operator is incorrect (#333) #326

Merged
merged 4 commits into from
Jul 28, 2023
Merged

Conversation

nrkramer
Copy link
Collaborator

@nrkramer nrkramer commented Jul 4, 2023

Demonstration that unique edges are "skipped" sometimes when adding to an EdgeSet_T. Wonder if it's hashing, equality, or user error?

Running this on my machine:
image

Which makes me believe we have a bug, are misunderstanding how std::unordered_set works, or I'm doing something silly.

Let me know what you guys think! @sbaldu @ZigRazor

Update

After much sleuthing, I've found the error to be innocuously hidden here.

It turns out our edge equality operator was incorrect. This causes the underlying hash bucket implemented by various STL incarnations to incorrectly match nodes that are otherwise proven unique (by our hashing function, but STL implementors sometimes check equality anyway).

(As an aside, maybe we should look at a better hash implementation. The bitwise xor ( ^ ) doesn't work for edges that use the same nodes (cycles) since the operation is mathematically symmetrical) - this can result in performance degradation in highly cyclical graphs. Copying boost::hash_combine seems like a good candidate)

@nrkramer nrkramer requested review from sbaldu and ZigRazor July 4, 2023 22:32
@github-actions github-actions bot added the test Something about test label Jul 4, 2023
@nrkramer nrkramer changed the title Demonstrate edge set skips unique edges [DEMO] Demonstrate edge set skips unique edges Jul 4, 2023
@nrkramer nrkramer marked this pull request as draft July 4, 2023 22:32
@ghost
Copy link

ghost commented Jul 4, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@codecov
Copy link

codecov bot commented Jul 4, 2023

Codecov Report

Merging #326 (1b4ed69) into master (7afc54e) will increase coverage by 0.00%.
The diff coverage is 97.72%.

@@           Coverage Diff           @@
##           master     #326   +/-   ##
=======================================
  Coverage   97.25%   97.25%           
=======================================
  Files          54       54           
  Lines        7934     7977   +43     
=======================================
+ Hits         7716     7758   +42     
- Misses        218      219    +1     
Flag Coverage Δ
unittests 97.25% <97.72%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
include/Graph/Graph.hpp 94.87% <ø> (ø)
test/GraphTest.cpp 99.80% <97.67%> (-0.20%) ⬇️
include/Utility/PointerHash.hpp 100.00% <100.00%> (ø)

@nrkramer nrkramer changed the title [DEMO] Demonstrate edge set skips unique edges [DEMO] Demonstrate edge set sometimes skips unique edges Jul 4, 2023
@sbaldu
Copy link
Collaborator

sbaldu commented Jul 5, 2023

This is weird, I tried to reproduce this error but I haven't been able to do it. I copy pasted your exact code and I get all the 11 edges.
I also tried different ways of adding the edges to the graph and it always works fine:

  graph.addEdge(&edge1);
  CXXGraph::T_EdgeSet<int> edgeSet;
  edgeSet.insert(std::make_shared<CXXGraph::DirectedEdge<int>>(edge1));
  CXXGraph::T_EdgeSet<int> edgeSet;
  edgeSet2.insert(std::make_shared<CXXGraph::DirectedEdge<int>>(edge1.getId(), edge1.getFrom(), edge1.getTo()));

Also, in the picture that you provided the hash indexes of the edges are all different, so I doubt that the error that you get is due to the hash function.

@ZigRazor
Copy link
Owner

ZigRazor commented Jul 5, 2023

Ok, there is a BUG, the skipped nodes seems to be "new" to the graph. What compiler you are using?

@ZigRazor
Copy link
Owner

ZigRazor commented Jul 5, 2023

As said @sbaldu, but also as we can see in the CI/CD where the tests are executed, your test does not fail.
I'm wondering about the fact that with some compiler these code does not work.

@nrkramer
Copy link
Collaborator Author

nrkramer commented Jul 6, 2023

What compiler you are using?

I'm using MSVC 14.36.32532 (v143)

Could it be that Microsoft has a bug in their std::unordered_set implementation? It seems unlikely, but possible...

@ZigRazor
Copy link
Owner

ZigRazor commented Jul 6, 2023

@nrkramer we can try to add in the CI/CD a workflow that works on windows and try to execute tests.
what do you think?

@nrkramer nrkramer mentioned this pull request Jul 8, 2023
@ZigRazor
Copy link
Owner

@nrkramer I think is time to open a new Issue to track this.
Can you open a comphrensive issue with all the details and the analysis done until now?
Thank you in advance.

@ZigRazor
Copy link
Owner

@nrkramer please resolve conflit so we can merge this PR and open a new Issue.

@github-actions github-actions bot added the core something about core label Jul 28, 2023
@nrkramer nrkramer changed the title [DEMO] Demonstrate edge set sometimes skips unique edges Edge equality operator is incorrect (#333) Jul 28, 2023
@nrkramer nrkramer marked this pull request as ready for review July 28, 2023 09:53
@nrkramer nrkramer added bug Something isn't working and removed test Something about test labels Jul 28, 2023
@nrkramer nrkramer added the Priority:Critical Priority Label for Critical Issue label Jul 28, 2023
@github-actions github-actions bot added the test Something about test label Jul 28, 2023
@nrkramer
Copy link
Collaborator Author

@ZigRazor It looks like the MSVC builder has some issues.

I'm going sleep since it's super late where I am. Feel free to merge once the other checks have passed.

@nrkramer nrkramer merged commit b5e90e9 into ZigRazor:master Jul 28, 2023
25 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core something about core Priority:Critical Priority Label for Critical Issue test Something about test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants