# \[HS.4.2a\]Incorrect: Something is off with your Hamiltonian!

**URL:** <https://discuss.pennylane.ai/t/hs-4-2a-incorrect-something-is-off-with-your-hamiltonian/9497>\
**Category:** Codebook\
**Created:** [September 11, 2026, 8:09am UTC](https://discuss.pennylane.ai/t/hs-4-2a-incorrect-something-is-off-with-your-hamiltonian/9497 "2026-09-11T08:09:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ring](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/ring/32/4429_2.png) [@Ring](https://discuss.pennylane.ai/u/Ring)\
**Post date:** [September 11, 2026, 8:09am UTC](https://discuss.pennylane.ai/t/hs-4-2a-incorrect-something-is-off-with-your-hamiltonian/9497/1 "2026-09-11T08:09:01Z")

</div>

Hi,

When i coding HS.4.2a PrepSelPrep on the Walk operator, it show incorrect.

error log\>\>\>

Incorrect: Something is off with your Hamiltonian!

my code\>\>\>

offes = [1/4,1/4,1/2]  
objs = [qml.Z(5),qml.Z(6),qml.Z(5)@qml.Z(6)]  
H = qml.Hamiltonian(offes,objs)

dev = qml.device(“default.qubit”, wires = range(7))

walk\_powers\_1 = [qml.pow(qml.Qubitization(H, control = [3,4]), i) for i in range(0,3)]  
walk\_powers\_2 = [qml.pow(qml.adjoint(qml.Qubitization(H, control = [3,4])), i) for i in reversed(range(1,3))]

bessel\_1 = [0.765197686557943666, 0.44005058574493355, 0.11490348493190051]  
J0, J1, J2 = bessel\_1

norm\_factor = J0 + 2_J1 + 2_J2

lcu\_coeffs = [  
J2 / norm\_factor,  
J1 / norm\_factor,  
J0 / norm\_factor,  
J1 / norm\_factor,  
J2 / norm\_factor  
]

lcu\_ops = [  
qml.s\_prod(-1, walk\_powers\_2[0]), # - W^{-2}  
qml.s\_prod(-1j, walk\_powers\_2[1]), # -i W^{-1}  
walk\_powers\_1[0], # I  
qml.s\_prod(1j, walk\_powers\_1[1]), # +i W^{1}  
qml.s\_prod(-1, walk\_powers\_1[2]) # - W^{2}  
]

lcu = qml.dot(lcu\_coeffs, lcu\_ops)

@qml.qnode(dev)  
def prep\_sel\_prep\_walk():  
qml.PrepSelPrep(lcu, control=[0,1,2])  
return qml.state()

encoded\_matrix = qml.matrix(prep\_sel\_prep\_walk, wire\_order=range(7))()[:4, :4]  
print("The encoded matrix is: ", encoded\_matrix)

output\>\>\>

```auto
The encoded matrix is: [[0.286+1.930e-16j 0. +0.000e+00j 0. +0.000e+00j 0. +0.000e+00j]
 [0. +0.000e+00j 0.469-1.039e-16j 0. +0.000e+00j 0. +0.000e+00j]
 [0. +0.000e+00j 0. +0.000e+00j 0.469-1.047e-16j 0. +0.000e+00j]
 [0. +0.000e+00j 0. +0.000e+00j 0. +0.000e+00j 0.531-1.501e-17j]]

```

 ![截图 2026-09-11 16-08-24](https://canada1.discourse-cdn.com/flex012/uploads/pennylane/original/2X/b/be89ec4a7c2822a0c5ccb9e52ebeff180ae8512c.jpeg)

 ![截图 2026-09-11 16-08-32](https://canada1.discourse-cdn.com/flex012/uploads/pennylane/original/2X/2/26e5c75d017cd34b792fa5c86427f35288ab3926.jpeg)

---

<div class="post-metadata">

**Author:** ![gabriela](https://avatars.discourse-cdn.com/v4/letter/g/db5fbb/32.png) [@gabriela](https://discuss.pennylane.ai/u/gabriela)\
**Post date:** [September 11, 2026, 7:59pm UTC](https://discuss.pennylane.ai/t/hs-4-2a-incorrect-something-is-off-with-your-hamiltonian/9497/2 "2026-09-11T19:59:31Z")

</div>

Hi @Ring, welcome to the Forum!

Your solution is almost there 🙌 Notice however that the last term of the Hamiltonian in the description of the Codercise is not a product of Pauli `Z` gates as you have in the `objs` list. That is what’s causing the error you are seeing.

There is one additional problem that you’ll run into after correcting the Hamiltonian, please doublecheck your `lcu_ops` list, one of the terms has a sign error.

I hope that helps, and good luck!
