# Help to building cost function

**URL:** <https://discuss.pennylane.ai/t/help-to-building-cost-function/4413>\
**Category:** PennyLane Help\
**Created:** [April 9, 2024, 9:35am UTC](https://discuss.pennylane.ai/t/help-to-building-cost-function/4413 "2024-04-09T09:35:49Z")\
**Posts on this page:** 1\
**Showing post:** 21

<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:** [April 29, 2024, 3:50pm UTC](https://discuss.pennylane.ai/t/help-to-building-cost-function/4413/21 "2024-04-29T15:50:09Z")

</div>

Hi @Kaushik,

That’s not the issue on its own. It’s something else that you’re doing in your code which is causing the issue.

I’ve used the SSVQE notebook [here](https://github.com/LegacYFTw/SSVQE/blob/main/SSVQE_Tutorial.ipynb) and modified `single_cost` as I mentioned before. I’ve added the comment “#modified” to the lines that I’ve modified. You can see my modified code below. If you run it with the latest version of PennyLane it runs well. Note that I haven’t modified `total_cost` here, and no errors show up from the line `cost +=w[state_idx]*single_cost(params, state_idx=state_idx)`.

I would suggest that you start from this notebook and make one change at a time until you reach an issue. Then you can identify the cause for your issue.

[SSVQE\_Tutorial\_mod.ipynb](https://discuss.pennylane.ai/uploads/short-url/t9HGMsjXqHGAffSq1pPJ1mIW9Y9.ipynb) (321.3 KB)

I hope this helps you.

---

_[View the full topic](https://discuss.pennylane.ai/t/help-to-building-cost-function/4413)._
