sammorley-short / gsc

gsc (Graph State Compass)
GNU General Public License v3.0
9 stars 3 forks source link

pytests 10 of tests fail; example test-lc-equivalence code fails.. #7

Open patrick-burridge opened 3 years ago

patrick-burridge commented 3 years ago

I do not understand details of this program well. I just report what happen best I can.

install process:

$ uname -a
Linux [name] 5.10.13-arch1-1 #1 SMP PREEMPT Wed, 03 Feb 2021 23:44:07 +0000 x86_64 GNU/Linux

jetbrains pycharm 2020.2.3 VCS -> get from version control https://github.com/sammorley-short/gsc bottom right 'interpreter' box labeled like 'python 3.9 (gcs)' -> add interpreter -> virtualenv local terminal -> python setup.py install then install the two requirements.txt packages however

git clone https://github.com/sammorley-short/pynauty.git cd pynauty wget users.cecs.anu.edu.au/~bdm/nauty/nauty27b11.tar.gz tar -xf nauty27b11.tar.gz ln -s nauty27b11 nauty make virtenv-ins

pynauty installed good snippet

gcc -pthread -shared -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -fno-semantic-interposition -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now build/temp.linux-x86_64-3.9/src/nautywrap.o nauty/nauty.o nauty/nautil.o nauty/naugraph.o nauty/schreier.o nauty/naurng.o -L/usr/lib -o build/lib.linux-x86_64-3.9/pynauty/nautywrap.cpython-39-x86_64-linux-gnu.so
pip install --upgrade .
Processing /home/name/PycharmProjects/gsc/pynauty
Using legacy 'setup.py install' for pynauty, since package 'wheel' is not installed.
Installing collected packages: pynauty
    Running setup.py install for pynauty ... done
Successfully installed pynauty-0.6.0

pytest summary snippet

======================================================================================================= short test summary info ========================================================================================================
FAILED tests/test_README_examples.py::test_LC_explore_example - TypeError: missing 'vertex_coloring' attribute
FAILED tests/test_README_examples.py::test_LC_equiv_example - TypeError: No loop matching the specified signature and casting was found for ufunc true_divide
FAILED tests/test_README_examples.py::test_prime_dimension_explore_example - TypeError: missing 'vertex_coloring' attribute
FAILED tests/test_explore_class.py::test_explore_lc_orbit - TypeError: missing 'vertex_coloring' attribute
FAILED tests/test_explore_class.py::test_ququart_pair - TypeError: missing 'vertex_coloring' attribute
FAILED tests/test_get_nauty.py::test_find_rep_nodes - TypeError: missing 'vertex_coloring' attribute
FAILED tests/test_get_nauty.py::test_hash_graph - TypeError: missing 'vertex_coloring' attribute
FAILED tests/test_get_nauty.py::test_canonical_relabel - TypeError: missing 'vertex_coloring' attribute
FAILED tests/test_get_nauty.py::test_prime_power_hash_examples - TypeError: missing 'vertex_coloring' attribute
FAILED tests/test_is_lc_equiv.py::test_is_lc_equiv - TypeError: No loop matching the specified signature and casting was found for ufunc true_divide
=============================================================================================== 10 failed, 8 passed, 2 skipped in 1.69s ================================================================================================
(venv) [name@name gsc]$ 

lc-equivalence code example used

# Import Python packages
import networkx as nx
# Import local modules
from gsc.is_lc_equiv import are_lc_equiv

# Create a linear 4 node graph
edges = [(0, 1), (1, 2), (2, 3)]
graph_a = nx.Graph()
graph_a.add_edges_from(edges)

# Create a 4 node ring graph
edges = [(0, 1), (1, 2), (2, 3), (3, 0)]
graph_b = nx.Graph()
graph_b.add_edges_from(edges)

# Create a 4 node ring graph
edges = [(0, 2), (2, 1), (1, 3), (3, 0)]
graph_c = nx.Graph()
graph_c.add_edges_from(edges)

# Checks equivalence between graph A and graph B
is_equiv, local_us = are_lc_equiv(graph_a, graph_b)
print(is_equiv)
print(local_us)

