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

MPS and MPO interface updates #285

Closed
6 of 17 tasks
mtfishman opened this issue Apr 16, 2020 · 7 comments
Closed
6 of 17 tasks

MPS and MPO interface updates #285

mtfishman opened this issue Apr 16, 2020 · 7 comments
Assignees
Labels
api Issues related to the interface enhancement New feature or request mps Issues related to MPS/MPO functionality

Comments

@mtfishman
Copy link
Member

mtfishman commented Apr 16, 2020

Here are some proposals for improving the MPS and MPO algebra interface:

  • Introduce a function product that wraps contract(::MPO, ::MPS) that attempts to return the output site indices to the original MPS site indices (for example, with a simple call to replace_siteinds!). This is called product since it is very similar to the ProjMPO product function, and you could imagine this operation being used in a global Krylov method using MPS/MPO.
  • Introduce a function product(A::MPO, B::MPO) that works like matmul(::ITensor, ::ITensor) where the two MPOs have the same pairs of site indices, and returns an MPO with the same pairs of site indices as the input. It would do the operation mapprime(prime(A)*B,2,1).
  • Introduce add(::MPS, ::MPS, ::MPS...) for summing many MPS, with the fancier algorithm use in sum(::Vector{MPS}).
  • Make contract(::MPS, ::MPS) that is like inner/dot but does not dag the first MPS, and doesn't match the site indices by default (a more literal MPS * MPS contraction).
  • Rename mul(::MPO, ::MPS)/applympo(::MPO, ::MPS) to contract(::MPO, ::MPS), with an alias *. We can also provide contract(H::MPS, psi::MPO) = contract(psi, H).
  • Rename mul(::MPO, ::MPO)/multmpo to contract(::MPO, ::MPO).
  • Change the name of sum(::MPS, ::MPS) to add/+.

And for other miscellaneous improvements:

  • Add reverse_sites!(::Union{MPS,MPO}) to reverse the site ordering of the MPS/MPO (useful for some quantum computing applications, where you might want to reverse the qubit ordering).
  • Add Vector(::MPS) and Matrix(::MPO) conversion which converts an MPS/MPO into the equivalent exponentially large Vector or Matrix (useful for ED comparisons).
  • Provide an MPO(sites) function that fills with Empty ITensors.
  • Add versions of MPO(...) constructors that accept an element type.
  • In *(x::Number, ::AbstractMPS), instead of multiplying the middle tensor by x, instead multiply the tensors between the left and right orthogonality center by x^(1/N) where N is the distance between llim and rlim.
  • Add norm for MPS/MPO.
  • Add lognorm and loginner/logdot for MPS/MPO (proposed here).
  • MPS(sites) where length(sites) == 1 doesn't work right now.
  • Add more priming and tagging functions.
  • Add an "unsafe" version of setindex! that does not change the orthogonality center, for operations that you know will not affect the orthogonality center.
@mtfishman mtfishman added api Issues related to the interface enhancement New feature or request mps Issues related to MPS/MPO functionality labels Apr 16, 2020
@mtfishman mtfishman added this to the Version 0.1 milestone Apr 16, 2020
@mtfishman
Copy link
Member Author

Some of these have been implemented in #290, at least the breaking changes. The rest would be new features and can be implemented after v0.1.

@emstoudenmire
Copy link
Collaborator

@mtfishman ok to remove the 0.1 Milestone tag from this, then, if the rest of these will be post 0.1 changes?

@mtfishman mtfishman removed this from the Version 0.1 milestone Apr 28, 2020
@mtfishman
Copy link
Member Author

Yes, all of these are non-breaking. Just removed.

@GTorlai
Copy link
Contributor

GTorlai commented May 21, 2020

It would be useful to have a function returning the normalization of an MPS with large N without a gauge center (e.g. for gradient-based optimizations of randomly initialized MPS). Depending on the initial MPS parameters, a direct calculation of the normalization typically becomes unstable for large N. The following function fixes the problem by computing the log-normalization:

function lognormalization(psi::MPS)                                   
  blob = dag(psi[1]) * prime(psi[1], "Link")
  localZ = real((dag(blob)*blob)[])
  logZ = 0.5*log(localZ)
  blob /= sqrt(localZ)

  for j in 2:length(psi)-1
    blob = blob * dag(psi[j]);
    blob = blob * prime(psi[j], "Link")
    localZ = real((dag(blob)*blob)[])
    logZ += 0.5*log(localZ)
    blob /= sqrt(localZ)
  end

  blob = blob * dag(psi[length(psi)]);
  blob = blob * prime(psi[length(psi)],"Link")
  logZ += log(real(blob[]))
  return logZ
end;

@emstoudenmire
Copy link
Collaborator

emstoudenmire commented May 21, 2020 via email

@GTorlai
Copy link
Contributor

GTorlai commented May 21, 2020

Yes, good point, that would be enough.

@mtfishman
Copy link
Member Author

I'm working on this right now, by the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issues related to the interface enhancement New feature or request mps Issues related to MPS/MPO functionality
Projects
None yet
Development

No branches or pull requests

3 participants