Skip to content

Commit

Permalink
README reformat.
Browse files Browse the repository at this point in the history
  • Loading branch information
white-noise committed Sep 6, 2024
1 parent 79d9bfb commit 31b2542
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

![test workflow](https://github.com/ichuang/pyqsp/actions/workflows/run_tests.yml/badge.svg)

<!-- *TODO: add some symbols for the main headings, add a title that matches the title of the repo, and overall remove extraneous lists of outputs and inputs outside of a dedicated example section.*
*Additionally, find ways to center figures, replace these figures with updated ones in better formatting, and possibly get things to play nice with dark mode, etc.* -->

<!-- Brackets still not extending for bmatrix, etc. -->
<!-- *TODO: add some symbols for the main headings, add a title that matches the title of the repo, and overall remove extraneous lists of outputs and inputs outside of a dedicated example section.* -->

## Introduction

Expand Down Expand Up @@ -66,7 +62,9 @@ The guiding principle to take away from the discussion above is the following: t

This package includes various tools for plotting aspects of the computed QSP unitaries, many of which can be run from the command line. As an example, in the chart below the dashed line shows the target ideal polynomial QSP *response function* approximating a scaled version of $1/a$ over a sub-interval of $[-1,1]$. The dark line shows the real part of an actual response function, i.e., the matrix element $P_x(a)$, achieved by a QSP circuit with computed phases, while the blue line shows the imaginary part of the QSP response, with `n = 20` (the length of the QSP phase list less one).

![QSP response function for the inverse function 1/a](https://github.com/ichuang/pyqsp/blob/master/docs/ex_inversion.png)
<p align="center">
<img src="https://github.com/ichuang/pyqsp/blob/master/docs/ex_inversion.png" alt="QSP response function for the inverse function 1/a" width="75%"/>
</p>

This was generated by running `pyqsp --plot --tolerance=0.01 --seqargs 3 invert`, which also spits out the the following verbose text:

Expand All @@ -90,23 +88,29 @@ pyqsp --plot-positive-only --plot --polyargs=19,10 --plot-real-only --polyname p
```
yields QSP phases for a degree `19` polynomial approximation, using the error function applied to `kappa * a`, where `kappa` is `10`. This also gives a plotted response function:

![Example QSP response function approximating the sign function](https://github.com/ichuang/pyqsp/blob/master/docs/ex_amplitude_amplification.png)
<p align="center">
<img src="https://github.com/ichuang/pyqsp/blob/master/docs/ex_amplitude_amplification.png" alt="Example QSP response function approximating the sign function" width="75%"/>
</p>

A threshold function further generalizes on the sign function, e.g., as used in distinguishing eigenvalues or singular values through windowing. Running
```
pyqsp --plot-real-only --plot --polyargs=20,20 --polyname poly_thresh poly
```
yields QSP phases for a degree `20` polynomial approximation, using two error functions applied to `kappa * 20`, with a plotted response function:

![Example QSP response function approximating a threshold function](https://github.com/ichuang/pyqsp/blob/master/docs/ex_bandpass_response.png)
<p align="center">
<img src="https://github.com/ichuang/pyqsp/blob/master/docs/ex_bandpass_response.png" alt="Example QSP response function approximating a threshold function" width="75%"/>
</p>

In addition to approximations to piecewise continuous functions, the smooth trigonometric functions sine and cosine functions also often appear, e.g., in Hamiltonian simulation. Running:
```
pyqsp --plot --func "np.cos(3*x)" --polydeg 6 --plot-qsp-model polyfunc
```
produces QSP phases for a degree `6` polynomial approximation of `cos(3*x)`, with the plotted response function:

![Example QSP response function approximating a cosine function](https://github.com/ichuang/pyqsp/blob/master/docs/IMAGE-sample-qsp-response-for-cos-using-tf-order-6.png?raw=true)
<p align="center">
<img src="https://github.com/ichuang/pyqsp/blob/master/docs/IMAGE-sample-qsp-response-for-cos-using-tf-order-6.png?raw=true" alt="Example QSP response function approximating a cosine function" width="75%"/>
</p>

This last example also shows how an arbitrary function can be specified (using a `numpy` expression) as a string, and fit using an arbitrary order polynomial (may need to be even or odd, to match the function), using optimization via tensorflow, and a keras model. The example also shows an alternative style of plot, produced using the `--plot-qsp-model` flag.

Expand Down Expand Up @@ -177,19 +181,21 @@ For instance, the current file returns approximations to cosine, sine, and a ste
<img src="https://github.com/ichuang/pyqsp/blob/master/docs/ex_cosine_approximation.png" alt="QSP response function approximating trigonometric cosine" width="75%"/>
</p>

<!-- ![QSP response function approximating trigonometric cosine](https://github.com/ichuang/pyqsp/blob/master/docs/ex_cosine_approximation.png) -->

As the quality of the approximation is quite high, causing the three intended plots to superpose, we include a logarithmic plot of the pairwise difference between the plotted values, indicating near-machine-precision limited performance.

Other benefits of the `symmetric_qsp` method appear when we approximate a scaled version of $1/x$. This is implemented in `pyqsp/sym_qsp_opt.py` for the choices `kappa = 5` (specifying the domain of valid approximation) and `epsilon = 0.01` (the uniform approximation error on the domain). We plot this approximation, indicating the region of validity from `[-1, -1/kappa]`-union-`[1/kappa, 1]` in gray, clearly showing that the approximation error bound and QSP phase error bounds are satisfied in the valid region.

![QSP response function approximating scaled 1/x](https://github.com/ichuang/pyqsp/blob/master/docs/ex_qsp_inverse_approx.png)
<p align="center">
<img src="https://github.com/ichuang/pyqsp/blob/master/docs/ex_qsp_inverse_approx.png" alt="QSP response function approximating scaled 1/x" width="75%"/>
</p>

> :round_pushpin: Previously the computation of QSP phases to approximate 1/x was limited by two factors: (1) the instability of direct polynomial completion methods in the `laurent` approach, and (2) integer overflow errors resulting from computing coefficients of the analytic polynomial approximation in a naïve way. The plot above has been generated in a way which avoids both issues, and its degree can be easily pushed into the hundreds. The plot above uses `d = 155`.
Finally, we can move away from functions for which we have analytic descriptions of their Chebyshev expansions to general piecewise continuous functions for which we numerically compute Chebyshev interpolants. One such example is the step function, plotted analogously below.

![QSP response function approximating a step function](https://github.com/ichuang/pyqsp/blob/master/docs/ex_step_approximation.png)
<p align="center">
<img src="https://github.com/ichuang/pyqsp/blob/master/docs/ex_step_approximation.png" alt="QSP response function approximating a step function" width="75%"/>
</p>

As in the case of trigonometric cosine and inverse, the step function's approximation is also excellent within the specified region, and far more forgiving in its generation than with the earlier `laurent` method.

Expand Down

0 comments on commit 31b2542

Please sign in to comment.