# binary trees in ITensorNetworks

**URL:** <https://itensor.discourse.group/t/binary-trees-in-itensornetworks/2263>\
**Category:** ITensor Julia Questions\
**Created:** [February 25, 2025, 6:48pm UTC](https://itensor.discourse.group/t/binary-trees-in-itensornetworks/2263 "2025-02-25T18:48:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nico](https://avatars.discourse-cdn.com/v4/letter/n/b5a626/32.png) [@nico](https://itensor.discourse.group/u/nico)\
**Post date:** [February 25, 2025, 6:48pm UTC](https://itensor.discourse.group/t/binary-trees-in-itensornetworks/2263/1 "2025-02-25T18:48:58Z")

</div>

Hello, I’ve been playing with the ITensornetworks package and want to implement a simple TTN such as below (example with 4 physical sites)  
7  
/ \

5 6

/ \ / \

1 2 3 4  
| | | |

with the dangling dimensions equal to 2. I know how to do it on a tree in which every node has a extra physical leg with the function siteinds()

```julia
using ITensorNetworks: ttn
using ITensors
using Graphs: uniform_tree
using DataGraphs: vertex_data

n=4
psi=rand(2^n)
g=uniform_tree(n)
dmap = v -> 2
is = siteinds(dmap, g)
cutoff=0.001
tensor = ITensor(psi, vertex_data(is)...)
ttn(tensor, is; cutoff)

```

but I don’t know how to do it for the simple tree above where the physical legs are only at the bottom.  
Any suggestions would be highly appreciated!  
Thanks

---

<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:** [March 2, 2025, 12:29am UTC](https://itensor.discourse.group/t/binary-trees-in-itensornetworks/2263/2 "2025-03-02T00:29:33Z")

</div>

Hi @nico ,  
Unless it’s important that your network be initialized by factorizing a single initial tensor (the one you called `tensor` in your code above) then the simplest thing would be to create a tree tensor network on the graph you want to use by passing `g` to the `ITensorNetworks.ttn` constructor. Then you can use code like:

```auto
t[2] = ITensor(...)

```

to replace individual tensors with the ones you want, even having different indices from what they originally have (i.e. adding site indices on the sites you want). I think as long as the virtual indices still connect to form a tree you should be ok. (You may get an error if you create a loop.)

Please give it a try to see if that works for you.

Please also keep in mind that ITensorNetworks is in a somewhat experimental state and is not documented yet.

---

<div class="post-metadata">

**Author:** ![nico](https://avatars.discourse-cdn.com/v4/letter/n/b5a626/32.png) [@nico](https://itensor.discourse.group/u/nico)\
**Post date:** [March 3, 2025, 11:20am UTC](https://itensor.discourse.group/t/binary-trees-in-itensornetworks/2263/3 "2025-03-03T11:20:44Z")

</div>

Thank you I’ll give it a try. Also thanks to you and the entire ITensor team for the work you’re doing
