Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use simpler constructors for heavy hex lattice #109

Merged
merged 7 commits into from
Aug 8, 2023

Conversation

JoeyT1994
Copy link
Contributor

Further update to Heavy Hex dynamics example by simplifying the graph construction procedure based on the new features in the PR ITensor/NamedGraphs.jl#37 in NamedGraphs.jl

Also fixed a few bugs in beliefpropagation.jl which cropped up in testing.

@codecov-commenter
Copy link

codecov-commenter commented Aug 4, 2023

Codecov Report

Merging #109 (7d50eb3) into main (0f96a0a) will increase coverage by 0.14%.
The diff coverage is 100.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##             main     #109      +/-   ##
==========================================
+ Coverage   78.41%   78.56%   +0.14%     
==========================================
  Files          65       65              
  Lines        3693     3695       +2     
==========================================
+ Hits         2896     2903       +7     
+ Misses        797      792       -5     
Files Changed Coverage Δ
src/beliefpropagation/beliefpropagation.jl 92.75% <100.00%> (ø)

... and 2 files with indirect coverage changes

end

#Create the heavy_hex grid of the same structure as https://www.nature.com/articles/s41586-023-06096-3.
function create_eagle_processor()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think eagle_processor_graph would be a better name.

Also, I guess it is easy enough to make it generic to any numbers of loops:

function eagle_processor_graph(dims::Tuple)
  g = hexagonal_lattice_graph(dims)
  g = decorate_graph_edges(g)
  # Define new_x, new_Y
  add_vertices!(g, [(1, new_y), (new_x, 1)])
  add_edge!(g, (1, new_y - 1) => (1, new_y))
  add_edge!(g, (new_x, 2) => (new_x, 1))
end

eagle_processor_graph(dims::Integer...) = eagle_processor_graph(dims)

