wolfram-bridge 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. wolfram_bridge-0.1.0/LICENSE +21 -0
  2. wolfram_bridge-0.1.0/PKG-INFO +208 -0
  3. wolfram_bridge-0.1.0/README.md +175 -0
  4. wolfram_bridge-0.1.0/pyproject.toml +55 -0
  5. wolfram_bridge-0.1.0/setup.cfg +4 -0
  6. wolfram_bridge-0.1.0/tests/test_cache.py +51 -0
  7. wolfram_bridge-0.1.0/tests/test_compat.py +253 -0
  8. wolfram_bridge-0.1.0/tests/test_fault.py +436 -0
  9. wolfram_bridge-0.1.0/tests/test_full.py +907 -0
  10. wolfram_bridge-0.1.0/tests/test_imitate.py +41 -0
  11. wolfram_bridge-0.1.0/tests/test_kernel_session.py +71 -0
  12. wolfram_bridge-0.1.0/tests/test_mappings_real.py +176 -0
  13. wolfram_bridge-0.1.0/wolfram_bridge/__init__.py +10 -0
  14. wolfram_bridge-0.1.0/wolfram_bridge/compat/__init__.py +13 -0
  15. wolfram_bridge-0.1.0/wolfram_bridge/compat/_core/__init__.py +0 -0
  16. wolfram_bridge-0.1.0/wolfram_bridge/compat/_core/ai_plugin.py +133 -0
  17. wolfram_bridge-0.1.0/wolfram_bridge/compat/_core/ai_providers/__init__.py +0 -0
  18. wolfram_bridge-0.1.0/wolfram_bridge/compat/_core/ai_providers/base.py +30 -0
  19. wolfram_bridge-0.1.0/wolfram_bridge/compat/_core/ai_providers/claude.py +47 -0
  20. wolfram_bridge-0.1.0/wolfram_bridge/compat/_core/ai_providers/deepseek.py +46 -0
  21. wolfram_bridge-0.1.0/wolfram_bridge/compat/_core/ai_providers/gemini.py +46 -0
  22. wolfram_bridge-0.1.0/wolfram_bridge/compat/_core/ai_providers/groq.py +50 -0
  23. wolfram_bridge-0.1.0/wolfram_bridge/compat/_core/candidate_finder.py +154 -0
  24. wolfram_bridge-0.1.0/wolfram_bridge/compat/_core/converters.py +160 -0
  25. wolfram_bridge-0.1.0/wolfram_bridge/compat/_core/error_classifier.py +107 -0
  26. wolfram_bridge-0.1.0/wolfram_bridge/compat/_core/fault_handler.py +186 -0
  27. wolfram_bridge-0.1.0/wolfram_bridge/compat/_core/interactor.py +134 -0
  28. wolfram_bridge-0.1.0/wolfram_bridge/compat/_core/kernel_ref.py +22 -0
  29. wolfram_bridge-0.1.0/wolfram_bridge/compat/_core/metadata.py +175 -0
  30. wolfram_bridge-0.1.0/wolfram_bridge/compat/_core/resolver.py +139 -0
  31. wolfram_bridge-0.1.0/wolfram_bridge/compat/_proxy_base.py +244 -0
  32. wolfram_bridge-0.1.0/wolfram_bridge/compat/_state.py +9 -0
  33. wolfram_bridge-0.1.0/wolfram_bridge/compat/mappings/matplotlib.yaml +347 -0
  34. wolfram_bridge-0.1.0/wolfram_bridge/compat/mappings/monitoring.yaml +198 -0
  35. wolfram_bridge-0.1.0/wolfram_bridge/compat/mappings/numpy.yaml +1114 -0
  36. wolfram_bridge-0.1.0/wolfram_bridge/compat/mappings/numpy_extra.yaml +608 -0
  37. wolfram_bridge-0.1.0/wolfram_bridge/compat/mappings/pandas.yaml +921 -0
  38. wolfram_bridge-0.1.0/wolfram_bridge/compat/mappings/perf.yaml +223 -0
  39. wolfram_bridge-0.1.0/wolfram_bridge/compat/mappings/scipy.yaml +1051 -0
  40. wolfram_bridge-0.1.0/wolfram_bridge/compat/mappings/sklearn.yaml +454 -0
  41. wolfram_bridge-0.1.0/wolfram_bridge/compat/mappings/sympy.yaml +936 -0
  42. wolfram_bridge-0.1.0/wolfram_bridge/compat/mappings/tensorflow.yaml +415 -0
  43. wolfram_bridge-0.1.0/wolfram_bridge/compat/mappings/torch.yaml +489 -0
  44. wolfram_bridge-0.1.0/wolfram_bridge/compat/matplotlib.py +9 -0
  45. wolfram_bridge-0.1.0/wolfram_bridge/compat/monitoring.py +9 -0
  46. wolfram_bridge-0.1.0/wolfram_bridge/compat/numpy.py +11 -0
  47. wolfram_bridge-0.1.0/wolfram_bridge/compat/pandas.py +731 -0
  48. wolfram_bridge-0.1.0/wolfram_bridge/compat/perf.py +11 -0
  49. wolfram_bridge-0.1.0/wolfram_bridge/compat/scipy.py +10 -0
  50. wolfram_bridge-0.1.0/wolfram_bridge/compat/seaborn.py +9 -0
  51. wolfram_bridge-0.1.0/wolfram_bridge/compat/sklearn.py +9 -0
  52. wolfram_bridge-0.1.0/wolfram_bridge/compat/sympy.py +10 -0
  53. wolfram_bridge-0.1.0/wolfram_bridge/compat/tensorflow.py +10 -0
  54. wolfram_bridge-0.1.0/wolfram_bridge/compat/torch.py +11 -0
  55. wolfram_bridge-0.1.0/wolfram_bridge/kernel.py +335 -0
  56. wolfram_bridge-0.1.0/wolfram_bridge.egg-info/PKG-INFO +208 -0
  57. wolfram_bridge-0.1.0/wolfram_bridge.egg-info/SOURCES.txt +58 -0
  58. wolfram_bridge-0.1.0/wolfram_bridge.egg-info/dependency_links.txt +1 -0
  59. wolfram_bridge-0.1.0/wolfram_bridge.egg-info/requires.txt +11 -0
  60. wolfram_bridge-0.1.0/wolfram_bridge.egg-info/top_level.txt +1 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 TurinFohlen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,208 @@
