-
Notifications
You must be signed in to change notification settings - Fork 27
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
Rework library interfaces #201
Open
N-Maas
wants to merge
48
commits into
master
Choose a base branch
from
nikolai/lib-rework
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Effectively a complete rework of the Python and C library interfaces. It is certainly a larger change than I initially thought it would be 😄
Goals are proper error handling, making the interfaces easier and less error-prone to use, extending the API, and making the behavior of the two interfaces more similar while reducing code duplication.
Within these constraints, the user-facing API stays similar to the old one.
Specifically, this PR:
nullptr
if it already has a return type) and additionally writes the error kind and error message to a struct of typemt_kahypar_error_t
do_for_all_*
methodsinitialize
is guaranteed to be called first, specifying lifetimes so that the partitioned hypergraph does not outlive its hypergraph, and adding a bunch of size/bounds checks: size checks for the provided data when constructing a (partitioned) hypergraph or fixed vertices, and bounds checks for all methods that access nodes, edges or blocks via an ID.Note, the C interface also gets a few new checks, but most of the checks used in Python don't really work for the C interface. Out of bounds indices and providing wrong sizes are still UB in C.
As a side note, the C interface is now actually usable with a C compiler.
Note that this PR does not implement proper input validation yet. I.e., reading an invalid input file still might cause a segfault even in the Python API. However, the PR already adjusts the API so that we can later implement runtime-configurable input validation without any kind of breaking change. This is done with a required context parameter for each function that constructs a (hyper)graph. While not necessary yet, it is an unproblematic change since the user needs to construct a context anyways and it allows to pass options that affect the IO via the context.