Ask Your Question
2

Parallel Interface to the Sage interpreter

asked 2016-11-14 18:16:14 -0600

ikol gravatar image

I am using the PSage()parallel interpreter as described here http://doc.sagemath.org/html/en/refer.... The interface works fine to evaluate multiple instances of function calls to functions of one or more scalar variables, however, if a function variable is array-like, the interface doesn't seem to work any more. I wonder if any special quoting is necessary for array-like arguments. Here is a minimal example. For reference, I copy the example from the above page, which works just fine, factor() has a single scalar variable.

v = [PSage() for _ in range(3)]
w = [x('factor(2^%s-1)'% randint(250,310)) for x in v]
w
[4057 * 8191 * 6740339310641 * 3340762283952395329506327023033,
 31 * 13367 * 2940521 * 164511353 * 70171342151 *
3655725065508797181674078959681,
 31 * 13367 * 2940521 * 164511353 * 70171342151 *
3655725065508797181674078959681]

However, the rosen() function with a single array-like/vector argument doesn't seem to work in the parallel interface. (The example below just calculates the same function value three times, but that is not the point here.)

from scipy.optimize import rosen

x0 = [1.3, 0.7, 0.8, 1.9, 1.2]
rosen(x0)
848.22000000000003

v = [PSage() for _ in range(3)]
w = [x('rosen(x0)') for x in v]
w
[Sage, Sage, Sage]

Does anyone have any suggestion?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2016-11-22 19:09:54 -0600

tmonteil gravatar image

If your parallel computations are calls to the same function with intependent parameters, you shoud have a look at the @parallel decorator.

edit flag offensive delete link more
0

answered 2016-11-15 10:23:32 -0600

ikol gravatar image

updated 2016-11-22 18:25:13 -0600

It turns out that the problem has nothing to do with scalar vs. vector variable. The bottom line is that PSage() takes a single STRING as parameter enclosed in quotes. The following (somewhat awkward) modification makes the parallel interface work properly.

from scipy.optimize import rosen

x0 = [1.3, 0.7, 0.8, 1.9, 1.2]
rosen(x0)
848.22000000000003

v = [PSage() for _ in range(3)]
w = [x(eval('rosen(%s)'% str(x0))) for x in v]
w
[848.22, 848.22, 848.22]

Unfortunately, using eval() does not solve the problem. Because the example here is instantaneous to compute, I haven't realized that the calculations were, in fact, executed sequentially and not in parallel. After looking at the PSage() code it is clear that the argument must be a single string and the fact that this example "worked" although not in parallel, must be some artifact of using an explicit eval(). Mea culpa, HOWEVER, I created a better example and opened a new ticket, because PSage() would be an exteremely good tool for this kind of thing.

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

1 follower

Stats

Asked: 2016-11-14 18:16:14 -0600

Seen: 76 times

Last updated: Nov 22 '16