localgeom 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.
Files changed (50) hide show
  1. localgeom-0.1.0/LICENSE +201 -0
  2. localgeom-0.1.0/PKG-INFO +169 -0
  3. localgeom-0.1.0/README.md +142 -0
  4. localgeom-0.1.0/local_coordinates/__init__.py +19 -0
  5. localgeom-0.1.0/local_coordinates/base.py +99 -0
  6. localgeom-0.1.0/local_coordinates/basis.py +244 -0
  7. localgeom-0.1.0/local_coordinates/connection.py +207 -0
  8. localgeom-0.1.0/local_coordinates/curved_flow.py +120 -0
  9. localgeom-0.1.0/local_coordinates/exponential_map.py +412 -0
  10. localgeom-0.1.0/local_coordinates/frame.py +143 -0
  11. localgeom-0.1.0/local_coordinates/jacobian.py +242 -0
  12. localgeom-0.1.0/local_coordinates/jet.py +761 -0
  13. localgeom-0.1.0/local_coordinates/metric.py +273 -0
  14. localgeom-0.1.0/local_coordinates/monge.py +110 -0
  15. localgeom-0.1.0/local_coordinates/normal_coords.py +500 -0
  16. localgeom-0.1.0/local_coordinates/plot_basis.py +220 -0
  17. localgeom-0.1.0/local_coordinates/riemann.py +146 -0
  18. localgeom-0.1.0/local_coordinates/svd.py +48 -0
  19. localgeom-0.1.0/local_coordinates/tangent.py +186 -0
  20. localgeom-0.1.0/local_coordinates/tensor.py +230 -0
  21. localgeom-0.1.0/localgeom.egg-info/PKG-INFO +169 -0
  22. localgeom-0.1.0/localgeom.egg-info/SOURCES.txt +48 -0
  23. localgeom-0.1.0/localgeom.egg-info/dependency_links.txt +1 -0
  24. localgeom-0.1.0/localgeom.egg-info/requires.txt +11 -0
  25. localgeom-0.1.0/localgeom.egg-info/top_level.txt +1 -0
  26. localgeom-0.1.0/pyproject.toml +48 -0
  27. localgeom-0.1.0/setup.cfg +4 -0
  28. localgeom-0.1.0/tests/test_base.py +89 -0
  29. localgeom-0.1.0/tests/test_basis.py +582 -0
  30. localgeom-0.1.0/tests/test_christoffel_change_of_basis.py +191 -0
  31. localgeom-0.1.0/tests/test_connection.py +872 -0
  32. localgeom-0.1.0/tests/test_curvature_comprehensive.py +614 -0
  33. localgeom-0.1.0/tests/test_curved_flow.py +127 -0
  34. localgeom-0.1.0/tests/test_exponential_map.py +1414 -0
  35. localgeom-0.1.0/tests/test_frame.py +289 -0
  36. localgeom-0.1.0/tests/test_geodesic_taylor_expansion.py +414 -0
  37. localgeom-0.1.0/tests/test_jacobian.py +385 -0
  38. localgeom-0.1.0/tests/test_jet.py +1093 -0
  39. localgeom-0.1.0/tests/test_metric.py +700 -0
  40. localgeom-0.1.0/tests/test_monge.py +965 -0
  41. localgeom-0.1.0/tests/test_monge_math_verification.py +363 -0
  42. localgeom-0.1.0/tests/test_normal_coords.py +2226 -0
  43. localgeom-0.1.0/tests/test_plot_basis.py +110 -0
  44. localgeom-0.1.0/tests/test_pullback_metric_basis.py +76 -0
  45. localgeom-0.1.0/tests/test_riemann_curvature_tensor.py +663 -0
  46. localgeom-0.1.0/tests/test_riemannian_ica.py +92 -0
  47. localgeom-0.1.0/tests/test_rnc_symmetry.py +812 -0
  48. localgeom-0.1.0/tests/test_tangent.py +827 -0
  49. localgeom-0.1.0/tests/test_tensor.py +528 -0
  50. localgeom-0.1.0/tests/test_tutorial_examples.py +603 -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,169 @@
