acps-math-visualizer 1.0.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.
@@ -0,0 +1,160 @@
1
+ """Headless PNG, CSV, and GIF rendering for numerical function products."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import csv
6
+ import math
7
+ from collections.abc import Sequence
8
+ from pathlib import Path
9
+
10
+ import matplotlib
11
+
12
+ matplotlib.use("Agg")
13
+
14
+ import matplotlib.pyplot as plt
15
+ import numpy as np
16
+ from matplotlib.animation import FuncAnimation, PillowWriter
17
+ from matplotlib.axes import Axes
18
+ from matplotlib.lines import Line2D
19
+
20
+ from .math_engine import SampledFunction
21
+ from .models import AnimationFrame
22
+
23
+
24
+ def render_static_plot(sample: SampledFunction, path: Path) -> None:
25
+ """Render a static curve without opening a desktop window."""
26
+
27
+ figure, axis = plt.subplots(figsize=(9, 5), dpi=140)
28
+ try:
29
+ axis.plot(sample.x, sample.y, color="#2563eb", linewidth=2.4, label="target function")
30
+ _style_axis(axis, sample.x)
31
+ finite_y = sample.y[np.isfinite(sample.y)]
32
+ _set_y_limits(axis, [float(np.min(finite_y)), float(np.max(finite_y))])
33
+ axis.set_title(f"Function Plot | y = {sample.normalized_expression}")
34
+ axis.legend(loc="upper right")
35
+ figure.tight_layout()
36
+ figure.savefig(path, bbox_inches="tight", metadata={"Software": "acps-math-visualizer"})
37
+ finally:
38
+ plt.close(figure)
39
+
40
+
41
+ def write_points_csv(sample: SampledFunction, path: Path) -> None:
42
+ """Write every numerical sample, preserving undefined points as blank cells."""
43
+
44
+ with path.open("w", encoding="utf-8", newline="") as stream:
45
+ writer = csv.writer(stream)
46
+ writer.writerow(["x", "y"])
47
+ for x_value, y_value in zip(sample.x, sample.y, strict=True):
48
+ writer.writerow(
49
+ [
50
+ f"{float(x_value):.12g}",
51
+ f"{float(y_value):.12g}" if math.isfinite(float(y_value)) else "",
52
+ ]
53
+ )
54
+
55
+
56
+ def render_transformation_gif(
57
+ sample: SampledFunction,
58
+ *,
59
+ trig_function: str,
60
+ frames: Sequence[AnimationFrame],
61
+ path: Path,
62
+ ) -> int:
63
+ """Interpolate mathematical keyframes and encode a self-contained GIF."""
64
+
65
+ interpolated = _interpolate_frames(frames)
66
+ curves = [_frame_values(sample.x, trig_function, frame) for frame in interpolated]
67
+ finite_values = np.concatenate([values[np.isfinite(values)] for values in curves])
68
+ if finite_values.size == 0:
69
+ raise ValueError("animation plan produced no finite values")
70
+
71
+ figure, axis = plt.subplots(figsize=(8, 4.8), dpi=110)
72
+ try:
73
+ (line,) = axis.plot([], [], color="#7c3aed", linewidth=2.5)
74
+ axis.axhline(0, color="#64748b", linewidth=0.8)
75
+ axis.axvline(0, color="#64748b", linewidth=0.8)
76
+ axis.set_xlim(float(sample.x[0]), float(sample.x[-1]))
77
+ _set_y_limits(axis, [float(np.min(finite_values)), float(np.max(finite_values))])
78
+ axis.grid(True, linestyle="--", alpha=0.3)
79
+ axis.set_xlabel("x")
80
+ axis.set_ylabel("y")
81
+
82
+ def update(frame_index: int) -> tuple[Line2D, ...]:
83
+ frame = interpolated[frame_index]
84
+ line.set_data(sample.x, curves[frame_index])
85
+ axis.set_title(
86
+ f"Transformation Lab | {frame.stage.replace('_', ' ').title()} "
87
+ f"({frame_index + 1}/{len(interpolated)})"
88
+ )
89
+ return (line,)
90
+
91
+ animation = FuncAnimation(
92
+ figure,
93
+ update,
94
+ frames=len(interpolated),
95
+ interval=110,
96
+ blit=False,
97
+ repeat=True,
98
+ cache_frame_data=False,
99
+ )
100
+ animation.save(path, writer=PillowWriter(fps=9))
101
+ finally:
102
+ plt.close(figure)
103
+ return len(interpolated)
104
+
105
+
106
+ def _style_axis(axis: Axes, x_values: np.ndarray) -> None:
107
+ axis.axhline(0, color="#64748b", linewidth=0.8)
108
+ axis.axvline(0, color="#64748b", linewidth=0.8)
109
+ axis.set_xlim(float(x_values[0]), float(x_values[-1]))
110
+ axis.set_xlabel("x")
111
+ axis.set_ylabel("y")
112
+ axis.grid(True, linestyle="--", alpha=0.3)
113
+
114
+
115
+ def _set_y_limits(axis: Axes, limits: list[float]) -> None:
116
+ lower, upper = limits
117
+ if math.isclose(lower, upper):
118
+ padding = max(1.0, abs(lower) * 0.1)
119
+ else:
120
+ padding = (upper - lower) * 0.12
121
+ axis.set_ylim(lower - padding, upper + padding)
122
+
123
+
124
+ def _interpolate_frames(frames: Sequence[AnimationFrame]) -> list[AnimationFrame]:
125
+ if len(frames) < 2:
126
+ raise ValueError("at least two animation keyframes are required")
127
+ result: list[AnimationFrame] = []
128
+ steps_per_transition = 12
129
+ for index in range(len(frames) - 1):
130
+ start = frames[index]
131
+ end = frames[index + 1]
132
+ for step in range(steps_per_transition):
133
+ amount = step / steps_per_transition
134
+ result.append(_blend_frames(start, end, amount))
135
+ result.append(frames[-1])
136
+ return result
137
+
138
+
139
+ def _blend_frames(start: AnimationFrame, end: AnimationFrame, amount: float) -> AnimationFrame:
140
+ def blend(name: str) -> float:
141
+ return float(getattr(start, name) + amount * (getattr(end, name) - getattr(start, name)))
142
+
143
+ return AnimationFrame(
144
+ stage=end.stage,
145
+ label=end.label,
146
+ detail=end.detail,
147
+ a=blend("a"),
148
+ b=blend("b"),
149
+ c=blend("c"),
150
+ d=blend("d"),
151
+ )
152
+
153
+
154
+ def _frame_values(x_values: np.ndarray, trig_function: str, frame: AnimationFrame) -> np.ndarray:
155
+ function = np.sin if trig_function == "sin" else np.cos
156
+ with np.errstate(all="ignore"):
157
+ return frame.a * function(frame.b * x_values + frame.c) + frame.d
158
+
159
+
160
+ __all__ = ["render_static_plot", "render_transformation_gif", "write_points_csv"]
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.4
2
+ Name: acps-math-visualizer
3
+ Version: 1.0.0
4
+ Summary: An ACPs multi-agent studio that turns abstract formulas into inspectable motion for secondary-school functions and university calculus. A Plotter Agent builds curves, data and animations; a Transformation Agent explains amplitude, period and phase; an Intuition Agent supplies memorable analogies. Built on acps-sdk 2.1.0 with ADP discovery, AIP v2 task routing, typed products and auditable traces for teaching, tutoring and self-study.
5
+ Author: ACPs Math Visualizer Engineering
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://pypi.org/project/acps-math-visualizer/
8
+ Keywords: acps,acps-sdk,multi-agent,mathematics,visualization,trigonometry,calculus,education
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Education
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Education
20
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
21
+ Classifier: Topic :: Scientific/Engineering :: Visualization
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/plain
25
+ Requires-Dist: acps-sdk==2.1.0
26
+ Requires-Dist: fastapi>=0.100.0
27
+ Requires-Dist: httpx>=0.25.0
28
+ Requires-Dist: matplotlib>=3.8.0
29
+ Requires-Dist: numpy>=1.26.0
30
+ Requires-Dist: pillow>=10.0.0
31
+ Requires-Dist: pydantic>=2.0.0
32
+ Requires-Dist: uvicorn>=0.27.0
33
+ Provides-Extra: dev
34
+ Requires-Dist: build>=1.0.0; extra == "dev"
35
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
36
+ Requires-Dist: ruff>=0.6.0; extra == "dev"
37
+ Requires-Dist: twine>=5.0.0; extra == "dev"
38
+
39
+ ACPs Math Visualizer coordinates Plotter, Transformation and Intuition agents through acps-sdk 2.1.0 to turn mathematical expressions into plots, transformation animations, data exports and accessible explanations.
@@ -0,0 +1,24 @@
1
+ acps_math_visualizer/__init__.py,sha256=2KSnuN8lY84-i1WclZ8o4WLqOTALsVl3-ouhQ6QW_Xc,118
2
+ acps_math_visualizer/__main__.py,sha256=JrClrDxKPuAwWR7yX8TnA80uKqPltFjzbOCNsTIBY54,107
3
+ acps_math_visualizer/cli.py,sha256=0DentUsRvCCkLhiUXPhDu4z53zdB4MZYCwndRVR0BcQ,2701
4
+ acps_math_visualizer/demo.py,sha256=xklBx6GnU31tGzRk6rSwmlFakahI40ekpQX87vYLBW4,4663
5
+ acps_math_visualizer/identity.py,sha256=0x13ub5RV8as6zGYkQjwdjtlcbLtn3F88EaqmWWTAGo,2023
6
+ acps_math_visualizer/math_engine.py,sha256=qof_fLsXyeEhi6WVd1dBFytuHRgaehN4xc2CgafjV8Q,11691
7
+ acps_math_visualizer/mesh.py,sha256=Yu7za4ooniovm4d2CTbJ9LJCplaxGUZkj04Me8aIB3o,1636
8
+ acps_math_visualizer/models.py,sha256=gCvptSMgjV3MvElSfS_Pw9unQuukUfkqXeU_syo5aug,5957
9
+ acps_math_visualizer/orchestrator.py,sha256=N_QmEVl64RqkW1QWNVNMEmKAYExom6gbQN-Hh3vjhL8,10318
10
+ acps_math_visualizer/protocol.py,sha256=AN9qxdcSJylNZC7nGnUzjLTlD2ee2QGNF9AuYHVUxfg,2053
11
+ acps_math_visualizer/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
+ acps_math_visualizer/registry.py,sha256=gmDFhsdc4GIE6zzk777YGU0g1uVx2etGZUyRWDfG6Rw,3145
13
+ acps_math_visualizer/runtime.py,sha256=_l8RCDXXvxF2jUbjluvFP_tILj2XcZInxmFfiWPH9CU,5425
14
+ acps_math_visualizer/visualization.py,sha256=eWckP8qIuJMUdWQiJ8li5V03cdl4BJj5atsJwMC0UWc,5560
15
+ acps_math_visualizer/agents/__init__.py,sha256=Asp_BamR3zKFjuSp-Viw2TB6LisN6VFIfVqmc1Y4Li0,235
16
+ acps_math_visualizer/agents/base.py,sha256=ewwAZ03XbzXdr2xwGCtQKEw8l58VU0B5Msy_wOPjPsI,4572
17
+ acps_math_visualizer/agents/intuition.py,sha256=p9WYWT0j4ByndD3AZmqWHgW8lz_BqPypk1aJrl09Vgg,7096
18
+ acps_math_visualizer/agents/plotter.py,sha256=5xnpA9-Ibxx9xBNB27zwB-xpcQbyWe2Rpc7p1rPwi7M,6208
19
+ acps_math_visualizer/agents/transformation.py,sha256=kg7hshX61ZZOwubjUnY3so42NmrjRG7lkMMCaQnezAk,9119
20
+ acps_math_visualizer-1.0.0.dist-info/METADATA,sha256=CFTeGvTHzzT0ElLjjaHa-Wu7ZZIEttFvU4wSX8leixs,2181
21
+ acps_math_visualizer-1.0.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
22
+ acps_math_visualizer-1.0.0.dist-info/entry_points.txt,sha256=rEvRKrcWLJTZwqNewA4FgZfGsJI7CLDuhgeoUpXMsS8,64
23
+ acps_math_visualizer-1.0.0.dist-info/top_level.txt,sha256=Ky18yBQJZlZTsWrKZpOA63gFFODHaMpxsHgFOVds1Ds,21
24
+ acps_math_visualizer-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ acps-math-viz = acps_math_visualizer.cli:main
@@ -0,0 +1 @@
1
+ acps_math_visualizer