Converting a script to .spyx

66 views
Skip to first unread message

pete.d...@port.ac.uk

unread,
Jun 4, 2014, 1:46:47 PM6/4/14
to sage-s...@googlegroups.com
Hi everyone,

I'm a bit stumped trying to convert a Sage script that uses the inbuilt Cone type to a Cython/spyx script. After various errors and false starts, the only modification I've made to the script is to put the line "from sage.all import *" at the top, and obviously to change the extension from .sage to .spyx. Compilation then succeeds (it failed on all of my previous attempts), and the first bit of the program runs, but it dies as soon as it hits a call to Cone as follows:

Traceback (most recent call last):
  File "/var/local/sage-6.2-i686-Linux/local/bin/sage-run-cython", line 9, in <module>
    eval(compile(s, tmp_filename(), 'exec'))
  File "/home/user/.sage/temp/host/14538/tmp_FhdVdN", line 1, in <module>
    
  File "_home_user_file_spyx_0.pyx", line 134, in init _home_user_file_spyx_0 (_home_user_file_spyx_0.c:2788)
    dual_cone = Cone( [generator.tolist() for generator in set_of_base_vectors] )
NameError: name 'Cone' is not defined


Obviously I've missed something, but I've no idea what, I haven't been able to find any documentation on using Sage inbuilt types in spyx files, only what I've gleaned from various forum posts. Any help would be greatly appreciated.

Thanks!
Pete

William Stein

unread,
Jun 4, 2014, 1:53:20 PM6/4/14
to sage-support
It would be easier to help you if you provided 100% code so that one
could exactly replicate the problem you're reporting without having to
look things up, code, etc. for 15-20 minutes (or more).

For what it's worth, using %cython mode in a worksheet with "from
sage.all import *" and Cone works..., and %cython mode just makes a
.pyx file with a little boilerplate, etc.

William


--
William Stein
Professor of Mathematics
University of Washington
http://wstein.org
Screen Shot 2014-06-04 at 10.51.32 AM.png

Volker Braun

unread,
Jun 4, 2014, 1:54:13 PM6/4/14
to sage-s...@googlegroups.com
Post a minimal test case that exhibits your problem.

You probably need to add "from sage.geometry.cone import Cone"

pete.d...@port.ac.uk

unread,
Jun 5, 2014, 5:01:54 AM6/5/14
to sage-s...@googlegroups.com
Hi guys,

Thanks for the advice so far. Here's a minimal example:

from sage.geometry.cone import Cone
C = Cone( [[1,0],[0,1]] )

And here's what happens when I try to run it:

Compiling test.spyx...


Traceback (most recent call last):

File "/var/local/sage-6.2/local/bin/sage-run-cython", line 9, in <module>
eval(compile(s, tmp_filename(), 'exec'))
File "/home/pete/.sage/temp/host/12036/tmp_uuKoyt", line 1, in <module>

File "_home_pete_test_spyx_0.pyx", line 6, in init _home_pete_test_spyx_0 (_home_pete_test_spyx_0.c:853)
from sage.geometry.cone import Cone
File "/var/local/sage-6.2/local/lib/python2.7/site-packages/sage/geometry/__init__.py", line 1, in <module>
import all
File "/var/local/sage-6.2/local/lib/python2.7/site-packages/sage/geometry/all.py", line 4, in <module>
from cone import Cone
File "/var/local/sage-6.2/local/lib/python2.7/site-packages/sage/geometry/cone.py", line 203, in <module>
from sage.combinat.posets.posets import FinitePoset
File "/var/local/sage-6.2/local/lib/python2.7/site-packages/sage/combinat/posets/__init__.py", line 3, in <module>
import all
File "/var/local/sage-6.2/local/lib/python2.7/site-packages/sage/combinat/posets/all.py", line 1, in <module>
from posets import Poset
File "/var/local/sage-6.2/local/lib/python2.7/site-packages/sage/combinat/posets/posets.py", line 132, in <module>
from sage.categories.sets_cat import Sets
File "/var/local/sage-6.2/local/lib/python2.7/site-packages/sage/categories/sets_cat.py", line 23, in <module>
from sage.categories.sets_with_partial_maps import SetsWithPartialMaps
File "/var/local/sage-6.2/local/lib/python2.7/site-packages/sage/categories/sets_with_partial_maps.py", line 16, in <module>
from objects import Objects
File "/var/local/sage-6.2/local/lib/python2.7/site-packages/sage/categories/objects.py", line 16, in <module>
from sage.categories.homset import Homset
File "/var/local/sage-6.2/local/lib/python2.7/site-packages/sage/categories/homset.py", line 68, in <module>
import morphism
File "morphism.pyx", line 1, in init sage.categories.morphism (sage/categories/morphism.c:8168)
File "map.pyx", line 1, in init sage.categories.map (sage/categories/map.c:10514)
File "parent.pxd", line 12, in init sage.structure.element (sage/structure/element.c:31961)
File "map.pxd", line 4, in init sage.structure.parent (sage/structure/parent.c:25651)
AttributeError: 'module' object has no attribute 'Map'

The import line suggested by Volker got me further than before, but I'm lost after that.

Thanks again,
Pete

Volker Braun

unread,
Jun 5, 2014, 7:30:09 AM6/5/14
to sage-s...@googlegroups.com
sage: %run test.spyx

works for me 

pete.d...@port.ac.uk

unread,
Jun 5, 2014, 7:39:29 AM6/5/14
to sage-s...@googlegroups.com
Interesting, it also works for me when run from the prompt. Unfortunately, I need to be able to run the script in an automated way from outside Sage, not just from a Sage prompt. I suppose I might be able to work around this issue with some shell scripting glue, but that will get pretty messy.

Sorry to be difficult! Any other suggestions, or am I on my own from here?

Thanks,
Pete

Volker Braun

unread,
Jun 5, 2014, 7:53:57 AM6/5/14
to sage-s...@googlegroups.com
echo '%run test.spyx' | sage

William Stein

unread,
Jun 5, 2014, 9:11:24 PM6/5/14
to sage-support
On Thu, Jun 5, 2014 at 4:39 AM, <pete.d...@port.ac.uk> wrote:
Interesting, it also works for me when run from the prompt. Unfortunately, I need to be able to run the script in an automated way from outside Sage, not just from a Sage prompt. I suppose I might be able to work around this issue with some shell scripting glue, but that will get pretty messy.

Sorry to be difficult! Any other suggestions, or am I on my own from here?

At a bare minimum, put

 import sage.all

somewhere in your Python client code before you even try to import the Cython code.   It is NOT supported to import random things in random order from the Sage library, which is precisely what you're doing by putting

   from sage.geometry.cone import Cone

in a Cython module, building it, and importing only that module.

William
 

Thanks,
Pete

--
You received this message because you are subscribed to the Google Groups "sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
To post to this group, send email to sage-s...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages