libsymtorch 0.1.1__tar.gz → 0.2.1__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.
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Ibrahim H.I. Abushawish
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.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ibrahim H.I. Abushawish
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,162 @@
1
+ Metadata-Version: 2.4
2
+ Name: libsymtorch
3
+ Version: 0.2.1
4
+ Summary: SymPy-to-Torch conversion and numerical integration
5
+ Author-email: "Ibrahim H.I. Abushawish" <ibrahim.hamed2701@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/ibeuler/symtorch
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Topic :: Scientific/Engineering :: Physics
11
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: torch>=2.5.1
16
+ Requires-Dist: sympy>=1.13.1
17
+ Requires-Dist: torchquad>=0.5.0
18
+ Requires-Dist: numpy>=2.4.2
19
+ Requires-Dist: scipy>=1.17.0
20
+ Requires-Dist: loguru>=0.7.3
21
+ Provides-Extra: dev
22
+ Requires-Dist: pytest>=8; extra == "dev"
23
+ Requires-Dist: build>=1; extra == "dev"
24
+ Requires-Dist: twine>=5; extra == "dev"
25
+ Provides-Extra: examples
26
+ Requires-Dist: matplotlib>=3.8; extra == "examples"
27
+ Dynamic: license-file
28
+
29
+ # symtorch (distribution: libsymtorch)
30
+
31
+ SymPy-to-Torch transcompilation and numerical integration library designed for extremely fast, batched evaluation on GPUs and CPUs.
32
+
33
+ Note: this module was first developed for [libphysics](https://github.com/ferhatpy/libphysics) — then it was split out into a standalone library to tackle generalized parallel computational bottlenecks.
34
+
35
+ ## Install (dev)
36
+
37
+ ```bash
38
+ pip install -e .
39
+ ```
40
+
41
+ ## Install (PyPI)
42
+
43
+ ```bash
44
+ pip install libsymtorch
45
+ ```
46
+
47
+ ## Requirements
48
+
49
+ This project depends on the packages listed in `requirements.txt`. The primary runtime requirements are:
50
+
51
+ - Python 3.8+
52
+ - torch==2.5.1+cu121 (or another `torch` build appropriate for your platform)
53
+ - sympy==1.13.1
54
+ - torchquad==0.5.0
55
+ - numpy==2.4.2
56
+ - scipy==1.17.0
57
+ - loguru==0.7.3
58
+
59
+ To install the pinned packages, run:
60
+
61
+ ```bash
62
+ pip install -r requirements.txt
63
+ ```
64
+
65
+ If you intend to use GPU acceleration, please install a `torch` wheel that matches your CUDA version (the example above is a CUDA-enabled wheel). For CPU-only environments, install the CPU `torch` wheel instead.
66
+
67
+ ## Quick Usage
68
+
69
+ `symtorch` bridges the gap between SymPy's symbolic manipulation and PyTorch's highly optimized batched tensor operations. You can transcompile symbolic integrals directly into callable PyTorch engines.
70
+
71
+ ```python
72
+ import torch
73
+ import symtorch
74
+ import sympy as sp
75
+
76
+ # 1. Define your integrands symbolically
77
+ x = sp.Symbol("x", real=True)
78
+ p = sp.Symbol("p", real=True)
79
+ expr = sp.Integral(sp.exp(-p * x**2), (x, -sp.oo, sp.oo))
80
+
81
+ # 2. Compile to SymTorch engine
82
+ lt = symtorch.SymTorch()
83
+ texpr = lt.torchify(expr)
84
+
85
+ # 3. Evaluate massively batched parameter grids on accelerators
86
+ p_grid = torch.linspace(0.5, 100.0, 10000, dtype=torch.float64, device="cuda").unsqueeze(-1)
87
+ re, im = texpr.torch_integrate_batched(
88
+ params_values=p_grid,
89
+ method="gauss-legendre",
90
+ N=501, # Force high quadrature scaling for difficult integrands
91
+ device="cuda", # Target accelerator natively
92
+ dtype=torch.float64,
93
+ chunk_size_params=4096 # Automatically chunks massive batches to avoid OOM
94
+ )
95
+ print("Real part:", re)
96
+ ```
97
+
98
+ ### Parameter Reference
99
+
100
+ When evaluating continuous integrals dynamically using `torch_integrate_batched()`, you have granular control over numerical performance constraints:
101
+
102
+ - **`params_values`** (`torch.Tensor`): Array parameter map corresponding to all substituted free variables defining your symbolic integral.
103
+ - **`method`** (`str`): The mapped quadrature strategy (e.g. `"gauss-legendre"`).
104
+ - **`N`** (`int`): Limits Quadrature nodes. Higher N bounds push stability on deeply oscillatory configurations (allowing you to surpass typical recursion bottlenecks) but proportionately scales VRAM and FLOP demands.
105
+ - **`device`** (`str` or `torch.device`): Device mapping (e.g., `"cpu"`, `"cuda"`, `"mps"`).
106
+ - **`dtype`** (`torch.dtype`): Evaluative precision schema (use `torch.float64` for analytic comparisons or exponential limits).
107
+ - **`chunk_size_params`** (`int`): Sub-array partitioning for the grid parameters. Ex: With a $1,000,000$ point map and $N=2000$, setting this to `2048` iteratively offloads pressure allowing safe calculation without Out-Of-Memory hazards.
108
+
109
+ ---
110
+
111
+ ## ⚡ Universals Benchmarks & Capabilities
112
+
113
+ A major component of SymTorch is overcoming conventional scaling walls embedded heavily in dynamic Python CPU evaluators (e.g., SciPy's recursive `quad`).
114
+
115
+ **SymTorch evaluates integrals up to ~2,640× faster than SciPy with similar accuracy, and can uniquely utilize massive static grids to achieve mathematically narrower error bounds on notoriously difficult oscillatory problems.**
116
+
117
+ _Evaluation constraints_: Uniform sequential sweeps covering $p \in [0.5, 100.0]$ across a $10,000$ point grid resolving analytical ground truths. N represents quadrature scaling depth.
118
+
119
+ ### Tabular Comparisons
120
+
121
+ | Case Name & Analytical Form | Grid | N | SymTorch ms/pt | SciPy ms/pt | Speedup | SymTorch Err | SciPy Err |
122
+ | :--- | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
123
+ | <br>**1_Gaussian**<br><br> $\int_{-\infty}^{\infty} e^{-p x^2}dx$<br><br> $= \sqrt{\frac{\pi}{p}}$<br><br> | 10000 | 121 | `0.00092` | `0.13262` | **144.0x** | `1.07e-14` | `3.72e-15` |
124
+ | | 10000 | 301 | `0.00332` | `0.14036` | **42.2x** | `2.13e-14` | `3.72e-15` |
125
+ | | 10000 | 501 | `0.00756` | `0.13877` | **18.3x** | `2.22e-14` | `3.72e-15` |
126
+ | | 10000 | 1001| `0.01996` | `0.13185` | **6.6x** | `2.27e-13` | `3.72e-15` |
127
+ | | 10000 | 2001| `0.06202` | `0.13026` | **2.1x** | `4.59e-13` | `3.72e-15` |
128
+ | <br>**2_Fourier_Gaussian**<br><br> $\int_{-\infty}^{\infty} e^{-x^2}e^{ipx}dx$<br><br> $= \sqrt{\pi}\,e^{-p^2/4}$<br><br> | 10000 | 121 | `0.00137` | `2.46700` | **1805.5x**| `2.65e-01` | `7.92e-10` |
129
+ | | 10000 | 301 | `0.00427` | `2.47832` | **580.4x** | `6.58e-03` | `7.92e-10` |
130
+ | | 10000 | 501 | `0.00949` | `2.42028` | **254.9x** | `4.58e-05` | `7.92e-10` |
131
+ | | 10000 | 1001| `0.02473` | `2.39489` | **96.8x** | `9.88e-12` | `7.92e-10` |
132
+ | | 10000 | 2001| `0.07130` | `2.49811` | **35.0x** | `3.05e-13` | `7.92e-10` |
133
+ | <br>**3_Damped_Cosine**<br><br> $\int_{0}^{\infty} e^{-x}\cos(px)dx$<br><br> $= \frac{1}{1+p^2}$<br><br> | 10000 | 121 | `0.00062` | `1.64998` | **2641.1x**| `2.07e-01` | `2.41e-09` |
134
+ | | 10000 | 301 | `0.00267` | `1.68845` | **632.9x** | `5.83e-02` | `2.41e-09` |
135
+ | | 10000 | 501 | `0.00657` | `1.67522` | **254.8x** | `2.20e-02` | `2.41e-09` |
136
+ | | 10000 | 1001| `0.01807` | `1.63858` | **90.7x** | `2.67e-03` | `2.41e-09` |
137
+ | | 10000 | 2001| `0.05752` | `1.63351` | **28.4x** | `5.72e-05` | `2.41e-09` |
138
+
139
+ _*To access raw LaTeX arrays, inspect: `tests/benchmarks/ultimate_universal_benchmark.tex`_
140
+ ### Key Identifications:
141
+ * **Speedup Range:** Depending on the quadrature depth (N) and integrand complexity, speedups scale dynamically from $\sim2\times$ (at massive $N=2001$ limits) up to $\sim2641\times$ (at standard $N=121$ baselines).
142
+ * **Oscillatory Bypassing:** When SciPy encounters intense structural oscillations (`Case 2`), its adaptive iteration bottoms out (capping at $10^{-10}$ error margins). By structurally projecting massive arrays via SymTorch (`N=1001+`) we cleanly break past recursive thresholds achieving up to $10^{-13}$ true numerical accuracy while retaining ~ $40\times$ faster wall-times!
143
+
144
+ ## Running Tests
145
+
146
+ To run the benchmarking suite locally across `symtorch` implementations:
147
+
148
+ ```bash
149
+ pytest tests/ -v
150
+ pytest tests/test_benchmark_ultimate.py -s # Generates local .csv, .md, & .tex format drops safely
151
+ ```
152
+
153
+ ## Examples & Tutorials
154
+
155
+ For more extensive usage—including plotting workflows and physics applications—check the [`examples/notebooks/`](examples/notebooks/) directory which includes:
156
+ - `01_the_basics.ipynb`
157
+ - `02_parameter_sweeps.ipynb`
158
+ - `03_scattering_and_wigner.ipynb`
159
+
160
+ ## License
161
+
162
+ Please see the [LICENSE](LICENSE) file in the root of the repository for usage and distribution terms.
@@ -0,0 +1,134 @@
1
+ # symtorch (distribution: libsymtorch)
2
+
3
+ SymPy-to-Torch transcompilation and numerical integration library designed for extremely fast, batched evaluation on GPUs and CPUs.
4
+
5
+ Note: this module was first developed for [libphysics](https://github.com/ferhatpy/libphysics) — then it was split out into a standalone library to tackle generalized parallel computational bottlenecks.
6
+
7
+ ## Install (dev)
8
+
9
+ ```bash
10
+ pip install -e .
11
+ ```
12
+
13
+ ## Install (PyPI)
14
+
15
+ ```bash
16
+ pip install libsymtorch
17
+ ```
18
+
19
+ ## Requirements
20
+
21
+ This project depends on the packages listed in `requirements.txt`. The primary runtime requirements are:
22
+
23
+ - Python 3.8+
24
+ - torch==2.5.1+cu121 (or another `torch` build appropriate for your platform)
25
+ - sympy==1.13.1
26
+ - torchquad==0.5.0
27
+ - numpy==2.4.2
28
+ - scipy==1.17.0
29
+ - loguru==0.7.3
30
+
31
+ To install the pinned packages, run:
32
+
33
+ ```bash
34
+ pip install -r requirements.txt
35
+ ```
36
+
37
+ If you intend to use GPU acceleration, please install a `torch` wheel that matches your CUDA version (the example above is a CUDA-enabled wheel). For CPU-only environments, install the CPU `torch` wheel instead.
38
+
39
+ ## Quick Usage
40
+
41
+ `symtorch` bridges the gap between SymPy's symbolic manipulation and PyTorch's highly optimized batched tensor operations. You can transcompile symbolic integrals directly into callable PyTorch engines.
42
+
43
+ ```python
44
+ import torch
45
+ import symtorch
46
+ import sympy as sp
47
+
48
+ # 1. Define your integrands symbolically
49
+ x = sp.Symbol("x", real=True)
50
+ p = sp.Symbol("p", real=True)
51
+ expr = sp.Integral(sp.exp(-p * x**2), (x, -sp.oo, sp.oo))
52
+
53
+ # 2. Compile to SymTorch engine
54
+ lt = symtorch.SymTorch()
55
+ texpr = lt.torchify(expr)
56
+
57
+ # 3. Evaluate massively batched parameter grids on accelerators
58
+ p_grid = torch.linspace(0.5, 100.0, 10000, dtype=torch.float64, device="cuda").unsqueeze(-1)
59
+ re, im = texpr.torch_integrate_batched(
60
+ params_values=p_grid,
61
+ method="gauss-legendre",
62
+ N=501, # Force high quadrature scaling for difficult integrands
63
+ device="cuda", # Target accelerator natively
64
+ dtype=torch.float64,
65
+ chunk_size_params=4096 # Automatically chunks massive batches to avoid OOM
66
+ )
67
+ print("Real part:", re)
68
+ ```
69
+
70
+ ### Parameter Reference
71
+
72
+ When evaluating continuous integrals dynamically using `torch_integrate_batched()`, you have granular control over numerical performance constraints:
73
+
74
+ - **`params_values`** (`torch.Tensor`): Array parameter map corresponding to all substituted free variables defining your symbolic integral.
75
+ - **`method`** (`str`): The mapped quadrature strategy (e.g. `"gauss-legendre"`).
76
+ - **`N`** (`int`): Limits Quadrature nodes. Higher N bounds push stability on deeply oscillatory configurations (allowing you to surpass typical recursion bottlenecks) but proportionately scales VRAM and FLOP demands.
77
+ - **`device`** (`str` or `torch.device`): Device mapping (e.g., `"cpu"`, `"cuda"`, `"mps"`).
78
+ - **`dtype`** (`torch.dtype`): Evaluative precision schema (use `torch.float64` for analytic comparisons or exponential limits).
79
+ - **`chunk_size_params`** (`int`): Sub-array partitioning for the grid parameters. Ex: With a $1,000,000$ point map and $N=2000$, setting this to `2048` iteratively offloads pressure allowing safe calculation without Out-Of-Memory hazards.
80
+
81
+ ---
82
+
83
+ ## ⚡ Universals Benchmarks & Capabilities
84
+
85
+ A major component of SymTorch is overcoming conventional scaling walls embedded heavily in dynamic Python CPU evaluators (e.g., SciPy's recursive `quad`).
86
+
87
+ **SymTorch evaluates integrals up to ~2,640× faster than SciPy with similar accuracy, and can uniquely utilize massive static grids to achieve mathematically narrower error bounds on notoriously difficult oscillatory problems.**
88
+
89
+ _Evaluation constraints_: Uniform sequential sweeps covering $p \in [0.5, 100.0]$ across a $10,000$ point grid resolving analytical ground truths. N represents quadrature scaling depth.
90
+
91
+ ### Tabular Comparisons
92
+
93
+ | Case Name & Analytical Form | Grid | N | SymTorch ms/pt | SciPy ms/pt | Speedup | SymTorch Err | SciPy Err |
94
+ | :--- | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
95
+ | <br>**1_Gaussian**<br><br> $\int_{-\infty}^{\infty} e^{-p x^2}dx$<br><br> $= \sqrt{\frac{\pi}{p}}$<br><br> | 10000 | 121 | `0.00092` | `0.13262` | **144.0x** | `1.07e-14` | `3.72e-15` |
96
+ | | 10000 | 301 | `0.00332` | `0.14036` | **42.2x** | `2.13e-14` | `3.72e-15` |
97
+ | | 10000 | 501 | `0.00756` | `0.13877` | **18.3x** | `2.22e-14` | `3.72e-15` |
98
+ | | 10000 | 1001| `0.01996` | `0.13185` | **6.6x** | `2.27e-13` | `3.72e-15` |
99
+ | | 10000 | 2001| `0.06202` | `0.13026` | **2.1x** | `4.59e-13` | `3.72e-15` |
100
+ | <br>**2_Fourier_Gaussian**<br><br> $\int_{-\infty}^{\infty} e^{-x^2}e^{ipx}dx$<br><br> $= \sqrt{\pi}\,e^{-p^2/4}$<br><br> | 10000 | 121 | `0.00137` | `2.46700` | **1805.5x**| `2.65e-01` | `7.92e-10` |
101
+ | | 10000 | 301 | `0.00427` | `2.47832` | **580.4x** | `6.58e-03` | `7.92e-10` |
102
+ | | 10000 | 501 | `0.00949` | `2.42028` | **254.9x** | `4.58e-05` | `7.92e-10` |
103
+ | | 10000 | 1001| `0.02473` | `2.39489` | **96.8x** | `9.88e-12` | `7.92e-10` |
104
+ | | 10000 | 2001| `0.07130` | `2.49811` | **35.0x** | `3.05e-13` | `7.92e-10` |
105
+ | <br>**3_Damped_Cosine**<br><br> $\int_{0}^{\infty} e^{-x}\cos(px)dx$<br><br> $= \frac{1}{1+p^2}$<br><br> | 10000 | 121 | `0.00062` | `1.64998` | **2641.1x**| `2.07e-01` | `2.41e-09` |
106
+ | | 10000 | 301 | `0.00267` | `1.68845` | **632.9x** | `5.83e-02` | `2.41e-09` |
107
+ | | 10000 | 501 | `0.00657` | `1.67522` | **254.8x** | `2.20e-02` | `2.41e-09` |
108
+ | | 10000 | 1001| `0.01807` | `1.63858` | **90.7x** | `2.67e-03` | `2.41e-09` |
109
+ | | 10000 | 2001| `0.05752` | `1.63351` | **28.4x** | `5.72e-05` | `2.41e-09` |
110
+
111
+ _*To access raw LaTeX arrays, inspect: `tests/benchmarks/ultimate_universal_benchmark.tex`_
112
+ ### Key Identifications:
113
+ * **Speedup Range:** Depending on the quadrature depth (N) and integrand complexity, speedups scale dynamically from $\sim2\times$ (at massive $N=2001$ limits) up to $\sim2641\times$ (at standard $N=121$ baselines).
114
+ * **Oscillatory Bypassing:** When SciPy encounters intense structural oscillations (`Case 2`), its adaptive iteration bottoms out (capping at $10^{-10}$ error margins). By structurally projecting massive arrays via SymTorch (`N=1001+`) we cleanly break past recursive thresholds achieving up to $10^{-13}$ true numerical accuracy while retaining ~ $40\times$ faster wall-times!
115
+
116
+ ## Running Tests
117
+
118
+ To run the benchmarking suite locally across `symtorch` implementations:
119
+
120
+ ```bash
121
+ pytest tests/ -v
122
+ pytest tests/test_benchmark_ultimate.py -s # Generates local .csv, .md, & .tex format drops safely
123
+ ```
124
+
125
+ ## Examples & Tutorials
126
+
127
+ For more extensive usage—including plotting workflows and physics applications—check the [`examples/notebooks/`](examples/notebooks/) directory which includes:
128
+ - `01_the_basics.ipynb`
129
+ - `02_parameter_sweeps.ipynb`
130
+ - `03_scattering_and_wigner.ipynb`
131
+
132
+ ## License
133
+
134
+ Please see the [LICENSE](LICENSE) file in the root of the repository for usage and distribution terms.
@@ -1,49 +1,49 @@
1
- [build-system]
2
- requires = ["setuptools>=61.0"]
3
- build-backend = "setuptools.build_meta"
4
-
5
- [tool.setuptools]
6
- package-dir = {"" = "src"}
7
-
8
- [tool.setuptools.packages.find]
9
- where = ["src"]
10
-
11
- [project]
12
- name = "libsymtorch"
13
- version = "0.1.1"
14
- authors = [
15
- { name="Ibrahim H.I. Abushawish", email="ibrahim.hamed2701@gmail.com" },
16
- ]
17
- description = "SymPy-to-Torch conversion and numerical integration"
18
- readme = "README.md"
19
- requires-python = ">=3.8"
20
- license = "MIT"
21
- license-files = ["LICENSE"]
22
- dependencies = [
23
- "torch>=2.5.1",
24
- "sympy>=1.13.1",
25
- "torchquad>=0.5.0",
26
- "numpy>=2.4.2",
27
- "scipy>=1.17.0",
28
- "loguru>=0.7.3",
29
- ]
30
-
31
- classifiers = [
32
- "Programming Language :: Python :: 3",
33
- "Operating System :: OS Independent",
34
- "Topic :: Scientific/Engineering :: Physics",
35
- "Topic :: Scientific/Engineering :: Mathematics",
36
- ]
37
-
38
- [project.optional-dependencies]
39
- dev = [
40
- "pytest>=8",
41
- "build>=1",
42
- "twine>=5",
43
- ]
44
- examples = [
45
- "matplotlib>=3.8",
46
- ]
47
-
48
- [project.urls]
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [tool.setuptools]
6
+ package-dir = {"" = "src"}
7
+
8
+ [tool.setuptools.packages.find]
9
+ where = ["src"]
10
+
11
+ [project]
12
+ name = "libsymtorch"
13
+ version = "0.2.1"
14
+ authors = [
15
+ { name="Ibrahim H.I. Abushawish", email="ibrahim.hamed2701@gmail.com" },
16
+ ]
17
+ description = "SymPy-to-Torch conversion and numerical integration"
18
+ readme = "README.md"
19
+ requires-python = ">=3.8"
20
+ license = "MIT"
21
+ license-files = ["LICENSE"]
22
+ dependencies = [
23
+ "torch>=2.5.1",
24
+ "sympy>=1.13.1",
25
+ "torchquad>=0.5.0",
26
+ "numpy>=2.4.2",
27
+ "scipy>=1.17.0",
28
+ "loguru>=0.7.3",
29
+ ]
30
+
31
+ classifiers = [
32
+ "Programming Language :: Python :: 3",
33
+ "Operating System :: OS Independent",
34
+ "Topic :: Scientific/Engineering :: Physics",
35
+ "Topic :: Scientific/Engineering :: Mathematics",
36
+ ]
37
+
38
+ [project.optional-dependencies]
39
+ dev = [
40
+ "pytest>=8",
41
+ "build>=1",
42
+ "twine>=5",
43
+ ]
44
+ examples = [
45
+ "matplotlib>=3.8",
46
+ ]
47
+
48
+ [project.urls]
49
49
  "Homepage" = "https://github.com/ibeuler/symtorch"
@@ -1,4 +1,4 @@
1
- [egg_info]
2
- tag_build =
3
- tag_date = 0
4
-
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,162 @@
1
+ Metadata-Version: 2.4
2
+ Name: libsymtorch
3
+ Version: 0.2.1
4
+ Summary: SymPy-to-Torch conversion and numerical integration
5
+ Author-email: "Ibrahim H.I. Abushawish" <ibrahim.hamed2701@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/ibeuler/symtorch
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Topic :: Scientific/Engineering :: Physics
11
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: torch>=2.5.1
16
+ Requires-Dist: sympy>=1.13.1
17
+ Requires-Dist: torchquad>=0.5.0
18
+ Requires-Dist: numpy>=2.4.2
19
+ Requires-Dist: scipy>=1.17.0
20
+ Requires-Dist: loguru>=0.7.3
21
+ Provides-Extra: dev
22
+ Requires-Dist: pytest>=8; extra == "dev"
23
+ Requires-Dist: build>=1; extra == "dev"
24
+ Requires-Dist: twine>=5; extra == "dev"
25
+ Provides-Extra: examples
26
+ Requires-Dist: matplotlib>=3.8; extra == "examples"
27
+ Dynamic: license-file
28
+
29
+ # symtorch (distribution: libsymtorch)
30
+
31
+ SymPy-to-Torch transcompilation and numerical integration library designed for extremely fast, batched evaluation on GPUs and CPUs.
32
+
33
+ Note: this module was first developed for [libphysics](https://github.com/ferhatpy/libphysics) — then it was split out into a standalone library to tackle generalized parallel computational bottlenecks.
34
+
35
+ ## Install (dev)
36
+
37
+ ```bash
38
+ pip install -e .
39
+ ```
40
+
41
+ ## Install (PyPI)
42
+
43
+ ```bash
44
+ pip install libsymtorch
45
+ ```
46
+
47
+ ## Requirements
48
+
49
+ This project depends on the packages listed in `requirements.txt`. The primary runtime requirements are:
50
+
51
+ - Python 3.8+
52
+ - torch==2.5.1+cu121 (or another `torch` build appropriate for your platform)
53
+ - sympy==1.13.1
54
+ - torchquad==0.5.0
55
+ - numpy==2.4.2
56
+ - scipy==1.17.0
57
+ - loguru==0.7.3
58
+
59
+ To install the pinned packages, run:
60
+
61
+ ```bash
62
+ pip install -r requirements.txt
63
+ ```
64
+
65
+ If you intend to use GPU acceleration, please install a `torch` wheel that matches your CUDA version (the example above is a CUDA-enabled wheel). For CPU-only environments, install the CPU `torch` wheel instead.
66
+
67
+ ## Quick Usage
68
+
69
+ `symtorch` bridges the gap between SymPy's symbolic manipulation and PyTorch's highly optimized batched tensor operations. You can transcompile symbolic integrals directly into callable PyTorch engines.
70
+
71
+ ```python
72
+ import torch
73
+ import symtorch
74
+ import sympy as sp
75
+
76
+ # 1. Define your integrands symbolically
77
+ x = sp.Symbol("x", real=True)
78
+ p = sp.Symbol("p", real=True)
79
+ expr = sp.Integral(sp.exp(-p * x**2), (x, -sp.oo, sp.oo))
80
+
81
+ # 2. Compile to SymTorch engine
82
+ lt = symtorch.SymTorch()
83
+ texpr = lt.torchify(expr)
84
+
85
+ # 3. Evaluate massively batched parameter grids on accelerators
86
+ p_grid = torch.linspace(0.5, 100.0, 10000, dtype=torch.float64, device="cuda").unsqueeze(-1)
87
+ re, im = texpr.torch_integrate_batched(
88
+ params_values=p_grid,
89
+ method="gauss-legendre",
90
+ N=501, # Force high quadrature scaling for difficult integrands
91
+ device="cuda", # Target accelerator natively
92
+ dtype=torch.float64,
93
+ chunk_size_params=4096 # Automatically chunks massive batches to avoid OOM
94
+ )
95
+ print("Real part:", re)
96
+ ```
97
+
98
+ ### Parameter Reference
99
+
100
+ When evaluating continuous integrals dynamically using `torch_integrate_batched()`, you have granular control over numerical performance constraints:
101
+
102
+ - **`params_values`** (`torch.Tensor`): Array parameter map corresponding to all substituted free variables defining your symbolic integral.
103
+ - **`method`** (`str`): The mapped quadrature strategy (e.g. `"gauss-legendre"`).
104
+ - **`N`** (`int`): Limits Quadrature nodes. Higher N bounds push stability on deeply oscillatory configurations (allowing you to surpass typical recursion bottlenecks) but proportionately scales VRAM and FLOP demands.
105
+ - **`device`** (`str` or `torch.device`): Device mapping (e.g., `"cpu"`, `"cuda"`, `"mps"`).
106
+ - **`dtype`** (`torch.dtype`): Evaluative precision schema (use `torch.float64` for analytic comparisons or exponential limits).
107
+ - **`chunk_size_params`** (`int`): Sub-array partitioning for the grid parameters. Ex: With a $1,000,000$ point map and $N=2000$, setting this to `2048` iteratively offloads pressure allowing safe calculation without Out-Of-Memory hazards.
108
+
109
+ ---
110
+
111
+ ## ⚡ Universals Benchmarks & Capabilities
112
+
113
+ A major component of SymTorch is overcoming conventional scaling walls embedded heavily in dynamic Python CPU evaluators (e.g., SciPy's recursive `quad`).
114
+
115
+ **SymTorch evaluates integrals up to ~2,640× faster than SciPy with similar accuracy, and can uniquely utilize massive static grids to achieve mathematically narrower error bounds on notoriously difficult oscillatory problems.**
116
+
117
+ _Evaluation constraints_: Uniform sequential sweeps covering $p \in [0.5, 100.0]$ across a $10,000$ point grid resolving analytical ground truths. N represents quadrature scaling depth.
118
+
119
+ ### Tabular Comparisons
120
+
121
+ | Case Name & Analytical Form | Grid | N | SymTorch ms/pt | SciPy ms/pt | Speedup | SymTorch Err | SciPy Err |
122
+ | :--- | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
123
+ | <br>**1_Gaussian**<br><br> $\int_{-\infty}^{\infty} e^{-p x^2}dx$<br><br> $= \sqrt{\frac{\pi}{p}}$<br><br> | 10000 | 121 | `0.00092` | `0.13262` | **144.0x** | `1.07e-14` | `3.72e-15` |
124
+ | | 10000 | 301 | `0.00332` | `0.14036` | **42.2x** | `2.13e-14` | `3.72e-15` |
125
+ | | 10000 | 501 | `0.00756` | `0.13877` | **18.3x** | `2.22e-14` | `3.72e-15` |
126
+ | | 10000 | 1001| `0.01996` | `0.13185` | **6.6x** | `2.27e-13` | `3.72e-15` |
127
+ | | 10000 | 2001| `0.06202` | `0.13026` | **2.1x** | `4.59e-13` | `3.72e-15` |
128
+ | <br>**2_Fourier_Gaussian**<br><br> $\int_{-\infty}^{\infty} e^{-x^2}e^{ipx}dx$<br><br> $= \sqrt{\pi}\,e^{-p^2/4}$<br><br> | 10000 | 121 | `0.00137` | `2.46700` | **1805.5x**| `2.65e-01` | `7.92e-10` |
129
+ | | 10000 | 301 | `0.00427` | `2.47832` | **580.4x** | `6.58e-03` | `7.92e-10` |
130
+ | | 10000 | 501 | `0.00949` | `2.42028` | **254.9x** | `4.58e-05` | `7.92e-10` |
131
+ | | 10000 | 1001| `0.02473` | `2.39489` | **96.8x** | `9.88e-12` | `7.92e-10` |
132
+ | | 10000 | 2001| `0.07130` | `2.49811` | **35.0x** | `3.05e-13` | `7.92e-10` |
133
+ | <br>**3_Damped_Cosine**<br><br> $\int_{0}^{\infty} e^{-x}\cos(px)dx$<br><br> $= \frac{1}{1+p^2}$<br><br> | 10000 | 121 | `0.00062` | `1.64998` | **2641.1x**| `2.07e-01` | `2.41e-09` |
134
+ | | 10000 | 301 | `0.00267` | `1.68845` | **632.9x** | `5.83e-02` | `2.41e-09` |
135
+ | | 10000 | 501 | `0.00657` | `1.67522` | **254.8x** | `2.20e-02` | `2.41e-09` |
136
+ | | 10000 | 1001| `0.01807` | `1.63858` | **90.7x** | `2.67e-03` | `2.41e-09` |
137
+ | | 10000 | 2001| `0.05752` | `1.63351` | **28.4x** | `5.72e-05` | `2.41e-09` |
138
+
139
+ _*To access raw LaTeX arrays, inspect: `tests/benchmarks/ultimate_universal_benchmark.tex`_
140
+ ### Key Identifications:
141
+ * **Speedup Range:** Depending on the quadrature depth (N) and integrand complexity, speedups scale dynamically from $\sim2\times$ (at massive $N=2001$ limits) up to $\sim2641\times$ (at standard $N=121$ baselines).
142
+ * **Oscillatory Bypassing:** When SciPy encounters intense structural oscillations (`Case 2`), its adaptive iteration bottoms out (capping at $10^{-10}$ error margins). By structurally projecting massive arrays via SymTorch (`N=1001+`) we cleanly break past recursive thresholds achieving up to $10^{-13}$ true numerical accuracy while retaining ~ $40\times$ faster wall-times!
143
+
144
+ ## Running Tests
145
+
146
+ To run the benchmarking suite locally across `symtorch` implementations:
147
+
148
+ ```bash
149
+ pytest tests/ -v
150
+ pytest tests/test_benchmark_ultimate.py -s # Generates local .csv, .md, & .tex format drops safely
151
+ ```
152
+
153
+ ## Examples & Tutorials
154
+
155
+ For more extensive usage—including plotting workflows and physics applications—check the [`examples/notebooks/`](examples/notebooks/) directory which includes:
156
+ - `01_the_basics.ipynb`
157
+ - `02_parameter_sweeps.ipynb`
158
+ - `03_scattering_and_wigner.ipynb`
159
+
160
+ ## License
161
+
162
+ Please see the [LICENSE](LICENSE) file in the root of the repository for usage and distribution terms.
@@ -9,5 +9,6 @@ src/libsymtorch.egg-info/top_level.txt
9
9
  src/symtorch/__init__.py
10
10
  src/symtorch/main.py
11
11
  tests/test_batching.py
12
+ tests/test_benchmark_ultimate.py
12
13
  tests/test_conversion.py
13
14
  tests/test_numerical.py