8000 Restructure Permutation by Adrien-Kahn · Pull Request #2067 · netket/netket · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Restructure Permutation #2067

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Restructure Permutation #2067

wants to merge 4 commits into from

Conversation

Adrien-Kahn
Copy link
Collaborator
@Adrien-Kahn Adrien-Kahn commented Jun 24, 2025

The clarification of names in Permutation as discussed with @PhilipVinc and @attila-i-szabo. The objective is to solve the confusion that might be caused by the property permutation actually encoding the inverse permutation.

Changes:

  • The constructor of Permutation now takes in either the permutation array or its inverse. name is now a keyword argument.
  • The Permutation property permutation is deprecated in favor of permutation_array and inverse_permutation_array.
  • __repr__ now returns the array of the permutation instead of its inverse.
  • __array__ is deprecated and replaced by Permutation.inverse_permutation_array for more clarity.

As far as I can tell, the PR is functional right now, but I think it's better to wait for Attila's PR to be merged so we can update the usage of the Permutation class in SpaceGroup and the likes, and avoid an avalanche of deprecation warnings.

Two other points:

  • There is the function apply_to_id in Permutation. From what I can see, it's only used twice inside the tests to obtain the permutation (instead of its inverse). Since it's effectively identical to p.permutation_array[x] now, would it make sense to deprecate it?
  • There is this HashableArray business going on, and I'm not sure what it's for (being able to hash permutation I guess?). I think what I wrote in that regard makes sense, but you should probably check.

Copy link
codecov bot commented Jun 24, 2025

Codecov Report

Attention: Patch coverage is 89.65517% with 3 lines in your changes missing coverage. Please review.

Project coverage is 84.98%. Comparing base (6db0f51) to head (b00be60).

Files with missing lines Patch % Lines
netket/utils/group/_permutation_group.py 89.65% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2067      +/-   ##
==========================================
+ Coverage   84.96%   84.98%   +0.02%     
==========================================
  Files         329      329              
  Lines       20142    20163      +21     
  Branches     2525     2528       +3     
==========================================
+ Hits        17113    17136      +23     
+ Misses       2244     2242       -2     
  Partials      785      785              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator
@attila-i-szabo attila-i-szabo left a comment

Choose a reason for hiding this comment

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

I'm happy with this, the suggestions are basically all on formatting

r"""
Creates a `Permutation` from an array of preimages of :code:`range(N)`.
Creates a `Permutation` from either the array of images `permutation_array` or preimages `inverse_permutation_array`. Note that the left action of a permutation on an array `a` is `a[inverse_permutation_array]`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Break up to lines of up to 70-80 characters as per PEP 8. Also, the first tagline should be no more than 1-2 of these lines, because it makes the autogenerated documentation weird. The "Note that" bit can come after an empty line - and probably expanded.

Comment on lines +44 to +48
Args:
permutation: (deprecated) 1D array listing :math:`g^{-1}(x)` for all :math:`0\le x \le N-1`.
name: Optional, custom name for the permutation.
permutation_array: 1D array listing :math:`g(x)` for all :math:`0\le x \le N-1`.
inverse_permutation_array: 1D array listing :math:`g^{-1}(x)` for all :math:`0\le x \le N-1`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shoudl mention that you only take one of the three arguments

arg_list = [permutation, permutation_array, inverse_permutation_array]
if sum([arg is not None for arg in arg_list]) != 1:
raise TypeError(
"Only one among `permutation`, `permutation_array` and `inverse_permutation_array` must be specified."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"Only one among `permutation`, `permutation_array` and `inverse_permutation_array` must be specified."
"Precisely one of `permutation`, `permutation_array`,\n"
"and `inverse_permutation_array` must be specified."

not specifying any of them is also bad


if permutation is not None:
warn_deprecation(
"The argument `permutation` is deprecated. In order to clarify notations, you should either pass the array of images `permutation_array` or preimages `inverse_permutation_array`."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"The argument `permutation` is deprecated. In order to clarify notations, you should either pass the array of images `permutation_array` or preimages `inverse_permutation_array`."
"The argument `permutation` is deprecated.\n\n"
"For clarity, you should either pass the array of images\n"
"`permutation_array` or preimages `inverse_permutation_array`.\n"
"The latter matches the the behaviour of `permutation`."


@deprecated("Deprecated in favor of `permutation.inverse_permutation_array`")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think there's an argument specifically for deprecating A in favour of B


arg_list = [permutation, permutation_array, inverse_permutation_array]
if sum([arg is not None for arg in arg_list]) != 1:
raise TypeError(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this a ValueError?

Returns:
a `Permutation` object encoding the same permutation
A `Permutation` object encoding the same permutation.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
A `Permutation` object encoding the same permutation.
A `Permutation` object that encodes the same permutation.

@attila-i-szabo
Copy link
Collaborator
  • __array__ is deprecated and replaced by Permutation.inverse_permutation_array for more clarity.

I'd be cautious with deprecating this because it can be used in other contexts.

  • There is this HashableArray business going on, and I'm not sure what it's for (being able to hash permutation I guess?). I think what I wrote in that regard makes sense, but you should probably check.

Yes, we need this so PermutationGroups can 7785 be passed to flax modules. It looks correct to me (and the tests would complain if it wasn't)

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.

2 participants
0