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

add node2vec C API implementation #2069

Conversation

ChuckHastings
Copy link
Collaborator

@ChuckHastings ChuckHastings commented Feb 11, 2022

Provides C API implementation wrapping node2vec.

@ChuckHastings ChuckHastings requested review from a team as code owners February 11, 2022 22:38
@ChuckHastings ChuckHastings self-assigned this Feb 11, 2022
@ChuckHastings ChuckHastings added 3 - Ready for Review improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Feb 11, 2022
@ChuckHastings ChuckHastings added this to the 22.04 milestone Feb 11, 2022
@codecov-commenter
Copy link

codecov-commenter commented Feb 12, 2022

Codecov Report

Merging #2069 (db88891) into branch-22.04 (3187fbf) will increase coverage by 0.08%.
The diff coverage is n/a.

Impacted file tree graph

@@               Coverage Diff                @@
##           branch-22.04    #2069      +/-   ##
================================================
+ Coverage         73.51%   73.59%   +0.08%     
================================================
  Files               156      156              
  Lines             10295    10316      +21     
================================================
+ Hits               7568     7592      +24     
+ Misses             2727     2724       -3     
Impacted Files Coverage Δ
python/cugraph/cugraph/tests/test_doctests.py 98.59% <0.00%> (-1.41%) ⬇️
python/cugraph/cugraph/structure/property_graph.py 96.42% <0.00%> (-0.20%) ⬇️
...ython/cugraph/cugraph/tests/test_property_graph.py 96.09% <0.00%> (+0.04%) ⬆️
.../cugraph/tests/test_edge_betweenness_centrality.py 84.93% <0.00%> (+0.60%) ⬆️
...graph/cugraph/tests/test_betweenness_centrality.py 83.01% <0.00%> (+0.62%) ⬆️
python/cugraph/cugraph/tests/test_graph_store.py 100.00% <0.00%> (+1.56%) ⬆️
python/cugraph/cugraph/tests/test_utils.py 75.55% <0.00%> (+4.44%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3187fbf...db88891. Read the comment docs.

@ChuckHastings ChuckHastings added the DO NOT MERGE Hold off on merging; see PR for details label Feb 15, 2022
@ChuckHastings ChuckHastings removed the DO NOT MERGE Hold off on merging; see PR for details label Feb 16, 2022
rapids-bot bot pushed a commit that referenced this pull request Feb 16, 2022
Pull out common cascading logic/error handling into a template function.  This cleans up the existing C API implementations and will make new C API implementations a bit simpler.

Note: #2069 uses the old paradigm.  Depending on merge order we might want to modify the node2vec implementation to use this technique also.  Can decide whether to do that in 2069 if this PR merges first, or if 2069 merges first we can either add that to this PR or leave it as tech debt to address later.

Authors:
  - Chuck Hastings (https://github.com/ChuckHastings)

Approvers:
  - Seunghwa Kang (https://github.com/seunghwak)

URL: #2077
: sampling_type_(sampling_type), p_(p), q_(q), use_alpha_cache_(use_alpha_cache)
{
}

sampling_params_t(int sampling_type, double p = 1.0, double q = 1.0, bool use_alpha_cache = false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we taking int sampling_type here but sampling_strategy_t sampling_type above? Better be consistent.

And more fundamentally, why do we have two functions seemingly doing the same thing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code (developed for C++) included a constructor that takes an int sampling_type and converts it into the enum. This original code is used by the current python/cython interface.

In implementing the C code, I wanted to use the enum directly (I think it's more clear in the calling code to use the enum). I added the new constructor to allow for construction from the enum directly. I intend to remove the old constructor once the python/cython code uses the new C API.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, and in that case, FIXME statement stating the intention will make this clearer.

cpp/src/c_api/random_walks.cpp Outdated Show resolved Hide resolved
bool compress_result_;
double p_;
double q_;
cugraph_random_walk_result_t* result_{};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it our convention to define member variables before functions? And don't forget {} at the end of variable names.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the {}. Not sure what you mean by your question.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What we typically have is

struct {
  functions(); ...
  variables; ...
};

but here

struct {
  variables;...
  functions(); ...
 };

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for this?

Copy link
Collaborator Author

@ChuckHastings ChuckHastings Feb 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. I interpreted your question as the opposite - hence my confusion.

What I have generally seen in our code base is that when we define a class we define it as:

class {
public:
   functions;
private:
   private_functions;
   variables;
};

But when we define a struct (essentially the same, only real difference is that everything is public) we define it as:

struct {
  variables;
  functions;
};

Admittedly, most of the structs that we define are to work around the nvcc problem with lambdas. My feeling (from a design perspective) was that this functor is really a heavier weight lambda. But you are correct in observing that it is more class-like. It does derive from an abstract struct, hence the need for a constructor as well as an operator()().

This is consistent across all of the C API functions. We can certainly change it if we like, but if we do we should fix the entire C API (and better to do it before we add too many more calls).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I guess the sampling_params_t is a struct but follows the class description in my above comment. So we have inconsistency there as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yes, you're right, actually, I also do {vairables; operators();} for struct (i.e. functors). Seeing https://github.com/rapidsai/cugraph/pull/2069/files#diff-1264d5c0712616b080bb085897241ca6ad0bd8d4d132c83a75be4edf229ce988L28, I erroneously thought that we do functions first (do we consider constructors as something special, or should this better be class, or should we resolve inconsistencies in ordering?).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seunghwak - I'll make a note to consider this and write up some options for us to discuss.

@BradReesWork
Copy link
Member

@gpucibot merge

@BradReesWork
Copy link
Member

@gpucibot merge

@rapids-bot rapids-bot bot merged commit d947fb9 into rapidsai:branch-22.04 Feb 17, 2022
@ChuckHastings ChuckHastings deleted the fea_node2vec_capi_implementation branch August 4, 2022 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement / enhancement to an existing function non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants