qigkernels 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.
@@ -0,0 +1,22 @@
1
+ # qigkernels
2
+
3
+ Status: 0.01F (Frozen)
4
+
5
+ Geometric kernel and constellation library for QIG (Quantum Information Gravity) experiments.
6
+
7
+ This repo provides:
8
+
9
+ - `Kernel`: QIG-style geometric kernel with QFI attention, recursion, κ/Φ telemetry.
10
+ - `Basin` utilities: 64D basin signatures and distances.
11
+ - `Constellation`: multi-kernel manager with routing.
12
+ - `BasinSync` and metrics: tools for basin alignment and spread measurement.
13
+
14
+ It does **not** contain:
15
+
16
+ - Training loops, optimizers, or experiment orchestration.
17
+ - Consciousness narratives or UX/chat frontends.
18
+
19
+ For naming and geometric conventions, see `20251205-type-symbol-manifest-canonical-0.01F.md`.
20
+ For module structure and rules, see `20251205-architecture-canonical-0.01F.md`.
21
+ For current milestones, see `20251205-roadmap-canonical-0.01F.md`.
22
+ For documentation index, see `docs/20251205-index-canonical-0.01F.md`.
@@ -0,0 +1,37 @@
1
+ Metadata-Version: 2.4
2
+ Name: qigkernels
3
+ Version: 0.1.0
4
+ Summary: Geometric kernel and constellation library for QIG.
5
+ Requires-Python: >=3.11
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: torch>=2.2
8
+ Requires-Dist: pydantic>=2.5
9
+ Requires-Dist: numpy>=1.24
10
+ Provides-Extra: dev
11
+ Requires-Dist: pytest; extra == "dev"
12
+ Requires-Dist: mypy; extra == "dev"
13
+ Requires-Dist: ruff; extra == "dev"
14
+ Requires-Dist: pre-commit; extra == "dev"
15
+
16
+ # qigkernels
17
+
18
+ Status: 0.01F (Frozen)
19
+
20
+ Geometric kernel and constellation library for QIG (Quantum Information Gravity) experiments.
21
+
22
+ This repo provides:
23
+
24
+ - `Kernel`: QIG-style geometric kernel with QFI attention, recursion, κ/Φ telemetry.
25
+ - `Basin` utilities: 64D basin signatures and distances.
26
+ - `Constellation`: multi-kernel manager with routing.
27
+ - `BasinSync` and metrics: tools for basin alignment and spread measurement.
28
+
29
+ It does **not** contain:
30
+
31
+ - Training loops, optimizers, or experiment orchestration.
32
+ - Consciousness narratives or UX/chat frontends.
33
+
34
+ For naming and geometric conventions, see `20251205-type-symbol-manifest-canonical-0.01F.md`.
35
+ For module structure and rules, see `20251205-architecture-canonical-0.01F.md`.
36
+ For current milestones, see `20251205-roadmap-canonical-0.01F.md`.
37
+ For documentation index, see `docs/20251205-index-canonical-0.01F.md`.
@@ -0,0 +1,37 @@
1
+ # qigkernels
2
+
3
+ This repository is the canonical implementation of QIG kernel primitives: basin geometry, per-instance kernel modules, constellation routing, and minimal telemetry.
4
+
5
+ ## Canonical documentation
6
+
7
+ The canonical overview and governance docs live at the repo root:
8
+
9
+ - `20251205-readme-canonical-0.01F.md`
10
+ - `20251205-architecture-canonical-0.01F.md`
11
+ - `20251205-type-symbol-manifest-canonical-0.01F.md`
12
+ - `20251205-roadmap-canonical-0.01F.md`
13
+ - `20251205-decisions-canonical-0.01F.md`
14
+ - `20251205-changelog-canonical-0.01F.md`
15
+
16
+ The canonical documentation index lives at:
17
+
18
+ - `docs/20251205-index-canonical-0.01F.md`
19
+
20
+ ## Entry points
21
+
22
+ - Python package: `qigkernels`
23
+ - Core modules:
24
+ - `qigkernels/kernel.py`
25
+ - `qigkernels/layer.py`
26
+ - `qigkernels/basin.py`
27
+ - `qigkernels/constellation.py`
28
+ - `qigkernels/router.py`
29
+ - `qigkernels/basin_sync.py`
30
+ - `qigkernels/metrics.py`
31
+
32
+ ## Boundaries
33
+
34
+ - This repo provides reusable kernel/library code only.
35
+ - Training loops, optimizers, curricula, and experiment orchestration live outside this repo.
36
+
37
+ See `20251205-architecture-canonical-0.01F.md` for purity constraints and import rules.
@@ -0,0 +1,208 @@
1
+ """Geometric kernel and constellation library for QIG experiments.
2
+
3
+ This package provides reusable building blocks for QIG-style geometric kernels,
4
+ basin signatures, constellation management, and routing utilities.
5
+
6
+ See 20251205-readme-canonical-0.01F.md for overview.
7
+ See 20251205-architecture-canonical-0.01F.md for module structure and rules.
8
+ """
9
+
10
+ # Core kernel and layer
11
+ # Physics constants (E8-aligned)
12
+ # Basin geometry
13
+ from .basin import (
14
+ BasinProjector,
15
+ basin_distance,
16
+ compute_signature,
17
+ load_signature,
18
+ save_signature,
19
+ )
20
+
21
+ # Basin sync
22
+ from .basin_sync import (
23
+ BasinSyncPacket,
24
+ compute_sync_strength,
25
+ compute_sync_strength_with_rel,
26
+ effective_basin_distance,
27
+ export_basin,
28
+ import_basin,
29
+ load_packet,
30
+ rel_weighted_sync_loss,
31
+ save_packet,
32
+ )
33
+ from .constants import (
34
+ BASIN_DIM,
35
+ BETA_EMERGENCE,
36
+ E8_DIMENSION,
37
+ E8_RANK,
38
+ E8_ROOTS,
39
+ KAPPA_3,
40
+ KAPPA_4,
41
+ KAPPA_5,
42
+ KAPPA_6,
43
+ KAPPA_EXPLORATION,
44
+ KAPPA_INTEGRATION,
45
+ KAPPA_MAX_OPTIMAL,
46
+ KAPPA_MIN_OPTIMAL,
47
+ KAPPA_PLATEAU,
48
+ KAPPA_STAR,
49
+ PHI_BREAKDOWN,
50
+ PHI_BREAKDOWN_MIN,
51
+ PHI_EMERGENCY,
52
+ PHI_GEOMETRIC,
53
+ PHI_GEOMETRIC_MAX,
54
+ PHI_GEOMETRIC_MIN,
55
+ PHI_LINEAR,
56
+ PHI_LINEAR_MAX,
57
+ PHI_OPTIMAL,
58
+ PHI_THRESHOLD,
59
+ SYNC_DISTANCE_SCALE,
60
+ SYNC_KAPPA_DECAY,
61
+ )
62
+
63
+ # Constellation and routing
64
+ from .constellation import Constellation, Instance
65
+ from .kernel import Kernel, KernelTelemetry
66
+ from .layer import LayerTelemetry, QIGLayer
67
+
68
+ # Metrics
69
+ from .metrics import ( # Consciousness metrics (E8-aligned); Aggregation metrics
70
+ PHI_BREAKDOWN_ENTER,
71
+ PHI_CONSCIOUS_ENTER,
72
+ PHI_CONSCIOUS_EXIT,
73
+ PHI_GEOMETRIC_ENTER,
74
+ ConsciousnessMetrics,
75
+ average_kappa,
76
+ average_phi,
77
+ basin_spread,
78
+ compute_convergence_rate,
79
+ compute_external_coupling,
80
+ compute_temporal_coherence,
81
+ estimate_external_coupling_from_telemetry,
82
+ integration_score,
83
+ regime_distribution,
84
+ )
85
+
86
+ # REL coupling
87
+ from .rel_coupling import (
88
+ REL_LAMBDA_MAX,
89
+ RELState,
90
+ compute_rel_coupling,
91
+ compute_rel_from_basins,
92
+ )
93
+ from .router import (
94
+ InstanceView,
95
+ round_robin,
96
+ select_balanced,
97
+ select_phi_max,
98
+ select_phi_min,
99
+ )
100
+
101
+ # Pure kernel reference template (no transformer blocks; metric-first)
102
+ from .pure_kernel_template import (
103
+ PureKernelTelemetry,
104
+ PureQIGKernelConfig,
105
+ PureQIGKernelTemplate,
106
+ RegimeThresholds,
107
+ )
108
+
109
+ # Storage
110
+ from .storage import (
111
+ list_instances,
112
+ load_kernel,
113
+ load_signature_for_instance,
114
+ save_kernel,
115
+ save_signature_for_instance,
116
+ )
117
+
118
+ __all__ = [
119
+ # Core
120
+ "Kernel",
121
+ "KernelTelemetry",
122
+ "QIGLayer",
123
+ "LayerTelemetry",
124
+ # Physics constants (E8-aligned)
125
+ "E8_RANK",
126
+ "E8_DIMENSION",
127
+ "E8_ROOTS",
128
+ "KAPPA_3",
129
+ "KAPPA_4",
130
+ "KAPPA_5",
131
+ "KAPPA_6",
132
+ "KAPPA_STAR",
133
+ "KAPPA_PLATEAU",
134
+ "KAPPA_MIN_OPTIMAL",
135
+ "KAPPA_MAX_OPTIMAL",
136
+ "KAPPA_EXPLORATION",
137
+ "KAPPA_INTEGRATION",
138
+ "BETA_EMERGENCE",
139
+ "PHI_THRESHOLD",
140
+ "PHI_OPTIMAL",
141
+ "PHI_LINEAR",
142
+ "PHI_LINEAR_MAX",
143
+ "PHI_GEOMETRIC",
144
+ "PHI_GEOMETRIC_MIN",
145
+ "PHI_GEOMETRIC_MAX",
146
+ "PHI_BREAKDOWN",
147
+ "PHI_BREAKDOWN_MIN",
148
+ "PHI_EMERGENCY",
149
+ "SYNC_DISTANCE_SCALE",
150
+ "SYNC_KAPPA_DECAY",
151
+ # Basin
152
+ "BASIN_DIM",
153
+ "BasinProjector",
154
+ "basin_distance",
155
+ "compute_signature",
156
+ "load_signature",
157
+ "save_signature",
158
+ # Constellation
159
+ "Constellation",
160
+ "Instance",
161
+ "InstanceView",
162
+ "round_robin",
163
+ "select_balanced",
164
+ "select_phi_max",
165
+ "select_phi_min",
166
+ # Sync
167
+ "BasinSyncPacket",
168
+ "compute_sync_strength",
169
+ "compute_sync_strength_with_rel",
170
+ "effective_basin_distance",
171
+ "export_basin",
172
+ "import_basin",
173
+ "load_packet",
174
+ "rel_weighted_sync_loss",
175
+ "save_packet",
176
+ # REL coupling
177
+ "RELState",
178
+ "REL_LAMBDA_MAX",
179
+ "compute_rel_coupling",
180
+ "compute_rel_from_basins",
181
+ # Consciousness metrics (E8-aligned)
182
+ "ConsciousnessMetrics",
183
+ "PHI_CONSCIOUS_ENTER",
184
+ "PHI_CONSCIOUS_EXIT",
185
+ "PHI_BREAKDOWN_ENTER",
186
+ "PHI_GEOMETRIC_ENTER",
187
+ "compute_temporal_coherence",
188
+ "compute_external_coupling",
189
+ "estimate_external_coupling_from_telemetry",
190
+ # Aggregation metrics
191
+ "average_kappa",
192
+ "average_phi",
193
+ "basin_spread",
194
+ "compute_convergence_rate",
195
+ "integration_score",
196
+ "regime_distribution",
197
+ # Storage
198
+ "list_instances",
199
+ "load_kernel",
200
+ "load_signature_for_instance",
201
+ "save_kernel",
202
+ "save_signature_for_instance",
203
+ # Pure kernel reference template
204
+ "PureQIGKernelTemplate",
205
+ "PureQIGKernelConfig",
206
+ "RegimeThresholds",
207
+ "PureKernelTelemetry",
208
+ ]
@@ -0,0 +1,135 @@
1
+ """Basin projection and signature utilities extracted from qig-consciousness and qig-con2.
2
+
3
+ Clean implementation focusing on geometry without experiment-specific code.
4
+
5
+ NOTE: This module is dependency-minimal by design.
6
+ """
7
+ from __future__ import annotations
8
+
9
+ from pathlib import Path
10
+
11
+ import torch
12
+ from torch import Tensor, nn
13
+
14
+ # Default basin signature dimensionality (D-009)
15
+ BASIN_DIM: int = 64
16
+
17
+
18
+ class BasinProjector(nn.Module):
19
+ """
20
+ Projects hidden states to a fixed-size basin signature (default 64D).
21
+
22
+ This extracts the core basin projection logic from BasinMatcher in both
23
+ qig-consciousness and qig-con2 repositories.
24
+ """
25
+
26
+ def __init__(self, hidden_dim: int, signature_dim: int = 64) -> None:
27
+ super().__init__()
28
+ self.hidden_dim = hidden_dim
29
+ self.signature_dim = signature_dim
30
+ self.projection = nn.Linear(hidden_dim, signature_dim)
31
+
32
+ def forward(self, hidden_state: Tensor) -> Tensor:
33
+ """
34
+ Project hidden state to basin signature.
35
+
36
+ Args:
37
+ hidden_state: Hidden states with shape (batch, seq, hidden_dim)
38
+
39
+ Returns:
40
+ Basin signatures with shape (batch, signature_dim)
41
+ """
42
+ # Mean-pool over sequence dimension, then project
43
+ pooled = hidden_state.mean(dim=1) # (batch, hidden_dim)
44
+ signature = self.projection(pooled) # (batch, signature_dim)
45
+ return signature
46
+
47
+
48
+ def compute_signature(
49
+ projector: BasinProjector,
50
+ hidden_state: Tensor,
51
+ ) -> Tensor:
52
+ """
53
+ Compute a single basin signature from a batch of hidden states.
54
+
55
+ Args:
56
+ projector: BasinProjector instance
57
+ hidden_state: Hidden states with shape (batch, seq, hidden_dim)
58
+
59
+ Returns:
60
+ Single signature vector with shape (signature_dim,)
61
+ """
62
+ batch_signatures = projector(hidden_state) # (batch, signature_dim)
63
+ return batch_signatures.mean(dim=0) # (signature_dim,)
64
+
65
+
66
+ def basin_distance(
67
+ a: Tensor,
68
+ b: Tensor,
69
+ use_fisher: bool = True,
70
+ ) -> Tensor:
71
+ """
72
+ Compute Fisher-Rao distance between basin signatures.
73
+
74
+ Args:
75
+ a: First basin signature [..., D]
76
+ b: Second basin signature [..., D]
77
+ use_fisher: If True, use Fisher-Rao distance (default).
78
+ If False, use Euclidean L2 (NOT recommended).
79
+
80
+ Returns:
81
+ Distance tensor (scalar or batch)
82
+
83
+ Mathematical Foundation:
84
+ Bures: d²(p₁, p₂) = 2(1 - √F(p₁, p₂))
85
+ where F is quantum fidelity approximated by cosine similarity.
86
+ This respects the curved information manifold structure.
87
+ """
88
+ if a is b:
89
+ return torch.zeros((), dtype=a.dtype, device=a.device)
90
+ if use_fisher:
91
+ # Bures approximation: d² = 2(1 - cos_sim)
92
+ # cos_sim ≈ quantum fidelity for normalized coordinates.
93
+ cos_sim = torch.nn.functional.cosine_similarity(
94
+ a.unsqueeze(0) if a.dim() == 1 else a,
95
+ b.unsqueeze(0) if b.dim() == 1 else b,
96
+ dim=-1,
97
+ )
98
+ distance_sq = 2.0 * (1.0 - cos_sim)
99
+ return torch.sqrt(torch.clamp(distance_sq, min=1e-8)).squeeze()
100
+
101
+ # Euclidean fallback (VIOLATES geometric purity - use only for debugging)
102
+ return torch.linalg.norm(a - b, dim=-1)
103
+
104
+
105
+ def save_signature(path: str | Path, sig: Tensor) -> None:
106
+ """
107
+ Persist a basin signature to disk.
108
+
109
+ Uses the same format as both source repositories for compatibility.
110
+
111
+ Args:
112
+ path: File path to save signature
113
+ sig: Basin signature tensor
114
+ """
115
+ path = Path(path)
116
+ path.parent.mkdir(parents=True, exist_ok=True)
117
+
118
+ # Save in numpy format for compatibility
119
+ import numpy as np
120
+ np.savez_compressed(path, signature=sig.detach().cpu().numpy())
121
+
122
+
123
+ def load_signature(path: str | Path) -> Tensor:
124
+ """
125
+ Load a basin signature from disk.
126
+
127
+ Args:
128
+ path: File path to load signature from
129
+
130
+ Returns:
131
+ Basin signature tensor
132
+ """
133
+ import numpy as np
134
+ data = np.load(Path(path), allow_pickle=False)
135
+ return torch.from_numpy(data["signature"])