Skip to main content

Coker

Coker is a mathematical programming toolkit and compiler pipeline for technical computing in Python. You define computations as ordinary Python callables, compile them into a symbolic representation, and lower that representation to multiple execution backends. The project is aimed at numerical modelling, optimisation, dynamics, and embedded-oriented execution workflows.

The current package metadata marks Coker as alpha software (Development Status :: 3 - Alpha).

What Coker does

Coker combines a few layers that usually live in separate tools:

  • Backend lowering to numpy, casadi, jax, pytorch, and sympy; the separately packaged native coker backend can be registered for compact workspace-oriented execution.
  • Differentiable execution models that support evaluation, composition, and conditional expressions.
  • Dynamics and variational problem tooling for ODE systems, transcription helpers, and solver-backed optimisation workflows.
  • Domain toolkits for spatial algebra, rigid-body kinematics, system modelling, and codesign-style mathematical programs.

Core capabilities

1. Compile Python callables into reusable functions

The primary entry point is coker.function. You describe argument spaces explicitly, provide a Python implementation, and choose a backend.

import numpy as np
from coker import function, Scalar, VectorSpace

f = function(
    arguments=[Scalar("x")],
    implementation=lambda x: 2 * x + 1,
    backend="numpy",
)
print(f(3))  # 7

A = np.array([[1.0, 0.0], [0.0, -1.0]])
g = function(
    arguments=[VectorSpace("x", 2)],
    implementation=lambda x: A @ x,
    backend="numpy",
)
print(g(np.array([1.0, 2.0])))  # [ 1. -2.]

2. Swap execution backends without rewriting the model

The same traced function can be lowered to different execution backends depending on the job:

  • numpy for direct numerical execution
  • casadi for optimisation-oriented symbolic workflows
  • jax for alternate array execution
  • pytorch for tensor-valued execution, autograd, and optional ODE/quadrature integration
  • sympy for symbolic inspection and printing
  • coker when the separately packaged coker_backend plugin is installed
from coker import function, Scalar

f_casadi = function(
    arguments=[Scalar("x")],
    implementation=lambda x: x**2,
    backend="casadi",
)

Optional extras declared by the package:

pip install "coker[casadi]"
pip install "coker[jax]"
pip install "coker[pytorch]"

Base installation:

pip install coker

Toolkit areas in this repository

Symbolic algebra and function composition

src/coker/algebra/ contains the tracing and function model used throughout the project. The test suite exercises:

  • scalar and vector symbolic ops
  • higher-order composition with FunctionSpace
  • conditional expressions via if_then_else
  • backend-specific lowering paths

Optional native Coker backend

The native coker backend is supplied by the separate coker_backend package. It lowers traced functions into a compact workspace-oriented graph; see docs/backend_architecture.rst for its artifact and runtime boundary.

Dynamics and optimisation

src/coker/dynamics/ exposes:

  • create_autonomous_ode
  • direct_sum
  • VariationalProblem
  • transcription helpers such as Legendre/LGR utilities
  • backend-specific solver parameters and solve status reporting

The dynamics tests cover variational solvers, callbacks, direct-sum composition, and constrained parameter-fitting style problems.

Robotics and modelling toolkits

The repository also includes domain-focused toolkits under src/coker/toolkits/:

  • spatial: rotations, isometries, screws, adjoint operators, quaternions
  • kinematics: rigid-body trees, joints, inertias, forward kinematics, dynamics examples
  • system_modelling: block/component modelling with a discoverable standard library
  • codesign: a small problem-builder API for optimisation-style programs

The test suite includes concrete examples such as a single pendulum, double pendulum, SCARA manipulator, and hexapod leg models.

Repository layout

src/coker/        Python package source
examples/         Small runnable examples
scripts/          Standalone modelling scripts
tests/            Backend, symbolic, dynamics, and toolkit coverage
docs/             Sphinx documentation

Example files worth reading first

  • docs/getting_started.rst — minimal symbolic function workflow
  • docs/backend_architecture.rst — native backend execution model
  • examples/pid_example.py — block-model style PID/plant composition
  • scripts/double_pendulum.py — dynamics-oriented script example
  • tests/benchmarks/benchmark_backends.py — benchmark scenarios for backend evaluation, ODE integration, and variational problems

Development

The repository uses uv in CI for environment management.

Install a development environment:

uv sync --group dev --extra casadi --extra jax --extra pytorch

Run the test suite:

uv run pytest

Build the documentation:

uv sync --group docs
uv run sphinx-build docs/ docs/_build/html -W --keep-going

Formatting and linting used in CI:

uv run black --check --diff src
uv run flake8 src tests docs examples scripts

Project status

The package metadata marks Coker as alpha-stage software. The repository already includes automated coverage for symbolic operations, backend lowering, dynamics, and toolkit examples.

License

Coker is licensed under the MPL-2.0. See LICENSE.TXT for the full text.

Metadata

Release files for coker 0.4.2

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

Source distribution (sdist)

Source distribution for coker 0.4.2
File Size Uploaded Provenance Actions
coker-0.4.2.tar.gz 122.3 kB With provenance Details for coker-0.4.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for coker 0.4.2
File Interpreter ABI Platform Actions
coker-0.4.2-py3-none-any.whl Python 3 none any Details for coker-0.4.2-py3-none-any.whl

Total release size: 269.6 kB

Release files / coker-0.4.2.tar.gz

Download URL coker-0.4.2.tar.gz
Size 122.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a1a9f9dc9a4fa2f0b362c27c9dd1858877b014bd2e4cb5292c832b87a8241675
BLAKE2b-256 checksum
How to use checksums
b1f112bdd57e8afef8003932c0af41593099242d88948efffed84b8315ec65e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

Release files / coker-0.4.2-py3-none-any.whl

Download URL coker-0.4.2-py3-none-any.whl
Size 147.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ee85a7e8d2eb91c82f29a922d90898ca929d87f977672093c420105ddccd9da0
BLAKE2b-256 checksum
How to use checksums
86be87cb79a07e550d39471891350b811960473499bb5490b94a4a8596f942bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

Security for coker 0.4.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for coker-0.4.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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