# How to define custom states in ITensor c++?

**URL:** <https://itensor.discourse.group/t/how-to-define-custom-states-in-itensor-c/1696>\
**Category:** ITensor C++ Questions\
**Created:** [May 9, 2024, 12:22pm UTC](https://itensor.discourse.group/t/how-to-define-custom-states-in-itensor-c/1696 "2024-05-09T12:22:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![longisland-icetea](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/longisland-icetea/32/540_2.png) [@longisland-icetea](https://itensor.discourse.group/u/longisland-icetea)\
**Post date:** [May 9, 2024, 12:22pm UTC](https://itensor.discourse.group/t/how-to-define-custom-states-in-itensor-c/1696/1 "2024-05-09T12:22:05Z")

</div>

As I know we can do custom state definition in julia like:

```julia
ITensors.state(::StateName"+", ::SiteType"Electron") = [0, 1/sqrt(2), 1/sqrt(2), 0]

```

But I haven’t get similar method in ITensor c++. In the source code I only find this:

```cpp
IndexVal
    state(std::string const& state)
        {
        if(state == "0" || state == "Emp") 
            {
            return s(1);
            }
        else 
        if(state == "+" || state == "Up") 
            {
            return s(2);
            }
        else 
        if(state == "-" || state == "Dn") 
            {
            return s(3);
            }
        else 
        if(state == "S" || state == "UpDn") 
            {
            return s(4);
            }
        else
            {
            throw ITError("State " + state + " not recognized");
            }
        return IndexVal{};
        }

```

So is it possible to define custom states in c++ version?

---

<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:** [May 20, 2024, 9:11am UTC](https://itensor.discourse.group/t/how-to-define-custom-states-in-itensor-c/1696/2 "2024-05-20T09:11:58Z")

</div>

It’s a good question, but no, we did not design such a system to do custom states or sites (meaning outside of the ones provided by the library) in the C++ version, mainly because in C++11 we found it difficult to do this without a lot of tricks involving pointers etc. It might be easier now with C++20 but we have been focusing our development activities on the Julia version.

---

<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:** [June 18, 2024, 6:58am UTC](https://itensor.discourse.group/t/how-to-define-custom-states-in-itensor-c/1696/3 "2024-06-18T06:58:56Z")

</div>

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