This was a wild head-scratcher for me to hunt down, but I now am sure LetL
is the culprit. Here's a small example:
ParallelEvaluate[LetL[{id = $KernelID, sq = id*id}, sq]]
which gives
With: Variable 1 in local variable specification {1} requires a value.
With: Variable 2 in local variable specification {2} requires a value.
With: Variable 3 in local variable specification {3} requires a value.
General: Further output of With::lvws will be suppressed during this calculation
Out[1] = {With[{1}, With[{1}, 1]], With[{2}, With[{4}, 4]], With[{3}, With[{9}, 9]], With[{4}, With[{16}, 16]]}
A similar failure happens with
ParallelTable[LetL[{x = i j}, x^2], {i, 1, 3}, {j, 1, 3}]
ParallelMap[LetL[{f = #^2}, Sqrt[f]] &, Range[1, 10]]
Question: Can we formulate LetL in a way that it performs correctly inside a ParallelEvaluate
, ParallelTable
, and other Parallel
functions?
Partial answer: Put LetL
in its own package and evaluate ParallelNeeds["LetL`"]
. Then the above examples work correctly. I use LetL
enough that I have it in my auto-loaded packages, and I don't always want to launch multiple kernels on startup.
Alternative question to solve my use case: How can I get LetL
to be ParallelNeeds
ed when additional kernels are launched?
With[{a = 1}, {b = a}, b]
. Although the syntax highlighting is still incorrect, that might work for you. At leastParallelEvaluate[With[{id = $KernelID}, {sq = id*id}, sq]]
does what I expect. $\endgroup$LetL
in my code :P $\endgroup$mathematica/Let.wl
into$UserBaseDirectory/Applications
. I haveNeeds["Let`"];
in my$UserBaseDirectory/Kernel/init.m
. That's all that goes into my example. $\endgroup$