{"id":28256608,"url":"https://github.com/qiauil/torchfsm","last_synced_at":"2025-06-16T17:31:52.318Z","repository":{"id":292002643,"uuid":"888451431","full_name":"qiauil/torchfsm","owner":"qiauil","description":"TorchFSM: Fourier Spectral Method with PyTorch","archived":false,"fork":false,"pushed_at":"2025-06-05T07:58:29.000Z","size":75695,"stargazers_count":43,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-05T08:45:06.665Z","etag":null,"topics":["deep-learning","differentiable-simulations","pde","physics-simulation","pytorch"],"latest_commit_sha":null,"homepage":"https://qiauil.github.io/torchfsm/","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/qiauil.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2024-11-14T12:26:27.000Z","updated_at":"2025-05-15T00:24:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"954d31ef-4859-4a8c-8885-65a8098bc601","html_url":"https://github.com/qiauil/torchfsm","commit_stats":null,"previous_names":["qiauil/torchfsm"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qiauil%2Ftorchfsm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qiauil%2Ftorchfsm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qiauil%2Ftorchfsm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qiauil%2Ftorchfsm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qiauil","download_url":"https://codeload.github.com/qiauil/torchfsm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qiauil%2Ftorchfsm/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":258189646,"owners_count":22662428,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["deep-learning","differentiable-simulations","pde","physics-simulation","pytorch"],"created_at":"2025-05-19T22:17:11.884Z","updated_at":"2025-06-16T17:31:52.310Z","avatar_url":"https://github.com/qiauil.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  \u003cimg src=\"./docs/assets/pics/readme/icon_torchfsm.png\" width=\"100\"/\u003e\n  \u003cbr\u003eTorchFSM\u003cbr\u003e\n\u003c/h1\u003e\n\u003ch4 align=\"center\"\u003eFourier Spectral Method with PyTorch\u003c/h4\u003e\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://pypi.org/project/torchfsm/\"\u003e\n  \u003cimg src=\"https://img.shields.io/pypi/v/torchfsm.svg\" alt=\"PyPI\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://github.com/qiauil/torchfsm/releases\"\u003e\n  \u003cimg src=\"https://img.shields.io/github/release-date/qiauil/torchfsm?color=yellow\" alt=\"Release Date\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://github.com/qiauil/torchfsm/blob/main/LICENSE\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/license-MIT-green\" alt=\"License\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://doi.org/10.5281/zenodo.15350210\"\u003e\n  \u003cimg src=\"https://zenodo.org/badge/DOI/10.5281/zenodo.15350210.svg\" alt=\"DOI\"\u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  [\u003ca href=\"https://qiauil.github.io/torchfsm/\"\u003e Documentation \u0026 Examples\u003c/a\u003e]\n\u003c/p\u003e\n\n\n## TL;DR\n`TorchFSM` is a PyTorch-based library for solving PDEs using Fourier spectral method. It is designed for physics-based deep learning and differentiable simulations.\n\n## Simple Example\nBuild a Burger equation with provided operators (the Burgers equation is also available at `torchfsm.pde`):\n```python\nfrom torchfsm.operator import Operator, Convection, Laplacian\n\ndef Burgers(nu:float) -\u003e Operator:\n    return nu*Laplacian()-Convection()\nburgers=Burgers(0.01)\n```\nSimulate the Burgers equation at 1D mesh:\n```python\nfrom torchfsm.mesh import MeshGrid\nfrom torchfsm.plot import plot_traj\nfrom torchfsm.traj_recorder import AutoRecorder\nimport torch\n\ndevice='cuda' if torch.cuda.is_available() else 'cpu'\nL=1.0; N=128; \nmesh=MeshGrid([(0,L,N)],device=device)\nx=mesh.bc_mesh_grid()\nu_0=torch.sin(2*torch.pi*x/L)+0.5\n\ntraj=burgers.integrate(u_0=u_0,mesh=mesh,\n    dt=0.01,step=200,\n    trajectory_recorder=AutoRecorder(),\n)\nplot_traj(traj,animation=False,cmap=\"managua\")\n```\n![Burgers 1D](./docs/assets/pics/readme/burgers_1d.png)\n\nDirectly simulate the Burgers on 2D mesh with the same operator:\n```python\nmesh=MeshGrid([(0,L,N),(0,L,N)],device=device)\nx,y=mesh.bc_mesh_grid()\nu_0=torch.cat([torch.sin(2*torch.pi*x/L)*torch.cos(4*torch.pi*y/L),\n               torch.cos(2*torch.pi*x/L)*torch.sin(4*torch.pi*y/L)],\n              dim=1)\n\ntraj=burgers.integrate(u_0=u_0,mesh=mesh,\n    dt=0.01,step=50,\n    trajectory_recorder=AutoRecorder(),\n)\n\nplot_traj(traj,animation=False,cmap=\"managua\")\n```\n![Burgers 1D](./docs/assets/pics/readme/burgers_2d.png)\n## Feature\n\n* **Modular by design**: TorchFSM offers a modular architecture with essential mathematical operators—like divergence, gradient, and convection—so you can build custom solvers like stacking building blocks, quickly and intuitively.\n\n* **GPU-accelerated**: TorchFSM leverages GPU computing to speed up simulations dramatically. Run complex 3D PDEs in minutes, not hours, with seamless hardware acceleration.\n\n* **Batched simulation support**: Built on PyTorch, TorchFSM enables batched simulations with varied initial conditions—ideal for parameter sweeps, uncertainty quantification, or ensemble analysis.\n\n* **Differentiable and ML-ready**: Fully differentiable by design, TorchFSM integrates naturally with machine learning workflows—for residual operators, differentiable physics, or dataset generation.\n\n## Installation\n\n* Install through pip: `pip install torchfsm`\n* Install the latest version through pip: `pip install git+https://github.com/qiauil/torchfsm`\n* Install locally: Download the repository and run `pip install .`\n\n## Documentations\n\nCheck 👉 [here](https://qiauil.github.io/torchfsm/).\n\n## Citation\n\nWe will be happy if you use `TorchFSM` in your research. If you find our work useful, please consider citing our repository:\n\n```\n@software{liu_2025_15350210,\n  author       = {Liu, Qiang and\n                  Koehler, Felix and\n                  Thuerey, Nils},\n  title        = {TorchFSM: Fourier Spectral Method with PyTorch},\n  month        = may,\n  year         = 2025,\n  publisher    = {Zenodo},\n  doi          = {10.5281/zenodo.15350210},\n  url          = {https://doi.org/10.5281/zenodo.15350210},\n}\n```\n\n## Further Information\n\n* `TorchFSM` is mainly built by \u003ca href=\"https://qiauil.github.io/\"\u003eQiang Liu\u003c/a\u003e, \u003ca href=\"https://fkoehler.site/\"\u003eFelix Koehler\u003c/a\u003e, and \u003ca href=\"https://ge.in.tum.de/about/n-thuerey/\"\u003eNils Thuerey\u003c/a\u003e at \u003ca href=\"https://ge.in.tum.de\"\u003ePhysics Based Simulation Group, Technical University of Munich\u003c/a\u003e \u003cimg src=\"./docs/assets/pics/readme/TUM.svg\" width=\"16\"\u003e \u003c/h6\u003e. We are grateful for all \u003ca href=\"https://github.com/qiauil/torchfsm/graphs/contributors\"\u003econtributors\u003c/a\u003e!\n* If you are more familiar with Jax, please check our Jax alternative [Exponax](https://github.com/Ceyron/exponax)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqiauil%2Ftorchfsm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqiauil%2Ftorchfsm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqiauil%2Ftorchfsm/lists"}