Skip to main content

Topological Adam optimizer family for PyTorch with coherence-gated field dynamics and trajectory-topology gating

Project description

Topological Adam

Release License: MIT Tests

Topological Adam is a PyTorch optimizer package for studying Adam-compatible update rules with field-dynamics and trajectory-topology diagnostics. It keeps the standard torch.optim.Optimizer interface while exposing reproducible baselines, ablations, and internal metrics for optimizer research.

The current recommended optimizer is TopologicalAdamV3. TopologicalAdamV4 is an experimental branch for update trajectories with loop or oscillation structure.

Statement of Need

Optimizer papers and software releases are hard to evaluate when a proposed method cannot be installed, reduced to a baseline, or reproduced under the same tuning protocol as Adam. This repository provides an installable implementation of several related Adam-family optimizers, together with tests, benchmark scripts, stored benchmark outputs, and JOSS paper source.

The target users are machine-learning researchers, numerical-methods researchers, and reviewers who want to inspect or benchmark Adam-style mechanisms with explicit diagnostics. The package complements torch.optim rather than replacing it: the main variants retain Adam-style state and include disabled-mechanism settings that reduce to Adam or AdamW for tests and ablations.

Installation

Published releases are installed with pip:

pip install topological-adam

For JOSS review or unreleased development, install from the repository:

git clone https://github.com/RRG314/topological-adam.git
cd topological-adam
pip install -e .
pip install -r requirements-dev.txt

Quickstart

import torch.nn as nn
from topological_adam import TopologicalAdamV3

model = nn.Sequential(nn.Linear(784, 256), nn.ReLU(), nn.Linear(256, 10))
optimizer = TopologicalAdamV3(model.parameters(), lr=1e-3)

TopologicalAdamV3 can be used anywhere a standard PyTorch optimizer is used:

for batch, target in loader:
    optimizer.zero_grad(set_to_none=True)
    loss = criterion(model(batch), target)
    loss.backward()
    optimizer.step()

Optimizer Family

Optimizer Role Notes
TopologicalAdam Legacy implementation Preserved for backward compatibility and provenance.
TopologicalAdamV2 Previous supported branch Adds reusable field diagnostics and stopping helpers.
TopologicalAdamV3 Recommended branch Uses slow and fast gradient-EMA fields, a coherence gate, and optional cautious updates. With w_topo=0, cautious=False, it reduces exactly to Adam or AdamW.
TopologicalAdamSDS Experimental branch SDS-inspired optimizer candidate retained for comparison and further testing.
TopologicalAdamV4 Experimental trajectory-topology branch Computes projected turning/winding statistics from the optimizer trajectory, with optional exact Vietoris-Rips H1 persistence. With loop_gate=False, it reduces exactly to Adam or AdamW.

Diagnostics

V3 exposes field-level diagnostics when track_stats=True:

optimizer = TopologicalAdamV3(model.parameters(), lr=1e-3, track_stats=True)

# after optimizer.step()
stats = optimizer.field_metrics()
print(stats["energy"], stats["j_t"], stats["gate"], stats["align_cos"])

V4 exposes trajectory diagnostics for loop-structured dynamics:

from topological_adam import TopologicalAdamV4

optimizer = TopologicalAdamV4(model.parameters(), lr=1e-3)

# after several optimizer steps
for metric in optimizer.trajectory_metrics():
    print(metric["gate"], metric["winding"], metric["kappa_ema"])

The exact persistent-homology path is opt-in because it is intended for small trajectory windows and diagnostics:

optimizer = TopologicalAdamV4(
    model.parameters(),
    lr=1e-3,
    n_planes=3,
    persistence_every=50,
)

See docs/trajectory-topology.md for the V4 mechanism, limitations, and benchmark interpretation.

Evidence and Reproducibility

The repository reports wins, parity results, and losses. Benchmark scripts tune each optimizer over the same learning-rate grid before fresh-seed evaluation.

  • V3 reaches the measurement floor on the included ill-conditioned quadratic where tuned Adam stalls near 8e-5.
  • V3 improves the included noisy teacher-student regression on 9 of 10 fresh seeds in fresh_seed_confirmation.json.
  • V3 is generally at parity with tuned Adam on ordinary noisy classification tasks.
  • V4 wins on the synthetic rotating-field task it targets, is at parity on sklearn digits MLP, and loses on noisy teacher-student regression.
  • A small reviewer-facing reference benchmark trains a real-data sklearn digits MLP with Adam, AdamW, V3, and V4 under a documented tune-then-fresh protocol.

Entry points:

Reproduce the stored benchmark outputs:

python examples/reference_training_benchmark.py --out reference_training_results.json
python examples/benchmark_v3_suite.py
python examples/confirm_fresh_seeds.py --results benchmark_v3_results.json
python examples/benchmark_v4_suite.py
python examples/make_topology_figures.py

Tests and Packaging

Run the test suite:

python -m pytest tests/ -q

Build and check the package:

python -m build
python -m twine check dist/*

The tests cover exact Adam/AdamW reduction, optimizer state compatibility, V3 field gating, V4 winding and persistence computations, trajectory gating behavior, benchmark smoke paths, and legacy imports. GitHub Actions runs the test suite on Python 3.10 and 3.12.

Repository Layout

  • topological_adam/: installable Python package.
  • examples/: benchmark, reproduction, and figure-generation scripts.
  • tests/: unit, integration, reduction, and smoke tests.
  • docs/: reviewer-facing method notes, benchmark summaries, and figures.
  • paper.md and paper.bib: JOSS paper source and references.
  • CITATION.cff: citation metadata for software reuse.
  • CONTRIBUTING.md: contribution, issue, and support guidelines.

JOSS Materials

The JOSS paper source is paper.md, with references in paper.bib. Reviewer navigation notes are in docs/joss-readiness.md.

The branch version is 2.2.0. The PyPI release should be created only after the JOSS/readiness branch is merged and the release workflow is confirmed.

Citation

If you use this package, cite CITATION.cff.

License

MIT. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

topological_adam-2.2.0.tar.gz (384.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

topological_adam-2.2.0-py3-none-any.whl (31.7 kB view details)

Uploaded Python 3

File details

Details for the file topological_adam-2.2.0.tar.gz.

File metadata

  • Download URL: topological_adam-2.2.0.tar.gz
  • Upload date:
  • Size: 384.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for topological_adam-2.2.0.tar.gz
Algorithm Hash digest
SHA256 e8393e854fa828bdef1cbb6f8408a059dc35d155fea220d1209feaf5c3df1e82
MD5 457ab0a5d1b0bbba20ffde7cd0daf2de
BLAKE2b-256 5463c82c2bdeeae9884b435fc891e41c62fb3acf915c6c7f5dd8c26b0da7d0be

See more details on using hashes here.

Provenance

The following attestation bundles were made for topological_adam-2.2.0.tar.gz:

Publisher: publish-pypi.yml on RRG314/topological-adam

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file topological_adam-2.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for topological_adam-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed36e8fa1068eefa8e51b43a40d2cd02615f1f7caa4ef631301a696035bd59e3
MD5 063782772f6c37f818c1de232e470588
BLAKE2b-256 e1e76de92cf4b1f989acdb93adcc05ece570df71bea87df69bf73d0eb7c6204a

See more details on using hashes here.

Provenance

The following attestation bundles were made for topological_adam-2.2.0-py3-none-any.whl:

Publisher: publish-pypi.yml on RRG314/topological-adam

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page