ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 03 May 2017 09:02:30 -0500Caching with @parallelhttp://ask.sagemath.org/question/37497/caching-with-parallel/So I have a function which I want to run in a parallel manner as I'll need to run the function a few million times. The thing is, I know that quite a few times, I'll have duplicate information. So I want to speed up the process even more by skipping the ones I don't need. Here's what I have so far:
@parallel(ncpus=7)
def parallel_function(initial,allElts,e1,e2):
untested = set([initial])
verified = set([])
potentials = getPotentials(e1,e2)
while untested:
curTest = untested.pop()
verified.add(curTest)
for e in allElts:
newElt = someProp(potentials,curTest,e)
if newElt not in verified:
untested.add(newElt)
return verified
def testElts(allElts, potentials):
initial = allElts[0]
returnInfo = {}
for tup in list(parallel_function([(initial,allElts,e1,e2) for e1 in allElts for e2 in allElts)):
returnInfo[tup[0][0][2]] = tup[1]
***NOTE*** The above is an exmple. I've tried to dumb it down to try and give a better feel of the functions I'm working with. So consider the above more "pseudo" code than real code in case I missed something
We're assuming that allElts has at least 1 million elements, so this function will take a while. Notice that the parallel_function is a fairly intense function itself, but given any two element, the "getPotentials" function might return similar results. So basically I want to skip my while loop if I've already tested these "potentials" before.
I've tried looking into how caching works in parallel environments, but there doesn't seem to be too much. Would caching in this case be possible with @cache_function? If not, can I do a dictionary that stores the values and access the information that way? Since parallel processing creates forks I assume that means the dictionary information is not necessarily accessible by everyone? Or is that not accurate?
Any help on this would be beneficial. Thanks.aram.dermenjianWed, 03 May 2017 09:02:30 -0500http://ask.sagemath.org/question/37497/Caching sagetex resultshttp://ask.sagemath.org/question/9255/caching-sagetex-results/Is there a way to cache computations already done in a latex file using sagetex so that, for example, if I add a Sage code line in `foo.tex` when I run `sage foo.sagetex.sage` the computation starts from that line and not from the beginning?
The best thing would be that when one uses sagetex, Sage remembers what formulas are already computed and stored in foo.sout, and recomputes them only when they are modified. Do you think it's possible?
Thanks!MicheleMon, 20 Aug 2012 06:33:30 -0500http://ask.sagemath.org/question/9255/Can I cache a rendered 3d graphic (for @interact)?http://ask.sagemath.org/question/7969/can-i-cache-a-rendered-3d-graphic-for-interact/I'd like to make a simple interact for the notebook which shows a certain 3d object, and lets the user move a point around in the object and see data about that point. (For example, the object could be the domain of a certain function, and the data could have to do with values of the function in `RR^2`). The problem is that the 3d object takes a few seconds to render, and every time the point moves, the object has to be re-rendered. This makes the interact unusable.
So can I somehow tell Sage to just add one point to the object which it's already rendered? Note that I am pre-computing the 3d object and storing it in a variable, `g`. Then my interact function just takes coordinates as input and does
(g + point3d(x,y,z)).show()
But this is still too slow :(
----
UPDATE: The method described in the question about [fast show for cached plots](http://ask.sagemath.org/question/517/fast-show-for-cached-plots-for-interact) will probably solve this problem too!nilesFri, 25 Feb 2011 09:44:16 -0600http://ask.sagemath.org/question/7969/