# replacetag usage for mps

**URL:** https://itensor.discourse.group/t/replacetag-usage-for-mps/985
**Category:** ITensor Julia Questions
**Tags:** mps
**Created:** [June 28, 2023, 12:45pm UTC](https://itensor.discourse.group/t/replacetag-usage-for-mps/985 "2023-06-28T12:45:50Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Bob](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@Bob](https://itensor.discourse.group/u/Bob)
#### Post date: [June 28, 2023, 12:45pm UTC](https://itensor.discourse.group/t/replacetag-usage-for-mps/985/1 "2023-06-28T12:45:50Z")

</div>

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](https://itensor.github.io/ITensors.jl/dev/MPSandMPO.html#ITensors.replacetags-Tuple%7Btypeof(linkinds),%20ITensors.AbstractMPS%7D). 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.

```auto
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.

```auto
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

```

---

<div class="post-metadata">

### Author: ![ryanlevy](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/ryanlevy/32/150_2.png) [@ryanlevy](https://itensor.discourse.group/u/ryanlevy)
#### Post date: [June 28, 2023, 1:01pm UTC](https://itensor.discourse.group/t/replacetag-usage-for-mps/985/2 "2023-06-28T13:01:55Z")

</div>

I think this is what you want:

```julia
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

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

```

---

<div class="post-metadata">

### Author: ![miles](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/miles/32/6_2.png) [@miles](https://itensor.discourse.group/u/miles)
#### Post date: [June 28, 2023, 1:15pm UTC](https://itensor.discourse.group/t/replacetag-usage-for-mps/985/3 "2023-06-28T13:15:04Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Bob](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@Bob](https://itensor.discourse.group/u/Bob)
#### Post date: [June 28, 2023, 1:44pm UTC](https://itensor.discourse.group/t/replacetag-usage-for-mps/985/4 "2023-06-28T13:44:04Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Bob](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@Bob](https://itensor.discourse.group/u/Bob)
#### Post date: [June 28, 2023, 2:32pm UTC](https://itensor.discourse.group/t/replacetag-usage-for-mps/985/5 "2023-06-28T14:32:47Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ryanlevy](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/ryanlevy/32/150_2.png) [@ryanlevy](https://itensor.discourse.group/u/ryanlevy)
#### Post date: [June 28, 2023, 2:54pm UTC](https://itensor.discourse.group/t/replacetag-usage-for-mps/985/6 "2023-06-28T14:54:20Z")

</div>

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

```julia
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…
