{"id":34100043,"url":"https://github.com/qub-asl/gradgen","last_synced_at":"2026-04-08T17:00:54.234Z","repository":{"id":153042001,"uuid":"591422976","full_name":"QUB-ASL/gradgen","owner":"QUB-ASL","description":"Autodiff from Python to Embedded Rust","archived":false,"fork":false,"pushed_at":"2026-04-05T00:14:11.000Z","size":2980,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-04-05T02:19:50.407Z","etag":null,"topics":["autodiff","codegen","nostd","python","rust"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/QUB-ASL.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2023-01-20T18:10:37.000Z","updated_at":"2026-04-03T21:59:01.000Z","dependencies_parsed_at":"2023-07-26T09:14:02.667Z","dependency_job_id":null,"html_url":"https://github.com/QUB-ASL/gradgen","commit_stats":null,"previous_names":["alphaville/gradgen"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/QUB-ASL/gradgen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QUB-ASL%2Fgradgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QUB-ASL%2Fgradgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QUB-ASL%2Fgradgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QUB-ASL%2Fgradgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/QUB-ASL","download_url":"https://codeload.github.com/QUB-ASL/gradgen/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QUB-ASL%2Fgradgen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31564915,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"ssl_error","status_checked_at":"2026-04-08T14:31:17.202Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autodiff","codegen","nostd","python","rust"],"created_at":"2025-12-14T16:35:40.209Z","updated_at":"2026-04-08T17:00:54.184Z","avatar_url":"https://github.com/QUB-ASL.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e    \n \u003cimg alt=\"cgapp logo\" src=\"https://i.postimg.cc/G3M2szz5/Logo-Makr-4z-HKa0.png\" width=\"224px\"/\u003e\u003cbr/\u003e    \n    \n    \n\u003c!-- ![PyPI - Downloads](https://img.shields.io/pypi/dm/gradgen?color=blue\u0026style=flat-square)  --\u003e\n[![CI](https://github.com/QUB-ASL/gradgen/actions/workflows/python-tests.yml/badge.svg)](https://github.com/QUB-ASL/gradgen/actions/workflows/python-tests.yml)  [![Docs site](https://img.shields.io/badge/docs-GitHub_Pages-blue)](https://qub-asl.github.io/gradgen/) [![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/)\n \n\u003c/div\u003e    \n\n\n# Gradgen: what it does\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/QUB-ASL/gradgen/refs/heads/main/docs/img/gradgen-what-it-does.png\" alt=\"Gradgen overview\" width=\"80%\" /\u003e\n\u003c/p\u003e\n\n**Gradgen** is a Python library for symbolic differentiation and (embedded) Rust code generation.\n\n## Code generation example\n\n[See documentation](https://qub-asl.github.io/gradgen/docs/basics/codegen)\n\nHere is an example where we will define the function \n\n$$f(x, u) = \\Vert x \\Vert_2^2 + u  \\sin(x_1) + x_2  x_3,$$\n\nfor a three-dimensional input $x$ and scalar $u$.\n\nThe goal is to generate Rust code for the functions $f$, $Jf$ (the Jacobian matrix\nof $f$). \n\nFurthermore, we want to generate a Rust function that computes simultaneous $f$ \nand $\\nabla_x f$. This often is computationally more efficient compared to computing\n$f(x, u)$ and $\\nabla_x f(x, u)$ in separate functions (look for `FunctionBundle` below).\n\n```python\nfrom gradgen import CodeGenerationBuilder, Function, RustBackendConfig, SXVector, sin\n\n# Define the symbolic inputs.\nx = SXVector.sym(\"x\", 3)\nu = SXVector.sym(\"u\", 1)\n\n# Build a simple scalar-valued function of x and u\n# f(x, u) = ||x||_2^2 + u_1 * sin(x_1) + x_2 * x_3\nf_expr = x.norm2sq() + u[0] * sin(x[0]) + x[1] * x[2]\n\n# Define a Function object\nf = Function(\n    \"energy\",\n    [x, u],\n    [f_expr],\n    input_names=[\"x\", \"u\"],\n    output_names=[\"energy\"],\n)\n\n# (Optional) Evaluate f in Python\nx_value = [1.0, 2.0, -0.5]\nu_value = [3.0]\nprint(\"f(x, u) =\", f(x_value, u_value))\n\n# Generate code\nproject = (\n    CodeGenerationBuilder()\n    .with_backend_config(\n        RustBackendConfig()\n        .with_crate_name(\"my_kernel\")\n        .with_backend_mode(\"no_std\")\n        .with_scalar_type(\"f64\")\n    )\n    .for_function(f)\n        .add_primal()\n        .add_jacobian()\n        .add_joint(\n            FunctionBundle()\n            .add_f()\n            .add_jf(wrt=0)\n        )\n        .with_simplification(\"medium\")\n        .done()\n    .build(Path(__file__).resolve().parent / \"codegen_kernel\")\n)\n```\n\nSee the [demos](./demos) and this more complete [tutorial](https://qub-asl.github.io/gradgen/docs/basics/codegen).\n\n## Special case: optimal control\n\n[See tutorial](https://qub-asl.github.io/gradgen/docs/basics/ocp)\n\nIn applications such as optimal control, the generated code\ncan become too large very easily. \nHowever, the problem structure can be exploited to generate\ncode with complexity that doesn't increase with the prediction \nhorizon.\n\nInstead of completely unrolled code, **Gradgen** exploits\nthe problem structure to create high-performance, \nhuman-readable embeddable Rust code.\n\nSee this complete [tutorial](https://qub-asl.github.io/gradgen/docs/basics/ocp) for details.\n\n## Unique features\n\n- Truly embdedable safe Rust code with optional [`#[no_std]`](https://docs.rust-embedded.org/book/intro/no-std.html), no dynamic memory allocation, no `panic!`s\n- Specialised code generation tools for optimal control problems ([docs](https://qub-asl.github.io/gradgen/docs/basics/ocp))\n- Very efficient code generation thanks to modular code generation using [`map`](./demos/map_zip/), [`zip`](./demos/zip_3/), [`repeat`](./demos/composed_function/), and `chain` high-order functions.\n- Supports both single (`f32`) and double (`f64`) precision arithmetic\n\n## Where to go next?\n\nSee the [demos](./demos) and this more complete [documentation](https://qub-asl.github.io/gradgen/docs) for details.\n\n## Show us some love!\n\nIf you find **Gradgen** useful, give us a star on GitHub!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqub-asl%2Fgradgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqub-asl%2Fgradgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqub-asl%2Fgradgen/lists"}