# Codebook: Product Formulas

**URL:** <https://discuss.pennylane.ai/t/codebook-product-formulas/7518>\
**Category:** Codebook\
**Created:** [November 8, 2024, 10:33pm UTC](https://discuss.pennylane.ai/t/codebook-product-formulas/7518 "2024-11-08T22:33:13Z")\
**Posts on this page:** 4\
**Page:** 1

<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:** [November 8, 2024, 10:33pm UTC](https://discuss.pennylane.ai/t/codebook-product-formulas/7518/1 "2024-11-08T22:33:13Z")

</div>

Ask here about the [“Product Formulas” Codebook topic](https://pennylane.ai/codebook/14-hamiltonian-simulation/01-trotterization) from the “ Hamiltonian Simulation” module.

---

<div class="post-metadata">

**Author:** ![Javi512](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/javi512/32/3413_2.png) [@Javi512](https://discuss.pennylane.ai/u/Javi512)\
**Post date:** [November 29, 2024, 10:54pm UTC](https://discuss.pennylane.ai/t/codebook-product-formulas/7518/2 "2024-11-29T22:54:04Z")

</div>

**Hello everyone,**

I’m currently working on the **Product Formulas** codebook and tackling the **Trotter Error** codersice. In this codersice, we’re asked to complete the code for the _trotter\_XandZ_ function, which implements a “Trotterized circuit for evolving a qubit with H = alpha Z + beta X”, as described in the instructions.

Here’s the solution I’ve tried submitting:

```
H = qml.dot([alpha,beta],[qml.PauliZ(0),qml.PauliX(0)])
qml.TrotterProduct(H,time,n)

```

However, when I submit this code, I encounter the error:

```
Error: 'tensor' object has no attribute 'name'

```

After testing it in a Jupyter notebook, I found that the error arises when I define a vector for the **n** argument in the function. The goal is to plot **n versus the error** using **np.arange(1, n)**. Switching to Python’s built-in **range(1, n)** resolves the error, but it produces the following plot:

 ![error_XandZ_vs_n](https://canada1.discourse-cdn.com/flex012/uploads/pennylane/original/2X/f/ff391bf891380db951ec2e37524f759e45fea9ef.jpeg)

Does anyone have any insight on why that error is arising? Or, regarding my solution, is it okay as it is? Thank you in advance for your help! 😄

---

<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:** [December 3, 2024, 12:09am UTC](https://discuss.pennylane.ai/t/codebook-product-formulas/7518/3 "2024-12-03T00:09:49Z")

</div>

Hi @Javi512 ,

You’re not expected to use `qml.TrotterProduct` here. The goal is that within the `trotter_XandZ` function you apply RZ and RX gates for each of the trotter steps.

I hope this helps!

---

<div class="post-metadata">

**Author:** ![Javi512](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/javi512/32/3413_2.png) [@Javi512](https://discuss.pennylane.ai/u/Javi512)\
**Post date:** [December 3, 2024, 4:40pm UTC](https://discuss.pennylane.ai/t/codebook-product-formulas/7518/4 "2024-12-03T16:40:22Z")

</div>

It worked!

Thank you @CatalinaAlbornoz 😄.
