origami-engine-mjx 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.
- origami_engine_mjx-0.1.0/LICENSE +201 -0
- origami_engine_mjx-0.1.0/MANIFEST.in +10 -0
- origami_engine_mjx-0.1.0/PKG-INFO +156 -0
- origami_engine_mjx-0.1.0/README.md +114 -0
- origami_engine_mjx-0.1.0/docs/API_REFERENCE.md +176 -0
- origami_engine_mjx-0.1.0/docs/ARCHITECTURE.md +42 -0
- origami_engine_mjx-0.1.0/docs/BACKENDS.md +36 -0
- origami_engine_mjx-0.1.0/docs/COLAB_GPU.md +37 -0
- origami_engine_mjx-0.1.0/docs/CONTRIBUTING.md +95 -0
- origami_engine_mjx-0.1.0/docs/CREASE_FORMAT.md +155 -0
- origami_engine_mjx-0.1.0/docs/EVALUATION.md +106 -0
- origami_engine_mjx-0.1.0/docs/GETTING_STARTED.md +204 -0
- origami_engine_mjx-0.1.0/docs/GLOSSARY.md +42 -0
- origami_engine_mjx-0.1.0/docs/MIGRATION.md +38 -0
- origami_engine_mjx-0.1.0/docs/SIMULATION.md +130 -0
- origami_engine_mjx-0.1.0/docs/TROUBLESHOOTING.md +76 -0
- origami_engine_mjx-0.1.0/docs/TUTORIALS.md +207 -0
- origami_engine_mjx-0.1.0/docs/crease_pattern_plot.png +0 -0
- origami_engine_mjx-0.1.0/examples/01_evaluate_cpu_jax.py +42 -0
- origami_engine_mjx-0.1.0/examples/01_evaluate_reference.py +27 -0
- origami_engine_mjx-0.1.0/examples/02_evaluate_warp_gpu.py +31 -0
- origami_engine_mjx-0.1.0/examples/02_json_input.py +37 -0
- origami_engine_mjx-0.1.0/examples/03_batch_population.py +50 -0
- origami_engine_mjx-0.1.0/examples/03_inspect_pattern.py +40 -0
- origami_engine_mjx-0.1.0/examples/04_evaluate_population.py +32 -0
- origami_engine_mjx-0.1.0/examples/05_plot_pattern.py +36 -0
- origami_engine_mjx-0.1.0/examples/README.md +45 -0
- origami_engine_mjx-0.1.0/examples/colab_gpu_validation.py +92 -0
- origami_engine_mjx-0.1.0/experiments/TIMELINE.md +76 -0
- origami_engine_mjx-0.1.0/experiments/prototype_notebooks.zip +0 -0
- origami_engine_mjx-0.1.0/origami_engine/crease_patterns/reference_miura_4x4.json +34 -0
- origami_engine_mjx-0.1.0/origami_engine/schemas/crease_pattern.schema.json +51 -0
- origami_engine_mjx-0.1.0/origami_engine_mjx/__init__.py +73 -0
- origami_engine_mjx-0.1.0/origami_engine_mjx/backend.py +69 -0
- origami_engine_mjx-0.1.0/origami_engine_mjx/backends/__init__.py +73 -0
- origami_engine_mjx-0.1.0/origami_engine_mjx/backends/base.py +73 -0
- origami_engine_mjx-0.1.0/origami_engine_mjx/backends/jax_backend.py +217 -0
- origami_engine_mjx-0.1.0/origami_engine_mjx/backends/warp_backend.py +212 -0
- origami_engine_mjx-0.1.0/origami_engine_mjx/constants.py +69 -0
- origami_engine_mjx-0.1.0/origami_engine_mjx/crease_patterns/reference_miura_4x4.json +34 -0
- origami_engine_mjx-0.1.0/origami_engine_mjx/engine.py +172 -0
- origami_engine_mjx-0.1.0/origami_engine_mjx/evaluation.py +87 -0
- origami_engine_mjx-0.1.0/origami_engine_mjx/geometry.py +120 -0
- origami_engine_mjx-0.1.0/origami_engine_mjx/model.py +211 -0
- origami_engine_mjx-0.1.0/origami_engine_mjx/patterns.py +98 -0
- origami_engine_mjx-0.1.0/origami_engine_mjx/plotting.py +122 -0
- origami_engine_mjx-0.1.0/origami_engine_mjx/schemas/crease_pattern.schema.json +51 -0
- origami_engine_mjx-0.1.0/origami_engine_mjx/serialization.py +124 -0
- origami_engine_mjx-0.1.0/origami_engine_mjx/types.py +77 -0
- origami_engine_mjx-0.1.0/origami_engine_mjx.egg-info/PKG-INFO +156 -0
- origami_engine_mjx-0.1.0/origami_engine_mjx.egg-info/SOURCES.txt +57 -0
- origami_engine_mjx-0.1.0/origami_engine_mjx.egg-info/dependency_links.txt +1 -0
- origami_engine_mjx-0.1.0/origami_engine_mjx.egg-info/entry_points.txt +2 -0
- origami_engine_mjx-0.1.0/origami_engine_mjx.egg-info/requires.txt +26 -0
- origami_engine_mjx-0.1.0/origami_engine_mjx.egg-info/top_level.txt +1 -0
- origami_engine_mjx-0.1.0/pyproject.toml +86 -0
- origami_engine_mjx-0.1.0/setup.cfg +4 -0
- origami_engine_mjx-0.1.0/tests/test_evaluation.py +120 -0
- origami_engine_mjx-0.1.0/tests/test_packaging.py +50 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
include origami_engine/schemas/*.json
|
|
2
|
+
include origami_engine/crease_patterns/*.json
|
|
3
|
+
include docs/*.md
|
|
4
|
+
include docs/crease_pattern_plot.png
|
|
5
|
+
include examples/*.py
|
|
6
|
+
include examples/README.md
|
|
7
|
+
include experiments/TIMELINE.md
|
|
8
|
+
include experiments/prototype_notebooks.zip
|
|
9
|
+
include LICENSE
|
|
10
|
+
include README.md
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: origami-engine-mjx
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Dual-backend (MJX-JAX / MJX-Warp) MuJoCo MJX origami folding simulator
|
|
5
|
+
Author-email: ihsan <ihsanmuhammadkhoirul@students.unnes.ac.id>
|
|
6
|
+
Keywords: origami,crease-pattern,mujoco,mjx,jax,warp,folding-simulation,gpu
|
|
7
|
+
Classifier: Development Status :: 3 - Alpha
|
|
8
|
+
Classifier: Intended Audience :: Developers
|
|
9
|
+
Classifier: Intended Audience :: Science/Research
|
|
10
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: jsonschema>=4.18
|
|
21
|
+
Requires-Dist: matplotlib>=3.7
|
|
22
|
+
Requires-Dist: mujoco>=3.0
|
|
23
|
+
Requires-Dist: numpy>=1.24
|
|
24
|
+
Requires-Dist: shapely>=2.0
|
|
25
|
+
Provides-Extra: jax
|
|
26
|
+
Requires-Dist: mujoco-mjx>=3.0; extra == "jax"
|
|
27
|
+
Requires-Dist: jax>=0.4; extra == "jax"
|
|
28
|
+
Provides-Extra: warp
|
|
29
|
+
Requires-Dist: mujoco-warp>=3.0; extra == "warp"
|
|
30
|
+
Requires-Dist: warp-lang>=1.0; extra == "warp"
|
|
31
|
+
Provides-Extra: render
|
|
32
|
+
Requires-Dist: imageio[ffmpeg]>=2.34; extra == "render"
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
36
|
+
Requires-Dist: ruff>=0.9; extra == "dev"
|
|
37
|
+
Requires-Dist: mypy>=1.14; extra == "dev"
|
|
38
|
+
Requires-Dist: pre-commit>=3.8; extra == "dev"
|
|
39
|
+
Provides-Extra: all
|
|
40
|
+
Requires-Dist: origami-engine-mjx[dev,jax,render,warp]; extra == "all"
|
|
41
|
+
Dynamic: license-file
|
|
42
|
+
|
|
43
|
+
# origami-engine-mjx
|
|
44
|
+
|
|
45
|
+
Dual-backend **MuJoCo MJX** origami folding simulator — a migration of `origami-engine` from the classic MuJoCo C++ runtime to MJX, with two interchangeable backends in one package:
|
|
46
|
+
|
|
47
|
+
| Backend | Flag | Engine | Hardware | Best for |
|
|
48
|
+
|---|---|---|---|---|
|
|
49
|
+
| **MJX-JAX** | `backend="jax"` | `mujoco.mjx` on JAX/XLA | CPU (local dev), NVIDIA GPU, TPU (Colab) | Differentiable simulation, `jax.jit` / `jax.vmap` / `jax.lax.scan`, CPU testing |
|
|
50
|
+
| **MJX-Warp** | `backend="warp"` | `mujoco.warp` on NVIDIA Warp | NVIDIA CUDA GPU only (Colab T4) | High-throughput batched population evaluation |
|
|
51
|
+
|
|
52
|
+
The crease-pattern parsing, geometry reconstruction, and MJCF model generation are **shared** between backends — only the simulation execution differs.
|
|
53
|
+
|
|
54
|
+
## Install
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# Core (geometry, patterns, XML generation — no GPU needed)
|
|
58
|
+
pip install origami-engine-mjx
|
|
59
|
+
|
|
60
|
+
# + MJX-JAX backend (CPU works out of the box)
|
|
61
|
+
pip install 'origami-engine-mjx[jax]'
|
|
62
|
+
|
|
63
|
+
# + MJX-Warp backend (requires NVIDIA CUDA GPU)
|
|
64
|
+
pip install 'origami-engine-mjx[warp]'
|
|
65
|
+
|
|
66
|
+
# Everything
|
|
67
|
+
pip install 'origami-engine-mjx[all]'
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Quick start
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from origami_engine_mjx import OrigamiEngine, load_default_creases
|
|
74
|
+
|
|
75
|
+
# CPU (local dev) — MJX-JAX
|
|
76
|
+
engine = OrigamiEngine(backend="jax")
|
|
77
|
+
creases = load_default_creases()
|
|
78
|
+
|
|
79
|
+
# Single simulation -> forward displacement (m)
|
|
80
|
+
score = engine.evaluate(creases, duration=2.0)
|
|
81
|
+
print(f"forward displacement: {score:.4f} m")
|
|
82
|
+
|
|
83
|
+
# Batch population evaluation
|
|
84
|
+
population = [creases, creases, creases] # replace with your genomes
|
|
85
|
+
result = engine.evaluate_population(population, duration=2.0)
|
|
86
|
+
print(result.scores)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
On Google Colab with an NVIDIA T4:
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
engine = OrigamiEngine(backend="warp") # CUDA GPU via MuJoCo Warp
|
|
93
|
+
result = engine.evaluate_population(population, duration=8.0, batch_size=128)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`backend="auto"` picks `warp` if a CUDA GPU is available, otherwise `jax`.
|
|
97
|
+
|
|
98
|
+
## Architecture
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
origami_engine_mjx/
|
|
102
|
+
├── __init__.py # public API: OrigamiEngine, Crease, build_pattern, ...
|
|
103
|
+
├── constants.py # physical / solver constants (shared)
|
|
104
|
+
├── types.py # Crease, Pattern, SimulationResult, PopulationResult
|
|
105
|
+
├── geometry.py # crease graph -> faces -> spanning tree (shared, Shapely)
|
|
106
|
+
├── model.py # generate_xml(): Pattern -> MJCF XML (shared, no MuJoCo needed)
|
|
107
|
+
├── serialization.py # JSON crease I/O (shared)
|
|
108
|
+
├── patterns.py # reference Miura patterns (shared)
|
|
109
|
+
├── plotting.py # crease-pattern plots (shared)
|
|
110
|
+
├── backend.py # lazy import guards for mujoco / mjx-jax / mjx-warp
|
|
111
|
+
├── engine.py # OrigamiEngine — public facade, backend selection
|
|
112
|
+
├── evaluation.py # evaluate_individual / evaluate_population
|
|
113
|
+
├── backends/
|
|
114
|
+
│ ├── base.py # SimulationBackend ABC
|
|
115
|
+
│ ├── __init__.py # registry + get_backend(name)
|
|
116
|
+
│ ├── jax_backend.py # MJX-JAX: put_model / make_data / mjx.step, jit option
|
|
117
|
+
│ └── warp_backend.py # MJX-Warp: mjw.make_model / make_data / mjw.step (GPU)
|
|
118
|
+
├── schemas/ # JSON schema for crease files
|
|
119
|
+
└── crease_patterns/ # reference_miura_4x4.json
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for details, [docs/BACKENDS.md](docs/BACKENDS.md) for a backend comparison, and [docs/COLAB_GPU.md](docs/COLAB_GPU.md) for GPU validation.
|
|
123
|
+
|
|
124
|
+
## Performance notes
|
|
125
|
+
|
|
126
|
+
- **MJX-JAX on CPU is slow for mesh-contact models**: the 16-face reference Miura model costs ~70 s/step on CPU (mesh–mesh collision in XLA). Tiny models run at ~1.4 s/step. Use CPU only for correctness tests with short durations; use GPU for real workloads.
|
|
127
|
+
- **JIT compilation of `mjx.step` is expensive** for this model; the JAX backend runs eager by default (`jit=False`).
|
|
128
|
+
- On a Colab T4 GPU, both backends should be dramatically faster — see `examples/colab_gpu_validation.py` and benchmark in `docs/COLAB_GPU.md`.
|
|
129
|
+
|
|
130
|
+
## Examples
|
|
131
|
+
|
|
132
|
+
| Script | Demonstrates |
|
|
133
|
+
|---|---|
|
|
134
|
+
| `examples/01_evaluate_cpu_jax.py` | Single sim + population on CPU (MJX-JAX) |
|
|
135
|
+
| `examples/02_evaluate_warp_gpu.py` | MJX-Warp on NVIDIA GPU |
|
|
136
|
+
| `examples/03_batch_population.py` | Batch population evaluation with configurable batch size |
|
|
137
|
+
| `examples/colab_gpu_validation.py` | Full GPU validation + benchmark script for Colab T4 |
|
|
138
|
+
|
|
139
|
+
## Tests
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
pip install -e '.[dev,jax]'
|
|
143
|
+
pytest tests_mjx -q # fast tests (no long sims)
|
|
144
|
+
pytest tests_mjx -q -m slow # includes short MJX-CPU simulations
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Docs
|
|
148
|
+
|
|
149
|
+
- [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) — package layout, data flow, backend responsibilities
|
|
150
|
+
- [docs/BACKENDS.md](docs/BACKENDS.md) — MJX-JAX vs MJX-Warp: semantics, features, limitations
|
|
151
|
+
- [docs/COLAB_GPU.md](docs/COLAB_GPU.md) — Colab T4 setup, validation checklist, benchmarking
|
|
152
|
+
- [docs/MIGRATION.md](docs/MIGRATION.md) — migrating from `origami-engine` (classic MuJoCo)
|
|
153
|
+
|
|
154
|
+
## License
|
|
155
|
+
|
|
156
|
+
Apache-2.0
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# origami-engine-mjx
|
|
2
|
+
|
|
3
|
+
Dual-backend **MuJoCo MJX** origami folding simulator — a migration of `origami-engine` from the classic MuJoCo C++ runtime to MJX, with two interchangeable backends in one package:
|
|
4
|
+
|
|
5
|
+
| Backend | Flag | Engine | Hardware | Best for |
|
|
6
|
+
|---|---|---|---|---|
|
|
7
|
+
| **MJX-JAX** | `backend="jax"` | `mujoco.mjx` on JAX/XLA | CPU (local dev), NVIDIA GPU, TPU (Colab) | Differentiable simulation, `jax.jit` / `jax.vmap` / `jax.lax.scan`, CPU testing |
|
|
8
|
+
| **MJX-Warp** | `backend="warp"` | `mujoco.warp` on NVIDIA Warp | NVIDIA CUDA GPU only (Colab T4) | High-throughput batched population evaluation |
|
|
9
|
+
|
|
10
|
+
The crease-pattern parsing, geometry reconstruction, and MJCF model generation are **shared** between backends — only the simulation execution differs.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# Core (geometry, patterns, XML generation — no GPU needed)
|
|
16
|
+
pip install origami-engine-mjx
|
|
17
|
+
|
|
18
|
+
# + MJX-JAX backend (CPU works out of the box)
|
|
19
|
+
pip install 'origami-engine-mjx[jax]'
|
|
20
|
+
|
|
21
|
+
# + MJX-Warp backend (requires NVIDIA CUDA GPU)
|
|
22
|
+
pip install 'origami-engine-mjx[warp]'
|
|
23
|
+
|
|
24
|
+
# Everything
|
|
25
|
+
pip install 'origami-engine-mjx[all]'
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick start
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from origami_engine_mjx import OrigamiEngine, load_default_creases
|
|
32
|
+
|
|
33
|
+
# CPU (local dev) — MJX-JAX
|
|
34
|
+
engine = OrigamiEngine(backend="jax")
|
|
35
|
+
creases = load_default_creases()
|
|
36
|
+
|
|
37
|
+
# Single simulation -> forward displacement (m)
|
|
38
|
+
score = engine.evaluate(creases, duration=2.0)
|
|
39
|
+
print(f"forward displacement: {score:.4f} m")
|
|
40
|
+
|
|
41
|
+
# Batch population evaluation
|
|
42
|
+
population = [creases, creases, creases] # replace with your genomes
|
|
43
|
+
result = engine.evaluate_population(population, duration=2.0)
|
|
44
|
+
print(result.scores)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
On Google Colab with an NVIDIA T4:
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
engine = OrigamiEngine(backend="warp") # CUDA GPU via MuJoCo Warp
|
|
51
|
+
result = engine.evaluate_population(population, duration=8.0, batch_size=128)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`backend="auto"` picks `warp` if a CUDA GPU is available, otherwise `jax`.
|
|
55
|
+
|
|
56
|
+
## Architecture
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
origami_engine_mjx/
|
|
60
|
+
├── __init__.py # public API: OrigamiEngine, Crease, build_pattern, ...
|
|
61
|
+
├── constants.py # physical / solver constants (shared)
|
|
62
|
+
├── types.py # Crease, Pattern, SimulationResult, PopulationResult
|
|
63
|
+
├── geometry.py # crease graph -> faces -> spanning tree (shared, Shapely)
|
|
64
|
+
├── model.py # generate_xml(): Pattern -> MJCF XML (shared, no MuJoCo needed)
|
|
65
|
+
├── serialization.py # JSON crease I/O (shared)
|
|
66
|
+
├── patterns.py # reference Miura patterns (shared)
|
|
67
|
+
├── plotting.py # crease-pattern plots (shared)
|
|
68
|
+
├── backend.py # lazy import guards for mujoco / mjx-jax / mjx-warp
|
|
69
|
+
├── engine.py # OrigamiEngine — public facade, backend selection
|
|
70
|
+
├── evaluation.py # evaluate_individual / evaluate_population
|
|
71
|
+
├── backends/
|
|
72
|
+
│ ├── base.py # SimulationBackend ABC
|
|
73
|
+
│ ├── __init__.py # registry + get_backend(name)
|
|
74
|
+
│ ├── jax_backend.py # MJX-JAX: put_model / make_data / mjx.step, jit option
|
|
75
|
+
│ └── warp_backend.py # MJX-Warp: mjw.make_model / make_data / mjw.step (GPU)
|
|
76
|
+
├── schemas/ # JSON schema for crease files
|
|
77
|
+
└── crease_patterns/ # reference_miura_4x4.json
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for details, [docs/BACKENDS.md](docs/BACKENDS.md) for a backend comparison, and [docs/COLAB_GPU.md](docs/COLAB_GPU.md) for GPU validation.
|
|
81
|
+
|
|
82
|
+
## Performance notes
|
|
83
|
+
|
|
84
|
+
- **MJX-JAX on CPU is slow for mesh-contact models**: the 16-face reference Miura model costs ~70 s/step on CPU (mesh–mesh collision in XLA). Tiny models run at ~1.4 s/step. Use CPU only for correctness tests with short durations; use GPU for real workloads.
|
|
85
|
+
- **JIT compilation of `mjx.step` is expensive** for this model; the JAX backend runs eager by default (`jit=False`).
|
|
86
|
+
- On a Colab T4 GPU, both backends should be dramatically faster — see `examples/colab_gpu_validation.py` and benchmark in `docs/COLAB_GPU.md`.
|
|
87
|
+
|
|
88
|
+
## Examples
|
|
89
|
+
|
|
90
|
+
| Script | Demonstrates |
|
|
91
|
+
|---|---|
|
|
92
|
+
| `examples/01_evaluate_cpu_jax.py` | Single sim + population on CPU (MJX-JAX) |
|
|
93
|
+
| `examples/02_evaluate_warp_gpu.py` | MJX-Warp on NVIDIA GPU |
|
|
94
|
+
| `examples/03_batch_population.py` | Batch population evaluation with configurable batch size |
|
|
95
|
+
| `examples/colab_gpu_validation.py` | Full GPU validation + benchmark script for Colab T4 |
|
|
96
|
+
|
|
97
|
+
## Tests
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
pip install -e '.[dev,jax]'
|
|
101
|
+
pytest tests_mjx -q # fast tests (no long sims)
|
|
102
|
+
pytest tests_mjx -q -m slow # includes short MJX-CPU simulations
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Docs
|
|
106
|
+
|
|
107
|
+
- [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) — package layout, data flow, backend responsibilities
|
|
108
|
+
- [docs/BACKENDS.md](docs/BACKENDS.md) — MJX-JAX vs MJX-Warp: semantics, features, limitations
|
|
109
|
+
- [docs/COLAB_GPU.md](docs/COLAB_GPU.md) — Colab T4 setup, validation checklist, benchmarking
|
|
110
|
+
- [docs/MIGRATION.md](docs/MIGRATION.md) — migrating from `origami-engine` (classic MuJoCo)
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
Apache-2.0
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# API Reference
|
|
2
|
+
|
|
3
|
+
> **Documentation map:** [README](../README.md) · [Getting Started](GETTING_STARTED.md) · [Tutorials](TUTORIALS.md) · [Crease Format](CREASE_FORMAT.md) · [Simulation](SIMULATION.md) · [Evaluation](EVALUATION.md) · **API Reference** · [Architecture](ARCHITECTURE.md) · [Troubleshooting](TROUBLESHOOTING.md) · [Glossary](GLOSSARY.md) · [Contributing](CONTRIBUTING.md)
|
|
4
|
+
|
|
5
|
+
Complete reference for the public API of `origami_engine` (version `0.1.1`). All names below are importable from the package root:
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
import origami_engine
|
|
9
|
+
|
|
10
|
+
origami_engine.__all__ # full export list
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Import paths
|
|
14
|
+
|
|
15
|
+
| Import style | Example | Notes |
|
|
16
|
+
|---|---|---|
|
|
17
|
+
| Package root (recommended) | `from origami_engine import Crease, run_simulation` | Stable public surface |
|
|
18
|
+
| Focused module | `from origami_engine.dynamics import run_simulation` | Fine for new code |
|
|
19
|
+
| Legacy facade | `from origami_engine.simulation import Crease, ...` | Backward-compatible re-exports (also re-exports all constants) |
|
|
20
|
+
|
|
21
|
+
**MuJoCo import guard** (`origami_engine/backend.py`): the `mujoco` import is guarded. Geometry, serialization, plotting, and constants work without MuJoCo installed; `generate_xml`, `run_simulation`, `drive_table`, `paper_centroid`, and `render_individual` call `require_mujoco(...)`, which raises a helpful `RuntimeError` if `mujoco` is missing.
|
|
22
|
+
|
|
23
|
+
## Domain types (`origami_engine.types`)
|
|
24
|
+
|
|
25
|
+
### `Crease` — frozen dataclass
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
Crease(p1: tuple[float, float], p2: tuple[float, float], angle: float)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
A single crease segment. `p1`/`p2` are 2D points in sheet coordinates (`0..S`, `S=1.0`); `angle` is the signed target fold angle in **radians** — negative = mountain, positive = valley.
|
|
32
|
+
|
|
33
|
+
### `Pattern` — dataclass
|
|
34
|
+
|
|
35
|
+
Returned by `build_pattern`. Fields: `valid: bool`, `reason: str`, `faces: list | None` (Shapely polygons), `edges: list[dict] | None` (each `{"i", "j", "p", "q", "crease"}`), `root: int`, `parent: dict`, `depth: dict`, `tree_edge: dict`, `loop_edges: list[int] | None`, `n_faces: int`, `n_loops: int`. See [CREASE_FORMAT.md](CREASE_FORMAT.md).
|
|
36
|
+
|
|
37
|
+
### `SimulationResult` — dataclass
|
|
38
|
+
|
|
39
|
+
Returned by `run_simulation`. Fields: `model` (`mujoco.MjModel`), `data` (`mujoco.MjData`), `pattern: Pattern`, `info: dict` (`hinges`, `targets`, `n_faces`, `n_hinges`, `n_loops`), `initial_centroid: np.ndarray` (2,), `final_centroid: np.ndarray` (2,).
|
|
40
|
+
|
|
41
|
+
## Pattern construction & I/O
|
|
42
|
+
|
|
43
|
+
### `build_pattern(creases) -> Pattern`
|
|
44
|
+
|
|
45
|
+
(`origami_engine.geometry`) Reconstruct polygonal faces and the spanning-tree hinge graph from a crease list. `creases` may be a `Crease` list, dict list, or JSON path (normalized internally is **not** done here — pass normalized creases or dicts with `p1/p2/angle`; see `normalize_creases`). Pure Shapely — no MuJoCo needed. Validation reasons: `"no faces"`, `"sliver face (area …)"`, `"faces do not tile the sheet"`, `"disconnected faces"`.
|
|
46
|
+
|
|
47
|
+
### `normalize_creases(creases) -> list[Crease]`
|
|
48
|
+
|
|
49
|
+
(`origami_engine.serialization`) Coerce a JSON path, list of `Crease`, or list of dicts into `list[Crease]`. Raises `ValueError` (`None`, empty, missing keys, bad item type) / `TypeError` (non-list input).
|
|
50
|
+
|
|
51
|
+
### `load_creases_from_json(path) -> list[Crease]`
|
|
52
|
+
|
|
53
|
+
Load and **schema-validate** a crease JSON file (both forms documented in [CREASE_FORMAT.md](CREASE_FORMAT.md)). `angle_unit` in `radian|radians|rad|degree|degrees|deg` (default radian; degrees converted via `np.deg2rad`). Raises `ValueError` on schema violation or missing keys (message includes the crease index).
|
|
54
|
+
|
|
55
|
+
### `save_creases_to_json(creases, path, angle_unit="radian") -> Path`
|
|
56
|
+
|
|
57
|
+
Serialize creases to JSON (object form with `angle_unit` + `creases`), creating parent dirs. `angle_unit` must be `"radian"` or `"degree"` (else `ValueError`). Angles are converted to the requested unit.
|
|
58
|
+
|
|
59
|
+
### `CREASE_SCHEMA`
|
|
60
|
+
|
|
61
|
+
The packaged JSON Schema (dict) loaded from `origami_engine/schemas/crease_pattern.schema.json` (shipped as package data). Use with `jsonschema.validate(payload, CREASE_SCHEMA)` in your own tooling.
|
|
62
|
+
|
|
63
|
+
## Reference patterns (`origami_engine.patterns`)
|
|
64
|
+
|
|
65
|
+
| Export | Description |
|
|
66
|
+
|---|---|
|
|
67
|
+
| `DEFAULT_PATTERN_JSON` | `Path` to the packaged `origami_engine/crease_patterns/reference_miura_4x4.json` (shipped in wheel and sdist; falls back to the repo-root `crease_patterns/` copy in odd layouts) |
|
|
68
|
+
| `load_default_creases() -> list[Crease]` | Load `DEFAULT_PATTERN_JSON` (24 creases, 16 faces, 9 loop edges); only if the file is missing, fall back to the embedded `reference_miura_render_creases()` (same topology) |
|
|
69
|
+
| `reference_miura_legacy_creases() -> list[Crease]` | Embedded legacy 4×4 Miura-ori crease list (used by tests/examples) |
|
|
70
|
+
| `reference_miura_render_creases() -> list[Crease]` | Embedded render-tuned Miura-ori crease list (used by the renderer) |
|
|
71
|
+
|
|
72
|
+
## Model generation (`origami_engine.model`)
|
|
73
|
+
|
|
74
|
+
### `generate_xml(pat, creases, name="origami_free", coll_thick=None) -> tuple[str, dict]`
|
|
75
|
+
|
|
76
|
+
Build the MJCF XML string for a validated `Pattern` (see [SIMULATION.md](SIMULATION.md) for the full structure). Parameters: `pat` — `Pattern` from `build_pattern`; `creases` — normalized creases (target angles are looked up by edge index); `name` — model name attribute; `coll_thick` — `None` for single-geom mode, or a thickness value enabling separate visual/collision geoms. Returns `(xml, info)` where `info = {"hinges": [{"name", "face", "edge", "target"}...], "targets": np.ndarray, "n_faces", "n_hinges", "n_loops"}`. Requires MuJoCo (raises `RuntimeError` via `require_mujoco` otherwise).
|
|
77
|
+
|
|
78
|
+
## Simulation (`origami_engine.dynamics`)
|
|
79
|
+
|
|
80
|
+
### `run_simulation(creases, duration=8.0, fold_duration=3.0, vibrate=True, amp_x=VIB_AMP_X, amp_z=VIB_AMP_Z, freq_hz=VIB_FREQ) -> SimulationResult`
|
|
81
|
+
|
|
82
|
+
Full pipeline: normalize → build pattern → generate XML → `MjModel`/`MjData` → step loop with smoothstep actuator ramp (`s = t²(3−2t)`, `ctrl = s·targets`) and optional sinusoidal table vibration → stability check. Raises `ValueError` (`duration <= 0`, invalid pattern) and `FloatingPointError` (non-finite qpos). See [SIMULATION.md](SIMULATION.md).
|
|
83
|
+
|
|
84
|
+
### `drive_table(model, data, t, amp_x=VIB_AMP_X, amp_z=VIB_AMP_Z, freq_hz=VIB_FREQ) -> None`
|
|
85
|
+
|
|
86
|
+
Kinematically vibrate the support table: sets `qpos = amp·sin(2πft)` and `qvel = amp·2πf·cos(2πft)` on the `table_x`/`table_z` slide joints. Defaults `amp_x=0.0`, `amp_z=0.0013`, `freq_hz=75.0`.
|
|
87
|
+
|
|
88
|
+
### `paper_centroid(model, data) -> np.ndarray`
|
|
89
|
+
|
|
90
|
+
Mean XY of `data.geom_xpos` over all geoms whose body is not `table`. Raises `ValueError` if no paper geoms exist.
|
|
91
|
+
|
|
92
|
+
## Evaluation (`origami_engine.evaluation`)
|
|
93
|
+
|
|
94
|
+
### `compute_forward_displacement(sim_result, trajectory=(1.0, 0.0, 0.0)) -> float`
|
|
95
|
+
|
|
96
|
+
`dot(final_centroid − initial_centroid, normalize(trajectory))`. `trajectory`: 2/3-vector direction or `(N,2)/(N,3)` waypoints (N ≥ 2, direction = last − first). Raises `ValueError` on malformed/zero/non-finite input. See [EVALUATION.md](EVALUATION.md).
|
|
97
|
+
|
|
98
|
+
### `evaluate_individual(creases, duration=8.0, trajectory=(1.0, 0.0, 0.0), fold_duration=3.0, vibrate=True, amp_x=VIB_AMP_X, amp_z=VIB_AMP_Z, freq_hz=VIB_FREQ, return_details=False) -> float | dict`
|
|
99
|
+
|
|
100
|
+
Run one simulation and return its forward displacement. With `return_details=True` returns a dict: `displacement`, `initial_centroid`, `final_centroid`, `duration`, `trajectory`, `n_faces`, `n_loops`.
|
|
101
|
+
|
|
102
|
+
### `evaluate_population(individuals, duration=8.0, trajectory=(1.0, 0.0, 0.0), fold_duration=3.0, vibrate=True, amp_x=VIB_AMP_X, amp_z=VIB_AMP_Z, freq_hz=VIB_FREQ, workers=1, error_policy="raise") -> list[float]`
|
|
103
|
+
|
|
104
|
+
Score a list of crease inputs. `workers=1` → sequential; `workers>1` → `ProcessPoolExecutor` (`max_workers = min(workers, len(individuals))`). `error_policy="raise"` wraps failures in `RuntimeError("individual {i} failed ...")`; `"nan"` yields `float("nan")` for failed slots. Order preserved.
|
|
105
|
+
|
|
106
|
+
## Visualization (`origami_engine.plotting`)
|
|
107
|
+
|
|
108
|
+
### `plot_pattern(creases, pat=None) -> None`
|
|
109
|
+
|
|
110
|
+
Matplotlib figure of the flat pattern: sheet rectangle, Mountain = crimson dashed / Valley = royalblue dash-dot, each crease labelled with its angle in degrees, face indices in gray, loop edges as black `x`, legend, equal aspect, title `"{N} creases | {M} faces | {K} loop edges (x)"` (or `"… | INVALID: {reason}"`). Calls `plt.show()`; under the Agg backend grab the figure with `plt.gcf()` and save it (see [TUTORIALS.md](TUTORIALS.md), Tutorial 7).
|
|
111
|
+
|
|
112
|
+
## Rendering script (`origami_engine.render_individual`)
|
|
113
|
+
|
|
114
|
+
Also installed as the **`origami-render`** console command (`[project.scripts]` in `pyproject.toml`).
|
|
115
|
+
|
|
116
|
+
| Function | Signature | Description |
|
|
117
|
+
|---|---|---|
|
|
118
|
+
| `trace_simulation` | `(creases, duration=2.0, fold_duration=3.0, fps=24, trajectory=(1,0,0), vibrate=True, amp_x, amp_z, freq_hz)` | Simulate + capture frames (720×720 `mujoco.Renderer`, camera lookat `[0.5,0.5,0.05]`, distance 2.5, azimuth 90, elevation −30). Returns dict with `frames`, centroids, `forward_displacement`, `model`, `data`, `info`, `pattern` |
|
|
119
|
+
| `export_video` | `(frames, output_path, fps=24) -> bool` | MP4 via imageio/libx264 (`yuv420p`); falls back to `.gif` (returns `False`). `ValueError` if no frames |
|
|
120
|
+
| `main` | `()` | CLI body: default pattern, `duration=20.0`, `fold_duration=1e-6`; writes `individual_simulation.mp4` + `render_report.json` into the **current working directory** and prints the report |
|
|
121
|
+
|
|
122
|
+
## Constants (`origami_engine.constants`)
|
|
123
|
+
|
|
124
|
+
All re-exported from the package root and from `origami_engine.simulation`:
|
|
125
|
+
|
|
126
|
+
| Constant | Value | Meaning |
|
|
127
|
+
|---|---|---|
|
|
128
|
+
| `S` | `1.0` | Sheet side length |
|
|
129
|
+
| `THICK` | `1e-4` | Paper thickness |
|
|
130
|
+
| `PAPER_MASS` | `0.2` | Sheet mass |
|
|
131
|
+
| `Z0` | `THICK + 0.001` | Initial paper z-offset |
|
|
132
|
+
| `MIN_FACE_AREA` | `1e-4 · S²` | Sliver-face rejection threshold |
|
|
133
|
+
| `MAX_FOLD` | `0.98π` | Hinge target clip |
|
|
134
|
+
| `KP` / `KV` | `2.0` / `0.15` | Hinge position-actuator gains |
|
|
135
|
+
| `DAMPING` | `0.003` | Hinge damping |
|
|
136
|
+
| `FORCE_MAX` | `2.0` | Actuator force limit |
|
|
137
|
+
| `MU_PAPER` / `MU_TABLE` | `0.3` / `0.5` | Friction coefficients |
|
|
138
|
+
| `VIB_FREQ` / `VIB_AMP_X` / `VIB_AMP_Z` | `75.0` / `0.0` / `0.0013` | Table vibration defaults |
|
|
139
|
+
| `EQ_SOLREF` / `EQ_SOLIMP` | `"0.005 1"` / `"0.95 0.99 0.001"` | Equality constraint solver params |
|
|
140
|
+
| `STRETCH_K` / `STRETCH_DAMP` / `STRETCH_MAX` | `5e4` / `50` / `1e-4` | Edge stretch spring params |
|
|
141
|
+
| `K_PANEL` / `D_PANEL` | `1e5` / `50` | Panel stiffness/damping |
|
|
142
|
+
| `MAX_STRAIN` / `COLL_THICK` | `0.005` / `1e-5` | Strain cap / thin collision thickness |
|
|
143
|
+
| `M` / `V` | `+π/4` / `−π/4` | Canonical ±45° angles used by the reference pattern builders (note: the `Crease.angle` sign convention is negative=mountain, positive=valley) |
|
|
144
|
+
|
|
145
|
+
## Complete workflow example
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
from origami_engine import (
|
|
149
|
+
build_pattern,
|
|
150
|
+
evaluate_individual,
|
|
151
|
+
load_default_creases,
|
|
152
|
+
plot_pattern,
|
|
153
|
+
run_simulation,
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
creases = load_default_creases() # 24-crease Miura-ori reference
|
|
157
|
+
pat = build_pattern(creases) # validate topology
|
|
158
|
+
assert pat.valid, pat.reason
|
|
159
|
+
|
|
160
|
+
plot_pattern(creases, pat) # visualize the flat pattern
|
|
161
|
+
|
|
162
|
+
result = run_simulation(creases, duration=8.0)
|
|
163
|
+
print(result.info["n_faces"], "faces,", result.info["n_hinges"], "hinges")
|
|
164
|
+
|
|
165
|
+
score = evaluate_individual(creases, duration=8.0, trajectory=(1.0, 0.0, 0.0))
|
|
166
|
+
print(f"forward displacement: {score:.6f} m")
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## See also
|
|
170
|
+
|
|
171
|
+
- [GETTING_STARTED.md](GETTING_STARTED.md) — installation (pip / uv / source) and first run
|
|
172
|
+
- [TUTORIALS.md](TUTORIALS.md) — nine step-by-step recipes
|
|
173
|
+
- [CREASE_FORMAT.md](CREASE_FORMAT.md) — crease & JSON schema reference
|
|
174
|
+
- [SIMULATION.md](SIMULATION.md) — XML model structure, step loop, rendering
|
|
175
|
+
- [EVALUATION.md](EVALUATION.md) — fitness functions and population evaluation
|
|
176
|
+
- [ARCHITECTURE.md](ARCHITECTURE.md) — module layout and data flow
|