Ask Your Question
0

TypeError with graphs.RandomGNP

asked 2018-11-27 07:29:09 -0600

jrc92 gravatar image

I tried calling gnp = graphs.RandomGNP(20, .1, algorithm = 'sage') and it gave me the following error

TypeError                                 Traceback (most recent call last)
<ipython-input-147-7915a3a5dbc9> in <module>()
----> 1 gnp = graphs.RandomGNP(Integer(20), RealNumber('.1'), algorithm = 'sage')

/anaconda3/envs/graphs/lib/python3.6/site-packages/sage/graphs/generators/random.py in RandomGNP(n, p, seed, fast, algorithm)
    122         # We use the Sage generator
    123         from sage.graphs.graph_generators_pyx import RandomGNP as sageGNP
--> 124         return sageGNP(n, p)
    125     else:
    126         raise ValueError("'algorithm' must be equal to 'networkx' or to 'Sage'.")

/anaconda3/envs/graphs/lib/python3.6/site-packages/sage/graphs/graph_generators_pyx.pyx in sage.graphs.graph_generators_pyx.RandomGNP (build/cythonized/sage/graphs/graph_generators_pyx.c:1366)()
     68     # integers are on 31 bits. We thus set the pivot value to p*2^31
     69     cdef float RAND_MAX_f = (1<<31)*1.0
---> 70     cdef int pp = int(round(p*(1<<31)))
     71 
     72     if directed:

TypeError: type sage.rings.real_mpfr.RealNumber doesn't define __round__ method

Not sure what went wrong here.. Appreciate any help! Thank you!

edit retag flag offensive close merge delete

Comments

Did you install Sage with Conda? Or do you just have Anaconda in your PATH?

slelievre gravatar imageslelievre ( 2018-11-27 12:26:24 -0600 )edit

typical sage+python3 error ; already fixed in the latest beta

FrédéricC gravatar imageFrédéricC ( 2018-11-27 13:09:59 -0600 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2018-11-27 12:25:52 -0600

slelievre gravatar image

This works in Python2-based Sage, but not yet in Python3-based Sage.

Either you are using Python3-based Sage, or you have Anaconda in your PATH and it is interfering with Sage.

If your Sage is Python2-based, try removing Anaconda from your PATH before you start Sage.

If your Sage is Python3-based, I suggest also having a Python2-based Sage handy.

Currently, SageMath built with Python3 is still work in progress. You have found one place where it is not ready yet. While testing out Python3-based SageMath is encouraged, it is recommended to also have a Python2-based Sage to use when one hits such a limitation.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2018-11-27 07:29:09 -0600

Seen: 66 times

Last updated: Nov 27 '18