1
+ Metadata-Version: 2.4
2
+ Name: wolfram_bridge
3
+ Version: 0.1.0
4
+ Summary: Python → Wolfram Language bridge via PTY, with compat layer for NumPy/SciPy/pandas/PyTorch etc.
5
+ Author: TurinFohlen
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/TurinFohlen/wolfram-pty
8
+ Project-URL: Repository, https://github.com/TurinFohlen/wolfram-pty
9
+ Keywords: wolfram,mathematica,bridge,pty,compat,numpy,scipy,pandas,pytorch,tensorflow
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Requires-Python: >=3.9
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: pexpect
25
+ Requires-Dist: pyyaml
26
+ Provides-Extra: wxf
27
+ Requires-Dist: wolframclient>=1.4.0; extra == "wxf"
28
+ Provides-Extra: ai
29
+ Requires-Dist: requests; extra == "ai"
30
+ Provides-Extra: plot
31
+ Requires-Dist: matplotlib; extra == "plot"
32
+ Dynamic: license-file
33
+
34
+ wolfram-pty
35
+
36
+ A lightweight Python bridge to the Wolfram Engine for restricted environments – zero scientific dependencies, 800+ mapped functions.
37
+
38
+ https://img.shields.io/pypi/v/wolfram-pty
39
+ https://img.shields.io/badge/License-MIT-yellow.svg
40
+
41
+ ---
42
+
43
+ 🎯 What is it?
44
+
45
+ wolfram-pty lets you call the full power of Wolfram Language directly from Python – perfect for constrained environments like Termux, Docker containers, Raspberry Pi, CI/CD pipelines where installing heavy scientific libraries (numpy, pandas, etc.) is impractical.
46
+
47
+ · Zero scientific dependencies – all heavy lifting is done by the Wolfram Engine; Python only needs the standard library.
48
+ · Persistent kernel session – a single kernel instance keeps state across calls.
49
+ · File‑based output – results are saved as JSON/PNG/TXT and read back with Python’s built‑in modules.
50
+ · Automatic caching – identical expressions return cached results instantly.
51
+ · Metadata‑driven compatibility layer – already maps 835+ functions from NumPy, SciPy, pandas, PyTorch, TensorFlow, SymPy, scikit‑learn, Matplotlib and more.
52
+ · Resilient – automatic kernel restart on failure, serialised request queue, no activation race conditions.
53
+
54
+ ---
55
+
56
+ ✨ Features
57
+
58
+ · 🔥 Zero scientific libraries – no numpy, no pandas, just plain Python.
59
+ · 🚀 Persistent kernel – start once, evaluate many times with full state retention.
60
+ · 📦 File output mode – reliable, parse‑free communication via files.
61
+ · 🧠 Smart cache – reuse results for identical expressions.
62
+ · 🧩 Drop‑in replacements – use familiar NumPy/SciPy syntax, powered by Wolfram.
63
+ · 🛠️ Auto‑recovery – kernel crashes? It restarts automatically.
64
+ · 🔌 Easy configuration – set two environment variables and you’re ready.
65
+
66
+ ---
67
+
68
+ 🚀 Quick Start
69
+
70
+ Installation
71
+
72
+ ```bash
73
+ pip install wolfram-pty
74
+ ```
75
+
76
+ ⚠️ Note: This package does not include the Wolfram Engine. You must obtain a valid licence from Wolfram Research and install it yourself.
77
+
78
+ Set up the kernel path
79
+
80
+ Tell wolfram-pty where your Wolfram kernel is:
81
+
82
+ ```bash
83
+ export WOLFRAM_EXEC=/path/to/your/wolfram-kernel # e.g. /usr/local/bin/math
84
+ export WOLFRAM_PWFILE=~/.Wolfram/Licensing/mathpass # optional, password file
85
+ ```
86
+
87
+ Basic usage
88
+
89
+ ```python
90
+ from wolfram_pty import WolframKernel
91
+
92
+ k = WolframKernel() # singleton kernel, starts only once
93
+
94
+ # Evaluate an expression, get a string back
95
+ print(k.evaluate("2+2")) # "4"
96
+
97
+ # Batch evaluation
98
+ results = k.batch_evaluate(["Range[5]", "Pi", "Det[{{1,2},{3,4}}]"])
99
+ print(results) # ["{1,2,3,4,5}", "Pi", "-2"]
100
+
101
+ # Use the familiar NumPy interface (powered by Wolfram)
102
+ from wolfram_pty.compat import numpy as np
103
+ a = np.array([1,2,3]) # bypasses kernel – pure Python list
104
+ b = np.fft.fft(a) # actually calls Wolfram's Fourier
105
+ print(b) # complex array (read from a JSON file)
106
+ ```
107
+
108
+ ---
109
+
110
+ 📁 File Output Mode (Core Mechanism)
111
+
112
+ All results are written to files and read back with standard Python – no parsing hassle, no dependencies.
113
+
114
+ ```python
115
+ # Save result as a JSON file
116
+ file_path = k.evaluate_to_file("Range[5]", fmt="json")
117
+ print(file_path) # /sdcard/wolfram_out/xxx.json
118
+
119
+ # Read it with the built‑in json module
120
+ import json
121
+ with open(file_path) as f:
122
+ data = json.load(f) # [1,2,3,4,5]
123
+
124
+ # Generate a plot and save as PNG
125
+ img_path = k.evaluate_to_file("Plot[Sin[x], {x,0,2Pi}]", fmt="png")
126
+ ```
127
+
128
+ ---
129
+
130
+ 🧠 Automatic Caching
131
+
132
+ The second time you ask for the same expression, the result is returned instantly from the cache.
133
+
134
+ ```python
135
+ # First call – kernel runs
136
+ path1 = k.evaluate_to_file("Range[10000]")
137
+
138
+ # Second call – cache hit, almost instantaneous
139
+ path2 = k.evaluate_to_file("Range[10000]")
140
+
141
+ # Force recompute (e.g. for random numbers)
142
+ path3 = k.evaluate_to_file("RandomReal[1,1000]", no_cache=True)
143
+
144
+ # Clean cache files older than 7 days
145
+ k.clear_cache(older_than_days=7)
146
+ ```
147
+
148
+ ---
149
+
150
+ 📚 Supported Libraries (835+ functions)
151
+
152
+ The wolfram_pty.compat submodule provides drop‑in replacements for popular scientific Python libraries – everything is translated to Wolfram calls.
153
+
154
+ Library Functions Example
155
+ NumPy 200+ np.array, np.fft.fft, np.linalg.solve
156
+ SciPy 143 scipy.integrate.quad, scipy.optimize.minimize
157
+ pandas 125 pd.DataFrame, df.groupby, pd.read_csv
158
+ PyTorch 66 torch.tensor, torch.add, torch.nn.ReLU
159
+ TensorFlow 55 tf.constant, tf.matmul, tf.nn.softmax
160
+ SymPy 71 sympy.symbols, sympy.diff, sympy.solve
161
+ scikit‑learn 60 sklearn.preprocessing.StandardScaler, sklearn.cluster.KMeans
162
+ Matplotlib 47 plt.plot, plt.imshow, seaborn
163
+ Performance 50+ tqdm, logging, time, psutil
164
+
165
+ How to use them:
166
+
167
+ ```python
168
+ from wolfram_pty.compat import numpy as np
169
+ from wolfram_pty.compat import scipy
170
+ from wolfram_pty.compat import pandas as pd
171
+ # … and so on
172
+ ```
173
+
174
+ ---
175
+
176
+ ⚙️ Configuration
177
+
178
+ All settings are controlled via environment variables:
179
+
180
+ Variable Default Description
181
+ WOLFRAM_EXEC /root/.../math Path to the Wolfram kernel executable
182
+ WOLFRAM_PWFILE ~/.Wolfram/Licensing/mathpass Path to the password file (optional)
183
+ WOLFRAM_CACHE_DIR /sdcard/wolfram_cache Directory for cached results
184
+ WOLFRAM_OUT_DIR /sdcard/wolfram_out Default output directory for files
185
+
186
+ ---
187
+
188
+ ⚠️ Important Legal Notice
189
+
190
+ This software only provides a communication interface to the Wolfram Engine and does not include, bundle, or distribute the Wolfram Engine itself.
191
+ Users must obtain a valid licence directly from Wolfram Research and comply with their terms.
192
+ The developers of wolfram-pty assume no liability for any unauthorised use of the Wolfram Engine.
193
+
194
+ ---
195
+
196
+ 📄 License
197
+
198
+ MIT License © 2025 TurinFohlen
199
+
200
+ ---
201
+
202
+ 🤝 Contributing
203
+
204
+ Issues and pull requests are welcome! If you’d like to add mappings for more functions, create a YAML file in mappings/ and make sure tests pass.
205
+
206
+ ---
207
+
208
+ Happy computing – even in the most constrained environments!
@@ -0,0 +1,175 @@
1
+ wolfram-pty
2
+
3
+ A lightweight Python bridge to the Wolfram Engine for restricted environments – zero scientific dependencies, 800+ mapped functions.
4
+
5
+ https://img.shields.io/pypi/v/wolfram-pty
6
+ https://img.shields.io/badge/License-MIT-yellow.svg
7
+
8
+ ---
9
+
10
+ 🎯 What is it?
11
+
12
+ wolfram-pty lets you call the full power of Wolfram Language directly from Python – perfect for constrained environments like Termux, Docker containers, Raspberry Pi, CI/CD pipelines where installing heavy scientific libraries (numpy, pandas, etc.) is impractical.
13
+
14
+ · Zero scientific dependencies – all heavy lifting is done by the Wolfram Engine; Python only needs the standard library.
15
+ · Persistent kernel session – a single kernel instance keeps state across calls.
16
+ · File‑based output – results are saved as JSON/PNG/TXT and read back with Python’s built‑in modules.
17
+ · Automatic caching – identical expressions return cached results instantly.
18
+ · Metadata‑driven compatibility layer – already maps 835+ functions from NumPy, SciPy, pandas, PyTorch, TensorFlow, SymPy, scikit‑learn, Matplotlib and more.
19
+ · Resilient – automatic kernel restart on failure, serialised request queue, no activation race conditions.
20
+
21
+ ---
22
+
23
+ ✨ Features
24
+
25
+ · 🔥 Zero scientific libraries – no numpy, no pandas, just plain Python.
26
+ · 🚀 Persistent kernel – start once, evaluate many times with full state retention.
27
+ · 📦 File output mode – reliable, parse‑free communication via files.
28
+ · 🧠 Smart cache – reuse results for identical expressions.
29
+ · 🧩 Drop‑in replacements – use familiar NumPy/SciPy syntax, powered by Wolfram.
30
+ · 🛠️ Auto‑recovery – kernel crashes? It restarts automatically.
31
+ · 🔌 Easy configuration – set two environment variables and you’re ready.
32
+
33
+ ---
34
+
35
+ 🚀 Quick Start
36
+
37
+ Installation
38
+
39
+ ```bash
40
+ pip install wolfram-pty
41
+ ```
42
+
43
+ ⚠️ Note: This package does not include the Wolfram Engine. You must obtain a valid licence from Wolfram Research and install it yourself.
44
+
45
+ Set up the kernel path
46
+
47
+ Tell wolfram-pty where your Wolfram kernel is:
48
+
49
+ ```bash
50
+ export WOLFRAM_EXEC=/path/to/your/wolfram-kernel # e.g. /usr/local/bin/math
51
+ export WOLFRAM_PWFILE=~/.Wolfram/Licensing/mathpass # optional, password file
52
+ ```
53
+
54
+ Basic usage
55
+
56
+ ```python
57
+ from wolfram_pty import WolframKernel
58
+
59
+ k = WolframKernel() # singleton kernel, starts only once
60
+
61
+ # Evaluate an expression, get a string back
62
+ print(k.evaluate("2+2")) # "4"
63
+
64
+ # Batch evaluation
65
+ results = k.batch_evaluate(["Range[5]", "Pi", "Det[{{1,2},{3,4}}]"])
66
+ print(results) # ["{1,2,3,4,5}", "Pi", "-2"]
67
+
68
+ # Use the familiar NumPy interface (powered by Wolfram)
69
+ from wolfram_pty.compat import numpy as np
70
+ a = np.array([1,2,3]) # bypasses kernel – pure Python list
71
+ b = np.fft.fft(a) # actually calls Wolfram's Fourier
72
+ print(b) # complex array (read from a JSON file)
73
+ ```
74
+
75
+ ---
76
+
77
+ 📁 File Output Mode (Core Mechanism)
78
+
79
+ All results are written to files and read back with standard Python – no parsing hassle, no dependencies.
80
+
81
+ ```python
82
+ # Save result as a JSON file
83
+ file_path = k.evaluate_to_file("Range[5]", fmt="json")
84
+ print(file_path) # /sdcard/wolfram_out/xxx.json
85
+
86
+ # Read it with the built‑in json module
87
+ import json
88
+ with open(file_path) as f:
89
+ data = json.load(f) # [1,2,3,4,5]
90
+
91
+ # Generate a plot and save as PNG
92
+ img_path = k.evaluate_to_file("Plot[Sin[x], {x,0,2Pi}]", fmt="png")
93
+ ```
94
+
95
+ ---
96
+
97
+ 🧠 Automatic Caching
98
+
99
+ The second time you ask for the same expression, the result is returned instantly from the cache.
100
+
101
+ ```python
102
+ # First call – kernel runs
103
+ path1 = k.evaluate_to_file("Range[10000]")
104
+
105
+ # Second call – cache hit, almost instantaneous
106
+ path2 = k.evaluate_to_file("Range[10000]")
107
+
108
+ # Force recompute (e.g. for random numbers)
109
+ path3 = k.evaluate_to_file("RandomReal[1,1000]", no_cache=True)
110
+
111
+ # Clean cache files older than 7 days
112
+ k.clear_cache(older_than_days=7)
113
+ ```
114
+
115
+ ---
116
+
117
+ 📚 Supported Libraries (835+ functions)
118
+
119
+ The wolfram_pty.compat submodule provides drop‑in replacements for popular scientific Python libraries – everything is translated to Wolfram calls.
120
+
121
+ Library Functions Example
122
+ NumPy 200+ np.array, np.fft.fft, np.linalg.solve
123
+ SciPy 143 scipy.integrate.quad, scipy.optimize.minimize
124
+ pandas 125 pd.DataFrame, df.groupby, pd.read_csv
125
+ PyTorch 66 torch.tensor, torch.add, torch.nn.ReLU
126
+ TensorFlow 55 tf.constant, tf.matmul, tf.nn.softmax
127
+ SymPy 71 sympy.symbols, sympy.diff, sympy.solve
128
+ scikit‑learn 60 sklearn.preprocessing.StandardScaler, sklearn.cluster.KMeans
129
+ Matplotlib 47 plt.plot, plt.imshow, seaborn
130
+ Performance 50+ tqdm, logging, time, psutil
131
+
132
+ How to use them:
133
+
134
+ ```python
135
+ from wolfram_pty.compat import numpy as np
136
+ from wolfram_pty.compat import scipy
137
+ from wolfram_pty.compat import pandas as pd
138
+ # … and so on
139
+ ```
140
+
141
+ ---
142
+
143
+ ⚙️ Configuration
144
+
145
+ All settings are controlled via environment variables:
146
+
147
+ Variable Default Description
148
+ WOLFRAM_EXEC /root/.../math Path to the Wolfram kernel executable
149
+ WOLFRAM_PWFILE ~/.Wolfram/Licensing/mathpass Path to the password file (optional)
150
+ WOLFRAM_CACHE_DIR /sdcard/wolfram_cache Directory for cached results
151
+ WOLFRAM_OUT_DIR /sdcard/wolfram_out Default output directory for files
152
+
153
+ ---
154
+
155
+ ⚠️ Important Legal Notice
156
+
157
+ This software only provides a communication interface to the Wolfram Engine and does not include, bundle, or distribute the Wolfram Engine itself.
158
+ Users must obtain a valid licence directly from Wolfram Research and comply with their terms.
159
+ The developers of wolfram-pty assume no liability for any unauthorised use of the Wolfram Engine.
160
+
161
+ ---
162
+
163
+ 📄 License
164
+
165
+ MIT License © 2025 TurinFohlen
166
+
167
+ ---
168
+
169
+ 🤝 Contributing
170
+
171
+ Issues and pull requests are welcome! If you’d like to add mappings for more functions, create a YAML file in mappings/ and make sure tests pass.
172
+
173
+ ---
174
+
175
+ Happy computing – even in the most constrained environments!
@@ -0,0 +1,55 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "wolfram_bridge"
7
+ version = "0.1.0"
8
+ description = "Python → Wolfram Language bridge via PTY, with compat layer for NumPy/SciPy/pandas/PyTorch etc."
9
+ readme = "README.md"
10
+ license = { text = "MIT" }
11
+ authors = [
12
+ { name = "TurinFohlen" },
13
+ ]
14
+ keywords = ["wolfram", "mathematica", "bridge", "pty", "compat", "numpy", "scipy", "pandas", "pytorch", "tensorflow"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Intended Audience :: Developers",
18
+ "Intended Audience :: Science/Research",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.9",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Topic :: Scientific/Engineering",
26
+ "Topic :: Software Development :: Libraries :: Python Modules",
27
+ ]
28
+ requires-python = ">=3.9"
29
+ dependencies = [
30
+ "pexpect",
31
+ "pyyaml",
32
+ ]
33
+
34
+ [project.optional-dependencies]
35
+ wxf = ["wolframclient>=1.4.0"]
36
+ ai = ["requests"]
37
+ plot = ["matplotlib"]
38
+
39
+ [project.urls]
40
+ Homepage = "https://github.com/TurinFohlen/wolfram-pty"
41
+ Repository = "https://github.com/TurinFohlen/wolfram-pty"
42
+
43
+ [tool.setuptools.packages.find]
44
+ where = ["."]
45
+ include = ["wolfram_bridge*"]
46
+
47
+ [tool.setuptools.package-data]
48
+ "wolfram_bridge.compat" = ["mappings/*.yaml"]
49
+
50
+ [tool.pytest.ini_options]
51
+ testpaths = ["tests"]
52
+
53
+
54
+ [project.entry-points."plugins"]
55
+ # 将来插件可以在此注册。
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env python3
2
+ import os
3
+ import time
4
+ import hashlib
5
+ from wolfram_bridge import WolframKernel, CACHE_DIR
6
+
7
+ def test_cache():
8
+ print("="*50)
9
+ print("开始测试缓存功能")
10
+ print("="*50)
11
+
12
+ k = WolframKernel()
13
+ expr = "Range[1000]" # 一个中等大小的数组
14
+ fmt = "wxf"
15
+
16
+ # 计算哈希,用于定位缓存文件
17
+ expr_hash = hashlib.sha256(expr.encode()).hexdigest()
18
+ cache_path = os.path.join(CACHE_DIR, f"{expr_hash}.{fmt}")
19
+
20
+ # 第一次调用(应触发实际计算)
21
+ print("\n[1] 第一次调用 (应触发内核计算)")
22
+ path1 = k.evaluate_to_file(expr, fmt=fmt)
23
+ print(f" 结果文件: {path1}")
24
+ print(f" 缓存文件是否存在? {os.path.exists(cache_path)}")
25
+
26
+ # 短暂等待,确保文件写完毕
27
+ time.sleep(1)
28
+
29
+ # 第二次调用(应命中缓存)
30
+ print("\n[2] 第二次调用 (应命中缓存,不触发内核)")
31
+ path2 = k.evaluate_to_file(expr, fmt=fmt)
32
+ print(f" 结果文件: {path2}")
33
+ # 缓存文件应该还在
34
+ print(f" 缓存文件是否存在? {os.path.exists(cache_path)}")
35
+
36
+ # 清理缓存
37
+ print("\n[3] 清除缓存")
38
+ k.clear_cache()
39
+ print(f" 缓存文件是否存在? {os.path.exists(cache_path)}")
40
+
41
+ # 第三次调用(缓存已清,应重新计算)
42
+ print("\n[4] 第三次调用 (缓存已清,应重新计算)")
43
+ path3 = k.evaluate_to_file(expr, fmt=fmt)
44
+ print(f" 结果文件: {path3}")
45
+ print(f" 缓存文件是否存在? {os.path.exists(cache_path)}")
46
+
47
+ print("\n✅ 测试完成。请观察控制台输出中是否出现内核计算日志(INFO 级别的 'Export[...]' 等)。")
48
+ print(" 如果第二次调用没有出现此类日志,说明缓存生效。")
49
+
50
+ if __name__ == "__main__":
51
+ test_cache()