Skip to main content

Cadence: learning through flat, deep and recursive settlement

Cadence

Documentation · Quickstart · Examples · Interactive overview · Preprint · Pragma Research

PyPI CI Python License: GPL v3

Start with a small flat network. Add ordinary depth when the task needs it.

Cadence is an experimental learning library built from bounded patches with local state, input and output ports, retained relations and prediction-error readback. Connected patches settle together to answer; learning repairs their relations from experience. Recursive observers read other patches' live states and exact errors, feeding back into that same settlement. This is the observer-like, self-reading structure behind Cadence.

This README describes 0.60.0 on main. Flat and ordinary deep networks are the recommended starting points. Choose the smallest ordinary network that learns the task, and measure prediction quality and latency before scaling it. Depth can support a capable routine; arbitrary depth is not a speed guarantee.

Recursive observers are experimental. They participate in every synchronous solve and may slow every call, including familiar routine work. Their benefit over capable ordinary networks is unproven. Automatic on-demand attention and independent population clocks are not public features. See the experimental capability boundary.

Choose how the brain responds

Layout What it does When to start here
Flat: a simple routine response Each patch reads sensors directly. With parameters fixed, patch states can settle independently. Small direct mappings, calibration and the first inexpensive baseline.
Deep: co-settling representations Ordinary populations read earlier populations' live states. All layers settle together, with returning influence through their shared constraints. Routines that need learned intermediate features or combined sensory information.
Experimental recursive feedback Observers read live states and exact current prediction errors. An observer can itself be observed. An explicit experiment against capable ordinary controls, with all extra work measured.

All three use the same patch rule, learning methods and whole-brain qualification. These are choices of wiring, not three neuron classes or speed settings. A small flat layout is a useful fast baseline; actual latency depends on size, coupling, learning and the task. Ordinary layers already provide feedback through joint settlement; observers are not needed to enable it.

System 1 means learned routine competence; it can need several ordinary layers. System 2 names the intended useful recursive correction when routine competence fails. The complete cycle—cheap routine, useful correction, then retained cheap routine—has not been demonstrated. A coherent changing beat, a familiar game situation or walking a known path can all be routine. Equilibrium in this behavioral sense means sustained competence, not an unchanging output. Numerical settlement alone can still give a wrong answer about the world: compare forecasts with later observations and measure actual task outcomes.

Build the layout inside one Cortex. The application supplies observations, executes actions and reports outcomes through one brain/body interface; it does not attach an evaluator to every population. Start with the flat and ordinary deep quickstarts. Explicit observer wiring remains available in the experimental recipes.

Install

Python 3.11 or later. The default engine needs only the standard library:

python -m pip install "cadence-net==0.60.0"
python -c "import cadence; print(cadence.__version__)"

For reproducible work, retain the installed package and its source with saved brains; see checkpoint requirements.

Optional PyTorch execution uses the same learning rule and final reference check. Install the gpu extra, then choose Cortex(device="cpu"), Cortex(device="mps") or Cortex(device="cuda"):

python -m pip install "cadence-net[gpu]==0.60.0"

Small brains can be faster on the default engine. Measure the complete workload; see devices, precision and batching.

Teach a small body model

This flat brain learns how a supplied one-dimensional simulator moves. It sees position and commanded velocity, then predicts the next position. Teaching, readiness checks and final probes use different inputs. Predictions come from the settled brain; the simulator supplies only measured teaching and test values.

from cadence import Brain, Cortex, bootstrap

# Supplied simulator: one quarter-second of movement.
def advance(position, velocity):
    return position + 0.25 * velocity


def measurements(positions, velocities):
    return [
        ({"body": [x, u]}, {"next_position": [advance(x, u)]})
        for x in positions for u in velocities
    ]


layout = Cortex(seed=2)
body = layout.input("body", shape=2)
response = layout.column("response", patches=1, inputs=body)
layout.output("next_position", shape=1, reads=response)
brain = layout.build()

report = bootstrap(
    brain,
    measurements((-0.5, 0.5), (-0.8, 0.8)),
    checks=measurements((-0.25, 0.25), (-0.4, 0.4)),
    max_error=0.06, epochs=30,
)
assert report["passed"], report

# Final free predictions: no answer is clamped or supplied as an input.
for position, velocity in ((0.35, -0.4), (-0.35, 0.4)):
    forecast = brain.predict({"body": [position, velocity]})["next_position"][0]
    assert abs(forecast - advance(position, velocity)) < 0.06

# Live operation: retain activity, execute, then learn the actual consequence.
inputs = {"body": [0.35, -0.4]}
activity = brain.step(inputs)
assert activity["accepted"]
measured = advance(0.35, -0.4)
assert brain.observe(inputs, {"next_position": [measured]})["accepted"]