1
+ Metadata-Version: 2.4
2
+ Name: localgeom
3
+ Version: 0.1.0
4
+ Summary: A JAX-based framework for differential geometry computations on Riemannian manifolds
5
+ Author-email: EddieCunningham <edmondcunnin@umass.edu>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/EddieCunningham/local_coordinates
8
+ Project-URL: Repository, https://github.com/EddieCunningham/local_coordinates
9
+ Keywords: jax,differential-geometry,riemannian,manifold,curvature,geodesic
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
12
+ Classifier: Topic :: Scientific/Engineering :: Physics
13
+ Requires-Python: >=3.12
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: jax>=0.4.20
17
+ Requires-Dist: jaxlib>=0.4.20
18
+ Requires-Dist: equinox>=0.11.0
19
+ Requires-Dist: jaxtyping>=0.2.20
20
+ Requires-Dist: plum-dispatch>=2.0.0
21
+ Requires-Dist: diffrax>=0.5.0
22
+ Requires-Dist: einops>=0.7.0
23
+ Requires-Dist: matplotlib>=3.8.0
24
+ Provides-Extra: test
25
+ Requires-Dist: pytest>=8.3.5; extra == "test"
26
+ Dynamic: license-file
27
+
28
+ # local_coordinates
29
+
30
+ A JAX-based framework for differential geometry computations on Riemannian manifolds.
31
+
32
+ ## Overview
33
+
34
+ The `local_coordinates` library provides a type-safe, coordinate-aware system for performing differential geometry computations. It leverages JAX's automatic differentiation to compute not just gradients, but also Hessians, enabling second-order geometric computations like curvature tensors and geodesics.
35
+
36
+ **Key use cases:**
37
+
38
+ - Computing Riemannian metrics and their properties
39
+ - Calculating curvature tensors (Riemann, Ricci, scalar)
40
+ - Working with coordinate transformations and pullback metrics
41
+ - Computing geodesics via exponential and logarithmic maps
42
+ - Transforming to Riemann normal coordinates
43
+
44
+ ## Features
45
+
46
+ - **Jets**: Second-order automatic differentiation storing value, gradient, and Hessian
47
+ - **Riemannian Metrics**: Define metrics, compute inner products, raise and lower indices
48
+ - **Connections**: Levi-Civita connection and Christoffel symbols
49
+ - **Curvature**: Riemann curvature tensor, Ricci tensor, and scalar curvature
50
+ - **Coordinate Transformations**: Pullback metrics under coordinate changes
51
+ - **Normal Coordinates**: Transform to Riemann normal coordinates where the metric is locally Euclidean
52
+ - **Geodesics**: Exponential and logarithmic maps via Taylor approximation or ODE integration
53
+
54
+ ## Installation
55
+
56
+ ### Using uv (recommended)
57
+
58
+ ```bash
59
+ uv sync
60
+ ```
61
+
62
+ ### Using pip
63
+
64
+ ```bash
65
+ pip install -e .
66
+ ```
67
+
68
+ ### Requirements
69
+
70
+ - Python 3.12+
71
+ - JAX and jaxlib
72
+ - Equinox
73
+ - jaxtyping
74
+ - diffrax (for ODE-based geodesic computation)
75
+
76
+ ## Quick Start
77
+
78
+ ```python
79
+ import jax
80
+ import jax.numpy as jnp
81
+ from jax import Array
82
+ from local_coordinates.jet import Jet, function_to_jet
83
+ from local_coordinates.basis import BasisVectors, get_standard_basis
84
+ from local_coordinates.metric import RiemannianMetric
85
+ from local_coordinates.connection import Connection, get_levi_civita_connection
86
+ from local_coordinates.riemann import (
87
+ RiemannCurvatureTensor,
88
+ RicciTensor,
89
+ get_riemann_curvature_tensor,
90
+ get_ricci_tensor,
91
+ )
92
+
93
+ # Define a position-dependent metric
94
+ def metric_components(x: Array) -> Array:
95
+ return jnp.array([
96
+ [1 + 0.1*x[0]**2, 0.0],
97
+ [0.0, 1 + 0.1*x[1]**2]
98
+ ])
99
+
100
+ # Create the metric at a point
101
+ p: Array = jnp.array([1.0, 1.0])
102
+ basis: BasisVectors = get_standard_basis(p)
103
+ metric_jet: Jet = function_to_jet(metric_components, p)
104
+ metric: RiemannianMetric = RiemannianMetric(basis=basis, components=metric_jet)
105
+
106
+ # Compute geometric quantities
107
+ connection: Connection = get_levi_civita_connection(metric)
108
+ riemann: RiemannCurvatureTensor = get_riemann_curvature_tensor(connection)
109
+ ricci: RicciTensor = get_ricci_tensor(connection, R=riemann)
110
+
111
+ # Scalar curvature
112
+ g_inv: Array = jnp.linalg.inv(metric.components.value)
113
+ scalar_curvature: Array = jnp.einsum("ij,ij->", g_inv, ricci.components.value)
114
+
115
+ print(f"Metric at p:\n{metric.components.value}")
116
+ print(f"Scalar curvature: {scalar_curvature}")
117
+ ```
118
+
119
+ ## Library Architecture
120
+
121
+ ```
122
+ local_coordinates/
123
+ ├── jet.py # Jets: second-order Taylor data (value, gradient, hessian)
124
+ ├── jacobian.py # Jacobians for coordinate transformations
125
+ ├── basis.py # BasisVectors: tangent space bases
126
+ ├── frame.py # Frame: basis vectors with Lie brackets
127
+ ├── tangent.py # TangentVector: vectors in tangent spaces
128
+ ├── tensor.py # Tensor: generic (k,l) tensors
129
+ ├── metric.py # RiemannianMetric: inner products on tangent spaces
130
+ ├── connection.py # Connection: Christoffel symbols, covariant derivatives
131
+ ├── riemann.py # RiemannCurvatureTensor and RicciTensor
132
+ ├── normal_coords.py # Riemann normal coordinates
133
+ └── exponential_map.py # Exponential and logarithmic maps
134
+ ```
135
+
136
+ ## Documentation
137
+
138
+ For comprehensive documentation with examples, see [TUTORIAL.md](TUTORIAL.md).
139
+
140
+ AI assistant skills for task-specific guidance are available in `.cursor/skills/`:
141
+
142
+ | Skill | Description |
143
+ |-------|-------------|
144
+ | **create-riemannian-metric** | Create RiemannianMetric objects from metric functions |
145
+ | **compute-curvature** | Compute Levi-Civita connection, Riemann tensor, Ricci tensor |
146
+ | **pullback-metric** | Compute pullback metrics under coordinate transformations |
147
+ | **riemann-normal-coordinates** | Transform objects to Riemann normal coordinates |
148
+ | **compute-geodesics** | Compute geodesics via exponential/logarithmic maps |
149
+ | **jet-differentiation** | Use Jets for second-order automatic differentiation |
150
+
151
+ ## Important Conventions
152
+
153
+ ### Column-Vector Convention
154
+
155
+ The library uses the column-vector convention throughout:
156
+
157
+ - Basis vectors are stored as columns of matrices
158
+ - `E[:, j]` represents the j-th basis vector
159
+ - `E[a, j]` is the a-th component of the j-th basis vector
160
+
161
+ ### Index Conventions
162
+
163
+ - Christoffel symbols: `Gamma[i, j, k]` = Γ^k\_ij
164
+ - Riemann tensor: `R[i, j, k, m]` = R^m\_ijk
165
+ - Tensors use 1-based indexing for raise/lower operations
166
+
167
+ ## License
168
+
169
+ See [LICENSE](LICENSE) for details.
@@ -0,0 +1,142 @@
1
+ # local_coordinates
2
+
3
+ A JAX-based framework for differential geometry computations on Riemannian manifolds.
4
+
5
+ ## Overview
6
+
7
+ The `local_coordinates` library provides a type-safe, coordinate-aware system for performing differential geometry computations. It leverages JAX's automatic differentiation to compute not just gradients, but also Hessians, enabling second-order geometric computations like curvature tensors and geodesics.
8
+
9
+ **Key use cases:**
10
+
11
+ - Computing Riemannian metrics and their properties
12
+ - Calculating curvature tensors (Riemann, Ricci, scalar)
13
+ - Working with coordinate transformations and pullback metrics
14
+ - Computing geodesics via exponential and logarithmic maps
15
+ - Transforming to Riemann normal coordinates
16
+
17
+ ## Features
18
+
19
+ - **Jets**: Second-order automatic differentiation storing value, gradient, and Hessian
20
+ - **Riemannian Metrics**: Define metrics, compute inner products, raise and lower indices
21
+ - **Connections**: Levi-Civita connection and Christoffel symbols
22
+ - **Curvature**: Riemann curvature tensor, Ricci tensor, and scalar curvature
23
+ - **Coordinate Transformations**: Pullback metrics under coordinate changes
24
+ - **Normal Coordinates**: Transform to Riemann normal coordinates where the metric is locally Euclidean
25
+ - **Geodesics**: Exponential and logarithmic maps via Taylor approximation or ODE integration
26
+
27
+ ## Installation
28
+
29
+ ### Using uv (recommended)
30
+
31
+ ```bash
32
+ uv sync
33
+ ```
34
+
35
+ ### Using pip
36
+
37
+ ```bash
38
+ pip install -e .
39
+ ```
40
+
41
+ ### Requirements
42
+
43
+ - Python 3.12+
44
+ - JAX and jaxlib
45
+ - Equinox
46
+ - jaxtyping
47
+ - diffrax (for ODE-based geodesic computation)
48
+
49
+ ## Quick Start
50
+
51
+ ```python
52
+ import jax
53
+ import jax.numpy as jnp
54
+ from jax import Array
55
+ from local_coordinates.jet import Jet, function_to_jet
56
+ from local_coordinates.basis import BasisVectors, get_standard_basis
57
+ from local_coordinates.metric import RiemannianMetric
58
+ from local_coordinates.connection import Connection, get_levi_civita_connection
59
+ from local_coordinates.riemann import (
60
+ RiemannCurvatureTensor,
61
+ RicciTensor,
62
+ get_riemann_curvature_tensor,
63
+ get_ricci_tensor,
64
+ )
65
+
66
+ # Define a position-dependent metric
67
+ def metric_components(x: Array) -> Array:
68
+ return jnp.array([
69
+ [1 + 0.1*x[0]**2, 0.0],
70
+ [0.0, 1 + 0.1*x[1]**2]
71
+ ])
72
+
73
+ # Create the metric at a point
74
+ p: Array = jnp.array([1.0, 1.0])
75
+ basis: BasisVectors = get_standard_basis(p)
76
+ metric_jet: Jet = function_to_jet(metric_components, p)
77
+ metric: RiemannianMetric = RiemannianMetric(basis=basis, components=metric_jet)
78
+
79
+ # Compute geometric quantities
80
+ connection: Connection = get_levi_civita_connection(metric)
81
+ riemann: RiemannCurvatureTensor = get_riemann_curvature_tensor(connection)
82
+ ricci: RicciTensor = get_ricci_tensor(connection, R=riemann)
83
+
84
+ # Scalar curvature
85
+ g_inv: Array = jnp.linalg.inv(metric.components.value)
86
+ scalar_curvature: Array = jnp.einsum("ij,ij->", g_inv, ricci.components.value)
87
+
88
+ print(f"Metric at p:\n{metric.components.value}")
89
+ print(f"Scalar curvature: {scalar_curvature}")
90
+ ```
91
+
92
+ ## Library Architecture
93
+
94
+ ```
95
+ local_coordinates/
96
+ ├── jet.py # Jets: second-order Taylor data (value, gradient, hessian)
97
+ ├── jacobian.py # Jacobians for coordinate transformations
98
+ ├── basis.py # BasisVectors: tangent space bases
99
+ ├── frame.py # Frame: basis vectors with Lie brackets
100
+ ├── tangent.py # TangentVector: vectors in tangent spaces
101
+ ├── tensor.py # Tensor: generic (k,l) tensors
102
+ ├── metric.py # RiemannianMetric: inner products on tangent spaces
103
+ ├── connection.py # Connection: Christoffel symbols, covariant derivatives
104
+ ├── riemann.py # RiemannCurvatureTensor and RicciTensor
105
+ ├── normal_coords.py # Riemann normal coordinates
106
+ └── exponential_map.py # Exponential and logarithmic maps
107
+ ```
108
+
109
+ ## Documentation
110
+
111
+ For comprehensive documentation with examples, see [TUTORIAL.md](TUTORIAL.md).
112
+
113
+ AI assistant skills for task-specific guidance are available in `.cursor/skills/`:
114
+
115
+ | Skill | Description |
116
+ |-------|-------------|
117
+ | **create-riemannian-metric** | Create RiemannianMetric objects from metric functions |
118
+ | **compute-curvature** | Compute Levi-Civita connection, Riemann tensor, Ricci tensor |
119
+ | **pullback-metric** | Compute pullback metrics under coordinate transformations |
120
+ | **riemann-normal-coordinates** | Transform objects to Riemann normal coordinates |
121
+ | **compute-geodesics** | Compute geodesics via exponential/logarithmic maps |
122
+ | **jet-differentiation** | Use Jets for second-order automatic differentiation |
123
+
124
+ ## Important Conventions
125
+
126
+ ### Column-Vector Convention
127
+
128
+ The library uses the column-vector convention throughout:
129
+
130
+ - Basis vectors are stored as columns of matrices
131
+ - `E[:, j]` represents the j-th basis vector
132
+ - `E[a, j]` is the a-th component of the j-th basis vector
133
+
134
+ ### Index Conventions
135
+
136
+ - Christoffel symbols: `Gamma[i, j, k]` = Γ^k\_ij
137
+ - Riemann tensor: `R[i, j, k, m]` = R^m\_ijk
138
+ - Tensors use 1-based indexing for raise/lower operations
139
+
140
+ ## License
141
+
142
+ See [LICENSE](LICENSE) for details.
@@ -0,0 +1,19 @@
1
+ """local_coordinates: differential geometry computations on Riemannian manifolds."""
2
+
3
+ __version__ = "0.1.0"
4
+
5
+ from local_coordinates.base import AbstractBatchableObject, auto_vmap
6
+ from local_coordinates.jet import Jet, function_to_jet, jet_decorator
7
+ from local_coordinates.jacobian import Jacobian
8
+ from local_coordinates.basis import BasisVectors, get_standard_basis
9
+ from local_coordinates.tangent import TangentVector
10
+ from local_coordinates.tensor import Tensor, TensorType
11
+ from local_coordinates.frame import Frame
12
+ from local_coordinates.metric import RiemannianMetric
13
+ from local_coordinates.connection import Connection, get_levi_civita_connection
14
+ from local_coordinates.riemann import (
15
+ RiemannCurvatureTensor,
16
+ RicciTensor,
17
+ get_riemann_curvature_tensor,
18
+ get_ricci_tensor,
19
+ )
@@ -0,0 +1,99 @@
1
+ import jax.numpy as jnp
2
+ from typing import Tuple, Union, Any
3
+ import equinox as eqx
4
+ from jaxtyping import PyTree
5
+ from functools import wraps
6
+ import abc
7
+ import jax.tree_util as jtu
8
+
9
+ __all__ = ["AbstractBatchableObject", "auto_vmap"]
10
+
11
+
12
+ def auto_vmap(f):
13
+ """Decorator that automatically vectorizes methods of AbstractBatchableObject.
14
+
15
+ Applies JAX's vmap to methods of objects inheriting from
16
+ AbstractBatchableObject, handling batched operations without explicit
17
+ vectorization code. It checks if the object is batched and, if so,
18
+ applies vmap to the method call.
19
+
20
+ Args:
21
+ f: The method to be vectorized
22
+
23
+ Returns:
24
+ A wrapped function that automatically handles batched inputs
25
+
26
+ Example:
27
+ ```python
28
+ class MyObject(AbstractBatchableObject):
29
+ @auto_vmap
30
+ def compute(self, x):
31
+ ...
32
+ ```
33
+ """
34
+ @wraps(f)
35
+ def f_wrapper(self, *args, **kwargs):
36
+ if self.batch_size:
37
+ if isinstance(self.batch_size, tuple):
38
+ axis_size = self.batch_size[0]
39
+ else:
40
+ axis_size = self.batch_size
41
+
42
+ def get_in_axis(arg):
43
+ if eqx.is_array(arg):
44
+ return 0 if arg.ndim > 0 and arg.shape[0] == axis_size else None
45
+ return None
46
+
47
+ in_axes_self = jtu.tree_map(get_in_axis, self)
48
+ in_axes_args = jtu.tree_map(get_in_axis, args)
49
+ in_axes_kwargs = jtu.tree_map(get_in_axis, kwargs)
50
+
51
+ return eqx.filter_vmap(
52
+ lambda s, a, k: f_wrapper(s, *a, **k),
53
+ in_axes=(in_axes_self, in_axes_args, in_axes_kwargs)
54
+ )(self, args, kwargs)
55
+ return f(self, *args, **kwargs)
56
+ return f_wrapper
57
+
58
+
59
+ class AbstractBatchableObject(eqx.Module, abc.ABC):
60
+ """Base class for objects that support batched operations.
61
+
62
+ Provides a consistent interface for handling batched computations,
63
+ including properties and methods to query batch dimensions and
64
+ perform batch operations. Objects can be treated independently or
65
+ as batches with the same API, enabling efficient vectorized
66
+ operations through JAX's vmap.
67
+ """
68
+
69
+ @property
70
+ @abc.abstractmethod
71
+ def batch_size(self) -> Union[Tuple[int], int, None]:
72
+ """Get the batch dimensions of this object.
73
+
74
+ Returns:
75
+ A tuple of the leading dimensions if batched multiple times,
76
+ an int if batched along a single dimension,
77
+ or None if not batched.
78
+ """
79
+ pass
80
+
81
+ @classmethod
82
+ def zeros_like(cls, other: "AbstractBatchableObject") -> "AbstractBatchableObject":
83
+ """Create a new instance with the same structure but all arrays zeroed."""
84
+ params, static = eqx.partition(other, eqx.is_array)
85
+ zero_params = jtu.tree_map(lambda x: jnp.zeros_like(x), params)
86
+ return eqx.combine(zero_params, static)
87
+
88
+ @property
89
+ def shape(self) -> PyTree:
90
+ """Get the shapes of all array parameters in this object."""
91
+ params, static = eqx.partition(self, eqx.is_array)
92
+ shapes = jtu.tree_map(lambda x: x.shape, params)
93
+ return shapes
94
+
95
+ def __getitem__(self, idx: Any):
96
+ """Extract a slice or subset of this batched object."""
97
+ params, static = eqx.partition(self, eqx.is_array)
98
+ sliced_params = jtu.tree_map(lambda x: x[idx], params)
99
+ return eqx.combine(sliced_params, static)