{"id":23215587,"url":"https://github.com/thanduriel/stablenn","last_synced_at":"2025-09-06T22:32:56.504Z","repository":{"id":92775851,"uuid":"310586815","full_name":"Thanduriel/StableNN","owner":"Thanduriel","description":"experiments to build stable neural networks for physical simulations","archived":false,"fork":false,"pushed_at":"2021-09-10T15:26:45.000Z","size":1131,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-05T13:44:20.867Z","etag":null,"topics":["deep-learning","numerical-integration","scientific-machine-learning","simulation"],"latest_commit_sha":null,"homepage":"","language":"C++","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/Thanduriel.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}},"created_at":"2020-11-06T12:06:10.000Z","updated_at":"2022-02-01T17:35:28.000Z","dependencies_parsed_at":"2023-04-21T09:35:59.513Z","dependency_job_id":null,"html_url":"https://github.com/Thanduriel/StableNN","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Thanduriel/StableNN","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thanduriel%2FStableNN","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thanduriel%2FStableNN/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thanduriel%2FStableNN/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thanduriel%2FStableNN/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Thanduriel","download_url":"https://codeload.github.com/Thanduriel/StableNN/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thanduriel%2FStableNN/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273973589,"owners_count":25200575,"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","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["deep-learning","numerical-integration","scientific-machine-learning","simulation"],"created_at":"2024-12-18T20:17:29.175Z","updated_at":"2025-09-06T22:32:56.480Z","avatar_url":"https://github.com/Thanduriel.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# StableNN\nA collection of experiments to build stable neural networks as explicit time-stepping schemes for physical simulations.\nThe two prototypical examples are the gravity pendulum and the 1D heat equation for non-homogeneous media.\n\n## Build\nThe only necessary dependency is\n* [libtorch](https://pytorch.org/get-started/locally/) installed anywhere,\n\nbut optionally you may also want\n* [SFML](https://www.sfml-dev.org/) to visualize the simulations; either installed such that cmake can find it or to build from source clone it into dependencies/SFML,\n* [Eigen](https://eigen.tuxfamily.org/index.php?title=Main_Page) for performance measures although the related code is commented out and not faster than the manual implementation.\n\nThen just run\n```sh\n$ git clone https://github.com/Thanduriel/StableNN.git\n$ cd StableNN\n$ mkdir build\n$ cd build\n$ cmake .. -DCMAKE_PREFIX_PATH=\"\u003cpath to libtorch\u003e/share/cmake/Torch\" -DUSE_GRAPHICS=\u003cON/OFF\u003e -DCMAKE_BUILD_TYPE=Release\n```\n\nMake sure to use a release build with `NDEBUG` defined for experiments, because otherwise very little data is generated to allow for debugging with reasonable speed.\n\nThe programs where tested with libtorch-1.7.0 and both g++-11.1 and msvc-19.29.\n## Usage\nEach simulation has its own executable, `pendulum` and `heateq`. All parameters are set in the code and require recompiling. General settings including the mode (training or evaluation) are set in `defs.hpp`. Parameters of the systems and networks can be found in `mainpendulum.cpp` + `pendulumeval.hpp` and `mainheateq.cpp` + `heateqeval.hpp`.\n\nMost parameters are saved with the network during training in an `.hparam` file of the same name. However, to load a network a few compile time parameters may need to be adjusted manually. These are the `NetType` and `UseWrapper`. A `nn::Integrator` also needs to be defined with the correct number of inputs. These are usually created by the problem specific evaluate functions. For pendulum uses the global value `NUM_INPUTS`, while for heateq values can be set per network using `wrapNetwork\u003c\u003e()` like this:\n```c++\nauto net1 = nn::load\u003cnn::Convolutional, USE_WRAPPER\u003e(params, \"cnn\");\nauto net2 = nn::load\u003cnn::ExtTCN, USE_WRAPPER\u003e(params, \"tcn_4\");\nauto net2 = nn::load\u003cnn::ExtTCN, USE_WRAPPER\u003e(params, \"tcn_8\");\n\n// NUM_INPUTS needs to be at least as high as the maximum number of steps expected by the network\nevaluate\u003cNUM_INPUTS\u003e(systems, states, timeStep, options, \n\t\t\t\tnet1, // default case without wrapper is a single step\n\t\t\t\twrapNetwork\u003c4\u003e(net2),\n\t\t\t\twrapNetwork\u003c8\u003e(net3));\n```\n\nFor examples how the various evaluation methods are used take a look at the `experiments` branch. The plot scripts provided can be used for basic visualization of the generated data but will require manual tweaks regading file names and the number of data series in a file.\nThere are also a number of matlab scripts that contain an implementation of the basic network for the pendulum and computation of its Jacobian. The required data can be imported by first saving the network weights via `nn::exportTensor()`.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthanduriel%2Fstablenn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthanduriel%2Fstablenn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthanduriel%2Fstablenn/lists"}