graspologic-org / graspologic

Python package for graph statistics

Home Page:https://graspologic-org.github.io/graspologic/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Error in `graph_match` with optimal transport

aurorarossi opened this issue · comments

Expected Behavior

A working graph_match function when transport=True.

Actual Behavior

Currently the function does not work when the parameter transport is set to True.

Example Code

import numpy as np
import matplotlib.pyplot as plt
from graspologic.match import graph_match

_, perm_inds, score, misc = graph_match(np.ones((2,2)), np.ones((2,2)),transport=True)

I also tried giving as input np.asmatrix(np.ones(2,2)) instead of np.ones((2,2)) but the error does not change.

Full Traceback

Traceback (most recent call last):
  File "mwe.py", line 5, in <module>
    _, perm_inds, score, misc = graph_match(np.ones((2,2)), np.ones((2,2)),transport=True)
  File "<@beartype(graspologic.match.wrappers.graph_match) at 0x7f7cdbd87b00>", line 506, in graph_match
  File "/home/aurossi/Projects/graphsAlignment/graspologic/graspologic/match/wrappers.py", line 311, in graph_match
    results = parallel(delayed(run_single_graph_matching)(seed) for seed in seeds)
  File "/home/aurossi/Projects/graphsAlignment/graphsAlignment/lib/python3.7/site-packages/joblib/parallel.py", line 1085, in __call__
    if self.dispatch_one_batch(iterator):
  File "/home/aurossi/Projects/graphsAlignment/graphsAlignment/lib/python3.7/site-packages/joblib/parallel.py", line 901, in dispatch_one_batch
    self._dispatch(tasks)
  File "/home/aurossi/Projects/graphsAlignment/graphsAlignment/lib/python3.7/site-packages/joblib/parallel.py", line 819, in _dispatch
    job = self._backend.apply_async(batch, callback=cb)
  File "/home/aurossi/Projects/graphsAlignment/graphsAlignment/lib/python3.7/site-packages/joblib/_parallel_backends.py", line 208, in apply_async
    result = ImmediateResult(func)
  File "/home/aurossi/Projects/graphsAlignment/graphsAlignment/lib/python3.7/site-packages/joblib/_parallel_backends.py", line 597, in __init__
    self.results = batch()
  File "/home/aurossi/Projects/graphsAlignment/graphsAlignment/lib/python3.7/site-packages/joblib/parallel.py", line 289, in __call__
    for func, args, kwargs in self.items]
  File "/home/aurossi/Projects/graphsAlignment/graphsAlignment/lib/python3.7/site-packages/joblib/parallel.py", line 289, in <listcomp>
    for func, args, kwargs in self.items]
  File "/home/aurossi/Projects/graphsAlignment/graspologic/graspologic/match/wrappers.py", line 297, in run_single_graph_matching
    solver.solve(seed)
  File "/home/aurossi/Projects/graphsAlignment/graspologic/graspologic/match/solver.py", line 258, in solve
    Q = self.compute_step_direction(gradient, rng)
  File "/home/aurossi/Projects/graphsAlignment/graspologic/graspologic/match/solver.py", line 57, in wrap
    result = f(*args, **kw)
  File "/home/aurossi/Projects/graphsAlignment/graspologic/graspologic/match/solver.py", line 330, in compute_step_direction
    Q = self.linear_sum_transport(gradient)
  File "/home/aurossi/Projects/graphsAlignment/graspologic/graspologic/match/solver.py", line 373, in linear_sum_transport
    warn=False,
  File "/home/aurossi/Projects/graphsAlignment/graphsAlignment/lib/python3.7/site-packages/ot/bregman.py", line 160, in sinkhorn
    **kwargs)
  File "/home/aurossi/Projects/graphsAlignment/graphsAlignment/lib/python3.7/site-packages/ot/bregman.py", line 447, in sinkhorn_knopp
    nx = get_backend(M, a, b)
  File "/home/aurossi/Projects/graphsAlignment/graphsAlignment/lib/python3.7/site-packages/ot/backend.py", line 163, in get_backend
    raise ValueError(str_type_error.format([type(a) for a in args]))
ValueError: All array should be from the same type/backend. Current types are : [<class 'numpy.matrix'>, <class 'numpy.ndarray'>, <class 'numpy.ndarray'>]

Your Environment

  • Python version: 3.7
  • graspologic version: 2.0.1

Additional Details

The case transport=False works.

hi @aurorarossi - I just tried the code you suggested with the most recent version of graspologic and POT, and it worked fine for me. you could try making sure both of those packages are up to date. do you know what version of POT you have installed when this is breaking?

before updating anything, would you mind telling us what versions of numpy and POT you have? If we are incompatable with particular versions of those packages I'd like to know it. Thanks!

POT version = 0.8.2 (last version)
numpy version = 1.21.6 (which is the last version compatible with python 3.7)
Updating python to version 3.10 I have the same problem of issue #998.
Thanks for the quick answer!

Thanks for the info, @aurorarossi. Unfortunately I haven't been able to replicate #998 yet myself so I am unsure what to recommend yet (and it looks like an error with an upstream dependency).

We don't officially support Python 3.10 yet (since we haven't tested and there may be random issues like this). Just to get you working for now, I would suggest a clean environment with Python 3.9 and see if that works for you? Please let me know if not.

@aurorarossi also, what platform (e.g. mac, windows, linux) are you on?

Until yesterday I used linux, but unfortunately my computer had some problems and from tomorrow I will use mac for a while

I tried to install graspologic on Mac with python 3.9 but when I run

from graspologic.match import graph_match

this happens and I do not know how to solve it

  File "/opt/anaconda3/envs/faqgraph/lib/python3.9/site-packages/numba-0.56.4-py3.9-macosx-10.9-x86_64.egg/numba/core/dispatcher.py", line 863, in enable_caching
    self._cache = FunctionCache(self.py_func)
  File "/opt/anaconda3/envs/faqgraph/lib/python3.9/site-packages/numba-0.56.4-py3.9-macosx-10.9-x86_64.egg/numba/core/caching.py", line 601, in __init__
    self._impl = self._impl_class(py_func)
  File "/opt/anaconda3/envs/faqgraph/lib/python3.9/site-packages/numba-0.56.4-py3.9-macosx-10.9-x86_64.egg/numba/core/caching.py", line 337, in __init__
    raise RuntimeError("cannot cache function %r: no locator available "
RuntimeError: cannot cache function '_center_distmat': no locator available for file '/opt/anaconda3/envs/faqgraph/lib/python3.9/site-packages/hyppo-0.3.2-py3.9.egg/hyppo/independence/dcorr.py'

@aurorarossi would you be able to make a fresh python 3.9 virtual environment (with nothing installed), try pip install graspologic, and then post the full console output here? this issue sounds like something did not get installed correctly

@bdpedigo I created a fresh python 3.9 env on my mac, pip install graspologic run smoothly and also the function graph_match with the parameter transport=True worked! Thanks a lot!

great! In that case, I will close this issue.

also, we just added Python 3.10 support officially yesterday #1010, so if you need to use that for some reason it may work now (I'd still recommend a new environment).