Comments (6)
This is the same WolframLanguage bug as witnessed in #22. It'll be fixed in 12.2 (I can reproduce on a 12.1 build, but not with a recent prototype build).
Messages that should be Quiet
-ed, are incorrectly issued in some cases.
from wolframclientforpython.
@DbxDev Thanks, could you please explain how to pass the input arguments from python to .m file and load it back as MMA expression in python {edges,vl,ew,vd}=ImportString[#,"PythonExpression"]&/@ {"[(1,2),(1,3),(1,4),(2,5),(2,6),(5,6),(3,4),(3,7),(6,7),(7,8),(2,9)]", "[1,2,3,4,5,6,7,8,9]","{(1,2):49.6,(1,3):74.4,(1,4):49.6,(2,5):37.2,(2,6):74.4,(5,6):49.6,(3,4):37.2,(3,7):24.8,(6,7):62,(7,8):37.2,(2,9):24.8}", "{1:[75.,25.,0],2:[115.,45.,0],3:[10.,5.,0],4:[45.,0,0],5:[90.,60.,0],6:[45.,55.,0],7:[0,25.,0],8:[10.,50.,0],9:[115.,25.,0]}"};
?
from wolframclientforpython.
I tried
from wolframclient.evaluation import WolframLanguageSession
from wolframclient.language import wl, wlexpr, Global
session = WolframLanguageSession()
edges = [(1, 2), (1, 3), (1, 4), (2, 5), (2, 6), (5, 6), (3, 4), (3, 7), (6, 7), (7, 8), (2, 9)]
vl = [1, 2, 3, 4, 5, 6, 7, 8, 9]
ew = {(1, 2): 49.6, (1, 3): 74.4, (1, 4): 49.6, (2, 5): 37.2, (2, 6): 74.4, (5, 6): 49.6, (3, 4): 37.2, (3, 7): 24.8, (6, 7): 62, (7, 8): 37.2, (2, 9): 24.8}
vd = {1: [75., 25., 0], 2: [115., 45., 0], 3: [10., 5., 0], 4: [45., 0, 0], 5: [90., 60., 0], 6: [45., 55., 0], 7: [0, 25., 0], 8: [10., 50., 0], 9: [115., 25., 0]}
with WolframLanguageSession() as s:
solution3d = wl.Get('test.m')
s.evaluate(Global.solution3d(edges, vd, vl, ew))
test.m includes
solution3d[edges_, vd_, vl_, ew_] := (
{edges,vl,ew,vd}=ImportString[#,"PythonExpression"]&/@{edges,vl,ew,vd};
edges = UndirectedEdge @@@ edges; vcoords = List @@ vd;
ew = Normal @ KeyMap[UndirectedEdge @@ # &,ew];
g3d = Graph3D[vl, edges, VertexCoordinates -> vcoords, EdgeWeight->ew, VertexLabels->Placed["Name",Center],
EdgeLabels->{e_:>Placed["EdgeWeight",Center]}, VertexSize->.5, BaseStyle->16];
edgeLengths3d = # -> Norm[vars3d[[First@#]] - vars3d[[Last@#]]] /.solution3d & /@ EdgeList[g3d];
vars3d = Array[Through[{x, y, z}@#] &, Length@vd];
\[Lambda] = 1/100.; lbnd = 0; ubnd = 500;
obj3d = Total[(Norm[vars3d[[First@#]] - vars3d[[Last@#]]] - # /. (Rule @@@ ew))^2 & /@ EdgeList[g3d]] + \[Lambda] * Total[Norm /@ (vars3d - Values@vd)];
solution3d = Last @ Minimize[{obj3d, And @@ Thread[lbnd <= Join @@ vars3d <= ubnd]}, Join @@ vars3d];
edgeLengths3d = # -> Norm[vars3d[[First@#]] - vars3d[[Last@#]]] /.solution3d & /@ EdgeList[g3d];
ResourceFunction["PrettyGrid"][{#, # /. ew, # /. edgeLengths3d} & /@EdgeList[g3d], "ColumnHeadings" -> {"edge", "EdgeWeight", "Edge Length"}];
z1 = Values[solution3d] // Partition[#, 3] &;
theFile = File["result.txt"];
Export[theFile, z1, "Table"];
)
I'm not sure if
solution3d = wl.Get('test.m')
s.evaluate(Global.solution3d(edges, vd, vl, ew))
this right, nothing is written to the txt file unfortunately. Could you please have a look?
from wolframclientforpython.
@DbxDev This is a kind reminder
from wolframclientforpython.
This goes beyond the scope of this ticket and should rather be discussed on stackoverflow.
You're confusing Wolfram Language representation in Python and actual code evaluation. The python code solution3d = wl.Get('test.m')
represents a WL expression that is never evaluated and should be replaced with s.evaluate(wl.Get('test.m'))
. It'll declare the WL function Global`solution3d
for the given session that you're using afterward.
Remember that WL code declared in Python (using wl.xxx
syntax) must be evaluated in a session using (session.evaluate(...)
) otherwise it stays inert!
from wolframclientforpython.
@DbxDev Thank you. Unfortunately, I couldn't run it successfully after making the change that has been suggested. I have opened a new thread on stackoverflow as you suggested.
from wolframclientforpython.
Related Issues (20)
- Error "No module named 'wolframclient.evaluation'" issued HOT 13
- Example to append a path and get a file? HOT 2
- Is it possible to avoid writing FullForm? HOT 1
- Calling the DSolve function in Python HOT 3
- 'Interpreter' Can't Feedback HOT 2
- How to specify the path of kernel HOT 2
- client hangs HOT 4
- wolframclient cannot locate kernel in Pop!_OS(linux distro) HOT 1
- Proper way to timeout an evaluation HOT 3
- Restarting a session if underlying kernel process is down HOT 2
- WolframEvaluatorPool(poolsize=10) fails to launch all kernels with "Reason is Failed to communicate with kernel"
- How to convert back "WolframObjects" to python objects HOT 1
- socket failures that take hours to heal
- Abort kernel computations HOT 1
- wl.WolframAlpha getting failed in WolframCloudSession HOT 4
- how
- wolframclient.exception.WolframParserException: Invalid version b''. HOT 4
- Can not timeout a session properly
- Feature Request: Initiate WolframKernel with a specified entitlement HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wolframclientforpython.