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

Remove usage of np.polyfit #2322

Open
purva-thakre opened this issue Apr 25, 2024 · 3 comments
Open

Remove usage of np.polyfit #2322

purva-thakre opened this issue Apr 25, 2024 · 3 comments
Labels
good first issue Good for newcomers non-quantum Requires no knowledge of quantum physics to fix / work on.

Comments

@purva-thakre
Copy link
Contributor

purva-thakre commented Apr 25, 2024

We use numpy.polyfit to define the extrapolation methods for ZNE. The related API in numpy has since changed to using numpy.polynomial instead of numpy.polyfit.

) -> Tuple[List[float], Optional[npt.NDArray[np.float64]]]:
"""Fits the ansatz to the (scale factor, expectation value) data using
``numpy.polyfit``, returning the optimal parameters and covariance matrix
of the parameters.

The transition guide has a helpful table for adjusting to the newer changes.

image

https://numpy.org/doc/stable/reference/generated/numpy.polynomial.polynomial.polyfit.html

@purva-thakre purva-thakre added the good first issue Good for newcomers label Apr 25, 2024
@natestemen natestemen added the non-quantum Requires no knowledge of quantum physics to fix / work on. label Apr 25, 2024
@purva-thakre
Copy link
Contributor Author

purva-thakre commented May 3, 2024

Looked into what this entails. With the newer API, the covariance matrix option was removed in np.polynomial.polynomial.polyfit.

Tests will fail due to TypeError: polyfit() got an unexpected keyword argument 'cov'.

scale_factors, exp_values, deg, w=weights, cov=True

So, we will have to work around numpy/numpy#20871 or keep using the older API.

There are two open PRs to allow the covariance matrix option in np.polynomial.polynomial.polyfit as a cov kwarg or a fit_with_covariance function. One has an inactive label. It's difficult to tell if cov will be an available option in the newer API.

@cosenal
Copy link
Contributor

cosenal commented May 7, 2024

It looks like the covariance matrix is used to calculate the error of the fit in

zne_error = np.sqrt(params_cov[order, order])

If one passes full=True to np.polynomial.polynomial.polyfit, they can then get the residuals of the fit and perhaps calculate the error from there?

@purva-thakre
Copy link
Contributor Author

they can then get the residuals of the fit and perhaps calculate the error from there?

By defining a function for this in mitiq, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers non-quantum Requires no knowledge of quantum physics to fix / work on.
Projects
None yet
Development

No branches or pull requests

3 participants