Migrate np.polyfit to np.polynomial.polynomial.polyfit#2984
Open
danstam wants to merge 4 commits intounitaryfoundation:mainfrom
Open
Migrate np.polyfit to np.polynomial.polynomial.polyfit#2984danstam wants to merge 4 commits intounitaryfoundation:mainfrom
danstam wants to merge 4 commits intounitaryfoundation:mainfrom
Conversation
natestemen
requested changes
Apr 2, 2026
Member
natestemen
left a comment
There was a problem hiding this comment.
I don't want this to be a breaking change, so can you make sure the coefficients are returned in the same order as previously?
Author
|
Added a reversal on the return value to keep the original coefficient ordering. |
natestemen
reviewed
Apr 4, 2026
Author
|
@natestemen Let me know if you need anything else. |
This was referenced Apr 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2322
Replaces the deprecated
np.polyfitAPI withnp.polynomial.polynomial.polyfitthroughoutmitiq/zne/inference.py.What changed and why
The main challenge was that the new API removed the
cov=Trueoption. The covariance matrix is now reconstructed manually using the weighted Vandermonde approach:One non-obvious issue:
full=Truesilently suppressesRankWarning— numpy only raises it whenfull=False. A manual rank-deficiency check (rank < deg + 1) was added to preserve the existingExtrapolationWarningbehavior.Other changes:
[a_0, a_1, ..., a_n]vs the old descending order[a_n, ..., a_1, a_0]np.polyval→np.polynomial.polynomial.polyval(argument order is reversed in the new API)[::-1]reversals in_ansatz_unknownand_ansatz_knownclosurescast(npt.NDArray[np.float64], ...)to satisfy mypy since numpy's type stubs forfull=Truereturn an imprecise typeAll 216 ZNE tests pass. Ruff and mypy clean.
AI use disclosure
I used Claude Code to help navigate the codebase and verify the Vandermonde covariance math. All implementation decisions and code reviews were done by me iteratively.