QuantumKitHub / MPSKitModels.jl

MIT License
20 stars 13 forks source link

Infinite range gives InexactError: trunc(Int64, Inf) #27

Open HumpyBlumpy opened 2 months ago

HumpyBlumpy commented 2 months ago

Hi,

Trying out one of the examples to create a Hamiltonian on an infinite chain:

using MPSKit, MPSKitModels, TensorKit
H = @mpoham sum(σᶻᶻ{i, i+1} + h * σˣ{i} for i in -Inf:Inf)

yields ERROR: InexactError: trunc(Int64, Inf). Tried replacing Inf with ∞ but it is not recognized. Am I missing a certain package or something? I have Julia 1.10

lkdvos commented 1 month ago

Hi,

My apologies for this inconvenience. The macro is supposed to handle these kinds of syntactic sugar features (in this case just replacing the range with InfiniteChain(L) where L is the unit cell) but at some point it became quite inconvenient to keep track of what are intuitive things that should be supported, and what is not. My own opinion on the matter is that it has taken too much development time for very little benefit, so I have been neglecting the macro a bit (again my apologies for that).

In this case, you can just simply replace the iterator with some type of lattice, which should then work. I will make sure to update the examples to reflect this.

As a side note, do you feel like this kind of syntax adds a lot of value? If so, I will definitely try and fix it and support this again. (Next week, as I am currently on holiday)

HumpyBlumpy commented 1 month ago

Thanks for the quick response. I think I managed to construct the Hamiltonian by copying parts of the source code for some of the predefined models. The syntax there is however somewhat cumbersome. I am not sure what you mean by

simply replace the iterator with some type of lattice

An example would help:) I tried
H = @mpoham sum(σᶻᶻ{i, i+1} + h * σˣ{i} for i in InfiniteChain(1)) but that didnt work.

leburgel commented 1 month ago

I think you need to add an explicit iteration over the vertices for it to know what to do. This should work I think:

H = @mpoham sum(σᶻᶻ(){i, i+1} + h * σˣ(){i} for i in vertices(InfiniteChain(1)))