# Correct way to define states for a new SiteType which has an alias

**URL:** <https://itensor.discourse.group/t/correct-way-to-define-states-for-a-new-sitetype-which-has-an-alias/655>\
**Category:** ITensor Julia Questions\
**Tags:** julia\
**Created:** [February 21, 2023, 1:05am UTC](https://itensor.discourse.group/t/correct-way-to-define-states-for-a-new-sitetype-which-has-an-alias/655 "2023-02-21T01:05:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![phx](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/phx/32/673_2.png) [@phx](https://itensor.discourse.group/u/phx)\
**Post date:** [February 21, 2023, 1:05am UTC](https://itensor.discourse.group/t/correct-way-to-define-states-for-a-new-sitetype-which-has-an-alias/655/1 "2023-02-21T01:05:26Z")

</div>

Hi there,  
I’m having some difficulties when I try to define a new SiteType, with some alias pointing to it.  
First of all, I defined a custom SiteType I call `vS=1/2`; for this type, I defined some states and operators, such as

```julia
function ITensors.state(::StateName"Up", ::SiteType"vS=1/2")
    return ...
end

```

Everything works as intended, so far.  
Now, I’d like to define an alias, named `HvS=1/2`, to this site type.  
I added some lines, mimicking the behaviour of some already existing site types:

```julia
ITensors.alias(::SiteType"HvS=1/2") = SiteType"vS=1/2"()

ITensors.space(st::SiteType"HvS=1/2") = ITensors.space(ITensors.alias(st))

function ITensors.state(sn::StateName, st::SiteType"HvS=1/2", s::Index; kwargs...)
    return ITensors.state(sn, ITensors.alias(st), s; kwargs...)
end

```

and so on for the operators.

The problem is, when I define an Index of this second site type, my definitions above for `vS=1/2` aren’t reached:

```julia
i = Index(4, "HvS=1/2")
state(i, "Up")

```

returns

```julia
ERROR: ArgumentError: Overload of "state" or "state!" functions not found for state name "Up" and Index tags "HvS=1/2"

```

If i try to follow the functions calls in the REPL with `@which` I get

```julia
@which ITensors.state(StateName("Up"), SiteType("HvS=1/2"), i)
state(sn::StateName, st::SiteType{HvS=1/2}, s::Index; kwargs...) in mypackage at ...

```

which is okay, this is the function I defined above; but then

```julia
@which ITensors.state(StateName("Up"), ITensors.alias(SiteType("HvS=1/2")), i)
state(::StateName, ::SiteType, ::Index; kwargs...) in ITensors at /opt/julia/packages/ITensors/LXBUp/src/physics/sitetype.jl:524

```

which is the “default” function in ITensors.jl which returns `nothing`.  
Here I thought that my `ITensors.state(::StateName"Up", ::SiteType"vS=1/2")` above would get called.  
What am I missing? Do I need do define something else?

---

<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:** [February 26, 2023, 9:14pm UTC](https://itensor.discourse.group/t/correct-way-to-define-states-for-a-new-sitetype-which-has-an-alias/655/2 "2023-02-26T21:14:18Z")

</div>

I think the reason for the error you are getting is that the `state` function shouldn’t be defined to take an `Index` argument. If you look at the [examples here](https://itensor.github.io/ITensors.jl/stable/examples/Physics.html#Making-a-Custom-state-Definition), they only take a StateName and SiteType.

When I remove the Index argument your alias approach worked correctly.

Here is a fully working example using a custom “S=3/2” SiteType as the original site type:

```julia
ITensors.space(::SiteType"S=3/2") = 4

ITensors.op(::OpName"Sz",::SiteType"S=3/2") =
  [+3/2 0 0 0
     0 +1/2 0 0
     0 0 -1/2 0
     0 0 0 -3/2]

ITensors.state(::StateName"Up",::SiteType"S=3/2") = [1.0, 0, 0, 0]

#---------------------------------------------

ITensors.alias(::SiteType"HvS=3/2") = SiteType"S=3/2"()

ITensors.space(st::SiteType"HvS=3/2") = ITensors.space(ITensors.alias(st))

function ITensors.state(sn::StateName, st::SiteType"HvS=3/2"; kwargs...)
  return ITensors.state(sn, ITensors.alias(st); kwargs...)
end

```