# Checks equivalence between graph A and graph C
is_equiv, local_us = are_lc_equiv(graph_a, graph_c)
print(is_equiv)
print(local_us)

lc-equivalence code example run result

/home/name/PycharmProjects/gsc/venv/bin/python /home/name/PycharmProjects/gsc/testgcs2.py
Traceback (most recent call last):
  File "/home/name/PycharmProjects/gsc/testgcs2.py", line 22, in <module>
    is_equiv, local_us = are_lc_equiv(graph_a, graph_b)
  File "/home/name/PycharmProjects/gsc/gsc/is_lc_equiv.py", line 126, in are_lc_equiv
    V = list(GF2nullspace(X))
  File "/home/name/PycharmProjects/gsc/gsc/is_lc_equiv.py", line 71, in GF2nullspace
    A = to_rref(A)
  File "/home/name/PycharmProjects/gsc/gsc/is_lc_equiv.py", line 55, in to_rref
    A[i] /= A[i, j]
TypeError: No loop matching the specified signature and casting was found for ufunc true_divide

Process finished with exit code 1

simpler test code that does work

# Test code
# Python packages
import random
import networkx as nx
from abp import GraphState
# Local modules
from gsc.utils import canonical_edge_order
from gsc.is_lc_equiv import are_lc_equiv
from gsc.explore_lc_orbit import qubit_LC, explore_lc_orbit
from gsc.graph_builders import create_prime_power_graph

def to_GraphState(graph):
    nodes = graph.nodes()
    edges = graph.edges()
    gs = GraphState()
    for node in nodes:
        gs.add_qubit(node)
        gs.act_hadamard(node)
    gs.act_czs(*edges)
    return gs

def gen_random_connected_graph(n, p=0.333):
    """ Generates a Erdos-Renyi G_n,p random graph """
    g = nx.fast_gnp_random_graph(n, p)
    while not nx.is_connected(g):
        g = nx.fast_gnp_random_graph(n, p)
    return g

g = gen_random_connected_graph(15)
gs = to_GraphState(g)
# Gets the original edges
g_edges = canonical_edge_order(g.edges())
gs_edges = canonical_edge_order(gs.edgelist())
# Randomly picks a node for local complementation
lc_node = random.choice(list(g.nodes()))
# Performs local complementation on both graphs
lc_g = qubit_LC(g, lc_node, 1)
lc_gs = to_GraphState(g)
lc_gs.local_complementation(lc_node)
# Checks that their edgelists are equal
lc_g_edges = canonical_edge_order(lc_g.edges())
lc_gs_edges = canonical_edge_order(lc_gs.edgelist())
assert lc_g_edges == lc_gs_edges
# Performs a second local complementation on same node
lc_lc_g = qubit_LC(lc_g, lc_node, 1)
lc_lc_gs = to_GraphState(lc_g)
lc_lc_gs.local_complementation(lc_node)
# Checks edgelists are equal and also equal to the originals
lc_lc_g_edges = canonical_edge_order(lc_lc_g.edges())
lc_lc_gs_edges = canonical_edge_order(lc_lc_gs.edgelist())

print(lc_lc_gs_edges)

simpler test code run result

/home/name/PycharmProjects/gsc/venv/bin/python /home/name/PycharmProjects/gsc/testgsc.py
((0, 1), (0, 2), (0, 4), (0, 7), (0, 8), (0, 9), (0, 10), (0, 12), (0, 14), (1, 3), (1, 10), (1, 11), (1, 12), (1, 14), (2, 6), (2, 8), (2, 11), (2, 13), (2, 14), (3, 12), (3, 14), (4, 6), (4, 7), (4, 14), (5, 7), (5, 9), (5, 11), (6, 8), (6, 9), (6, 10), (7, 9), (7, 12), (7, 13), (7, 14), (8, 10), (8, 12), (8, 14), (9, 13), (10, 11), (11, 14), (12, 13), (12, 14))

Process finished with exit code 0
sammorley-short commented 3 years ago

Have been working on this and some of them are now fixed, although not all (3/10 still failing). Will merge when we're all green, but til then you can find the most up-to-date version on https://github.com/sammorley-short/gsc/tree/develop.