Skip to main content

scaly

Scaly is a modelling and code-generation library for optimal control. You describe dynamics, costs and constraints once, and use the same description from prototyping in Python to deployment using generated C code.

import numpy as np
import scaly as sc

N = 20  # the decision vector w stacks N + 1 states of size 2, then N controls

@sc.function(sc.arg("x", 2), sc.arg("u", 1), sc.arg("xnext", 2))
def defect(x: sc.Expr, u: sc.Expr, xnext: sc.Expr) -> sc.Expr:
    return x + 0.1 * sc.concat([x[1:], u]) - xnext

@sc.problem(vars=sc.arg("w", 3 * N + 2), params=sc.arg("x0", 2))
def multiple_shooting(w: sc.Expr, x0: sc.Expr) -> sc.ProblemSpec[sc.Expr]:
    xs, us = w[: 2 * N + 2].reshape((N + 1, 2)), w[2 * N + 2 :].reshape((N, 1))
    defects = sc.vmap(defect, N)(xs[:-1], us, xs[1:]).vec()  # one loop, not N copies
    return sc.ProblemSpec(minimize=sc.sumsqr(xs) + 0.1 * sc.sumsqr(us), eq=(xs[0] - x0, defects))

solve = sc.solver(multiple_shooting, "ipopt")
w_opt, *_ = solve(np.array([1.0, 0.0]))

Behind the scenes, scaly traces the costs, constraints and their derivatives, generates and compiles on the fly C code to call them within the solver. You can also generate the same C code in a specific directory so you can embed it into an external application, either from Python:

from pathlib import Path
from scaly.codegen import write_module

write_module(solve, Path("generated/"))  # generated/multiple_shooting_ipopt.h and .c

or from the command line, naming the module and the function in it:

uv run scaly_codegen mymodule:solve -o generated/

Features

  • Wrap symbolic expressions in functions that you can compose freely. Differentiating a function (e.g. with sc.gradient) creates another function.
  • The input-output dependencies of a function are analyzed statically to generate efficient code for sparse Jacobians and Hessians.
  • Repeated structure (from sc.vmap) stays a loop. A horizon of identical stages compiles to one loop body, so the generated code stays small as the horizon grows.
  • The generated C code has a stable signature that is intentionally close to CasADi's for easy integration with existing tools.
  • Interfaces to quadratic and nonlinear optimization solvers such as PIQP and IPOPT are shipped with scaly. These interfaces are implemented as separate packages, allowing anyone to implement a custom solver plugin.
  • The core library is pure Python and only depends on NumPy and SciPy. The generated code is self-contained C (except for solver code that may depend on external libraries).

Installation

Scaly requires Python 3.12 or newer, on Linux and macOS, and only requires a C compiler to be pre-installed. It also runs on Windows for x86-64 processors, where the package installs its own C compiler and every solver except IPOPT is available. Using uv:

# install just the core library
uv add scaly    
# or with an additional solver interface
uv add "scaly[ipopt]"
# or with all solvers
uv add "scaly[solvers]"

You can of course also use pip by replacing uv add with pip install.

See Installation for more details.

Documentation

The documentation has a user guide, a description of how the compiler works, benchmark results against CasADi, and the API reference.

Scaly is still in development and the public API can still change between minor versions. See versioning policy for more details.

Acknowledgements

Scaly is developed by Tudor A. Oancea (main developer) and Colin N. Jones (methods and math), at the Predictive control lab from EPFL. This project is funded by the Swiss National Science Foundation through the NCCR Automation (grant agreement 51NF40_180545).

AI usage disclosure

This project has been substantially developed using AI coding agents (Claude, Codex and others), under the direction and review of the authors, who are responsible for the result.

License

BSD-2-Clause. See LICENSE.md.

Metadata

Release files for scaly 0.1.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 scaly 0.1.0
File Size Uploaded Provenance Actions
scaly-0.1.0.tar.gz 198.6 kB With provenance Details for scaly-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 443.9 kB

Release files / scaly-0.1.0.tar.gz

Download URL scaly-0.1.0.tar.gz
Size 198.6 kB
Tags Source
SHA-256 checksum
How to use checksums
94094244f0abfea6ecc49e453f3ce65018fe660b5e71a0742f1fc653f225322d
BLAKE2b-256 checksum
How to use checksums
2a4d7cd1adf739caa5e52396319383e08e38ad30c61c6deeb1177e2100565b84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 30, 2026.

Transparency log

Release files / scaly-0.1.0-py3-none-any.whl

Download URL scaly-0.1.0-py3-none-any.whl
Size 245.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8fe96321c8d34f29d21f88f7d743ee99782563561d3ae09515c61c705af50c83
BLAKE2b-256 checksum
How to use checksums
63b1d181913b722f203690543b57988621a0a23132a8eebc0d55288115d45646
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 30, 2026.

Transparency log

Security for scaly 0.1.0

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 scaly-0.1.0.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 Oct 30, 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