autoconj icon indicating copy to clipboard operation
autoconj copied to clipboard

ImportError: cannot import name 'toposort'

Open kayhan-batmanghelich opened this issue 7 years ago • 4 comments

Hey guys,

Very nice work!

It seems some of the functions are missing. Here is an example:

     44 from autograd.tracer import Node
---> 45 from autograd.util import toposort
     46 from autograd.util import subvals
     47 from autograd import core

ImportError: cannot import name 'toposort'

kayhan-batmanghelich avatar Dec 02 '18 06:12 kayhan-batmanghelich

I was able to make some progress by using the latest from autograd (https://github.com/HIPS/autograd), which now has the toposort function. Unfortunately I still have a problem when trying to run one of the examples:

Traceback (most recent call last): File ".\kalman_filter.py", line 97, in app.run(main) File "C:\ProgramData\Anaconda3\lib\site-packages\absl\app.py", line 300, in run _run_main(main, args) File "C:\ProgramData\Anaconda3\lib\site-packages\absl\app.py", line 251, in _run_main sys.exit(main(argv)) File ".\kalman_filter.py", line 79, in main marginal = make_marginal_fn() File ".\kalman_filter.py", line 46, in make_marginal_fn log_p_x1_y1, 0, SupportTypes.REAL, *([1.] * 4)) File "C:\autoconj\autoconj\conjugacy.py", line 213, in complete_conditional _trace_and_analyze(log_joint_fun, argnum, *args)) File "C:\autoconj\autoconj\conjugacy.py", line 157, in _trace_and_analyze graph = make_expr(log_joint_fun, *args) File "C:\autoconj\autoconj\tracers.py", line 88, in make_expr used_start_nodes = {n for n in toposort(end_node, lambda n: n.parents) File "C:\autoconj\autoconj\tracers.py", line 88, in used_start_nodes = {n for n in toposort(end_node, lambda n: n.parents) File "C:\autograd\autograd\util.py", line 25, in toposort if node in child_counts: TypeError: unhashable type: 'ExprNode'

dwrtz avatar Dec 02 '18 20:12 dwrtz

Switching to python 2.7 resolved this for me.

dwrtz avatar Dec 02 '18 20:12 dwrtz

@dwrtz I agree. It resolves some but not all problems. For example, this:

    20 from autograd import grad
     21 from autograd import value_and_grad
---> 22 from autograd import fmap_util
     23
     24 from . import conjugacy

ImportError: cannot import name fmap_util

kayhan-batmanghelich avatar Dec 02 '18 20:12 kayhan-batmanghelich

Thanks so much for digging in! Kayhan, good to hear from you!

Looks like you’ve already found this code is currently only Python 2.7 compatible.

The fmap stuff is vestigial (from the fmap-everywhere branch of Autograd, which I meant to remove). I’ll take a look at that when I can.

mattjj avatar Dec 04 '18 22:12 mattjj