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

Implement simple cycle search Python binding #804

Closed
wants to merge 1 commit into from

Conversation

GenieTim
Copy link
Contributor

@GenieTim GenieTim commented Nov 8, 2024

This is the new iteration of #803 after switching to a new branch.

@szhorvat
Copy link
Member

szhorvat commented Nov 9, 2024

@ntamas What kind of interface do you prefer for returning vertices or edges? This function returns both at the moment. In contrast, get_shortest_paths() has an output parameter that controls whether to return one or the other (and could in principle be extended to support returning both).

I don't have a strong opinion, and I'm not experienced enough with Python to know what's the most natural.

@@ -8,7 +8,8 @@ requires = [
# Workaround based on this commit:
# https://github.com/harfbuzz/uharfbuzz/commit/9b607bd06fb17fcb4abe3eab5c4f342ad08309d7
"setuptools>=64,<72.2.0; platform_python_implementation == 'PyPy'",
"setuptools>=64; platform_python_implementation != 'PyPy'"
"setuptools>=64; platform_python_implementation != 'PyPy'",
"cmake>=3.12"
Copy link
Member

Choose a reason for hiding this comment

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

This change is unrelated to the PR but it's a nice addition. File a separate PR with this and I'll be happy to merge.

Copy link
Member

Choose a reason for hiding this comment

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

C/igraph needs CMake 3.18 or later.

Copy link
Member

@szhorvat szhorvat Nov 15, 2024

Choose a reason for hiding this comment

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

@ntamas Is CMake needed even when building with an external igraph? I thought pkg-config was sufficient then.

Copy link
Member

Choose a reason for hiding this comment

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

It's not needed for an external igraph but it's needed for the vendored one. There's no way to specify this to Python build backends, though so it's easier to just include the build dependency - it won't hurt to have it there even if the user ends up linking to an external igraph.

@ntamas
Copy link
Member

ntamas commented Nov 13, 2024

I don't have a strong opinion, and I'm not experienced enough with Python to know what's the most natural.

Well, neither option is really "natural"; I believe that if this was a pure Python package I would have implemented a dataclass with two members, one for the vertices and one for the edges.

The new ctypes-based interface would generate a function that returns a tuple with both output arguments. In the case of the now-current Python interface I would try to keep things consistent with get_shortest_paths() so let's try to do it the same way unless it becomes super complicated.

@GenieTim
Copy link
Contributor Author

The new ctypes-based interface would generate a function that returns a tuple with both output arguments. In the case of the now-current Python interface I would try to keep things consistent with get_shortest_paths() so let's try to do it the same way unless it becomes super complicated.

My argument against that is the fact, that you have to call the function twice if you want both. Given the high performance impact for large graphs, it seems a bit wasteful to force the user to run it twice.

To me, returning a tuple is pythonic; there are plenty of built-in Python functions that act just like that, for example divmod, zip, enumerate or dict.items.

Correspondingly, if this is an open discussion, I would rather propose to open a PR to change get_shortest_paths() to return a tuple as well. If it's not an open discussion, or you would not want to impose this breaking change upon the users, I will adjust the code to act accordingly.

One possibility: introduce an optional output parameter as requested, but allow a third value, "both", in which case it acts as I propose it to and returns the edges & vertices as a tuple. Then, I would introduce the same for the get_shortest_paths() function and possibly deprecate the output parameter.

@szhorvat
Copy link
Member

szhorvat commented Nov 13, 2024

For context, a new Python interface is in the works: https://github.com/igraph/python-igraph-ctypes Tuples definitely do make sense and as @ntamas said, the new interface will use them.

One possible option for the old interface is to support output = "both", which will return a tuple, without breaking the existing interface.

It is still a question how much effort is worth putting into the old interface given that the new one is coming. Many people do use the old interface, and since at the moment we are very low on resources, it may take a long before it becomes ready. Thus "low resources" becomes and argument both for and against continuing to improve the old interface.

The one to make the final decision in @ntamas

@GenieTim
Copy link
Contributor Author

A sorry, I was not aware of this new interface and misemphasized the "would", thank you for the context. Then I agree, it's probably best to stick to what we have now. I will draft a new PR soonish.

@ntamas
Copy link
Member

ntamas commented Nov 13, 2024

Let's try supporting output="both" and then we can return a tuple there. Typing would be a bit more complicated for such a function, but the old interface does not use types anyway so it's not a problem.

@szhorvat
Copy link
Member

This is superseded by #806, right?

@szhorvat szhorvat closed this Nov 15, 2024
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