Ask here about the “Product Formulas” Codebook topic from the “ Hamiltonian Simulation” module.
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:
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!
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!
It worked!
Thank you @CatalinaAlbornoz .