pygeomatic 0.1.0__py3-none-any.whl
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/__init__.py +316 -0
- pygeomatic/article.py +624 -0
- pygeomatic/coercions.json +50 -0
- pygeomatic/coercions.py +195 -0
- pygeomatic/emit.py +47 -0
- pygeomatic/extensions.py +249 -0
- pygeomatic/functions/__init__.py +0 -0
- pygeomatic/functions/helpers.py +93 -0
- pygeomatic/functions/implementations/__init__.py +47 -0
- pygeomatic/functions/implementations/annotation_functions.py +134 -0
- pygeomatic/functions/implementations/array.py +42 -0
- pygeomatic/functions/implementations/autograd_functions.py +121 -0
- pygeomatic/functions/implementations/basic_figures.py +186 -0
- pygeomatic/functions/implementations/boolean_functions.py +294 -0
- pygeomatic/functions/implementations/complex_functions.py +174 -0
- pygeomatic/functions/implementations/curve_functions.py +92 -0
- pygeomatic/functions/implementations/intersections.py +250 -0
- pygeomatic/functions/implementations/ode_functions.py +90 -0
- pygeomatic/functions/implementations/planar_geometry.py +320 -0
- pygeomatic/functions/implementations/polygons.py +186 -0
- pygeomatic/functions/implementations/property_functions.py +25 -0
- pygeomatic/functions/implementations/rotation_functions.py +57 -0
- pygeomatic/functions/implementations/scalar_functions.py +170 -0
- pygeomatic/functions/implementations/special_functions.py +124 -0
- pygeomatic/functions/implementations/tangent_functions.py +23 -0
- pygeomatic/functions/implementations/tensor_functions.py +194 -0
- pygeomatic/functions/implementations/translation_functions.py +96 -0
- pygeomatic/functions/overloads/__init__.py +12 -0
- pygeomatic/functions/overloads/abs.py +11 -0
- pygeomatic/functions/overloads/add.py +7 -0
- pygeomatic/functions/overloads/create_overload.py +134 -0
- pygeomatic/functions/overloads/div.py +7 -0
- pygeomatic/functions/overloads/exp.py +7 -0
- pygeomatic/functions/overloads/log.py +7 -0
- pygeomatic/functions/overloads/mul.py +7 -0
- pygeomatic/functions/overloads/neg.py +7 -0
- pygeomatic/functions/overloads/pow.py +11 -0
- pygeomatic/functions/overloads/sqrt.py +7 -0
- pygeomatic/functions/overloads/sub.py +7 -0
- pygeomatic/generate.py +94 -0
- pygeomatic/inference.py +273 -0
- pygeomatic/macros.json +165 -0
- pygeomatic/macros.py +362 -0
- pygeomatic/nodes.py +933 -0
- pygeomatic/palette.py +79 -0
- pygeomatic/parse.py +177 -0
- pygeomatic/prompting.py +165 -0
- pygeomatic/registry.py +432 -0
- pygeomatic/runner.py +100 -0
- pygeomatic/store.py +345 -0
- pygeomatic/system_nodes.py +137 -0
- pygeomatic-0.1.0.dist-info/METADATA +395 -0
- pygeomatic-0.1.0.dist-info/RECORD +55 -0
- pygeomatic-0.1.0.dist-info/WHEEL +4 -0
- pygeomatic-0.1.0.dist-info/licenses/LICENSE +21 -0
pygeomatic/__init__.py
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
"""pygeomatic — Python mirror of the geomatic DSL function library.
|
|
2
|
+
|
|
3
|
+
Every public function maps 1:1 to a geomatic command (dashes become
|
|
4
|
+
underscores: `reduce-sum` → `reduce_sum`). Calls compute numeric values where
|
|
5
|
+
possible AND record onto the active Store's tape; `emit()` turns the tape into
|
|
6
|
+
geomatic DSL lines. `abs`/`pow`/`min`/`max`/`round`/... that would shadow
|
|
7
|
+
Python builtins get a trailing underscore.
|
|
8
|
+
|
|
9
|
+
Example:
|
|
10
|
+
import pygeomatic as gm
|
|
11
|
+
|
|
12
|
+
with gm.Store() as s:
|
|
13
|
+
a = gm.point(1, 2, out="a")
|
|
14
|
+
b = gm.point(4, 6)
|
|
15
|
+
d = gm.distance(a, b)
|
|
16
|
+
gm.highlight(a, b)
|
|
17
|
+
print(gm.emit(s))
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from .article import ( # noqa: F401
|
|
21
|
+
ArticleError,
|
|
22
|
+
ArticleResult,
|
|
23
|
+
article_mode,
|
|
24
|
+
compile_article,
|
|
25
|
+
run_article,
|
|
26
|
+
)
|
|
27
|
+
from .coercions import allow_coercions, coercions_enabled # noqa: F401
|
|
28
|
+
from .emit import emit, render_command, render_token # noqa: F401
|
|
29
|
+
from .extensions import ( # noqa: F401
|
|
30
|
+
ManifestError,
|
|
31
|
+
load_extensions,
|
|
32
|
+
loaded_extensions,
|
|
33
|
+
unload_extensions,
|
|
34
|
+
)
|
|
35
|
+
from .generate import ( # noqa: F401
|
|
36
|
+
GenerateResult,
|
|
37
|
+
GenerationError,
|
|
38
|
+
extract_code,
|
|
39
|
+
generate_dsl,
|
|
40
|
+
)
|
|
41
|
+
from .macros import ( # noqa: F401
|
|
42
|
+
BUILTIN_SOURCE,
|
|
43
|
+
MacroDef,
|
|
44
|
+
MacroError,
|
|
45
|
+
load_builtin_macros,
|
|
46
|
+
load_macros,
|
|
47
|
+
loaded_macros,
|
|
48
|
+
unload_macros,
|
|
49
|
+
)
|
|
50
|
+
from .palette import ColorPalette, build_palette, color_ids, load_colors # noqa: F401
|
|
51
|
+
from .parse import DslParseError, parse_dsl # noqa: F401
|
|
52
|
+
from .prompting import python_name, system_prompt # noqa: F401
|
|
53
|
+
from .runner import RunResult, run_generated # noqa: F401
|
|
54
|
+
from .nodes import ( # noqa: F401
|
|
55
|
+
AngleMark,
|
|
56
|
+
Arc,
|
|
57
|
+
Array,
|
|
58
|
+
Arrow,
|
|
59
|
+
BezierCubic,
|
|
60
|
+
BezierQuadratic,
|
|
61
|
+
Bool,
|
|
62
|
+
Circle,
|
|
63
|
+
Complex,
|
|
64
|
+
CurlyBracket,
|
|
65
|
+
CurvedArrow,
|
|
66
|
+
DimensionLine,
|
|
67
|
+
Dummy,
|
|
68
|
+
Ellipse,
|
|
69
|
+
GNode,
|
|
70
|
+
IdRef,
|
|
71
|
+
LeaderLine,
|
|
72
|
+
Line,
|
|
73
|
+
NODE_CLASSES,
|
|
74
|
+
NODE_PROPERTIES,
|
|
75
|
+
Pin,
|
|
76
|
+
Plot,
|
|
77
|
+
Point,
|
|
78
|
+
PointGradient,
|
|
79
|
+
Polygon,
|
|
80
|
+
Polynomial,
|
|
81
|
+
PropRef,
|
|
82
|
+
RegularPolygon,
|
|
83
|
+
Scalar,
|
|
84
|
+
ScalarGradient,
|
|
85
|
+
Text,
|
|
86
|
+
TextBox,
|
|
87
|
+
Trail,
|
|
88
|
+
Trajectory,
|
|
89
|
+
Triangle,
|
|
90
|
+
VectorField,
|
|
91
|
+
)
|
|
92
|
+
from .registry import REGISTRY, FunctionDef, P # noqa: F401
|
|
93
|
+
from .store import ( # noqa: F401
|
|
94
|
+
Command,
|
|
95
|
+
Store,
|
|
96
|
+
TextLit,
|
|
97
|
+
current_store,
|
|
98
|
+
node,
|
|
99
|
+
reset_default_store,
|
|
100
|
+
)
|
|
101
|
+
from .system_nodes import ( # noqa: F401
|
|
102
|
+
SYSTEM_NODE_ATTRS,
|
|
103
|
+
SYSTEM_NODE_IDS,
|
|
104
|
+
SYSTEM_NODES,
|
|
105
|
+
SystemNode,
|
|
106
|
+
register_system_nodes,
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def __getattr__(name: str) -> GNode:
|
|
111
|
+
# System defaults are per-Store instances (and reassignable, last-write-
|
|
112
|
+
# wins), so `gm.p0` / `gm.learning_rate` must resolve against the ACTIVE
|
|
113
|
+
# store at access time rather than bind one instance at import.
|
|
114
|
+
node_id = SYSTEM_NODE_ATTRS.get(name)
|
|
115
|
+
if node_id is not None:
|
|
116
|
+
return current_store().nodes[node_id]
|
|
117
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def __dir__() -> list:
|
|
121
|
+
return sorted(set(globals()) | set(SYSTEM_NODE_ATTRS))
|
|
122
|
+
|
|
123
|
+
# Import the barrels for their registration side effects, then re-export the
|
|
124
|
+
# public callables.
|
|
125
|
+
from .functions import implementations as _implementations # noqa: F401
|
|
126
|
+
from .functions import overloads as _overloads # noqa: F401
|
|
127
|
+
|
|
128
|
+
from .functions.implementations.basic_figures import ( # noqa: F401
|
|
129
|
+
arc,
|
|
130
|
+
bezier_cubic,
|
|
131
|
+
bezier_quadratic,
|
|
132
|
+
circle,
|
|
133
|
+
ellipse,
|
|
134
|
+
ellipse_from_foci,
|
|
135
|
+
line,
|
|
136
|
+
point,
|
|
137
|
+
scalar,
|
|
138
|
+
text,
|
|
139
|
+
triangle,
|
|
140
|
+
)
|
|
141
|
+
from .functions.implementations.planar_geometry import ( # noqa: F401
|
|
142
|
+
angle,
|
|
143
|
+
area_circle,
|
|
144
|
+
area_triangle,
|
|
145
|
+
bisect_angle,
|
|
146
|
+
centroid,
|
|
147
|
+
circumcenter,
|
|
148
|
+
distance,
|
|
149
|
+
incenter,
|
|
150
|
+
mid_point,
|
|
151
|
+
project_point,
|
|
152
|
+
reflect_point,
|
|
153
|
+
slope_of_line,
|
|
154
|
+
)
|
|
155
|
+
from .functions.implementations.intersections import ( # noqa: F401
|
|
156
|
+
intersection_circle_circle,
|
|
157
|
+
intersection_line_bezier_quadratic,
|
|
158
|
+
intersection_line_circle,
|
|
159
|
+
intersection_line_ellipse,
|
|
160
|
+
intersection_line_line,
|
|
161
|
+
)
|
|
162
|
+
from .functions.implementations.curve_functions import ( # noqa: F401
|
|
163
|
+
clear_trail,
|
|
164
|
+
evaluate_polynomial,
|
|
165
|
+
plot,
|
|
166
|
+
plot_inverse,
|
|
167
|
+
polynomial,
|
|
168
|
+
trail,
|
|
169
|
+
)
|
|
170
|
+
from .functions.implementations.polygons import ( # noqa: F401
|
|
171
|
+
convex_hull,
|
|
172
|
+
polygon,
|
|
173
|
+
polygon_from_side,
|
|
174
|
+
polyline,
|
|
175
|
+
rectangle,
|
|
176
|
+
regular_polygon,
|
|
177
|
+
square,
|
|
178
|
+
)
|
|
179
|
+
from .functions.implementations.tangent_functions import tangent # noqa: F401
|
|
180
|
+
from .functions.implementations.scalar_functions import ( # noqa: F401
|
|
181
|
+
acos,
|
|
182
|
+
asin,
|
|
183
|
+
atan,
|
|
184
|
+
atan2,
|
|
185
|
+
ceil,
|
|
186
|
+
cos,
|
|
187
|
+
deg2rad,
|
|
188
|
+
floor,
|
|
189
|
+
log10,
|
|
190
|
+
max_,
|
|
191
|
+
min_,
|
|
192
|
+
mod,
|
|
193
|
+
rad2deg,
|
|
194
|
+
reciprocal,
|
|
195
|
+
relu,
|
|
196
|
+
round_,
|
|
197
|
+
sigmoid,
|
|
198
|
+
sign,
|
|
199
|
+
sin,
|
|
200
|
+
tan,
|
|
201
|
+
tanh,
|
|
202
|
+
x_coord,
|
|
203
|
+
y_coord,
|
|
204
|
+
)
|
|
205
|
+
from .functions.implementations.complex_functions import ( # noqa: F401
|
|
206
|
+
arg,
|
|
207
|
+
complex_,
|
|
208
|
+
conj,
|
|
209
|
+
fft,
|
|
210
|
+
ifft,
|
|
211
|
+
imag,
|
|
212
|
+
real,
|
|
213
|
+
)
|
|
214
|
+
from .functions.implementations.tensor_functions import ( # noqa: F401
|
|
215
|
+
arange,
|
|
216
|
+
circular_arange,
|
|
217
|
+
cumsum,
|
|
218
|
+
linspace,
|
|
219
|
+
ones,
|
|
220
|
+
ones_like,
|
|
221
|
+
reduce_max,
|
|
222
|
+
reduce_mean,
|
|
223
|
+
reduce_min,
|
|
224
|
+
reduce_std,
|
|
225
|
+
reduce_sum,
|
|
226
|
+
reduce_var,
|
|
227
|
+
reshape,
|
|
228
|
+
softmax,
|
|
229
|
+
zeros,
|
|
230
|
+
zeros_like,
|
|
231
|
+
)
|
|
232
|
+
from .functions.implementations.array import array, get_array_element # noqa: F401
|
|
233
|
+
from .functions.implementations.translation_functions import ( # noqa: F401
|
|
234
|
+
animate,
|
|
235
|
+
translate,
|
|
236
|
+
translate_array,
|
|
237
|
+
)
|
|
238
|
+
from .functions.implementations.rotation_functions import rotate # noqa: F401
|
|
239
|
+
from .functions.implementations.autograd_functions import ( # noqa: F401
|
|
240
|
+
backprop,
|
|
241
|
+
gradient_descent_step,
|
|
242
|
+
minimize,
|
|
243
|
+
param,
|
|
244
|
+
partial,
|
|
245
|
+
reevaluate,
|
|
246
|
+
vector_field,
|
|
247
|
+
zero_grad,
|
|
248
|
+
)
|
|
249
|
+
from .functions.implementations.boolean_functions import ( # noqa: F401
|
|
250
|
+
and_,
|
|
251
|
+
bin_to_dec_ones_complement,
|
|
252
|
+
bin_to_dec_twos_complement,
|
|
253
|
+
bin_to_dec_unsigned,
|
|
254
|
+
bool_,
|
|
255
|
+
eq,
|
|
256
|
+
filter_,
|
|
257
|
+
fp_to_bin,
|
|
258
|
+
ge,
|
|
259
|
+
gt,
|
|
260
|
+
int_to_bin,
|
|
261
|
+
le,
|
|
262
|
+
lt,
|
|
263
|
+
not_,
|
|
264
|
+
or_,
|
|
265
|
+
uint_to_bin,
|
|
266
|
+
xor,
|
|
267
|
+
)
|
|
268
|
+
from .functions.implementations.special_functions import ( # noqa: F401
|
|
269
|
+
clear,
|
|
270
|
+
copy,
|
|
271
|
+
help_,
|
|
272
|
+
hide,
|
|
273
|
+
highlight,
|
|
274
|
+
remove,
|
|
275
|
+
set_fill,
|
|
276
|
+
set_stroke,
|
|
277
|
+
show,
|
|
278
|
+
)
|
|
279
|
+
from .functions.implementations.ode_functions import ( # noqa: F401
|
|
280
|
+
eval_ode,
|
|
281
|
+
flow,
|
|
282
|
+
simulate_sde,
|
|
283
|
+
solve_ode,
|
|
284
|
+
)
|
|
285
|
+
from .functions.implementations.annotation_functions import ( # noqa: F401
|
|
286
|
+
annotate_angle_mark,
|
|
287
|
+
annotate_arrow,
|
|
288
|
+
annotate_curly_bracket,
|
|
289
|
+
annotate_curved_arrow,
|
|
290
|
+
annotate_dim_line,
|
|
291
|
+
annotate_leader_line,
|
|
292
|
+
annotate_pin,
|
|
293
|
+
annotate_text_box,
|
|
294
|
+
)
|
|
295
|
+
from .functions.overloads import ( # noqa: F401
|
|
296
|
+
abs_,
|
|
297
|
+
add,
|
|
298
|
+
div,
|
|
299
|
+
exp,
|
|
300
|
+
log,
|
|
301
|
+
mul,
|
|
302
|
+
neg,
|
|
303
|
+
pow_,
|
|
304
|
+
sqrt,
|
|
305
|
+
sub,
|
|
306
|
+
)
|
|
307
|
+
|
|
308
|
+
# The builtin macros (public/geomatic/macros/geometry.json, shipped as
|
|
309
|
+
# pygeomatic/macros.json) are auto-loaded like the interactive editor does —
|
|
310
|
+
# after everything above, so builtin-keyword collisions are detectable and
|
|
311
|
+
# existing gm attributes (gm.load_colors) are never clobbered.
|
|
312
|
+
load_builtin_macros()
|
|
313
|
+
|
|
314
|
+
# id → hex of the load-colors macro, derived (not hardcoded) from the macro
|
|
315
|
+
# body — hence built only after the builtin macros are registered.
|
|
316
|
+
PALETTE: dict[str, str] = build_palette()
|