replacetag usage for mps

I am trying to do something fairly simple but am having some trouble with the usage.

I am looking at replacetags! as it applies to MPS. The documentation does not contain any replacetags! MPS examples (that I could find) and I’m not able to infer from the source code what args is supposed to be.

Here is a MWE.

Any advice on how to achieve this would be appreciated.

begin
    d = 2
    N = 5
    n = d^N
    x = LinRange(2, 6, n)
    f = x
    inds = siteinds(d, N)
    MWE = MPS(f, inds) # Has default "Link,n=#" 
    newlinktags = ["α,n=$(i)" for i = 1:(N-1)]
    replacetags!(linkinds, MWE, newlinktags) # throws error, see below
end

This gives the following error.

ERROR: MethodError: no method matching replacetags(::Vector{Index{Int64}}, ::Vector{String})
Closest candidates are:
  replacetags(::Union{Tuple{Vararg{IndexT}}, Vector{IndexT}} where IndexT<:Index, ::Any, ::Any, ::Any...; kwargs...) at ~/.julia/packages/ITensors/fpBnt/src/indexset.jl:512
  replacetags(::Union{Tuple{Vararg{IndexT}}, Vector{IndexT}} where IndexT<:Index, ::Pair...; kwargs...) at ~/.julia/packages/ITensors/fpBnt/src/indexset.jl:505
  replacetags(::ITensors.AbstractMPS, ::Any...; set_limits, kwargs...) at ~/.julia/packages/ITensors/fpBnt/src/mps/abstractmps.jl:722

I think this is what you want:

replacetags!(MWE, "Link" => "α" )

I’ll let others comment for a more comprehensive answer, but I’ll also add you can specify the prime level (plev) as well

replacetags!(MWE, "Link"=>"α" ; plev = 1) # this will do nothing
1 Like

Agreed that we need some code examples for this! Thanks for letting us know. Please let us know below if Ryan’s solution does not quite do what you need, but it looks correct to me.

Yes! Thanks for the quick responses to you both. Ryan’s solution worked.

2 Likes

One follow-up.

Do you know how to replace the part of the tag associated with the site number?

For example, randomMPS returns an MPS with bond indices denoted by Link,l=1 while the MPS constructor will return all sites with n=1 in the tag. How could I replace the l= part of the tags in the MPS returned by randomMPS? (just for consistency)

In other words, go from Link,l=# to Link,n=#? I tried replacetags!(randMPS, "l=" => "n=") but it does not appear to change anything.

I’m sorry I don’t know a cleaner way to write this without splat-ing, but

newInds = ["l=$i" => "n=$i" for i=1:N]
replacetags!(MWE, "Link" => "α", newInds... )

Or a similar as a for loop. I suspect there’s a fancier way to do this but it’s escaping me at the moment…

1 Like