# Constructing Hamiltonian which contains a variable

**URL:** <https://discuss.pennylane.ai/t/constructing-hamiltonian-which-contains-a-variable/4107>\
**Category:** PennyLane Help\
**Created:** [February 16, 2024, 12:27pm UTC](https://discuss.pennylane.ai/t/constructing-hamiltonian-which-contains-a-variable/4107 "2024-02-16T12:27:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaushik](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/kaushik/32/2546_2.png) [@Kaushik](https://discuss.pennylane.ai/u/Kaushik)\
**Post date:** [February 16, 2024, 12:27pm UTC](https://discuss.pennylane.ai/t/constructing-hamiltonian-which-contains-a-variable/4107/1 "2024-02-16T12:27:07Z")

</div>

I want to make a hamiltonian for a lattice and decompose it , then run ssvqe algorithm on it to get the band structure of the lattice. so i need to decompose a a hamiltonian which is containing k as variable. Can you help me how to build the code to define the hamiltonian and run the ssvqe on it so that i get continuous energy for each k value?

---

<div class="post-metadata">

**Author:** ![isaacdevlugt](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/isaacdevlugt/32/1159_2.png) [@isaacdevlugt](https://discuss.pennylane.ai/u/isaacdevlugt)\
**Post date:** [February 19, 2024, 10:43pm UTC](https://discuss.pennylane.ai/t/constructing-hamiltonian-which-contains-a-variable/4107/2 "2024-02-19T22:43:54Z")

</div>

Hey @Kaushik! Sounds like you’re just starting on this project, so I can give you some good resources to help you along:

- VQE (in a QChem context, but a good read!): [A brief overview of VQE | PennyLane Demos](https://pennylane.ai/qml/demos/tutorial_vqe/)
- Condensed matter example (see building Hamiltonians, lattices, etc.): [Modeling the toric code on a quantum computer | PennyLane Demos](https://pennylane.ai/qml/demos/tutorial_toric_code/)

Can’t hurt to sift through all of our demos to see if something better fits your needs: [Demos | PennyLane](https://pennylane.ai/qml/demonstrations/)

Interestingly, I also found this repo that has SSVQE with PennyLane, but keep in mind that it’s 3 years old and some features might be deprecated or removed altogether. Might help get some ideas flowing though!

- [SSVQE/SSVQE\_Tutorial.ipynb at main · LegacYFTw/SSVQE · GitHub](https://github.com/LegacYFTw/SSVQE/blob/main/SSVQE_Tutorial.ipynb)

Let me know if this helps 🙂
