How concode0/clifra works
Purpose and Runtime
clifra is a Python 3.10+ / PyTorch 2.0+ library for layout-first Clifford algebra computation and neural-network layers. Its central abstraction is an algebra host that owns metric/signature-dependent layouts, planning policy, and precompiled operation executors. PyTorch tensors are the runtime representation; operations support full-lane and compact grade storage.
Key public package surface: clifra/__init__.py. Core construction and ownership live in clifra/core/foundation/host.py and clifra/core/config.py.
Algebra Foundation and Storage Contracts
Foundation modules define the algebra’s basis, signature/manifold metadata, device handling, numerical validation, and tensor-layout rules. Layouts establish how selected grades are packed into tensor lanes, forming the compatibility boundary between callers, planners, executors, and layers.
• clifra/core/foundation/basis.py
• clifra/core/foundation/layout.py
• clifra/core/foundation/manifold.py
Analysis and Policy Selection
Analysis derives algebra-specific facts used to select efficient or stable implementations: signatures, dimensions, commutation, spectral/geodesic behavior, sampling, symmetry, and operation policy. This is the decision layer before execution planning rather than a tensor-operation runtime.
• clifra/core/analysis/pipeline.py
• clifra/core/analysis/policy.py
• clifra/core/analysis/signature.py
Static Planning Pipeline
Planning turns an operation request plus input/output layouts into reusable static plans. It covers geometric/context products, unary operations, permutations, metrics, actions, exponentials, and layout conversion; tree/flow modules organize dispatch and execution structure. The host exposes planning methods such as plan_product, which produce callable executors.
• clifra/core/planning/planner.py
• clifra/core/planning/product.py
• clifra/core/planning/layouts.py
Tensor Execution and Algebra Kernels
Execution modules apply compiled plans to PyTorch tensors, preserving the selected layout contract. Runtime algebra modules provide underlying tensor, form, energy, and metric machinery. This separates static algebra/layout decisions from batch-shaped dynamic tensor computation.
• clifra/core/execution/product.py
• clifra/core/execution/exp.py
• clifra/core/runtime/algebra.py
Primary flow: caller creates an algebra host → requests a grade layout → planner analyzes layouts/policy and compiles an operation → executor consumes tensors whose final lane dimension matches the layout → output is returned in the requested layout.
PyTorch Modeling Layer
Higher-level layers package planned algebra operations into trainable PyTorch components: primitives implement Clifford-aware linear, product, versor/rotor, projection, normalization, and activation behavior; blocks provide attention; adapters map conventional representations into algebra layouts. Functional and criterion modules expose corresponding stateless operations and losses.
• clifra/layers/primitives/linear.py
• clifra/layers/blocks/attention.py
• clifra/layers/adapters/conformal.py
Optimization and Research Consumer
The optimizer supports post-update manifold handling keyed by parameter tags (spin, sphere, euclidean), keeping geometric constraints outside ordinary layer forward paths. research/continuum_solver is a repository-local downstream system using charts, bivector fields, planned operations, curricula, and logging for continuum-deformation experiments.
• clifra/optimizers/riemannian.py
• research/continuum_solver/engine.py
• research/continuum_solver/field.py
Benchmarking and Documentation Boundary
Benchmark infrastructure runs configured suites, records measurements/artifacts, and publishes generated material under docs. Documentation is MkDocs-based; GitHub Actions run tests and docs builds. No application server or external runtime service is indicated.
• benchmarks/run.py
• benchmarks/suite/runner.py
• .github/workflows/tests.yml
Main entry points: host.py Algebra Host · planner.py Operation Planner · pipeline.py Analysis Pipeline · layout.py Grade Layouts
Components 24
Algebra Foundation
Metric-aware algebra ownership and storage contracts.
- Algebra Host · Owns signature-dependent layouts, policy, and compiled executors.
clifra/core/foundation/host.py - Core Config
clifra/core/config.py - Basis & Signature
clifra/core/foundation/basis.py - Manifold Metadata
clifra/core/foundation/manifold.py - Grade Layouts · Defines packed final-lane representations for selected grades.
clifra/core/foundation/layout.py
Analysis, Planning & Execution
Static decisions compile into tensor executors.
- Analysis Pipeline · Derives algebra-specific implementation facts.
clifra/core/analysis/pipeline.py - Operation Policy
clifra/core/analysis/policy.py - Signature Analysis
clifra/core/analysis/signature.py - Operation Planner · Compiles operation requests and layouts into reusable plans.
clifra/core/planning/planner.py - Product Planning
clifra/core/planning/product.py - Layout Planning
clifra/core/planning/layouts.py - Product Executor · Applies compiled product plans to batch-shaped tensors.
clifra/core/execution/product.py - Exponential Executor
clifra/core/execution/exp.py - Runtime Algebra Kernels · Provides tensor, form, energy, and metric machinery.
clifra/core/runtime/algebra.py
PyTorch Modeling
Trainable components built on planned operations.
- Clifford Linear
clifra/layers/primitives/linear.py - Clifford Attention
clifra/layers/blocks/attention.py - Conformal Adapter
clifra/layers/adapters/conformal.py
Consumers & Tooling
Optimization, research, and benchmark consumers.
- Riemannian Optimizer · Applies tag-selected post-update manifold constraints.
clifra/optimizers/riemannian.py - Continuum Solver · Uses planned operations for continuum-deformation experiments.
research/continuum_solver/engine.py - Bivector Field
research/continuum_solver/field.py - Benchmark Entry
benchmarks/run.py - Benchmark Suites · Records configured measurements and artifacts.
benchmarks/suite/runner.py - CI Tests & Docs
.github/workflows/tests.yml
Other components
- Public API
clifra/__init__.py
Connections 26
- Public API → Algebra Host: creates
- Algebra Host → Core Config: uses
- Algebra Host → Basis & Signature: owns
- Algebra Host → Manifold Metadata: owns
- Algebra Host → Grade Layouts: creates
- Algebra Host → Operation Planner: requests plans
- Analysis Pipeline → Signature Analysis: derives
- Analysis Pipeline → Operation Policy: selects
- Basis & Signature → Analysis Pipeline: algebra facts
- Grade Layouts → Operation Planner: input/output contract
- Operation Policy → Operation Planner: implementation choice
- Operation Planner → Product Planning: dispatches
- Operation Planner → Layout Planning: dispatches
- Product Planning → Product Executor: compiled plan
- Operation Planner → Exponential Executor: compiled plan
- Product Executor → Runtime Algebra Kernels: tensor kernels
- Exponential Executor → Runtime Algebra Kernels: tensor kernels
- Clifford Linear → Algebra Host: uses algebra operations
- Clifford Attention → Clifford Linear: composes
- Conformal Adapter → Grade Layouts: maps representations
- Riemannian Optimizer → Clifford Linear: updates tagged parameters
- Continuum Solver → Algebra Host: uses planned operations
- Continuum Solver → Bivector Field: evolves
- Benchmark Entry → Benchmark Suites: runs
- Benchmark Suites → Algebra Host: benchmarks
- CI Tests & Docs → Benchmark Entry: automation boundary