pygeomatic 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.
- pygeomatic-0.1.0/.gitignore +218 -0
- pygeomatic-0.1.0/LICENSE +21 -0
- pygeomatic-0.1.0/PKG-INFO +395 -0
- pygeomatic-0.1.0/README.md +374 -0
- pygeomatic-0.1.0/pyproject.toml +44 -0
- pygeomatic-0.1.0/src/pygeomatic/__init__.py +316 -0
- pygeomatic-0.1.0/src/pygeomatic/article.py +624 -0
- pygeomatic-0.1.0/src/pygeomatic/coercions.json +50 -0
- pygeomatic-0.1.0/src/pygeomatic/coercions.py +195 -0
- pygeomatic-0.1.0/src/pygeomatic/emit.py +47 -0
- pygeomatic-0.1.0/src/pygeomatic/extensions.py +249 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/__init__.py +0 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/helpers.py +93 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/implementations/__init__.py +47 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/implementations/annotation_functions.py +134 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/implementations/array.py +42 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/implementations/autograd_functions.py +121 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/implementations/basic_figures.py +186 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/implementations/boolean_functions.py +294 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/implementations/complex_functions.py +174 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/implementations/curve_functions.py +92 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/implementations/intersections.py +250 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/implementations/ode_functions.py +90 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/implementations/planar_geometry.py +320 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/implementations/polygons.py +186 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/implementations/property_functions.py +25 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/implementations/rotation_functions.py +57 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/implementations/scalar_functions.py +170 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/implementations/special_functions.py +124 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/implementations/tangent_functions.py +23 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/implementations/tensor_functions.py +194 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/implementations/translation_functions.py +96 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/overloads/__init__.py +12 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/overloads/abs.py +11 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/overloads/add.py +7 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/overloads/create_overload.py +134 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/overloads/div.py +7 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/overloads/exp.py +7 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/overloads/log.py +7 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/overloads/mul.py +7 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/overloads/neg.py +7 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/overloads/pow.py +11 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/overloads/sqrt.py +7 -0
- pygeomatic-0.1.0/src/pygeomatic/functions/overloads/sub.py +7 -0
- pygeomatic-0.1.0/src/pygeomatic/generate.py +94 -0
- pygeomatic-0.1.0/src/pygeomatic/inference.py +273 -0
- pygeomatic-0.1.0/src/pygeomatic/macros.json +165 -0
- pygeomatic-0.1.0/src/pygeomatic/macros.py +362 -0
- pygeomatic-0.1.0/src/pygeomatic/nodes.py +933 -0
- pygeomatic-0.1.0/src/pygeomatic/palette.py +79 -0
- pygeomatic-0.1.0/src/pygeomatic/parse.py +177 -0
- pygeomatic-0.1.0/src/pygeomatic/prompting.py +165 -0
- pygeomatic-0.1.0/src/pygeomatic/registry.py +432 -0
- pygeomatic-0.1.0/src/pygeomatic/runner.py +100 -0
- pygeomatic-0.1.0/src/pygeomatic/store.py +345 -0
- pygeomatic-0.1.0/src/pygeomatic/system_nodes.py +137 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
# Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
# poetry.lock
|
|
109
|
+
# poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
# pdm.lock
|
|
116
|
+
# pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
# pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# Redis
|
|
135
|
+
*.rdb
|
|
136
|
+
*.aof
|
|
137
|
+
*.pid
|
|
138
|
+
|
|
139
|
+
# RabbitMQ
|
|
140
|
+
mnesia/
|
|
141
|
+
rabbitmq/
|
|
142
|
+
rabbitmq-data/
|
|
143
|
+
|
|
144
|
+
# ActiveMQ
|
|
145
|
+
activemq-data/
|
|
146
|
+
|
|
147
|
+
# SageMath parsed files
|
|
148
|
+
*.sage.py
|
|
149
|
+
|
|
150
|
+
# Environments
|
|
151
|
+
.env
|
|
152
|
+
.envrc
|
|
153
|
+
.venv
|
|
154
|
+
env/
|
|
155
|
+
venv/
|
|
156
|
+
ENV/
|
|
157
|
+
env.bak/
|
|
158
|
+
venv.bak/
|
|
159
|
+
|
|
160
|
+
# Spyder project settings
|
|
161
|
+
.spyderproject
|
|
162
|
+
.spyproject
|
|
163
|
+
|
|
164
|
+
# Rope project settings
|
|
165
|
+
.ropeproject
|
|
166
|
+
|
|
167
|
+
# mkdocs documentation
|
|
168
|
+
/site
|
|
169
|
+
|
|
170
|
+
# mypy
|
|
171
|
+
.mypy_cache/
|
|
172
|
+
.dmypy.json
|
|
173
|
+
dmypy.json
|
|
174
|
+
|
|
175
|
+
# Pyre type checker
|
|
176
|
+
.pyre/
|
|
177
|
+
|
|
178
|
+
# pytype static type analyzer
|
|
179
|
+
.pytype/
|
|
180
|
+
|
|
181
|
+
# Cython debug symbols
|
|
182
|
+
cython_debug/
|
|
183
|
+
|
|
184
|
+
# PyCharm
|
|
185
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
186
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
188
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
189
|
+
# .idea/
|
|
190
|
+
|
|
191
|
+
# Abstra
|
|
192
|
+
# Abstra is an AI-powered process automation framework.
|
|
193
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
194
|
+
# Learn more at https://abstra.io/docs
|
|
195
|
+
.abstra/
|
|
196
|
+
|
|
197
|
+
# Visual Studio Code
|
|
198
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
199
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
200
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
201
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
202
|
+
# .vscode/
|
|
203
|
+
# Temporary file for partial code execution
|
|
204
|
+
tempCodeRunnerFile.py
|
|
205
|
+
|
|
206
|
+
# Ruff stuff:
|
|
207
|
+
.ruff_cache/
|
|
208
|
+
|
|
209
|
+
# PyPI configuration file
|
|
210
|
+
.pypirc
|
|
211
|
+
|
|
212
|
+
# Marimo
|
|
213
|
+
marimo/_static/
|
|
214
|
+
marimo/_lsp/
|
|
215
|
+
__marimo__/
|
|
216
|
+
|
|
217
|
+
# Streamlit
|
|
218
|
+
.streamlit/secrets.toml
|
pygeomatic-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TinyVolt
|
|
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,395 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pygeomatic
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python mirror of the geomatic DSL function library; records calls for deterministic DSL emission
|
|
5
|
+
Project-URL: Homepage, https://github.com/TinyVolt/pygeomatic
|
|
6
|
+
Project-URL: Repository, https://github.com/TinyVolt/pygeomatic
|
|
7
|
+
Project-URL: Issues, https://github.com/TinyVolt/pygeomatic/issues
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Requires-Dist: numpy>=1.26
|
|
19
|
+
Requires-Dist: pydantic>=2.7
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# pygeomatic
|
|
23
|
+
|
|
24
|
+
Python mirror of the geomatic DSL function library. Every public
|
|
25
|
+
function maps 1:1 to a geomatic command; calling it computes numeric values
|
|
26
|
+
(numpy) where possible **and** records the call onto a tape, from which
|
|
27
|
+
`emit()` produces geomatic DSL lines deterministically.
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
import pygeomatic as gm
|
|
31
|
+
|
|
32
|
+
with gm.Store() as s:
|
|
33
|
+
a = gm.point(1, 2) # assignment target → output id `a`
|
|
34
|
+
b = gm.point(4, 6)
|
|
35
|
+
d = gm.distance(a, b) # float(d) == 5.0
|
|
36
|
+
c = gm.circle(a, 3)
|
|
37
|
+
m = gm.mid_point(c.center, b) # property access → `c.center`
|
|
38
|
+
gm.highlight(a, b)
|
|
39
|
+
print(gm.emit(s))
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
a = \point 1 2
|
|
44
|
+
b = \point 4 6
|
|
45
|
+
d = \distance a b
|
|
46
|
+
c = \circle a 3
|
|
47
|
+
m = \mid-point c.center b
|
|
48
|
+
\highlight a b
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Conventions
|
|
52
|
+
|
|
53
|
+
- **Function names** = DSL keyword with dashes → underscores (`reduce-sum` →
|
|
54
|
+
`reduce_sum`). Names that would shadow Python builtins get a trailing
|
|
55
|
+
underscore: `abs_`, `pow_`, `min_`, `max_`, `round_`, `bool_`, `filter_`,
|
|
56
|
+
`and_`, `or_`, `not_`, `complex_`, `help_`.
|
|
57
|
+
- **Output ids**: an assignment target names the output —
|
|
58
|
+
`fwd_traj = gm.point(3, 4)` emits `fwd-traj = \point 3 4` (underscores
|
|
59
|
+
become dashes), and multi-target assignment works at any arity:
|
|
60
|
+
`a, b, c = gm.scalar(1), gm.scalar(2), gm.scalar(3)` names all three. The
|
|
61
|
+
optional `out="my-id"` keyword overrides it. Chained `a = b = gm.scalar(1)`
|
|
62
|
+
records one command per target (`a = \scalar 1`, `b = \scalar 1`; the
|
|
63
|
+
python object carries the first id, the store holds a clone per extra).
|
|
64
|
+
Anything ambiguous or unsafe (no assignment, attribute targets, loop reuse
|
|
65
|
+
of a name, a name shaped like an engine auto-name, a taken id) silently
|
|
66
|
+
falls back to a dashed auto-id (`num-0`, `p-1`). Explicit ids must match the DSL grammar:
|
|
67
|
+
start with a letter, letters/digits/dashes, **no underscores** — and must
|
|
68
|
+
not look like engine auto-names (`num0`, `p3`, `text1`): the engine
|
|
69
|
+
generates those for internal nodes (property accessors, literals, array
|
|
70
|
+
elements) and a collision creates a reactive cycle that hangs the tab.
|
|
71
|
+
pygeomatic's dashed ids can never collide. Inference reads the caller's
|
|
72
|
+
bytecode, not its source, so it behaves identically everywhere: files,
|
|
73
|
+
`run_generated`, the REPL, `python -c`, notebooks, `exec`'d strings.
|
|
74
|
+
- **Infix arithmetic** works on Scalar / Complex / Array nodes (with number
|
|
75
|
+
literals on either side): `c = a + b` records `c = \add a b`; `- * /` and
|
|
76
|
+
unary `-` map to `\sub`, `\mul`, `\div`, `\neg`, and Arrays broadcast
|
|
77
|
+
elementwise. Chains of the same associative op fuse into ONE variadic
|
|
78
|
+
command: `d = a + b + c` emits `d = \add a b c`. `**`/`@`, in-place ops
|
|
79
|
+
(`acc += 2` would silently diverge from the reactive node — write
|
|
80
|
+
`total = acc + 2`), and infix on any other node type (Point, Circle, ...)
|
|
81
|
+
raise instructively — use the explicit functions (`gm.pow_`,
|
|
82
|
+
`gm.translate`, ...).
|
|
83
|
+
- **Array indexing / iteration**: `x = arr[i]` records
|
|
84
|
+
`x = \get-array-element arr i` (`i` an int or a Scalar node; literal
|
|
85
|
+
negative indices are normalized against the record-time length — the engine
|
|
86
|
+
has no negative indexing). `len(arr)` is a plain record-time int (records
|
|
87
|
+
nothing), so `for k in range(len(arr)): arr[k]` and `for el in arr:` unroll
|
|
88
|
+
into one command per element. Slices and `arr[i] = v` have no DSL
|
|
89
|
+
equivalent and raise.
|
|
90
|
+
- **Node properties** are exactly the whitelist in
|
|
91
|
+
[nodeProperties.ts](../src/lib/geomatic/state/nodeProperties.ts)
|
|
92
|
+
(`p.x`, `circ.center`, `circ.center.x`, ...); each access returns a node that
|
|
93
|
+
serializes to the `base.field` argument form. Read raw numbers via
|
|
94
|
+
`node.numeric`, `float(node)`, `complex(node)`.
|
|
95
|
+
- **str / bool convenience**: passing a Python `str` for a Text parameter (or
|
|
96
|
+
`bool` for a Bool parameter) records an implicit `\text "..."` / `\bool`
|
|
97
|
+
command first, then references it.
|
|
98
|
+
- **System default nodes**: every canvas (and every `Store`) starts with the
|
|
99
|
+
engine's defaults — `p0` (the origin), `T`/`F`, `learning-rate`,
|
|
100
|
+
`animation-speed`, `unit`, `grid-points`, `grid-opacity`, `grid-bg-color`,
|
|
101
|
+
`grid-origin` — so reference them directly without defining them:
|
|
102
|
+
`gm.line(gm.p0, gm.point(1, 1))` (dashed ids become underscores:
|
|
103
|
+
`gm.learning_rate`). They record no commands and resolve against the active
|
|
104
|
+
store at access time; reassigning one (`gm.scalar(0.5, out="learning-rate")`)
|
|
105
|
+
is allowed, matching the engine's last-write-wins `saveNode`. `gm.node(id)`
|
|
106
|
+
is the string-keyed equivalent.
|
|
107
|
+
- **Record-only commands**: functions whose computation lives in the engine
|
|
108
|
+
(plot, tangent, solve-ode/flow/simulate-sde, autograd ops, highlight/hide/...)
|
|
109
|
+
record onto the tape with correct signatures but produce nodes with unknown
|
|
110
|
+
(`None`) numerics. `translate`/`rotate`/`animate` do update numerics (final
|
|
111
|
+
state).
|
|
112
|
+
|
|
113
|
+
## Prompt → DSL generation (model-agnostic)
|
|
114
|
+
|
|
115
|
+
Three functions turn a natural-language prompt into DSL commands with any LLM;
|
|
116
|
+
pygeomatic never imports a provider SDK — you inject the model call:
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
import pygeomatic as gm
|
|
120
|
+
|
|
121
|
+
# 1. the system prompt (rendered from the live registry, never drifts)
|
|
122
|
+
system = gm.system_prompt()
|
|
123
|
+
|
|
124
|
+
# 2. your adapter: any callable (system, messages) -> reply text
|
|
125
|
+
def complete(system: str, messages: list[dict]) -> str:
|
|
126
|
+
# messages: [{"role": "user"|"assistant", "content": str}, ...]
|
|
127
|
+
# call OpenAI / Anthropic / a local model / anything, return the text
|
|
128
|
+
...
|
|
129
|
+
|
|
130
|
+
# 3. the loop: generate build(gm), run it, feed errors back (max_attempts tries)
|
|
131
|
+
result = gm.generate_dsl("a unit circle with 8 highlighted points on it", complete)
|
|
132
|
+
print("\n".join(result.dsl)) # geomatic DSL commands, ready to paste
|
|
133
|
+
print(result.code) # the python the model wrote
|
|
134
|
+
print(result.attempts) # how many tries it took
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Example adapter for an OpenAI-compatible chat endpoint (no SDK needed):
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
import json, urllib.request
|
|
141
|
+
|
|
142
|
+
def complete(system, messages):
|
|
143
|
+
body = {
|
|
144
|
+
"model": MODEL,
|
|
145
|
+
"messages": [{"role": "system", "content": system}, *messages],
|
|
146
|
+
}
|
|
147
|
+
req = urllib.request.Request(
|
|
148
|
+
f"{BASE_URL}/chat/completions",
|
|
149
|
+
data=json.dumps(body).encode(),
|
|
150
|
+
headers={"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"},
|
|
151
|
+
)
|
|
152
|
+
with urllib.request.urlopen(req) as resp:
|
|
153
|
+
return json.load(resp)["choices"][0]["message"]["content"]
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
The pieces are usable separately:
|
|
157
|
+
|
|
158
|
+
- `gm.system_prompt() -> str` — the full instructions + function reference.
|
|
159
|
+
- `gm.run_generated(code, timeout=20) -> RunResult` — executes code that
|
|
160
|
+
defines `build(gm)` in a subprocess (same interpreter, so run it from an
|
|
161
|
+
environment where pygeomatic is installed) and returns `.dsl` or `.error`.
|
|
162
|
+
- `gm.generate_dsl(prompt, complete, max_attempts=3) -> GenerateResult` —
|
|
163
|
+
the retry loop; raises `gm.GenerationError` (with the transcript) when all
|
|
164
|
+
attempts fail.
|
|
165
|
+
|
|
166
|
+
The model is asked to reply with one fenced code block defining `build(gm)`;
|
|
167
|
+
the harness (runner.py) owns the Store/emit plumbing. Errors — bad ids,
|
|
168
|
+
infix arithmetic, wrong arity, timeouts — come back as Python tracebacks and
|
|
169
|
+
are fed to the model verbatim for the next attempt.
|
|
170
|
+
|
|
171
|
+
## Type checking & coercions
|
|
172
|
+
|
|
173
|
+
Each argument is checked against the parameter type at emission (the same
|
|
174
|
+
acceptance rule as the engine's `CommandExecutor`), so a wrong-typed argument
|
|
175
|
+
raises in Python instead of producing DSL that fails in the browser. `Any`
|
|
176
|
+
takes anything, exact types pass, and an `Array` broadcasts into a scalar param
|
|
177
|
+
when its element type matches (`\point xs ys`).
|
|
178
|
+
|
|
179
|
+
The engine's **type-coercions** (feeding a `Line` where a `Scalar` is wanted,
|
|
180
|
+
an `Arrow` where an `Array` is wanted, ...) are **on by default**. Force strict
|
|
181
|
+
exact-type matching for a block with `allow_coercions(False)`:
|
|
182
|
+
|
|
183
|
+
```python
|
|
184
|
+
with gm.allow_coercions(False):
|
|
185
|
+
gm.text(a_scalar) # raises: Scalar is not a Text
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
The coercion table is **not hardcoded**: it is generated from the live
|
|
189
|
+
TypeScript into `src/pygeomatic/coercions.json` by `npm run gen:registry`
|
|
190
|
+
(which probes `canCoerce`/`canCoerceValue` over every node-type pair), so adding
|
|
191
|
+
a coercion in `type-coercion.ts` and regenerating is all it takes.
|
|
192
|
+
|
|
193
|
+
## Parsing DSL back (modification round-trips)
|
|
194
|
+
|
|
195
|
+
`gm.parse_dsl(text) -> dict[str, GNode]` is the inverse of `emit`: it replays
|
|
196
|
+
each line through the registered python functions onto the active store and
|
|
197
|
+
returns the store's id → node map, so you can modify a pasted scene
|
|
198
|
+
deterministically:
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
with gm.Store() as s:
|
|
202
|
+
nodes = gm.parse_dsl(existing_dsl)
|
|
203
|
+
gm.rotate(nodes["v"], nodes["center"], 30)
|
|
204
|
+
print(gm.emit(s)) # original lines round-tripped + the new commands
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Grammar = exactly what emit produces (numbers, id refs, whitelist-checked
|
|
208
|
+
property chains, quoted strings for `\text` only); define-before-use is
|
|
209
|
+
enforced. Engine-generated ids (`p0`, `num1`, ...) are accepted while
|
|
210
|
+
parsing — pasted scenes contain them — but stay rejected for authored
|
|
211
|
+
`out=` ids. Failures raise `gm.DslParseError` with the line number and line.
|
|
212
|
+
Extension commands parse once their manifest is loaded. A bare `\point 1 2`
|
|
213
|
+
re-emits with an auto id (`p-0 = \point 1 2`): same scene, different text.
|
|
214
|
+
|
|
215
|
+
## Articles: pygeomatic-in-markdown → CommandLink articles
|
|
216
|
+
|
|
217
|
+
Write geomatic articles as markdown with pygeomatic Python instead of raw DSL;
|
|
218
|
+
`compile_article` turns them into the `{label}(command)` span format. The Python runs once at compile time —
|
|
219
|
+
readers only ever receive deterministic DSL text.
|
|
220
|
+
|
|
221
|
+
````markdown
|
|
222
|
+
```pygeomatic
|
|
223
|
+
origin = gm.p0 # top-level code → hidden {}(...) setup spans
|
|
224
|
+
a = gm.point(3, 0)
|
|
225
|
+
walk = gm.line(origin, a)
|
|
226
|
+
gm.hide(walk)
|
|
227
|
+
|
|
228
|
+
with group("walk-x"): # a named run of commands for prose to reveal
|
|
229
|
+
gm.highlight(walk)
|
|
230
|
+
gm.show(walk) # last command gets the visible label
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Reach the point by {moving a distance}(ref:walk-x) of $3$ units.
|
|
234
|
+
Or reset it inline: {set scale to 1}(scale = gm.scalar(1)).
|
|
235
|
+
````
|
|
236
|
+
|
|
237
|
+
- **One store per article**: all fences and inline spans run in document order
|
|
238
|
+
sharing state, so ids and auto-names stay consistent.
|
|
239
|
+
- **Ref expansion**: every command of a group but the last becomes a hidden
|
|
240
|
+
`{}()` span before the visible one — a click always lands on a fully
|
|
241
|
+
set-up scene.
|
|
242
|
+
- **Inline spans** (`{label}(python statement)`) are the escape hatch for
|
|
243
|
+
one-offs; article mode is last-write-wins, so `s1 = gm.scalar(1)` reassigns
|
|
244
|
+
like the DSL line it becomes.
|
|
245
|
+
- **Round-trip gate**: the compiled document is replayed with `parse_dsl` in
|
|
246
|
+
document order; broken ordering or invalid DSL fails the compile, not the
|
|
247
|
+
reader.
|
|
248
|
+
- Regular code fences and `$...$` math are never scanned for spans.
|
|
249
|
+
|
|
250
|
+
```sh
|
|
251
|
+
uv run python scripts/compile_article.py article.md -o compiled.md # one file
|
|
252
|
+
uv run python scripts/compile_articles.py articles/ dist/ # a tree
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
(equivalently `gm.compile_article(md)` in-process or `gm.run_article(md)` in a
|
|
256
|
+
subprocess; both take `extensions=` / `macros=` / `allow_coercions=`.)
|
|
257
|
+
|
|
258
|
+
### Publishing from a content repo (GitHub Action)
|
|
259
|
+
|
|
260
|
+
A content repo publishes compiled articles with one workflow file; a compile
|
|
261
|
+
error in any article fails the push and nothing is published:
|
|
262
|
+
|
|
263
|
+
```yaml
|
|
264
|
+
name: Publish articles
|
|
265
|
+
on:
|
|
266
|
+
push: {branches: [main]}
|
|
267
|
+
jobs:
|
|
268
|
+
publish:
|
|
269
|
+
permissions: {contents: write}
|
|
270
|
+
uses: TinyVolt/pygeomatic/.github/workflows/publish-articles.yml@main
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
This compiles `articles/` and force-pushes the result (plus any non-markdown
|
|
274
|
+
assets) to a `dist` branch, which raw.githubusercontent.com serves with CORS.
|
|
275
|
+
Inputs: `source`, `publish-branch`, `extensions`, `macros`, `allow-coercions`,
|
|
276
|
+
and `pygeomatic-ref` — pin the latter to a tag or SHA for reproducible output.
|
|
277
|
+
For custom pipelines, the composite action `TinyVolt/pygeomatic@<ref>` runs
|
|
278
|
+
just the compile step (the `<ref>` you pin is also the exact pygeomatic
|
|
279
|
+
version used).
|
|
280
|
+
|
|
281
|
+
### Reading published articles
|
|
282
|
+
|
|
283
|
+
Once the `dist` branch exists, the article is live — readers open it at
|
|
284
|
+
|
|
285
|
+
```
|
|
286
|
+
https://www.tinyvolt.com/nova/<username>/<repo>/<article>
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
where `<article>` is the markdown file's path within `dist` (the `.md`
|
|
290
|
+
suffix is optional). E.g. `articles/intro.md` compiled from the repo
|
|
291
|
+
`alice/vectors` is read at `/nova/alice/vectors/intro`.
|
|
292
|
+
|
|
293
|
+
If the article uses extension commands or macros, bake their URLs into the
|
|
294
|
+
link you share so readers never load anything manually:
|
|
295
|
+
|
|
296
|
+
- `?ext=<manifest-url>` — extension manifest, loaded (sandboxed, from
|
|
297
|
+
whitelisted domains only) before the article renders.
|
|
298
|
+
- `?esm=<url>` — macro definitions, fetched and registered on page load.
|
|
299
|
+
|
|
300
|
+
## Extensions
|
|
301
|
+
|
|
302
|
+
Geomatic extension functions (loaded in the app from a `manifest.json`, see
|
|
303
|
+
`src/lib/geomatic/functions/extensionLoader.ts`) can be registered
|
|
304
|
+
dynamically. pygeomatic never runs their `compute` — emission only needs the
|
|
305
|
+
signature metadata the manifest carries, so extension calls are pure graph
|
|
306
|
+
record: outputs are record-only nodes of the declared `outputType` with
|
|
307
|
+
`.numeric` `None`.
|
|
308
|
+
|
|
309
|
+
```python
|
|
310
|
+
gm.load_extensions("dist/manifest.json") # path or URL; returns keywords
|
|
311
|
+
gm.la_vec2d(3, 4, out="v") # callable like any builtin
|
|
312
|
+
gm.loaded_extensions() # {source: [keywords]}
|
|
313
|
+
gm.unload_extensions("dist/manifest.json")
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
The registry is live: `system_prompt()` includes loaded extensions (category
|
|
317
|
+
`Extensions`) and drops them on unload. Re-loading a source replaces its
|
|
318
|
+
functions; colliding with a builtin keyword or another loaded source raises
|
|
319
|
+
`gm.ManifestError`. In the manifest, a required parameter must omit `default`
|
|
320
|
+
(or set it to `null`) — a present non-null `default` makes it optional. Only
|
|
321
|
+
the extension's `main` output is addressable; aux composite outputs exist
|
|
322
|
+
host-side only. `outputType`s outside the builtin node set get a generic
|
|
323
|
+
node (no properties) and dashed auto-ids (`widget-0`).
|
|
324
|
+
|
|
325
|
+
Subprocess runs start fresh, so pass manifests through:
|
|
326
|
+
|
|
327
|
+
```sh
|
|
328
|
+
uv run python scripts/build_to_dsl.py build.py --ext dist/manifest.json
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
(equivalently `gm.run_generated(code, extensions=[...])`).
|
|
332
|
+
|
|
333
|
+
## Macros
|
|
334
|
+
|
|
335
|
+
A macro is a named bundle of DSL commands — the format `downloadMacro.ts`
|
|
336
|
+
exports and `MacroLoader.ts` registers: `{"macro": "<name> [param ...]",
|
|
337
|
+
"commands": [...]}`. The builtin set the interactive editor auto-loads
|
|
338
|
+
(`public/geomatic/macros/geometry.json`) ships with pygeomatic as
|
|
339
|
+
`src/pygeomatic/macros.json` (a parity test keeps the copies identical) and is
|
|
340
|
+
registered on import, so `\load-colors`, `\zero-back-step loss`, ... parse and
|
|
341
|
+
are callable.
|
|
342
|
+
|
|
343
|
+
Invoking a macro records ONE line on the tape (never its body — parse → emit
|
|
344
|
+
still round-trips) while the body is replayed locally with engine semantics:
|
|
345
|
+
parameter names substituted by argument ids, unnamed body lines given the
|
|
346
|
+
engine's undashed auto ids (`p1`, `num0`), last-write-wins on reassignments.
|
|
347
|
+
Every node the body defines becomes a real store node later calls can
|
|
348
|
+
reference. An `id = \macro ...` invocation assigns the id to the last body
|
|
349
|
+
command if that command has no id of its own.
|
|
350
|
+
|
|
351
|
+
```python
|
|
352
|
+
gm.load_macros("my-macros.json") # path, URL, JSON string, or a
|
|
353
|
+
gm.load_macros([{...}], name="inline") # parsed list (name it for unload)
|
|
354
|
+
gm.zero_back_step(loss) # callable like any builtin
|
|
355
|
+
gm.loaded_macros() # {source: [keywords]}
|
|
356
|
+
gm.unload_macros("my-macros.json")
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
Collisions with builtins, extensions, or another source raise
|
|
360
|
+
`gm.MacroError`; re-loading a source replaces its macros. `gm.load_colors`
|
|
361
|
+
invokes the `load-colors` macro (identical store effect to the DSL line) and
|
|
362
|
+
wraps the created nodes in a `ColorPalette` (`pal.BLUE`); `gm.PALETTE`
|
|
363
|
+
(id → hex) is derived from the macro body, nothing is hardcoded.
|
|
364
|
+
Subprocess runs: `build_to_dsl.py build.py --macros my-macros.json`
|
|
365
|
+
(equivalently `gm.run_generated(code, macros=[...])`).
|
|
366
|
+
|
|
367
|
+
## Text is single-line
|
|
368
|
+
|
|
369
|
+
The DSL is line-based and the canvas renders text as single-line SVG `<text>`,
|
|
370
|
+
so newlines can neither be emitted nor displayed. Any newline in a text value
|
|
371
|
+
(with surrounding indentation) is collapsed to a single space at record time,
|
|
372
|
+
for `gm.text` and implicit Text coercions alike — use separate text nodes, not
|
|
373
|
+
`\n`, for multi-line layouts.
|
|
374
|
+
|
|
375
|
+
## Parity with the TypeScript registry
|
|
376
|
+
|
|
377
|
+
`registry.json` (function signatures) and `src/pygeomatic/coercions.json` (the
|
|
378
|
+
type-coercion table) are both generated from the live TS:
|
|
379
|
+
|
|
380
|
+
```sh
|
|
381
|
+
npm run gen:registry # → python/registry.json + python/src/pygeomatic/coercions.json
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
`tests/test_parity.py` asserts the Python registry matches it exactly
|
|
385
|
+
(keywords, parameter names/types/variadic/defaults, output types,
|
|
386
|
+
imperative/async flags, categories, overload operand types). Re-run it after
|
|
387
|
+
changing TS functions.
|
|
388
|
+
|
|
389
|
+
## Development
|
|
390
|
+
|
|
391
|
+
```sh
|
|
392
|
+
cd python
|
|
393
|
+
uv sync
|
|
394
|
+
uv run pytest
|
|
395
|
+
```
|