groupoid 0.1.0.dev1__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.
- groupoid/__init__.py +31 -0
- groupoid/aggregation.py +234 -0
- groupoid/cohomology.py +99 -0
- groupoid/groupoid.py +85 -0
- groupoid/laplacian.py +201 -0
- groupoid/manifold.py +71 -0
- groupoid/optimizer.py +208 -0
- groupoid/persistence.py +195 -0
- groupoid/sheaf.py +84 -0
- groupoid/transport.py +188 -0
- groupoid-0.1.0.dev1.dist-info/METADATA +258 -0
- groupoid-0.1.0.dev1.dist-info/RECORD +15 -0
- groupoid-0.1.0.dev1.dist-info/WHEEL +5 -0
- groupoid-0.1.0.dev1.dist-info/licenses/LICENSE +191 -0
- groupoid-0.1.0.dev1.dist-info/top_level.txt +1 -0
groupoid/transport.py
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"""Parallel transport on Riemannian manifolds for federated learning.
|
|
2
|
+
|
|
3
|
+
Implements parallel transport of tangent vectors along geodesics,
|
|
4
|
+
which is the geometric foundation of the groupoid morphisms. When
|
|
5
|
+
client A sends a gradient update to client B, the gradient must be
|
|
6
|
+
parallel-transported from A's tangent space to B's tangent space
|
|
7
|
+
to preserve geometric meaning.
|
|
8
|
+
|
|
9
|
+
This module provides:
|
|
10
|
+
- Schild's ladder approximation for general manifolds
|
|
11
|
+
- Pole ladder (more accurate, same cost)
|
|
12
|
+
- Exact transport on spheres and SPD matrices
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
import numpy as np
|
|
20
|
+
import numpy.typing as npt
|
|
21
|
+
from loguru import logger
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def schild_ladder(
|
|
25
|
+
manifold: Any, # geomstats manifold; no upstream type stubs
|
|
26
|
+
tangent_vec: npt.NDArray[np.float64],
|
|
27
|
+
base_point: npt.NDArray[np.float64],
|
|
28
|
+
end_point: npt.NDArray[np.float64],
|
|
29
|
+
n_rungs: int = 1,
|
|
30
|
+
) -> npt.NDArray[np.float64]:
|
|
31
|
+
"""Parallel transport via Schild's ladder.
|
|
32
|
+
|
|
33
|
+
An iterative approximation of parallel transport that only requires
|
|
34
|
+
the exponential and logarithmic maps. This is the coarser of the two
|
|
35
|
+
ladders: on S^2 its direction agrees with the analytic parallel
|
|
36
|
+
transport only to cosine ~0.98 and does not converge to the exact
|
|
37
|
+
value as ``n_rungs`` increases (see ``pole_ladder`` for the accurate
|
|
38
|
+
variant and LIMITATIONS.md for the measured behavior).
|
|
39
|
+
|
|
40
|
+
Parameters
|
|
41
|
+
----------
|
|
42
|
+
manifold
|
|
43
|
+
A geomstats manifold with exp and log maps.
|
|
44
|
+
tangent_vec
|
|
45
|
+
Tangent vector at base_point to transport.
|
|
46
|
+
base_point
|
|
47
|
+
Starting point on the manifold.
|
|
48
|
+
end_point
|
|
49
|
+
Destination point on the manifold.
|
|
50
|
+
n_rungs
|
|
51
|
+
Number of ladder rungs (higher = more accurate).
|
|
52
|
+
|
|
53
|
+
Returns
|
|
54
|
+
-------
|
|
55
|
+
np.ndarray
|
|
56
|
+
The transported tangent vector at end_point.
|
|
57
|
+
"""
|
|
58
|
+
metric = manifold.metric
|
|
59
|
+
direction = metric.log(end_point, base_point)
|
|
60
|
+
|
|
61
|
+
current_base = base_point
|
|
62
|
+
current_vec = tangent_vec
|
|
63
|
+
|
|
64
|
+
for _k in range(n_rungs):
|
|
65
|
+
step = direction * (1.0 / n_rungs)
|
|
66
|
+
next_base = metric.exp(step, current_base)
|
|
67
|
+
|
|
68
|
+
# Schild's ladder: reflect the antipodal endpoint through
|
|
69
|
+
# the midpoint of the base-to-next geodesic
|
|
70
|
+
u = metric.exp(-current_vec, current_base)
|
|
71
|
+
midpoint = metric.exp(step / 2.0, current_base)
|
|
72
|
+
log_mid_u = metric.log(u, midpoint)
|
|
73
|
+
u_prime = metric.exp(-log_mid_u, midpoint)
|
|
74
|
+
current_vec = metric.log(u_prime, next_base)
|
|
75
|
+
|
|
76
|
+
current_base = next_base
|
|
77
|
+
direction = metric.log(end_point, current_base)
|
|
78
|
+
|
|
79
|
+
result: npt.NDArray[np.float64] = current_vec
|
|
80
|
+
return result
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def pole_ladder(
|
|
84
|
+
manifold: Any, # geomstats manifold; no upstream type stubs
|
|
85
|
+
tangent_vec: npt.NDArray[np.float64],
|
|
86
|
+
base_point: npt.NDArray[np.float64],
|
|
87
|
+
end_point: npt.NDArray[np.float64],
|
|
88
|
+
n_rungs: int = 1,
|
|
89
|
+
) -> npt.NDArray[np.float64]:
|
|
90
|
+
"""Parallel transport via pole ladder.
|
|
91
|
+
|
|
92
|
+
A variant of Schild's ladder that uses geodesic symmetry instead
|
|
93
|
+
of midpoint construction. More accurate than Schild's ladder for
|
|
94
|
+
the same number of rungs, and exactly preserves the norm of the
|
|
95
|
+
transported vector on symmetric spaces.
|
|
96
|
+
|
|
97
|
+
Parameters
|
|
98
|
+
----------
|
|
99
|
+
manifold
|
|
100
|
+
A geomstats manifold with exp and log maps.
|
|
101
|
+
tangent_vec
|
|
102
|
+
Tangent vector at base_point to transport.
|
|
103
|
+
base_point
|
|
104
|
+
Starting point on the manifold.
|
|
105
|
+
end_point
|
|
106
|
+
Destination point on the manifold.
|
|
107
|
+
n_rungs
|
|
108
|
+
Number of ladder rungs.
|
|
109
|
+
|
|
110
|
+
Returns
|
|
111
|
+
-------
|
|
112
|
+
np.ndarray
|
|
113
|
+
The transported tangent vector at end_point.
|
|
114
|
+
"""
|
|
115
|
+
metric = manifold.metric
|
|
116
|
+
direction = metric.log(end_point, base_point)
|
|
117
|
+
|
|
118
|
+
current_base = base_point
|
|
119
|
+
current_vec = tangent_vec
|
|
120
|
+
|
|
121
|
+
for _k in range(n_rungs):
|
|
122
|
+
step = direction * (1.0 / n_rungs)
|
|
123
|
+
next_base = metric.exp(step, current_base)
|
|
124
|
+
|
|
125
|
+
# Pole construction: reflect through the midpoint of the geodesic
|
|
126
|
+
pole = metric.exp(-current_vec, current_base)
|
|
127
|
+
mid_of_geodesic = metric.exp(step / 2.0, current_base)
|
|
128
|
+
log_pole_from_mid = metric.log(pole, mid_of_geodesic)
|
|
129
|
+
reflected = metric.exp(-log_pole_from_mid, mid_of_geodesic)
|
|
130
|
+
current_vec = metric.log(reflected, next_base)
|
|
131
|
+
|
|
132
|
+
current_base = next_base
|
|
133
|
+
|
|
134
|
+
return current_vec
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def compute_transport_matrix(
|
|
138
|
+
manifold: Any, # geomstats manifold; no upstream type stubs
|
|
139
|
+
base_point: npt.NDArray[np.float64],
|
|
140
|
+
end_point: npt.NDArray[np.float64],
|
|
141
|
+
method: str = "pole",
|
|
142
|
+
n_rungs: int = 2,
|
|
143
|
+
) -> npt.NDArray[np.float64]:
|
|
144
|
+
"""Compute the parallel transport matrix between two points.
|
|
145
|
+
|
|
146
|
+
Constructs the full linear map T such that for any tangent vector v
|
|
147
|
+
at base_point, T @ v gives the parallel transport of v to end_point.
|
|
148
|
+
|
|
149
|
+
Parameters
|
|
150
|
+
----------
|
|
151
|
+
manifold
|
|
152
|
+
A geomstats manifold.
|
|
153
|
+
base_point
|
|
154
|
+
Starting point on the manifold.
|
|
155
|
+
end_point
|
|
156
|
+
Destination point on the manifold.
|
|
157
|
+
method
|
|
158
|
+
Transport method: "pole" or "schild".
|
|
159
|
+
n_rungs
|
|
160
|
+
Number of ladder rungs for the approximation.
|
|
161
|
+
|
|
162
|
+
Returns
|
|
163
|
+
-------
|
|
164
|
+
np.ndarray
|
|
165
|
+
Transport matrix of shape (dim, dim).
|
|
166
|
+
"""
|
|
167
|
+
transport_fn = pole_ladder if method == "pole" else schild_ladder
|
|
168
|
+
dim = base_point.shape[-1]
|
|
169
|
+
T = np.zeros((dim, dim))
|
|
170
|
+
|
|
171
|
+
# Transport each basis vector
|
|
172
|
+
for i in range(dim):
|
|
173
|
+
e_i = np.zeros(dim)
|
|
174
|
+
e_i[i] = 1.0
|
|
175
|
+
|
|
176
|
+
# Project onto tangent space at base_point
|
|
177
|
+
tangent = manifold.to_tangent(e_i, base_point)
|
|
178
|
+
|
|
179
|
+
transported = transport_fn(manifold, tangent, base_point, end_point, n_rungs=n_rungs)
|
|
180
|
+
T[:, i] = transported
|
|
181
|
+
|
|
182
|
+
logger.debug(
|
|
183
|
+
"Transport matrix computed ({} method, {} rungs): det={:.4f}",
|
|
184
|
+
method,
|
|
185
|
+
n_rungs,
|
|
186
|
+
np.linalg.det(T),
|
|
187
|
+
)
|
|
188
|
+
return T
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: groupoid
|
|
3
|
+
Version: 0.1.0.dev1
|
|
4
|
+
Summary: Research prototype: groupoid-based aggregation for federated learning on Riemannian manifolds
|
|
5
|
+
Author-email: Santiago Maniches <santiago.maniches@gmail.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/smaniches/GROUPOID
|
|
8
|
+
Project-URL: Repository, https://github.com/smaniches/GROUPOID
|
|
9
|
+
Project-URL: Documentation, https://smaniches.github.io/GROUPOID
|
|
10
|
+
Project-URL: Issues, https://github.com/smaniches/GROUPOID/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/smaniches/GROUPOID/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: federated-learning,riemannian-geometry,groupoid,topology,sheaf-theory,cohomology,topological-data-analysis
|
|
13
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Requires-Python: <3.13,>=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: geomstats>=0.7
|
|
25
|
+
Requires-Dist: pymanopt>=2.0
|
|
26
|
+
Requires-Dist: ripser>=0.6
|
|
27
|
+
Requires-Dist: persim>=0.3
|
|
28
|
+
Requires-Dist: POT>=0.9
|
|
29
|
+
Requires-Dist: networkx>=3.0
|
|
30
|
+
Requires-Dist: einops>=0.7
|
|
31
|
+
Requires-Dist: numpy<2.0,>=1.24
|
|
32
|
+
Requires-Dist: scipy<1.14,>=1.10
|
|
33
|
+
Requires-Dist: torch>=2.0
|
|
34
|
+
Requires-Dist: pydantic>=2.0
|
|
35
|
+
Requires-Dist: loguru>=0.7
|
|
36
|
+
Provides-Extra: privacy
|
|
37
|
+
Requires-Dist: opacus>=1.4; extra == "privacy"
|
|
38
|
+
Requires-Dist: tenseal>=0.3; extra == "privacy"
|
|
39
|
+
Provides-Extra: numerical
|
|
40
|
+
Requires-Dist: numba>=0.58; extra == "numerical"
|
|
41
|
+
Requires-Dist: jax>=0.4; extra == "numerical"
|
|
42
|
+
Requires-Dist: jaxlib>=0.4; extra == "numerical"
|
|
43
|
+
Provides-Extra: experiment
|
|
44
|
+
Requires-Dist: wandb>=0.16; extra == "experiment"
|
|
45
|
+
Provides-Extra: dev
|
|
46
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
47
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
48
|
+
Requires-Dist: hypothesis>=6.0; extra == "dev"
|
|
49
|
+
Requires-Dist: pytest-benchmark>=4.0; extra == "dev"
|
|
50
|
+
Requires-Dist: pytest-xdist>=3.0; extra == "dev"
|
|
51
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
52
|
+
Requires-Dist: pre-commit>=3.0; extra == "dev"
|
|
53
|
+
Requires-Dist: bandit>=1.7; extra == "dev"
|
|
54
|
+
Requires-Dist: pip-audit>=2.7; extra == "dev"
|
|
55
|
+
Requires-Dist: ruff>=0.1; extra == "dev"
|
|
56
|
+
Requires-Dist: black>=23.0; extra == "dev"
|
|
57
|
+
Requires-Dist: mypy>=1.0; extra == "dev"
|
|
58
|
+
Provides-Extra: docs
|
|
59
|
+
Requires-Dist: mkdocs>=1.5; extra == "docs"
|
|
60
|
+
Requires-Dist: mkdocs-material>=9.0; extra == "docs"
|
|
61
|
+
Requires-Dist: mkdocstrings[python]>=0.24; extra == "docs"
|
|
62
|
+
Provides-Extra: all
|
|
63
|
+
Requires-Dist: groupoid[dev,docs,experiment,numerical,privacy]; extra == "all"
|
|
64
|
+
Dynamic: license-file
|
|
65
|
+
|
|
66
|
+
# GROUPOID
|
|
67
|
+
|
|
68
|
+
[](https://github.com/smaniches/GROUPOID/actions/workflows/ci.yml)
|
|
69
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
70
|
+
[](https://www.python.org/downloads/)
|
|
71
|
+
[](#status)
|
|
72
|
+
[](https://doi.org/10.5281/zenodo.20563974)
|
|
73
|
+
|
|
74
|
+
> **Pre-alpha research prototype.** This is an early-stage exploration of
|
|
75
|
+
> groupoid-based aggregation for federated learning on Riemannian manifolds.
|
|
76
|
+
> It is not a production federated learning system. See
|
|
77
|
+
> [STATUS.md](STATUS.md) and [LIMITATIONS.md](LIMITATIONS.md).
|
|
78
|
+
|
|
79
|
+
## Overview
|
|
80
|
+
|
|
81
|
+
GROUPOID explores using transport groupoids, cellular sheaves, and
|
|
82
|
+
Riemannian geometry to aggregate model parameters across heterogeneous
|
|
83
|
+
federated clients. The core idea: instead of naive Euclidean averaging
|
|
84
|
+
(FedAvg), transport client parameters to a common frame via groupoid
|
|
85
|
+
morphisms, check cohomological consistency, and compute the intrinsic
|
|
86
|
+
Karcher mean on the parameter manifold.
|
|
87
|
+
|
|
88
|
+
## Implemented and tested
|
|
89
|
+
|
|
90
|
+
These components have working implementations with property-based and
|
|
91
|
+
integration tests:
|
|
92
|
+
|
|
93
|
+
- **Karcher mean** on Riemannian manifolds via geomstats (`groupoid.manifold`)
|
|
94
|
+
- **Transport groupoid**: morphism composition, inverse, composition
|
|
95
|
+
associativity verified by Hypothesis (`groupoid.groupoid`)
|
|
96
|
+
- **First cohomology H^1**: holonomy-based obstruction detection on the
|
|
97
|
+
cycle basis; coboundary vanishing and a multi-cycle independent
|
|
98
|
+
holonomy-product reference tested; an incompletely specified cocycle
|
|
99
|
+
(a cycle with a missing edge map) raises `IncompleteCocycleError`
|
|
100
|
+
rather than reporting a partial-product false positive
|
|
101
|
+
(`groupoid.cohomology`)
|
|
102
|
+
- **Cellular sheaf**: restriction maps with functoriality tested
|
|
103
|
+
(`groupoid.sheaf`)
|
|
104
|
+
- **Sheaf Laplacian**: connection Laplacian L = delta^T delta; PSD and
|
|
105
|
+
delta^T-delta equality verified on non-orthogonal restriction maps, plus
|
|
106
|
+
spectral analysis, algebraic connectivity, and diffusion convergence
|
|
107
|
+
tested (`groupoid.laplacian`)
|
|
108
|
+
- **Federated aggregation pipeline**: transport-aware aggregation with
|
|
109
|
+
H^1 consistency checking, multi-round convergence tested
|
|
110
|
+
(`groupoid.aggregation`)
|
|
111
|
+
|
|
112
|
+
## Implemented, validated against ground truth, not yet integrated
|
|
113
|
+
|
|
114
|
+
These modules have unit tests that validate behavior against a
|
|
115
|
+
known-correct reference, but are not yet wired into the main aggregation
|
|
116
|
+
pipeline:
|
|
117
|
+
|
|
118
|
+
- **Parallel transport**: Schild's ladder and pole ladder
|
|
119
|
+
(`groupoid.transport`). The pole ladder is validated against geomstats'
|
|
120
|
+
analytic parallel transport on S^2 -- it matches in direction
|
|
121
|
+
(cosine > 0.999) and magnitude. Schild's ladder is a coarser
|
|
122
|
+
first-order approximation and is asserted as such. See
|
|
123
|
+
[LIMITATIONS.md](LIMITATIONS.md) for the convergence caveat.
|
|
124
|
+
- **Persistent homology**: Vietoris-Rips filtration for divergence
|
|
125
|
+
tracking (`groupoid.persistence`). Unit-tested against point clouds of
|
|
126
|
+
known topology: a circle's dominant 1-cycle (via maximum persistence),
|
|
127
|
+
two-cluster component counting (`betti_0 == 2` at a finite filtration),
|
|
128
|
+
and a translation-invariant bottleneck distance. The persistence diagram
|
|
129
|
+
retains a homology-dimension label, and `track_divergence` compares H0
|
|
130
|
+
against H0 only (it does not pool features across dimensions); this is
|
|
131
|
+
verified against an independent minimum-spanning-tree reconstruction of
|
|
132
|
+
the H0 diagram. The Betti numbers are degenerate under the default
|
|
133
|
+
`thresh=inf` filtration; see [LIMITATIONS.md](LIMITATIONS.md).
|
|
134
|
+
|
|
135
|
+
## Implemented, smoke-tested, not yet integrated
|
|
136
|
+
|
|
137
|
+
This module has implementation with smoke-test coverage only -- the tests
|
|
138
|
+
check coarse sanity (steps stay on the manifold), not core correctness --
|
|
139
|
+
and it is not yet wired into the main aggregation pipeline:
|
|
140
|
+
|
|
141
|
+
- **Riemannian optimizers**: SGD and Adam with exponential map
|
|
142
|
+
retraction; smoke-tested to stay on the manifold after a step, with the
|
|
143
|
+
curvature-adaptive learning rate covered for both its damping and
|
|
144
|
+
fallback branches. Core descent/convergence behavior is not validated
|
|
145
|
+
(`groupoid.optimizer`)
|
|
146
|
+
|
|
147
|
+
## Status
|
|
148
|
+
|
|
149
|
+
Pre-alpha. See [STATUS.md](STATUS.md) for details.
|
|
150
|
+
|
|
151
|
+
## Related work / why not just use X?
|
|
152
|
+
|
|
153
|
+
GROUPOID sits at the intersection of three existing toolchains and is not a
|
|
154
|
+
replacement for any of them. It is an exploratory prototype of one specific
|
|
155
|
+
idea -- transport-groupoid aggregation with cohomological consistency checking
|
|
156
|
+
-- not a federated learning framework.
|
|
157
|
+
|
|
158
|
+
- **Flower / FedML / TensorFlow Federated** -- mature federated learning
|
|
159
|
+
frameworks providing the client/server communication, orchestration, and
|
|
160
|
+
real training loops that GROUPOID deliberately does **not** implement (see
|
|
161
|
+
[LIMITATIONS.md](LIMITATIONS.md): "Not a federated learning framework").
|
|
162
|
+
GROUPOID is about the *aggregation operator*, not the FL plumbing; in
|
|
163
|
+
principle a transport-aware aggregator like this one would be dropped into
|
|
164
|
+
such a framework, not used instead of it.
|
|
165
|
+
- **geomstats / pymanopt** -- Riemannian-geometry libraries. GROUPOID *uses*
|
|
166
|
+
geomstats for the manifold primitives (the Karcher mean delegates to
|
|
167
|
+
geomstats `FrechetMean`). What GROUPOID adds on top is the transport
|
|
168
|
+
groupoid, the H^1 holonomy/consistency check, and the cellular-sheaf
|
|
169
|
+
Laplacian wiring -- not the manifold geometry itself.
|
|
170
|
+
- **Cellular-sheaf spectral methods** (the sheaf-Laplacian line of work,
|
|
171
|
+
e.g. Hansen and Ghrist's spectral theory of cellular sheaves, and sheaf
|
|
172
|
+
neural networks) -- GROUPOID's sheaf Laplacian follows this line and is the
|
|
173
|
+
geometric machinery for detecting inconsistency across clients. The
|
|
174
|
+
contribution here is applying it to the federated-aggregation setting, not
|
|
175
|
+
the sheaf-Laplacian construction in the abstract.
|
|
176
|
+
|
|
177
|
+
In short: use Flower/FedML/TFF for the FL system, use geomstats/pymanopt for
|
|
178
|
+
manifold math; GROUPOID is a research prototype testing whether combining a
|
|
179
|
+
transport groupoid with sheaf-cohomological consistency yields a better
|
|
180
|
+
aggregation operator than Euclidean FedAvg. That hypothesis is **not yet
|
|
181
|
+
validated** (see [STATUS.md](STATUS.md)).
|
|
182
|
+
|
|
183
|
+
## Installation
|
|
184
|
+
|
|
185
|
+
Requires **Python 3.10, 3.11, or 3.12**. Python 3.13+ is not supported: the
|
|
186
|
+
`numpy<2.0` / `scipy<1.14` pins (needed for geomstats compatibility, see
|
|
187
|
+
[LIMITATIONS.md](LIMITATIONS.md)) have no wheels there, so `pip` will refuse
|
|
188
|
+
with a `Requires-Python` message rather than attempt a source build.
|
|
189
|
+
|
|
190
|
+
From source (not published on PyPI):
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
git clone https://github.com/smaniches/GROUPOID.git
|
|
194
|
+
cd GROUPOID
|
|
195
|
+
pip install -e ".[dev]"
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Quick example
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
import networkx as nx
|
|
202
|
+
import numpy as np
|
|
203
|
+
from geomstats.geometry.hypersphere import Hypersphere
|
|
204
|
+
from groupoid import TransportGroupoidAggregator
|
|
205
|
+
|
|
206
|
+
manifold = Hypersphere(dim=2)
|
|
207
|
+
graph = nx.DiGraph([("A", "B"), ("A", "C")])
|
|
208
|
+
|
|
209
|
+
aggregator = TransportGroupoidAggregator(
|
|
210
|
+
manifold=manifold, graph=graph, base_node="A"
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
# Register rotation matrices as transport maps
|
|
214
|
+
theta = np.pi / 6
|
|
215
|
+
R = np.array([
|
|
216
|
+
[np.cos(theta), -np.sin(theta), 0],
|
|
217
|
+
[np.sin(theta), np.cos(theta), 0],
|
|
218
|
+
[0, 0, 1],
|
|
219
|
+
])
|
|
220
|
+
aggregator.register_transport("A", "B", R)
|
|
221
|
+
aggregator.register_transport("A", "C", R.T)
|
|
222
|
+
|
|
223
|
+
client_params = {
|
|
224
|
+
"A": np.array([0.0, 0.0, 1.0]),
|
|
225
|
+
"B": np.array([0.1, 0.0, 0.995]),
|
|
226
|
+
"C": np.array([-0.1, 0.0, 0.995]),
|
|
227
|
+
}
|
|
228
|
+
client_params = {k: v / np.linalg.norm(v) for k, v in client_params.items()}
|
|
229
|
+
|
|
230
|
+
result = aggregator.aggregate(client_params)
|
|
231
|
+
print(f"H^1 = {result.h1_norm:.2e} (consistent: {result.is_consistent})")
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Running tests
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
pytest tests/ -v
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
The suite reaches 100% line and branch coverage of the `groupoid` package
|
|
241
|
+
on Python 3.10-3.12, enforced in CI:
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
pytest tests/ --cov=groupoid --cov-branch --cov-fail-under=100
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Coverage measures which lines run, not whether behavior is correct. See
|
|
248
|
+
[STATUS.md](STATUS.md) for the per-component validation depth, which
|
|
249
|
+
coverage alone does not capture.
|
|
250
|
+
|
|
251
|
+
## Documentation
|
|
252
|
+
|
|
253
|
+
[smaniches.github.io/GROUPOID](https://smaniches.github.io/GROUPOID)
|
|
254
|
+
|
|
255
|
+
## License
|
|
256
|
+
|
|
257
|
+
Copyright 2026 TOPOLOGICA LLC. Licensed under the
|
|
258
|
+
[Apache License, Version 2.0](LICENSE).
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
groupoid/__init__.py,sha256=xa-jzJ9DcEtAVOp_O4ETX39NSbvmoIFdtFdE6QCJiI4,839
|
|
2
|
+
groupoid/aggregation.py,sha256=5SbaiZkfA4HJGVR09n9oyzlEAGFyTN1eUZDVAcHoBYU,8768
|
|
3
|
+
groupoid/cohomology.py,sha256=CHZDSGjPPuDNXQG8f3xnx3sDlxpEmlYeWqRiCpfRNpU,3567
|
|
4
|
+
groupoid/groupoid.py,sha256=L2WmTG8-Sh_r6TsgmIJ077zRG-nz1OyYEqsorAJf1w0,1992
|
|
5
|
+
groupoid/laplacian.py,sha256=jqZEU6yvBocUqKg30XUojIUlDoGZVfyMEBKNRWhdG6w,6189
|
|
6
|
+
groupoid/manifold.py,sha256=2jP68SwLhbpl4EItvLBRnV6_k6l2thTFzchudIzjGJw,2100
|
|
7
|
+
groupoid/optimizer.py,sha256=RkbQMajLpso4U0jzUiarni9OCqBrUFcN_IVCzRpUEWg,6317
|
|
8
|
+
groupoid/persistence.py,sha256=BuiBr00qRAXMPjdlZKuBRFhBUwFge7v2a-rn5bTF3LU,7229
|
|
9
|
+
groupoid/sheaf.py,sha256=hlhvbP_rfQPy7t-EbvD8jTkjsRYv3eyk49Th2ehRNL0,2653
|
|
10
|
+
groupoid/transport.py,sha256=5ItpmiIEqjEzEcFY8H1EAWiJpWHg-9h2d-UVkLAnR9A,5816
|
|
11
|
+
groupoid-0.1.0.dev1.dist-info/licenses/LICENSE,sha256=qd0jMtXL8CN6XNdjjC4r2RX5u2FS6Y0TG1FtWTH4TTM,10766
|
|
12
|
+
groupoid-0.1.0.dev1.dist-info/METADATA,sha256=PNMFgU0OztRecB1yI2r2Agu5I-2rrqZhwA5GyGj8UQA,11087
|
|
13
|
+
groupoid-0.1.0.dev1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
14
|
+
groupoid-0.1.0.dev1.dist-info/top_level.txt,sha256=avPz-dSDwo-4zKd7EoxNoLEEwEOYTAtByUD6BTFV9bY,9
|
|
15
|
+
groupoid-0.1.0.dev1.dist-info/RECORD,,
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
Copyright 2024 TOPOLOGICA LLC
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
groupoid
|