Skip to content

Restore previous behavior to PolynomialTensor.rotate_basis() by default#1418

Merged
arettig merged 4 commits into
quantumlib:mainfrom
arettig:basis_change_compat
Jul 16, 2026
Merged

Restore previous behavior to PolynomialTensor.rotate_basis() by default#1418
arettig merged 4 commits into
quantumlib:mainfrom
arettig:basis_change_compat

Conversation

@arettig

@arettig arettig commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

PolynomialTensor's rotate_basis method previously used the transpose of the rotation matrix. This is not correct, but changing it in #805 broke users' code. A transpose flag is introduced to specify whether or not to transpose the rotation matrix, with True being the default for now (to be changed to the preferred False in a later release). A deprecation warning is given if the transpose flag is not specified.

PolynomialTensor's rotate_basis method previously used the transpose of the
rotation matrix. This is not correct, but changing it will break users code.
A transpose flag is introduced to specify whether or not to transpose the
rotation matrix, with True being the default for now. A deprecation warning
is given if the transpose flag is not specified.
@arettig
arettig requested a review from mhucka July 15, 2026 17:57

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a transpose parameter to the rotate_basis method in PolynomialTensor and InteractionRDM classes. By default, transpose is set to None, which triggers a DeprecationWarning and defaults to True to maintain backwards compatibility. When transpose=True, the rotation matrix is transposed before being applied. The existing tests and usages have been updated to explicitly set transpose=False where appropriate, and new tests have been added to verify the transpose behavior and the deprecation warning. There are no review comments, so I have no additional feedback to provide.

@mhucka mhucka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for doing this so quickly. Here are some minor change requests. Overall looks good!

Comment thread src/openfermion/ops/representations/interaction_rdm.py
Comment thread src/openfermion/ops/representations/polynomial_tensor.py Outdated
Comment thread src/openfermion/ops/representations/polynomial_tensor.py Outdated
Comment thread src/openfermion/ops/representations/polynomial_tensor.py Outdated
Comment thread src/openfermion/ops/representations/interaction_rdm.py Outdated
Comment thread src/openfermion/ops/representations/polynomial_tensor.py Outdated
Comment thread src/openfermion/ops/representations/polynomial_tensor.py Outdated
Comment thread src/openfermion/ops/representations/polynomial_tensor.py Outdated
Comment thread src/openfermion/ops/representations/polynomial_tensor_test.py Outdated
Changes the DeprecationWarning for using rotate_basis with no transpose
argument to the more proper FutureWarning. Also fixes some minor typos
and adds typing to functions.

@mhucka mhucka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

arettig added 2 commits July 16, 2026 16:38
general_rotate_basis is the function underlying the rotate_basis methods. This
function is explicitly used by ReCirq, so restoring the default behavior of the
rotate_basis methods is not enough to prevent breaking codes. general_rotate_basis
is now itself modified to transpose the rotation matrix by default.
Add the transpose parameter to rotate_basis() when used in the
jupyter notebook to avoid any warnings.
@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@arettig
arettig requested a review from mhucka July 16, 2026 17:25

@mhucka mhucka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks great! Thanks for doing this.

@mhucka mhucka added the area/health Involves code and/or project health label Jul 16, 2026
@arettig
arettig added this pull request to the merge queue Jul 16, 2026
Merged via the queue into quantumlib:main with commit 23ab426 Jul 16, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/health Involves code and/or project health priority/before-1.8.1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants