{"id":23029723,"url":"https://github.com/antononcube/raku-proc-zmqed","last_synced_at":"2025-08-14T21:16:02.586Z","repository":{"id":63903936,"uuid":"571398880","full_name":"antononcube/Raku-Proc-ZMQed","owner":"antononcube","description":"Proc::ZMQed provides external evaluators (Mathematica, Python, R, etc.) via ZMQ.","archived":false,"fork":false,"pushed_at":"2022-12-11T23:46:35.000Z","size":85,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-02T20:33:15.464Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Raku","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"artistic-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/antononcube.png","metadata":{"files":{"readme":"README-work.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-11-28T03:14:41.000Z","updated_at":"2023-03-30T17:30:09.000Z","dependencies_parsed_at":"2023-01-27T09:31:08.935Z","dependency_job_id":null,"html_url":"https://github.com/antononcube/Raku-Proc-ZMQed","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/antononcube/Raku-Proc-ZMQed","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antononcube%2FRaku-Proc-ZMQed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antononcube%2FRaku-Proc-ZMQed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antononcube%2FRaku-Proc-ZMQed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antononcube%2FRaku-Proc-ZMQed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antononcube","download_url":"https://codeload.github.com/antononcube/Raku-Proc-ZMQed/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antononcube%2FRaku-Proc-ZMQed/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262113313,"owners_count":23261002,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-15T14:16:57.095Z","updated_at":"2025-06-26T17:32:21.848Z","avatar_url":"https://github.com/antononcube.png","language":"Raku","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Raku Proc::ZMQed\n\nThis package, \"Proc::ZMQed\", provides external evaluators (Julia, Mathematica, Python, R, etc.) via \n[ZeroMQ (ZMQ)](https://zeromq.org).\n\nFunctionality-wise, a closely related Raku package is \n[\"Text::CodeProcessing\"](https://raku.land/zef:antononcube/Text::CodeProcessing), \n[AAp1]. For example, Raku can be used in Mathematica sessions (i.e. notebooks) with [AAp1] and [AAp2]; see [AA1] for more details.\nWith this package, \"Proc::ZMQed\", we can use Mathematica in Raku sessions. \n\n-----\n\n## Installation\n\nFrom GitHub:\n\n```\nzef install https://github.com/antononcube/Raku-Proc-ZMQed.git\n```\n\nFrom [Zef ecosystem](https://raku.land):\n\n```\nzef install Proc::ZMQed\n```\n\n-----\n\n## Usage example: symbolic computation with Mathematica\n\n*Mathematica is also known as Wolfram Language (WL).*\n\nThe following example shows:\n\n- Establishing connection to [Wolfram Engine](https://www.wolfram.com/engine/) (which is free for developers.)\n\n- Sending a formula for symbolic algebraic expansion.\n\n- Getting the symbolic result and evaluating it as a Raku expression.\n\n```perl6\nuse Proc::ZMQed;\n\n# Make object\nmy Proc::ZMQed::Mathematica $wlProc .= new(url =\u003e 'tcp://127.0.0.1', port =\u003e '5550');\n\n# Start the process (i.e. Wolfram Engine)\n$wlProc.start-proc;\n\nmy $cmd = 'Expand[(x+y)^4]';\nmy $wlRes = $wlProc.evaluate($cmd);\nsay \"Sent : $cmd\";\nsay \"Got  :\\n $wlRes\";\n\n# Send computation to Wolfram Engine\n# and get the result in Fortran form.\nsay '-' x 120;\n$cmd = 'FortranForm[Expand[($x+$y)^4]]';\n$wlRes = $wlProc.evaluate($cmd);\nsay \"Sent : $cmd\";\nsay \"Got  : $wlRes\";\n\n# Replace symbolic variables with concrete values \nmy $x = 5;\nmy $y = 3;\n\nuse MONKEY-SEE-NO-EVAL;\nsay 'EVAL($wlRes) : ', EVAL($wlRes);\n\n# Terminate process\n$wlProc.terminate;\n```\n\n**Remark:** Mathematica can have variables that start with `$`, which is handy if we want to\ntreat WE results as Raku expressions.\n\nHere is a corresponding flowchart:\n\n```mermaid\ngraph TD\n  WE{{Wolfram Engine}}\n  Raku{{Raku}}\n  CO[\"Create connection object\u003cbr\u003e(ZMQ sockets)\"]\n  SC[Send symbolic computation\u003cbr\u003eto Wolfram Engine]\n  AV[Assign values to symbols]\n  ES[Evaluate WE output string]\n  CO --\u003e SC --\u003e AV --\u003e ES\n  SC -.- Raku\n  SC -.-\u003e |ZMQ.send|WE\n  WE -.-\u003e |ZMQ.recv|SC\n  CO -.- Raku\n  AV -.- Raku\n  ES -.- |EVAL|Raku  \n```\n\n------\n\n## Setup\n\nIn this section we outline setup for different programming languages as \"servers.\"\n\nGenerally, there are two main elements to figure out:\n\n- What is the concrete Command Line Interface (CLI) name to use?\n\n  - And related code option. E.g. `julia -e` or `wolframscript -code`.\n  \n- Is ZMQ installed on the server system?\n\n\nThe CLI names can be specified with the option `cli-name`.\nThe code options can be specified with `code-option`.\n\n### Julia\n\nIn order to setup ZMQ computations with Julia start Julia and execute the commands:\n\n```julia\nusing Pkg\nPkg.add(\"ZMQ\")\nPkg.add(\"JSON\")\n```\n\n(Also, see the instructions at [\"Configure Julia for ExternalEvaluate\"](https://reference.wolfram.com/language/workflow/ConfigureJuliaForExternalEvaluate.html).) \n\nBy default \"Proc::ZMQed::Julia\" uses the CLI name `julia`. Here is an alternative setup:\n\n```{perl6, eval=FALSE}\nmy Proc::ZMQed::Julia $juliaProc .= new(url =\u003e 'tcp://127.0.0.1',\n                                        port =\u003e '5560',\n                                        cli-name =\u003e '/Applications/Julia-1.8.app/Contents/Resources/julia/bin/julia');\n```\n\n### Mathematica\n\nInstall [Wolfram Engine (WE)](https://www.wolfram.com/engine/). (As it was mentioned above, WE is free for developers. WE has ZMQ functionalities \"out of the box.\")\n\nMake sure `wolframscript` is installed. (This is the CLI name used with \"Proc::ZMQed::Mathematica\".)\n\n### Python\n\nInstall the ZMQ library [\"PyZMQ\"](https://pypi.org/project/pyzmq/). For example, with:\n\n```\npython -m pip install --user pyzmq\n```\n\nBy default \"Proc::ZMQed::Python\" uses the CLI name `python`.\nHere we connect to a Python virtual environment (made and used with \n[miniforge](https://github.com/conda-forge/miniforge)):\n\n```{perl6, eval=FALSE}\nmy Proc::ZMQed::Python $pythonProc .= new(url =\u003e 'tcp://127.0.0.1', \n                                          port =\u003e '5554', \n                                          cli-name =\u003e $*HOME ~ '/miniforge3/envs/SciPyCentric/bin/python');\n```\n\n------\n\n## Implementation details\n\nThe package architecture is Object-Oriented Programming (OOP) based and it is a combination of the OOP design patterns \nBuilder, Template Method, and Strategy.\n\nThe package has a general role \"Proc::ZMQed::Abstraction\" that plays Abstract class in Template method. \nThe concrete programming language of the classes provide concrete operations for:\n\n- ZMQ-server side code\n\n- Processing of setup code lines\n\nHere is the corresponding UML diagram:\n\n```perl6, output-lang=mermaid, output-prompt=NONE\nuse UML::Translators;\nto-uml-spec(\u003cProc::ZMQed::Abstraction Proc::ZMQed::Julia Proc::ZMQed::Mathematica Proc::ZMQed::Python Proc::ZMQed::R Proc::ZMQed::Raku\u003e, format=\u003e'mermaid');\n```\n\n(Originally, \"Proc::ZMQed::Abstraction\" was named \"Proc::ZMQish\", but the former seems a better fit for the role.)\n\nThe ZMQ connections are simple REP/REQ. It is envisioned that more complicated ZMQ patterns can be implemented in\nsubclasses. I have to say though, that my attempts to implement \n[\"Lazy Pirate\"](https://zguide.zeromq.org/docs/chapter4/)\nwere very unsuccessful because of the half-implemented (or missing) polling functionalities in [ASp1].\n(See the comments [here](https://github.com/arnsholt/Net-ZMQ/blob/master/lib/Net/ZMQ4/Poll.pm6).)\n\n\n------\n\n## TODO\n\n1. [ ] TODO Robust, comprehensive ZMQ-related failures handling.\n\n2. [ ] TODO More robust ZMQ patterns. \n\n   - Like the \"Lazy Pirate\" mentioned above.\n\n3. [ ] TODO Implement \"Proc::ZMQed::Java\".\n\n4. [ ] TODO Better message processing in \"Proc::ZMQed::R\". \n\n5. [ ] TODO Verify that \"Proc::ZMQed::JavaScript\" is working.\n  \n   - Currently, I have problems install ZMQ in JavaScript.\n\n------\n\n## References\n\n### Articles\n\n[AA1] Anton Antonov,\n[\"Connecting Mathematica and Raku\"](https://rakuforprediction.wordpress.com/2021/12/30/connecting-mathematica-and-raku/),\n(2021),\n[RakuForPrediction at WordPress]([https://rakuforprediction.wordpress.com/).\n\n\n### Packages\n\n[AAp1] Anton Antonov\n[Text::CodeProcessing Raku package](https://github.com/antononcube/Raku-Text-CodeProcessing),\n(2021-2022),\n[GitHub/antononcube](https://github.com/antononcube).\n\n[AAp2] Anton Antonov,\n[RakuMode Mathematica package](https://github.com/antononcube/ConversationalAgents/blob/master/Packages/WL/RakuMode.m),\n(2020-2021),\n[ConversationalAgents at GitHub/antononcube](https://github.com/antononcube/ConversationalAgents).\n\n[ASp1] Arne Skjærholt,\n[Net::ZMQ](https://github.com/arnsholt/Net-ZMQ),\n(2017),\n[GitHub/arnsholt](https://github.com/arnsholt).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantononcube%2Fraku-proc-zmqed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantononcube%2Fraku-proc-zmqed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantononcube%2Fraku-proc-zmqed/lists"}