(I didn't work out what the dangling vertices should be called in general).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I guess I forgot that they refer to "Eagle" specifically as the 127 qubit version.

Maybe we could make a generic ibm_processor_graph(dims) function, and then define eagle_processor_graph() = ibm_processor_graph(3, 6). I suppose that relies on the processors of different sizes having dangling indices in the same generic location, but we could always modify that part as needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the convention is usually that the dimensions are listed as (nrows, ncols), for example for matrices or grid graphs:

julia> randn(3, 6)
3×6 Matrix{Float64}:
 1.75374    0.733839  -2.31459   0.229901   0.38511    0.763495
 1.07339   -0.246599   1.71149   0.534501   1.16299    1.27957
 0.703778  -1.62359    0.095052  0.68742   -0.662432  -0.0861288

julia> t = ITensorNetwork(named_grid((3, 6)); link_space=2);

julia> @visualize t;
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 
    ⠀⠀⠀⠀⠀⠀⠀t(1, 6)⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 
    ⠀⠀⠀⠀⠀⠀⠀⠀2⡰⠁⠈⠉t(1, 5)⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 
    ⠀⠀⠀⠀⠀⠀⠀⠀⡜⠀⠀⠀⠀⠀⠀⢀⠎⠉⠒⠢2⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 
    ⠀⠀⠀⠀t(2, 6)⡀⠀⠀⢀2⠀⠀⠀⠀⠀t(1, 4)⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 
    ⠀⠀⠀⠀⠀⢀2⠀⠀⠀⠀t(2, 5)⠀⠀⠀⠀⠀2⠃⠀⠀⠉2⠤⢄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 
    ⠀⠀t(3, 6)⠀⠀⠀2⠎⠀⠀⠈⠉2⠤⢄⡀⡰⠁⠀⠀⠀⠀⠀t(1, 3)⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 
    ⠀⠀⠀⠀⠀⠀⠈⠑2⠤⣀⢀⠎⠀⠀⠀⠀⠀⠀t(2, 4)⠀⠀⠀⠀⠀2⠀⠀⠀⠀2t(1, 2)⠀⠀⠀⠀⠀⠀⠀⠀ 
    ⠀⠀⠀⠀⠀⠀⠀⠀t(3, 5)2⠀⠀⠀⠀2⠀⠀⠀⠀⠀2t(2, 3)⠀⠀⠀⠀⠀⢠⠃⠉⠒2⢄⡀⠀⠀⠀⠀⠀⠀ 
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈t(3, 4)⠀⠀⠀⠀⠀⠀⡜⠈⠉⠒⠤2⡀⠀⠀⢠2⠀⠀⠀t(1, 1)⠀⠀ 
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠑⠒2⣀⠀⠀⢀2⠀⠀⠀⠀⠀t(2, 2)⠀⠀⠀⠀2⠁⠀⠀⠀⠀⠀ 
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀t(3, 3)⠀⠀⠀⠀⠀2⠁⠀⠀⠈t(2, 1)⠀⠀⠀⠀ 
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉2⠢⠤⣀⡔⠁⠀⠀⠀⠀⠀⠀⡰⠁⠀⠀⠀⠀⠀⠀⠀ 
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀t(3, 2)⣀⡀⠀⡔2⠀⠀⠀⠀⠀⠀⠀⠀ 
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀t(3, 1)⠀⠀⠀⠀⠀⠀⠀ 
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 

Following that, shouldn't the dimensions of hexagonal_lattice_graph be switched? It seems like they are listed as (ncols, nrows).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good name for the function. I have made it a bit more generic and changed the name, although I think making the dangling vertices generic might not be needed as that graph doesn't have much meaning beyond the specific 3 x 6 IBM processor.

Copy link
Contributor Author

@JoeyT1994 JoeyT1994 Aug 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you're right that the rows and cols naming in hexagonal_lattice_graph should be switched (it names the vertices as (col, row) which is a mistake I made). But at the level here it is all symmetric (one could also call heavy_hex_lattice(6, 3) with appropriate vertex naming). It all just depends in which orientation you look at the processor as to what you define as a row/ a column.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I see what you mean and they aren't the same. In it's current implementation that drawing of your corresponds to hexagonal_lattice_graph(6, 3) whereas the above pictures I sent are hexagonal_lattice_graph(3, 6).

Obviously that makes it seem like we have rows and columns swapped in the function arguments but if you look at everything from a 90 degree orientation then we actually have them correct. I.e.
image
is hexagonal_lattice_graph(3, 6)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree we could have different interpretations of what the "rows" and "columns" of a hexagonal lattice mean, depending on the orientation we choose, and that would change what hexagonal_lattice_graph(nrows, ncolumns) means.

It seems like it is usually drawn how you just drew it in your last post, i.e. consistent with https://en.wikipedia.org/wiki/Hexagonal_lattice#Honeycomb_point_set and https://mathworld.wolfram.com/HexagonalGrid.html. So maybe we could go with that definition.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So with that definition, I guess the function in NamedGraphs.jl is fine? Or is there still a vertex naming issue, i.e. do the row and column labels of the vertices need to be switched?

Copy link
Contributor Author

@JoeyT1994 JoeyT1994 Aug 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that makes sense as I took the function from networkx which probably adopts the correct convention.
Nonetheless there is still a vertex naming issue in NamedGraphs.jl because I named the vertices as (col, row) instead of (row, col). Which I will make a PR to change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be addressed in: ITensor/NamedGraphs.jl#38

@JoeyT1994
Copy link
Contributor Author

Okay I implemented a more generic naming protocol and a way to determine the dangling indices. Now have functions for creating 3 of the named IBM processors, see:
https://www.oezratty.net/wordpress/wp-content/IBM-hex-lattice.png

@mtfishman
Copy link
Member

Looks great, thanks! Nice that it is so simple to make these exotic lattices.

@mtfishman mtfishman changed the title Heavy hex example V2 Use simpler constructors for heavy hex lattice Aug 8, 2023
@mtfishman mtfishman merged commit 77ec3cb into ITensor:main Aug 8, 2023
@JoeyT1994 JoeyT1994 deleted the HeavyHexExample branch August 8, 2023 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants