# Hamiltonian Simulation with QSP

**URL:** https://discuss.pennylane.ai/t/hamiltonian-simulation-with-qsp/8020
**Category:** PennyLane Help
**Created:** [February 18, 2025, 4:18pm UTC](https://discuss.pennylane.ai/t/hamiltonian-simulation-with-qsp/8020 "2025-02-18T16:18:10Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Shehara](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/shehara/32/2553_2.png) [@Shehara](https://discuss.pennylane.ai/u/Shehara)
#### Post date: [February 18, 2025, 4:18pm UTC](https://discuss.pennylane.ai/t/hamiltonian-simulation-with-qsp/8020/1 "2025-02-18T16:18:10Z")

</div>

Hello Everyone,

I am trying to perform Hamiltonian simulation by building a circuit using linear combinations of `cos(Ht)` and `-isin(Ht)` similar to the attached pic.

 ![Hamiltonian_Simulation](https://canada1.discourse-cdn.com/flex012/uploads/pennylane/original/2X/0/0def21fb4ec6548fb2f36a2343b60185556fc128.png)

I was able to find phase factors for `cos(Ht)` using **pyqsp** and **QSPPACK** packages. However, I can’t seem to approximate `-isin(Ht)` as a polynomial (because its complex) and calculate phase factors using above packages.

I would like to know if there is any other alternative way to build `-isin(Ht)` by first approximating `-sin(Ht)` and multiply using a quantum gate to obtain `-isin(Ht)`.

Or, is there any other way to approximate `-isin(Ht)` using these packages.

Thanks a lot for the assistance!

P.S: This is my code for calculating phase factors using **pyqsp** package.

```auto
# Import relevant modules and methods.
import matplotlib.pyplot as plt
import numpy as np
from pyqsp import angle_sequence, response
from pyqsp.poly import PolyTaylorSeries

# Specify definite-parity target function for QSP.
func = lambda x: np.sin(3 * x)
polydeg = 3 # Desired QSP protocol length.
max_scale = 0.5 # Maximum norm (<1) for rescaling.
true_func = lambda x: max_scale * func(x) # For error, include scale.

"""
With PolyTaylorSeries class, compute Chebyshev interpolant to degree
'polydeg' (using twice as many Chebyshev nodes to prevent aliasing).
"""
poly = PolyTaylorSeries().taylor_series(
    func=func,
    degree=polydeg,
    max_scale=max_scale,
    chebyshev_basis=True,
    cheb_samples=2 * polydeg,
)

# Compute full phases (and reduced phases, parity) using symmetric QSP.
(phiset, red_phiset, parity) = angle_sequence.QuantumSignalProcessingPhases(
    poly, method="sym_qsp", chebyshev_basis=True
)

"""
Plot response according to full phases.
Note that `pcoefs` are coefficients of the approximating polynomial,
while `target` is the true function (rescaled) being approximated.
"""
response.PlotQSPResponse(
    phiset, pcoefs=poly, target=true_func, sym_qsp=True, simul_error_plot=True
)

```

---

<div class="post-metadata">

### Author: ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)
#### Post date: [February 19, 2025, 2:21am UTC](https://discuss.pennylane.ai/t/hamiltonian-simulation-with-qsp/8020/2 "2025-02-19T02:21:55Z")

</div>

Hi @Shehara ,

Unfortunately we’re not experts on the pyqsp nor QSPPACK packages here. We’re experts on PennyLane though, which has functionality for Quantum Signal Processing and QSVT. You can take a look at our tutorials on these topics [here](https://pennylane.ai/search?q=QSP&contentType=DEMO).

I hope these PennyLane tutorials can help you out.

---

<div class="post-metadata">

### Author: ![Guillermo\_Alonso](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/guillermo_alonso/32/816_2.png) [@Guillermo\_Alonso](https://discuss.pennylane.ai/u/Guillermo_Alonso)
#### Post date: [February 19, 2025, 3:42am UTC](https://discuss.pennylane.ai/t/hamiltonian-simulation-with-qsp/8020/3 "2025-02-19T03:42:20Z")

</div>

To give you a little hint, apply an S gate after the first Hadamard, add a phase “i” in the black control 😉

---

<div class="post-metadata">

### Author: ![Shehara](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/shehara/32/2553_2.png) [@Shehara](https://discuss.pennylane.ai/u/Shehara)
#### Post date: [February 20, 2025, 3:59pm UTC](https://discuss.pennylane.ai/t/hamiltonian-simulation-with-qsp/8020/4 "2025-02-20T15:59:09Z")

</div>

Hi Catalina, Thank you so much for sharing the tutorials. I will go through them.

---

<div class="post-metadata">

### Author: ![Shehara](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/shehara/32/2553_2.png) [@Shehara](https://discuss.pennylane.ai/u/Shehara)
#### Post date: [February 20, 2025, 4:01pm UTC](https://discuss.pennylane.ai/t/hamiltonian-simulation-with-qsp/8020/5 "2025-02-20T16:01:13Z")

</div>

Thank you Guillermo, thanks a lot for the hint, yes indeed it applies the phase ‘i’, which is what I need. I will implement in Pennylane and see the results.

---

<div class="post-metadata">

### Author: ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)
#### Post date: [February 20, 2025, 9:22pm UTC](https://discuss.pennylane.ai/t/hamiltonian-simulation-with-qsp/8020/6 "2025-02-20T21:22:28Z")

</div>

Let us know if you have any PennyLane questions @Shehara !
