-
Notifications
You must be signed in to change notification settings - Fork 89
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
Add input validation #167
Add input validation #167
Conversation
readHypergraphFile now reports (almost) any syntactic error in the input file
Some of the tests expect that hyperedges of size 1 are included in the graph.
1) -lkahypar is order-sensitive and needs to be placed after the input file 2) linking boost is not necessary (already linked into the library file)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @N-Maas. This already looks great. I haven't reviewed everything yet, but here's a first round of comments.
Codecov Report
@@ Coverage Diff @@
## master #167 +/- ##
==========================================
+ Coverage 84.42% 84.60% +0.18%
==========================================
Files 204 206 +2
Lines 17797 18097 +300
Branches 9815 9945 +130
==========================================
+ Hits 15025 15311 +286
- Misses 2772 2786 +14
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
@@ -99,8 +99,6 @@ KAHYPAR_API void kahypar_improve_hypergraph_partition(kahypar_hypergraph_t* kahy | |||
kahypar_partition_id_t* improved_partition); | |||
|
|||
|
|||
KAHYPAR_API void kahypar_hypergraph_free(kahypar_hypergraph_t* kahypar_hypergraph); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line appeared twice in the file, which caused a compiler warning for me. Thus I removed one of the duplicates
index_vector.reserve(static_cast<size_t>(num_hyperedges) + /*sentinel*/ 1); | ||
index_vector.push_back(edge_vector.size()); | ||
if (line_number_vector != nullptr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to check if (validate_input)
?
@@ -419,7 +500,7 @@ static inline void readFixedVertexFile(Hypergraph& hypergraph, const std::string | |||
} | |||
file.close(); | |||
} else { | |||
std::cerr << "Error: File not found: " << filename << std::endl; | |||
ERROR("File not found: " << filename); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to use a CheckedIStream
here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CheckedIStream
only represents a single line, so I'm not sure how one would use it here. I guess I could add another class, e.g. CheckedIFStream
, which represents the complete file. But I don't know whether that is worth it
@@ -391,7 +472,7 @@ static inline void readPartitionFile(const std::string& filename, std::vector<Pa | |||
} | |||
file.close(); | |||
} else { | |||
std::cerr << "Error: File not found: " << std::endl; | |||
ERROR("File not found."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to use a CheckedIStream
here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(as above)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only got a few minor questions left. Other than those, this looks very good! 👍
Thank you very much for your efforts. I bet this will help a lot of people in the future!
(duplicated comment because the first is not visible in the conversation thread for me, seemingly a bug with the Github UI)
Conceptionally, yes. However, the way the function is currently written it only takes the |
Thank you very much, @N-Maas! 👍 |
Adds validation that the input is actually a correct hypergraph (currently, KaHyPar likely segfaults in such cases or even produces garbage output). This applies to hgr files as well as the C interface and the Python interface.
This includes three major changes:
The required time for the semantic checks is reported in the output. The checks can be disabled using the new flag
KAHYPAR_INPUT_VALIDATION
. Alternatively, all warnings can be promoted to errors usingKAHYPAR_INPUT_VALIDATION_PROMOTE_WARNINGS_TO_ERRORS
.