saved = brain.snapshot()  # JSON text: state, learned relations and source identity
restored = Brain.from_snapshot(saved)
assert restored.predict(inputs) == brain.predict(inputs)

This learns a small forward model, not a navigation policy. The live-control example uses a learned model to compare candidate actions and move an actual simulated body toward a goal. Its action search is supplied application code. It does not demonstrate automatic attention or a benefit from recursion.

settle and predict query without changing the brain. step retains qualified activity. observe also learns from supplied output witnesses; observe_batch learns from several independent examples while preserving live activity. Check qualified or accepted; predict raises SettlementError on refusal. A teaching clamp matching its target is not evidence of learning—check later predictions without targets.

Run the current examples

From a checkout of this release:

python -m pip install -e .
python examples/layout_learning.py --layout flat
python examples/layout_learning.py --layout deep
python examples/live_control.py --decisions 20 --seed 0
python examples/live_learning.py --seeds 0 2 7
Example What you can verify
Layout learning Start flat, then try ordinary deep layers; check fresh predictions, work and exact saved continuation. The optional --layout recursive experiment has different capacity and does not establish an advantage.
Learned body control Bootstrap a body model, select actions through explicit candidate search, execute them and admit actual outcomes.
History, retention and rewards Separate small tests of explicit sensory history, old-skill replay, reward learning/reversal and saved continuation.

All examples include batch learning, independent parallel brains, delayed reward and layout costs. History supplies explicit external memory; Reinforcement supplies discrete action-value learning and replay. Neither is an automatic planner or a guarantee of long-term success.

The public demos also include Amen, Atari, Patch World and Doom experiments. Their original engines and results have different versions and representations. They are historical application evidence, not completed reproductions on 0.60.0. In particular, the original Amen record-cell brain is not equivalent to one current flat patch. Consult the versioned performance evidence and current capability boundary before comparing them.

Learn more

Guide What it helps you do
Quickstart Build, teach, query and save your first brain
Layout quickstarts Construct recommended flat and ordinary deep networks, then optional observer experiments
Experimental capabilities Understand observer costs, unfinished System 2 behavior and current evidence limits
Brain design Choose sufficient observations, connected capacity and useful evaluation checks
Bootstrapping Prepare a skill and measure acquisition, retention and learning cost
Live operation Connect observations, actual outcomes, history, reward and control callbacks
Agent recipe Build integrations with the right contracts and capability claims
Architecture / API reference / Specification Understand the equations, exact calls and numerical guarantees

Qualification means constrained numerical stationarity, not a unique global minimum or task success. Saved brains bind exact implementation sources; retain those sources and application preprocessing with checkpoints. Broader capability and comparative efficiency require measured task evidence.

Development

Changes follow minimalism, user-friendliness and agent-friendliness. See the contributor instructions.

python -m pip install -e ".[dev]"
python -m pytest -q
python -m ruff check src tests
python -m ruff format --check src tests

Tests execute the README and documentation examples and check learning, mathematical derivatives, refusal and checkpoint continuation. Licensed under GPL-3.0-or-later.

Metadata

Release files for cadence-net 0.60.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cadence-net 0.60.0
File Size Uploaded
cadence_net-0.60.0.tar.gz 1.5 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for cadence-net 0.60.0
File Interpreter ABI Platform
cadence_net-0.60.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.6 MB

Release files / cadence_net-0.60.0.tar.gz

Download URL cadence_net-0.60.0.tar.gz
Size 1.5 MB
Tags Source
SHA-256 checksum
How to use checksums
0cacca683991760def000066df124df1e4cd7ff8addb7627897713abee68318c
BLAKE2b-256 checksum
How to use checksums
9b90f0ba44331e48c987ae2716789681ac9ed14af2aa4ae556bca744afcfb717
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.0

Release files / cadence_net-0.60.0-py3-none-any.whl

Download URL cadence_net-0.60.0-py3-none-any.whl
Size 63.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9e77566d202caca5f8af3237f60d2beb5aff8f90ee44e0543b053ebb9b08a669
BLAKE2b-256 checksum
How to use checksums
828f050d8b65aa5a9b8bd4ff2a5a32145c052526276ffc16c6d7562c9d83e044
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.0

Release history Release notifications | RSS feed

0.83.0

2 release files

0.82.0

2 release files

0.81.0

2 release files

This release

0.60.0 This release

2 release files

0.50.0

2 release files

0.49.0

2 release files

0.48.0

2 release files

0.47.0

2 release files

0.46.0

2 release files

0.45.0

2 release files

0.44.0

2 release files

0.43.0

2 release files

0.42.0

2 release files

0.20.1

2 release files

0.19.0

2 release files

0.18.0

2 release files

0.17.0

2 release files

0.16.0

2 release files

0.15.0

2 release files

0.14.0

2 release files

0.13.0

2 release files

0.12.0

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page