Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

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.G(sc.L("z", 2), sc.L("u", 1), sc.L("znext", 2)), sc.L("defect", ...))
def defect(inputs):
    z, u, znext = inputs
    return z + 0.1 * sc.concat([z[1:], u]) - znext

@sc.problem(vars=sc.L("w", 3 * N + 2), params=sc.L("z0", 2))
def multiple_shooting(w, z0):
    zs, us = w[: 2 * N + 2], w[2 * N + 2 :]
    defects = sc.vmap(defect, N, {"z": zs[:-2], "u": us, "znext": zs[2:]})  # one loop, not N copies
    return sc.ProblemSpec(minimize=sc.sumsqr(zs) + 0.1 * sc.sumsqr(us), eq=(zs[:2] - z0, 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. 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.0a1

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.0a1
File Size Uploaded Provenance Actions
scaly-0.1.0a1.tar.gz 165.9 kB With provenance Details for scaly-0.1.0a1.tar.gz

Built distribution (wheel)

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

Total release size: 370.4 kB

Release files / scaly-0.1.0a1.tar.gz

Download URL scaly-0.1.0a1.tar.gz
Size 165.9 kB
Tags Source
SHA-256 checksum
How to use checksums
134508824047d962adfd21bec105808bd160ed0f7b70554b9226b5a522c96ca4
BLAKE2b-256 checksum
How to use checksums
f8a09246646bc26e267fdfa6252f6552dc62e0ddc97410e7bf796e8f41ea2349
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 29, 2026.

Transparency log

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

Download URL scaly-0.1.0a1-py3-none-any.whl
Size 204.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
14551ab6ed31644d62af3cb06f052526b54993d83db52b9041cc25a9d7ed246d
BLAKE2b-256 checksum
How to use checksums
539981edb82806597d20f1e86c148b1f5fbaf3f157ae334d5d7d38da992d905c
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 29, 2026.

Transparency log

Security for scaly 0.1.0a1

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.0a1.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 29, 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