Skip to main content
16 events
when toggle format what by license comment
Oct 4, 2020 at 14:40 history edited flinty CC BY-SA 4.0
added 1034 characters in body
Oct 4, 2020 at 14:35 comment added flinty You should be using NMinimize because it's a numerical problem. The error is already returned - note that I return an association: Return[<|"Error" -> err, "Solution" -> sol, "EdgeLengths" -> edgeLengths3d|>];. From Python please try this: result = s.evaluate(Global.solution3d(edges, vd, vl, ew)) print(result) and you will see that result contains a dictionary where you can get the err like this: result["Error"]
Oct 4, 2020 at 14:28 comment added Natasha Ahh, that was my mistake. I failed to notice the square brackets in MMA syntax. The output is written successfully now. But from what I see using Print[] doesn't display the output in python . I'm not sure if there is a way to print these outputs in Python terminal. Also, could you please explain why solution3d = Last @ Minimize[{obj3d, And @@ Thread[lbnd <= Join @@ vars3d <= ubnd]}, Join @@ vars3d]; was changed to NMinimize ? Could you please suggest how to return err while using solution3d = Last @ Minimize[{obj3d, And @@ Thread[lbnd <= Join @@ vars3d <= ubnd]}, Join @@ vars3d]; ?
Oct 4, 2020 at 14:15 comment added flinty What is this syntax? Print(uedges) and Print(ew2). That's not correct Mathematica syntax. You should write Print[uedges]; and Print[ew2]; with brackets and semicolons, not parentheses.
Oct 4, 2020 at 14:13 comment added flinty You have Print in there but that first Tag Times... error means you've not ended each Print with a semicolon. Are you sure you've actually replaced your test.m file with my code above, or have you modified it?
Oct 4, 2020 at 14:08 comment added Natasha Messages displayed in command line here, call here and function here Could you please have a look?
Oct 4, 2020 at 13:05 comment added flinty @Natasha But it does work with that input for me from python. You should copy just the function solution3d into test.m and remove everything else, not the rest. You have to wait ~20 seconds or so for your test.py to finish executing. What problem are you experiencing? I am using Python 3.8.3 and Mathematica 12.1.1.0
Oct 4, 2020 at 4:54 comment added Natasha But when I pass 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]} from Python the code doesn't run successfully. Could you please suggest how the input arguments have to be passed from Python?
Sep 29, 2020 at 15:52 vote accept Natasha
Sep 29, 2020 at 15:44 comment added flinty From Python? Use this plotly.com/python/v3/3d-network-graph or this idtools.com.au/3d-network-graphs-python-mplot3d-toolkit . It's a lot of work. You'd probably be better off ditching python and just doing it all from within Mathematica, but you may have other reasons for using python.
Sep 29, 2020 at 15:42 comment added Natasha Thank you very much for the clarification. If you want visual outputs while driving Mathematica from python, you should rasterize and export them as images. I guess this will help me in viewing the 3D graph as a 2D image. May I know if there is a way to view the 3D image? Will I be able to export as a html file and view the 3D? If it is possible, could you please provide references to some examples that show how to do this?
Sep 29, 2020 at 15:34 comment added flinty Because it's unnecessary inside a function unless you are returning it, which you are not. You were also suppressing the output with a semicolon so it wouldn't show up either. Also you're not going to get any visual outputs calling it from Python anyway because you can't spawn a front-end, just a headless kernel. If you want visual outputs while driving Mathematica from python, you should rasterize and export them as images.
Sep 29, 2020 at 15:18 comment added Natasha Hi @flinty Thank you so much Yes, the results are reasonable. Could you please explain why the line g3d = Graph3D[vl, edges, VertexCoordinates -> vcoords, EdgeWeight->ew, VertexLabels->Placed["Name",Center], EdgeLabels->{e_:>Placed["EdgeWeight",Center]}, VertexSize->.5, BaseStyle->16]; has been removed. In Mathematica this was useful to visualize the graph network. But I am not sure why the graph object isn't working while running from Python. I would like to know if there is a way to create the graph object and visualize the network while running via wolframclient.
Sep 29, 2020 at 12:20 history edited flinty CC BY-SA 4.0
don't need File[...]
Sep 29, 2020 at 12:10 history edited flinty CC BY-SA 4.0
You don't need g3d because it's not used for display.
Sep 29, 2020 at 12:01 history answered flinty CC BY-SA 4.0