-
Notifications
You must be signed in to change notification settings - Fork 50
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 support for cython 3 #1143
Add support for cython 3 #1143
Conversation
freud/box.pyx
Outdated
# NOTE: cython<3.0 treats __mul__ and __rmul__ as one operation, so | ||
# type checks are needed. For cython>=3.0, __rmul__ is implemented |
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.
Do you need to support both Cython < 3 and Cython >= 3? I would strongly recommend requiring Cython 3, which would mean this note isn't needed.
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 require Cython >= 3? Won't people want to be able to build freud with older cython versions too?
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 don't think this will be a problem. I think you can require Cython 3 with no harm done. Most users will only need prebuilt packages, and those who do wish to build freud from source can do so with build isolation (on by default), which will install Cython into a temporary environment. Most Cython-using packages I know are just updating the requirement to 3.0.
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 was marked as resolved but does not appear to be resolved. I expected the comment would be deleted, and this would not require a utility method _mul_impl
. Try just implementing __mul__(self, scale)
without the argument inspection (assume the second argument is a scale) and then call __mul__
in __rmul__
.
def __rmul__(self, scale):
return self * scale
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 bumped the requirements to all have cython>=3.0.2, but forgot to simplify the implementation of mul and rmul. Should be good now.
Co-authored-by: Bradley Dice <bdice@bradleydice.com>
I've stumbled into some chatter about performance regression re cython 3.0 ( scikit-learn/scikit-learn#27086 ) . Would it make sense to benchmark before / after to see if we would be affected? Maybe not everything but just they key components that heavily rely on cython (msd?). |
Most of freud isn't doing heavy lifting in Cython -- it all happens in the C++ layer. I don't expect this to be a problem for freud which just uses Cython for bindings to C++. Always good to benchmark though. :) edit: even MSD is mostly calling out to other libraries in C++, if I remember correctly. |
I've run the MSD benchmark with cython 0.x and 3.x and there appears to be a very small performance slowdown. Given that all other benchmarks use less cython than MSD, I don't think we need to worry about performance regressions. Running with cython 0.x:
Running with cython 3.x:
|
@@ -692,5 +692,6 @@ | |||
] | |||
] | |||
} | |||
] | |||
], | |||
"5ddf603fa828b2130199b90d39fe4cb02072007c": [] |
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.
What’s this change?
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.
The benchmarking script records the SHA of the commit it was run on and the results. I cut the benchmarking script off before it got all the way done so it couldn't record all the results at the end. I can manually revert this change if necessary.
This PR enables builds of freud with cython>=3.0.2
Description
Small changes were made to accommodate changes to cython in their 3.0 release.
Motivation and Context
Cython has made a major release, which we need to support so we can continue to be compatible with new python versions as they are released.
Resolves: #1130
How Has This Been Tested?
We need to bump the newest supported version of cython in our latest testing configuration. Older testing configurations will continue to test against cython<3.0.0
Types of changes
Checklist: