# Error when using infsiteinds(...) with custom Hilbert space (ITensorInfiniteMPS)

**URL:** <https://itensor.discourse.group/t/error-when-using-infsiteinds-with-custom-hilbert-space-itensorinfinitemps/2048>\
**Category:** ITensor Julia Questions\
**Tags:** mps\
**Created:** [October 10, 2024, 9:19am UTC](https://itensor.discourse.group/t/error-when-using-infsiteinds-with-custom-hilbert-space-itensorinfinitemps/2048 "2024-10-10T09:19:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amoghanakru](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@amoghanakru](https://itensor.discourse.group/u/amoghanakru)\
**Post date:** [October 10, 2024, 9:19am UTC](https://itensor.discourse.group/t/error-when-using-infsiteinds-with-custom-hilbert-space-itensorinfinitemps/2048/1 "2024-10-10T09:19:06Z")

</div>

Hi,

I am trying to initialize a (product state) infinite MPS with a custom Hilbert space called “twospinsite” (defined at the very end). The relevant code block is:

```auto
#imports
include("twospinsite.jl")

N = 2 # Unit cell size

initstate(n) = isodd(n) ? "full" : "empty" #Creates a period-2 pattern of full/empty states
s = infsiteinds("twospinsite", N; initstate, conserve_qns)

ψ = InfMPS(s, initstate)

```

The last line causes an error: ` **ERROR:** LoadError: ArgumentError: Overload of "val" function not found for Index tags "Site,c=1,n=1,twospinsite"`. It is further worth noting that the output of `println(s)` is as follows:

```auto
 1: QN("charge",1) => 1
 2: QN("charge",0) => 2
 3: QN("charge",-1) => 1, (dim=4|id=39|"Site,c=1,n=2,twospinsite") <Out>
 1: QN("charge",1) => 1
 2: QN("charge",0) => 2
 3: QN("charge",-1) => 1]

```

and accordingly I suspect that the index tag putting the name ‘twospinsite’ at the end (instead of before ‘Site’) is the root of the problem. Unfortunately I’m not sure how to rectify that, and digging through the infsiteinds function did not make it clearer. It is worth noting that I am able to generate a **finite** MPS with this custom site type using the code

```auto
Nfinite = 55
sfinite = siteinds("twospinsite", Nfinite; conserve_qns)
ψfinite = random_mps(sfinite, initstate; linkdims=10)

```

and use it to start a successful finite DMRG run.

It is possible that I’ve misunderstood how to overload the val() functions, but I do suspect that the issue may be rectified by ensuring that the Index tag is generated as “twospinsite,Site,c=?,n=?” instead of the output I’ve obtained.

* * *

Here is where I define my custom Hilbert space. (Note that my conserved operator is called “charge” and is diagonal(1,0,0,-1).)

```auto
function ITensors.space(::SiteType"twospinsite";
                        conserve_qns=false)
  if conserve_qns
    return [QN("charge",1)=>1,QN("charge",0)=>2,
            QN("charge",-1)=>1]
  end
  return 4
  
end

ITensors.state(::StateName"full", ::SiteType"twospinsite") = [1.0, 0, 0, 0]
ITensors.state(::StateName"dfill", ::SiteType"twospinsite") = [0.0, 1, 0, 0]
ITensors.state(::StateName"cfill", ::SiteType"twospinsite") = [0.0, 0, 1, 0]
ITensors.state(::StateName"empty", ::SiteType"twospinsite") = [0.0, 0, 0, 1]

val(::ValName"full", ::SiteType"twospinsite") = 1
val(::ValName"dfill", ::SiteType"twospinsite") = 2
val(::ValName"cfill", ::SiteType"twospinsite") = 3
val(::ValName"empty", ::SiteType"twospinsite") = 4

#Operator Definitions...

```

---

<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:** [October 10, 2024, 11:41am UTC](https://itensor.discourse.group/t/error-when-using-infsiteinds-with-custom-hilbert-space-itensorinfinitemps/2048/2 "2024-10-10T11:41:22Z")

</div>

Your code got cut off (and `conserve_qns` is not defined), but I suspect the solution is to do `ITensors.val(...`, which seems to make things work for me

---

<div class="post-metadata">

**Author:** ![amoghanakru](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@amoghanakru](https://itensor.discourse.group/u/amoghanakru)\
**Post date:** [October 10, 2024, 12:06pm UTC](https://itensor.discourse.group/t/error-when-using-infsiteinds-with-custom-hilbert-space-itensorinfinitemps/2048/3 "2024-10-10T12:06:43Z")

</div>

Sorry, I’ve edited the original post to show the full code, not including that change val–\>ITensors.val which indeed made that particular Error go away. Thank you so much for the fix!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/itensor/original/1X/d3072b13e047cd06df7f3981547c0917d940dfa4.png) [@system](https://itensor.discourse.group/u/system)\
**Post date:** [October 20, 2024, 12:06pm UTC](https://itensor.discourse.group/t/error-when-using-infsiteinds-with-custom-hilbert-space-itensorinfinitemps/2048/4 "2024-10-20T12:06:51Z")

</div>

Closed on October 20, 2024, 12:06pm UTC

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
