ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 20 Oct 2019 11:37:06 -0500Stop Sage from overriding Python number typeshttps://ask.sagemath.org/question/48442/stop-sage-from-overriding-python-number-types/ I'm trying to play around with machine learning inside of the SageMath environment, but since Sage implicitly casts ints, floats, etc. to Integers, RealNumbers, etc., I'm running into problems such as this one:
```
...
--> model.add(Dense(Integer(1), activation="softmax"))
...
ValueError: Can't convert Python sequence with mixed types to Tensor.
```
So far, I've gotten around this by explicitly casting, so my line of code now looks like this:
```
...
model.add(Dense(int(1), activation="softmax"))
...
```
but I would rather not do this every time I create a model. Is there a way to stop Sage from implicitly casting, and instead use the default Python types?eniagaterSun, 20 Oct 2019 11:37:06 -0500https://ask.sagemath.org/question/48442/Exception does not show which line raised ithttps://ask.sagemath.org/question/32811/exception-does-not-show-which-line-raised-it/Hi there,
I'm new to sage, and made some sage scripts to improve my python scripts' performances. Then I load my script into a sage session, and run a test function.
When I get exception, it shows me the traceback with functions names only, without the instruction that triggered it. For example :
sage: f.runtest()
Generating keys ...
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
<ipython-input-3-abdb981a9bdb> in <module>()
----> 1 f.runtest()
<string> in runtest(self)
<string> in KeyGen(self)
/home/hack4u/Download/SageMath/src/sage/rings/rational.pyx in sage.rings.rational.Rational.__mod__ (/home/hack4u/Download/SageMath/src/build/cythonized/sage/rings/rational.c:22716)()
2541 n = rat.numer() % other
2542 d = rat.denom() % other
-> 2543 d = d.inverse_mod(other)
2544 return (n * d) % other
2545
/home/hack4u/Download/SageMath/src/sage/rings/integer.pyx in sage.rings.integer.Integer.inverse_mod (/home/hack4u/Download/SageMath/src/build/cythonized/sage/rings/integer.c:38530)()
6169 sig_off()
6170 if r == 0:
-> 6171 raise ZeroDivisionError, "Inverse does not exist."
6172 return ans
6173
ZeroDivisionError: Inverse does not exist.
And I have no idea which line in `KeyGen` does trigger that `ZeroDivisionError`. Any idea ?
matlinkWed, 16 Mar 2016 04:10:32 -0500https://ask.sagemath.org/question/32811/calling MixedIntegerLinearProgram gives AssertionError: The given source does not contain 'def'. How to fix this?https://ask.sagemath.org/question/30197/calling-mixedintegerlinearprogram-gives-assertionerror-the-given-source-does-not-contain-def-how-to-fix-this/When I call MixedIntegerLinearProgram I get the error AssertionError: The given source does not contain 'def'. This occurs both when calling any of its methods, like MixedIntegerLinearProgram.show(), and when viewing its documentation I get a backtrace in place of the documentation.
I am running Mac OS 10.11 (El Capitan). I get the same error in my emacs sage interpreter and Terminal. I recently tried to upgrade from sage 6.5 to 6.9 and the build failed; ask me about that if you think it's related. sage is installed to my home directory. Please ask if more details are needed.
Below is a full backtrace for a command I tried.
sage: g=Graph({0:[1,3],1:[0,2],2:[1,3],3:[2,0]})
sage: g
Graph on 4 vertices
sage: plot(g) #I checked my graph
sage: g.vertex_cut(0,2)
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-17-b3f3e7c533ca> in <module>()
----> 1 g.vertex_cut(Integer(0),Integer(2))
/Users/alejo/sage/local/lib/python2.7/site-packages/sage/graphs/generic_graph.pyc in vertex_cut(self, s, t, value_only, vertices, solver, verbose)
5525
5526 # Some vertices belong to part 1, some others to part 0
-> 5527 p.add_constraint(v[s] == 0)
5528 p.add_constraint(v[t] == 1)
5529
/Users/alejo/sage/src/sage/numerical/mip.pyx in sage.numerical.mip.MIPVariable.__getitem__ (build/cythonized/sage/numerical/mip.c:16841)()
2560 :meth:`MixedIntegerLinearProgram.new_variable`.
2561 """
-> 2562
2563 def __init__(self, parent, mip, vtype, name, lower_bound, upper_bound):
2564 r"""
/Users/alejo/sage/src/sage/numerical/mip.pyx in sage.numerical.mip.MixedIntegerLinearProgram.__call__ (build/cythonized/sage/numerical/mip.c:3714)()
490 self._linear_constraints_parent = LinearConstraintsParent(LF)
491 return self._linear_constraints_parent
--> 492
493 def __call__(self, x):
494 """
/Users/alejo/sage/src/sage/numerical/mip.pyx in sage.numerical.mip.MixedIntegerLinearProgram.linear_functions_parent (build/cythonized/sage/numerical/mip.c:3376)()
453 # Check for redundant constraints
454 self._check_redundant = check_redundant
--> 455 if check_redundant:
456 self._constraints = list()
457
/Users/alejo/sage/src/sage/misc/cachefunc.pyx in sage.misc.cachefunc.CachedFunction.__call__ (build/cythonized/sage/misc/cachefunc.c:4678)()
917 True
918 sage: f(y) is not f(x)
--> 919 True
920
921 """
/Users/alejo/sage/src/sage/misc/cachefunc.pyx in sage.misc.cachefunc.CachedFunction.argfix_init (build/cythonized/sage/misc/cachefunc.c:3203)()
719 """
720 A = ArgumentFixer(self.f,classmethod=self.is_classmethod)
--> 721 self._argument_fixer = A
722 if self.key:
723 self._fix_to_pos = self._fix_to_pos_and_create_key
/Users/alejo/sage/src/sage/misc/function_mangling.pyx in sage.misc.function_mangling.ArgumentFixer.__init__ (build/cythonized/sage/misc/function_mangling.c:862)()
122 cdef public tuple _default_tuple
123 def __init__(self, f, classmethod = False):
--> 124 try:
125 arg_names, varargs, varkw, defaults = sage_getargspec(f)
126 except AttributeError:
/Users/alejo/sage/local/lib/python2.7/site-packages/sage/misc/sageinspect.pyc in sage_getargspec(obj)
1382 source = sage_getsource(obj, is_binary=True)
1383 if source:
-> 1384 return inspect.ArgSpec(*_sage_getargspec_cython(source))
1385 else:
1386 func_obj = obj
/Users/alejo/sage/local/lib/python2.7/site-packages/sage/misc/sageinspect.pyc in _sage_getargspec_cython(source)
1007 """
1008 defpos = source.find('def ')
-> 1009 assert defpos > -1, "The given source does not contain 'def'"
1010 s = source[defpos:].strip()
1011 while s:
AssertionError: The given source does not contain 'def'lutherdriggersWed, 21 Oct 2015 21:18:39 -0500https://ask.sagemath.org/question/30197/Unsure why the 0 values error keeps coming uphttps://ask.sagemath.org/question/10186/unsure-why-the-0-values-error-keeps-coming-up/I am trying to code an algorithm to find the degrees of all small rank representations of $A_n$ that are equal to $p^2$ for some prime $p$. However, I think that my code should be correct, but it keeps giving me the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_24.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("W2ZuYW1lLCBjbmFtZV0gPSBBX2NvbWIycmVwKDMp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/tmp/tmp2u4eia/___code___.py", line 3, in <module>
exec compile(u'[fname, cname] = A_comb2rep(_sage_const_3 )
File "", line 1, in <module>
ValueError: need more than 0 values to unpack
The code for which it gives me this error is the following:
def A_comb2rep(p):
bound = p*p
name_fund = []
name_comb = []
A = lambda i: WeylCharacterRing("A{0}".format(i))
for i in range(bound):
for k in range(1,bound+1):
fw = A(i+1).fundamental_weights()
if A(i+1)(k * fw[1]).degree > bound:
break
else:
for v in fw:
if A(i+1)(k * v).degree() == bound:
name_fund.append([])
name_fund[len(name_fund)-1].append('A'+str(i+1)+'('str(k)+str(v)+')')
for i in range(bound): # now onto combinations of two of the fws #####
for k in fw:
fw = A(i+1).fundamental_weights()
if A(i+1)(fw[1] + fw[2]).degree() > bound:
break
else:
for j in fw:
rep = A(i+1)(j+k)
deg = rep.degree()
if deg == bound:
name_comb.append([])
name_comb[len(name_comb)-1].append('A'+str(i+1)+'['+str(j)+'+'+str(k)+']')
return name_comb, name_fund
A helpful answer would be one that answers: **What does `ValueError: need more than 0 values to unpack` mean and where should I look for tips on how to fix it**.
Many thanks for your time.JoshIzzardMon, 03 Jun 2013 07:06:38 -0500https://ask.sagemath.org/question/10186/debugging notebook programhttps://ask.sagemath.org/question/9826/debugging-notebook-program/
I get a SIGSEV (in "compiled" components ..) statement and a backtrace report stored in ./sage/crash_logs while running a large code in the written in the notebook.
How can I get the gdb prompt ?
Or what is the best way to debug this ?
FLAK45Mon, 25 Mar 2013 07:55:14 -0500https://ask.sagemath.org/question/9826/another "how to debug" issuehttps://ask.sagemath.org/question/8550/another-how-to-debug-issue/I primarily use Sage for numerical computation, working with numpy, scipy, gsl, R, etc. as well as my own interfaces to external software. Symbolic computing won't do much good on the types of problems I'm working on. I use Sage to have access to a wider variety of plotting options, as well as the wrappers and glue code. If it were possible, I would turn off symbolic computing completely as unnecessary overhead.
I've recently discovered that when running program 1 (say aaa.sage) followed by program 2 (bbb.sage), I get the not unusual error
TypeError: unable to simplify to float approximation
So I know I just need a float() somewhere to convert a symbolic value. If I exit Sage and start again, each program runs fine alone. It's only when the one is executed after the other that the error occurs. (I assume there's a way to clear the workspace without exiting, but I can't currently find it in the documentation).
The problem is Sage does not say where the error occurs. We've all seen the standard generic error pointing to:
exec(preparse_file(open(fpath).read()) + "\n", globals)
I now have large files of developed code and don't know how to find the offending line without laborious use of print statements. Any suggestions?
burningbrightTue, 13 Dec 2011 08:38:50 -0600https://ask.sagemath.org/question/8550/After debugging problem in building Sage library during initial build, how to continue?https://ask.sagemath.org/question/8191/after-debugging-problem-in-building-sage-library-during-initial-build-how-to-continue/Suppose you are building Sage, and an error comes up. Usually, in most spkgs, if there is something that needs to be changed in the code of the spkg, you can `cd` into the `spkg/build/` directory for the package, go into `src/`, fix the error (if you have any idea what it is, of course!) in the source, and then continue the `spkg-install` from there.
This is not the case in the Sage library spkg sage-x.y.z. itself, though. You have to do something else. I am trying to figure out what that is! I was once shown, but have forgotten. I've tried `$SAGE_ROOT/sage -b`, `$SAGE_ROOT/sage -ba`, and `./spkg-install`. I didn't really expect the first two to work, given that they would operate on the already copied files (not the ones in the build directory), but the latter also doesn't seem to work.
I remember having this exact problem, and cannot remember what to do. Help!kcrismanSat, 25 Jun 2011 14:43:26 -0500https://ask.sagemath.org/question/8191/What is your favorite way to debug sage code?https://ask.sagemath.org/question/7726/what-is-your-favorite-way-to-debug-sage-code/How do you debug sage code?
My favorite way do debug Python code is to use pdb in GUD emacs-mode.
I split the window into two buffers; in one I interact with pdb, in the other I see the code I'm debugging with the current line highlighted. When I step into a function which is defined in a different file, this window automatically shows the content of the new file.
Is it possible to use pdb and GUD with sage? Or is it possible to achieve this effect in a different way? Philipp SchneiderWed, 13 Oct 2010 10:42:44 -0500https://ask.sagemath.org/question/7726/Is notebook() mutually-exclusive from "./sage -gdb" mode?https://ask.sagemath.org/question/7606/is-notebook-mutually-exclusive-from-sage-gdb-mode/I tried running with the debugger attached, but my notebook became unresponsive. Tips?ccanoncSat, 21 Aug 2010 01:01:34 -0500https://ask.sagemath.org/question/7606/