Skip to content

Commit

Permalink
Update README for clarity.
Browse files Browse the repository at this point in the history
  • Loading branch information
white-noise committed Sep 2, 2024
1 parent 5aef91d commit edec9b7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ As in the case of trigonometric cosine, the step function's approximation is als

> :round_pushpin: The final plot given above is generated in a fairly simple way, but relies on a few, user-programmable inputs which we discuss with a subsection of the code given in `pyqsp/sym_qsp_plotting.py` below. The code given here is prefaced in the original file by proper imports, and the QSP phases generated by the Newton solver are used to generate the plots with further methods.
>
> :caution: Note that the arguments `chebyshev_basis` (a Boolean) and `cheb_samples` are both used here. The `chebyshev_basis` flag ensures that the behind-the-scenes optimization methods used in finding polynomial approximations work in the more stable Chebyshev basis, and that Chebyshev basis coefficients are returned. The `cheb_samples` argument chooses the number of Chebyshev node interpolation points with which this classical fit is computed; to prevent aliasing issues *it is best to choose `cheb_samples` to be greater than `degree`, which specifies the degree of the polynomial approximant*. Here `delta` scales as the approximate inverse gap between the regions where the desired function takes the extreme values 1 and -1.
> :warning: Note that the arguments `chebyshev_basis` (a Boolean) and `cheb_samples` are both used here. The `chebyshev_basis` flag ensures that the behind-the-scenes optimization methods used in finding polynomial approximations work in the more stable Chebyshev basis, and that Chebyshev basis coefficients are returned. The `cheb_samples` argument chooses the number of Chebyshev node interpolation points with which this classical fit is computed; to prevent aliasing issues *it is best to choose `cheb_samples` to be greater than `degree`, which specifies the degree of the polynomial approximant*. Here `delta` scales as the approximate inverse gap between the regions where the desired function takes the extreme values 1 and -1.
```python
# Generate Chebyshev coefs for approx sign function.
Expand All @@ -197,14 +197,14 @@ pcoefs = pg.generate(
cheb_samples=250)
pcoefs = pcoefs.coef

# Instantiate anonymous function using generated coefs.
# As an example, generate polynomial approximation as a callable function using above-computed coefs.
sign_fun = lambda x: np.polynomial.chebyshev.chebval(x, pcoefs)

# Slice out non-trivial coefficients; here degree=161, which has parity 1.
parity = 1
coef = pcoefs[parity::2]

# Iteratively optimize QSP protocol phases using Newton solver.
# Iteratively optimize QSP phases using Newton solver, which takes parity-reduced Chebyshev coefs.
(phases, err, total_iter, qsp_seq_opt) = sym_qsp_opt.newton_Solver(coef, parity, crit=1e-12)
```

Expand Down
Binary file modified docs/ex_step_approximation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pyqsp/sym_qsp_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def main():

# Generate simultaneous plots.
fig, axs = plt.subplots(2,sharex=True)
fig.suptitle('Approximating cosine with QSP to machine precision')
fig.suptitle('Approximating sign with QSP to machine precision')

# Standard plotting of relevant components.
axs[0].plot(samples, im_vals, 'r', label="QSP imag poly")
Expand Down

0 comments on commit edec9b7

Please sign in to comment.