ITensor / NamedGraphs.jl

Extension of `Graphs.jl` to graphs with named vertices.
MIT License
6 stars 3 forks source link

Make `hexagonal_lattice_graph` more consistent between periodic and non-periodic #57

Closed mtfishman closed 6 months ago

mtfishman commented 6 months ago

Changing the setting of periodic in hexagonal_lattice_graph changes the lattice size:

julia> using NamedGraphs

julia> nv(hexagonal_lattice_graph(2, 2; periodic=false))
16

julia> nv(hexagonal_lattice_graph(2, 2; periodic=true))
8

I think instead it should output graphs with the same number of vertices and structure, just with extra periodic edges if periodic=true. It is implemented that way right now because the periodic graphs are constructed by first constructing the corresponding non-periodic version of the lattice and then merging vertices, it could still be implemented that way with some code restructuring, for example having an inner non-periodic version which the periodic version calls. The current design makes it difficult to reason about what size lattice will get output. (@JoeyT1994)

JoeyT1994 commented 6 months ago

The current design is based off of Networkx in Python: https://networkx.org/documentation/stable/reference/generated/networkx.generators.lattice.hexagonal_lattice_graph.html

So you get the same output there:

image

I agree it would be better to just have a non-periodic version and then a periodic version that calls that and adds edges and still has the same number of vertices.

Unlike the square lattice, however, I think it is a bit more tricky to do that because there is a slight complexity of which vertices should actually wrap around to which ones in the periodic case in order to preserve the hexagonal structure. This is why n (the second argument) must be even for when you set the flag periodic=true and you can't do hexagonal_lattice_graph(1,1; periodic = true) (because neighboring columns of the lattice need to be shifted relative to each other).

Hence, as far as I understand, you can't just take the open boundary version and add edges (it would break the properties of the hexagonal lattice). You would need to create a new open boundary version which looks slightly weird because the right side of the right-most column would be broken and have some `dangling' vertices.

mtfishman commented 6 months ago

You're probably right. I think I was partially confused by #59, and not being sure how to interpret m and n in hexagonal_lattice_graph(m, n; periodic) in the case of periodic=true. Can I think of m and n as the number of rows and columns of hexagons, whether or not periodic=true? I can see why, in that case, the number of vertices won't be the same between periodic=true and false, since there are boundary vertices that are shared across the periodic boundary.

JoeyT1994 commented 6 months ago

Yeah m and n are the numbers of rows and columns of hexagons. If you then set the periodic flag to true it will build the m rows and n columns of hexagons but then "fuse" (merge vertices) the right-most column with the left-most one and "fuse" the top-most row with the bottom-most one

mtfishman commented 6 months ago

Makes sense, thanks for the clarification, I think besides #59 the behavior makes sense.