Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ITensors] [ENHANCEMENT] Add truncate keyword to the MPS constructor #1509

Closed
NuclearPowerNerd opened this issue Jun 21, 2024 · 7 comments
Closed
Labels
enhancement New feature or request ITensors Issues or pull requests related to the `ITensors` package.

Comments

@NuclearPowerNerd
Copy link
Contributor

Hello!

Sometimes I create MPS and I want a "lossless" version of whatever field that MPS represents (i.e., no truncation). It is useful for code and algorithm validation purposes. I know I could achieve this thru maxdim and/or cutoff but I think it would be a simple matter to add a new keyword argument to the MPS constructor, called truncate, which skips the truncation step in the SVD algorithm at the low level (buried in NDTensors).

So then it would be possible to call the constructor like this

A = MPS(f, truncate=false). 

truncate would default to true so existing behavior would be maintained.

If everyone agrees I'd be happy to prepare the pull request. I've read the contributing guidelines here.

Please let me know what you think.

@NuclearPowerNerd NuclearPowerNerd added enhancement New feature or request ITensors Issues or pull requests related to the `ITensors` package. labels Jun 21, 2024
@mtfishman
Copy link
Member

mtfishman commented Jun 21, 2024

I assume you are talking about the function for converting an ITensor to an MPS? Are you sure that isn't already the behavior if you don't specify any truncation parameters? I see:

julia> using ITensors, ITensorMPS

julia> i, j = Index.((2, 2))
((dim=2|id=59), (dim=2|id=472))

julia> a = random_itensor(i, j)
ITensor ord=2 (dim=2|id=59) (dim=2|id=472)
NDTensors.Dense{Float64, Vector{Float64}}

julia> x = MPS(a, [i, j])
MPS
[1] ((dim=2|id=59), (dim=2|id=289|"Link,n=1"))
[2] ((dim=2|id=289|"Link,n=1"), (dim=2|id=472))


julia> @show x[1];
x[1] = ITensor ord=2
Dim 1: (dim=2|id=59)
Dim 2: (dim=2|id=289|"Link,n=1")
NDTensors.Dense{Float64, Vector{Float64}}
 2×2
 -0.5213970227157092  0.8533142121769648
  0.8533142121769648  0.5213970227157092

julia> @show x[2];
x[2] = ITensor ord=2
Dim 1: (dim=2|id=289|"Link,n=1")
Dim 2: (dim=2|id=472)
NDTensors.Dense{Float64, Vector{Float64}}
 2×2
 -1.7428604446123537  0.7202766240206115
  0.0                 1.9874308479155949

which looks like it is doing a QR decomposition (and therefore isn't truncating):

julia> q, r = qr(a, i);

julia> @show q;
q = ITensor ord=2
Dim 1: (dim=2|id=59)
Dim 2: (dim=2|id=950|"Link,qr")
NDTensors.Dense{Float64, Vector{Float64}}
 2×2
 -0.5213970227157092  0.8533142121769648
  0.8533142121769648  0.5213970227157092

julia> @show r;
r = ITensor ord=2
Dim 1: (dim=2|id=950|"Link,qr")
Dim 2: (dim=2|id=472)
NDTensors.Dense{Float64, Vector{Float64}}
 2×2
 -1.7428604446123537  0.7202766240206115
  0.0                 1.9874308479155949

@mtfishman
Copy link
Member

If we are convinced that indeed by not setting any parameters it achieves the goal of your proposed truncate=false keyword argument interface, I don't think a new keyword argument is needed, but an action item could be to document the current behavior since it may be a bit hidden right now.

@NuclearPowerNerd
Copy link
Contributor Author

Hey @mtfishman , sorry for not being clearer. In the example above f was meant to be a vector of Float64 (at least in my head that's how I was thinking about it). I will investigate and confirm what you say (check the behavior when no parameters are specified in the call to the constructor).

@mtfishman
Copy link
Member

mtfishman commented Jun 21, 2024

How would you make an MPS from just a Vector{Float64}? Wouldn't you need a set if ITensor Indices, i.e. to define the site Indices of the MPS?

@NuclearPowerNerd
Copy link
Contributor Author

Right, not just Vector{Float64}. You would have had to create some indices probably using siteinds. So it would be something like MPS(f, sinds) where siteinds(d, N).

@NuclearPowerNerd
Copy link
Contributor Author

I'd say go ahead and close this. I experimented a bit more and I am finding that I get agreement down to ~1E-15 whether I specify maxdim and cutoff or don't pass them at all. Thus, I think no truncate keyword is necessary.

@mtfishman
Copy link
Member

Sounds good, thanks for following up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ITensors Issues or pull requests related to the `ITensors` package.
Projects
None yet
Development

No branches or pull requests

2 participants