On Mon, Aug 4, 2014 at 5:11 AM, Kevin Buzzard <kevin.m.buzz...@gmail.com> 
wrote:
> TL;DR: I am going to write a bash loop which loops through 1<=N<=10000 and
> feeds the number N into a function in a sage session, one session per N. 
Has
> anyone written a robust way of doing this already?

Yes, I implemented a robust way to do this long ago.  Use the @fork
decorator, and do *NOT* try to mutate a global variable in the
function you're calling -- this makes no sense because it happens in a
subprocess.

@fork
def g(N):
     f=ModularSymbols(N,2,1).cuspidal_subspace().hecke_
operator(3).matrix().change_ring(GF(5)).charpoly('t')
     print N,f; sys.stdout.flush()
     return f

N=Integer(1)
R.<t>=PolynomialRing(GF(5))
charpolys=[]
while N<=10000:
    charpolys.append(g(N))
    N += 1
    print get_memory_usage(), charpolys   # for testing


If you want to do several in parallel, you can easily do that too as
follows.  This will both completely eliminate memory leak issues, and
use all processors on your computer.

@parallel
def g(N):
     f=ModularSymbols(N,2,1).cuspidal_subspace().hecke_
operator(3).matrix().change_ring(GF(5)).charpoly('t')
     print N,f; sys.stdout.flush()
     return f

R.<t>=PolynomialRing(GF(5))
charpolys={}
for x in g([1..10000]):
    N = x[0][0][0]
    charpolys[N] = x[1]
    save(charpolys, 'charpolys.sobj')   # saves all so far to a single
file -- load later with load('charpolys.sobj')


The save above will save the charpolys dict to disk each time you get
back another charpoly.

Welcome to the modern world (though everything above just uses a few
Python functions from the late 1990s -- pickle and fork). Compared to
Magma, Sage is much, much better at this sort of stuff...

 -- William

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to