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

Hypergraph plot fails after contraction #36

Closed
nathanieltornow opened this issue May 26, 2024 · 1 comment
Closed

Hypergraph plot fails after contraction #36

nathanieltornow opened this issue May 26, 2024 · 1 comment

Comments

@nathanieltornow
Copy link

nathanieltornow commented May 26, 2024

Hi! :)

While playing around with the Hypergraph class, I found an issue (probably) with the Hypergraph.contract() method. In particular, after contracting two nodes, the Hypergraph.plot() function fails.

Here is an example:

import cotengra as ctg

inputs = [
    ('a', 'b', 'x'),
    ('b', 'c', 'd'),
    ('c', 'e', 'y'),
    ('e', 'a', 'd'),
]
output = ('x', 'y')
size_dict = {'x': 2, 'y': 3, 'a': 4, 'b': 5, 'c': 6, 'd': 7, 'e': 8}

hg = ctg.HyperGraph(inputs, output, size_dict)
hg.contract(0, 1) # comment this line to make the code work
hg.plot()

I would expect this code to plot the updated hypergraph with contracted nodes {0, 1} into the new node 4. However, code fails with:

Traceback (most recent call last):
  File "/home/nate/test/test.py", line 14, in <module>
    hg.plot()
  File "/home/nate/qvm/.venv/lib/python3.11/site-packages/cotengra/plot.py", line 15, in wrapped
    fig, ax = fn(*args, **kwargs)
              ^^^^^^^^^^^^^^^^^^^
  File "/home/nate/qvm/.venv/lib/python3.11/site-packages/cotengra/plot.py", line 55, in new_fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/nate/qvm/.venv/lib/python3.11/site-packages/cotengra/plot.py", line 1290, in plot_hypergraph
    hypergraph_compute_plot_info_G(
  File "/home/nate/qvm/.venv/lib/python3.11/site-packages/cotengra/plot.py", line 455, in hypergraph_compute_plot_info_G
    color = _node_colorer(nd)
            ^^^^^^^^^^^^^^^^^
  File "/home/nate/qvm/.venv/lib/python3.11/site-packages/cotengra/plot.py", line 432, in _node_colorer
    return node_colors[nd]
           ~~~~~~~~~~~^^^^
IndexError: list index out of range

Is this expected behavior? If not, there is probably some missing "bookkeeping" in the contract() method to ensure indices are correct.

Thank you!
Nate

(I'm on cotengra version 0.6.2)

@jcmgray
Copy link
Owner

jcmgray commented May 27, 2024

Thanks for the issue @nathanieltornow! should be fixed by e19e7db.

@jcmgray jcmgray closed this as completed May 27, 2024
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

No branches or pull requests

2 participants