{"id":20643585,"url":"https://github.com/caiyunapp/leibniz","last_synced_at":"2025-05-10T08:31:08.586Z","repository":{"id":54346334,"uuid":"208940378","full_name":"caiyunapp/leibniz","owner":"caiyunapp","description":"Leibniz is a python package which provide facilities to express learnable partial differential equations with PyTorch  ","archived":false,"fork":false,"pushed_at":"2021-09-13T15:55:04.000Z","size":1531,"stargazers_count":15,"open_issues_count":0,"forks_count":7,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-16T02:02:50.865Z","etag":null,"topics":["adjoint-method","bottleneck","cnn","differential-equations","hyperbolic-block","learnable","pde","physical-informed","python","pytorch","pytorch-cnn","pytorch-implementation","resnet","resunet","senet","unet","unet-3d","unet-pytorch"],"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/caiyunapp.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}},"created_at":"2019-09-17T02:22:52.000Z","updated_at":"2025-01-10T00:05:08.000Z","dependencies_parsed_at":"2022-08-13T12:50:22.029Z","dependency_job_id":null,"html_url":"https://github.com/caiyunapp/leibniz","commit_stats":null,"previous_names":[],"tags_count":52,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caiyunapp%2Fleibniz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caiyunapp%2Fleibniz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caiyunapp%2Fleibniz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caiyunapp%2Fleibniz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/caiyunapp","download_url":"https://codeload.github.com/caiyunapp/leibniz/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253389726,"owners_count":21900803,"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":["adjoint-method","bottleneck","cnn","differential-equations","hyperbolic-block","learnable","pde","physical-informed","python","pytorch","pytorch-cnn","pytorch-implementation","resnet","resunet","senet","unet","unet-3d","unet-pytorch"],"created_at":"2024-11-16T16:13:15.626Z","updated_at":"2025-05-10T08:31:06.730Z","avatar_url":"https://github.com/caiyunapp.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Leibniz\n\n[![DOI](https://zenodo.org/badge/208940378.svg)](https://zenodo.org/badge/latestdoi/208940378)\n[![Build Status](https://api.travis-ci.com/caiyunapp/leibniz.svg?branch=master)](http://travis-ci.com/caiyunapp/leibniz) \n\nLeibniz is a python package which provide facilities to express learnable differential equations with PyTorch\n\nWe also provide UNet, ResUNet and their variations, especially the Hyperbolic blocks for ResUNet.\n\nInstall\n--------\n\n```bash\npip install leibniz\n```\n\n\nHow to use\n-----------\n\n### Physics-informed\n\nAs an example we solve a very simple advection problem, a box-shaped material transported by a constant steady wind.\n\n![moving box](https://raw.githubusercontent.com/caiyunapp/leibniz/master/advection_3d.gif)\n\n\n```python\nimport torch as th\nimport leibniz as lbnz\n\nfrom leibniz.core3d.gridsys.regular3 import RegularGrid\nfrom leibniz.diffeq import odeint as odeint\n\n\ndef binary(tensor):\n    return th.where(tensor \u003e lbnz.zero, lbnz.one, lbnz.zero)\n\n# setup grid system\nlbnz.bind(RegularGrid(\n    basis='x,y,z',\n    W=51, L=151, H=51,\n    east=16.0, west=1.0,\n    north=6.0, south=1.0,\n    upper=6.0, lower=1.0\n))\nlbnz.use('x,y,z') # use xyz coordinate\n\n# giving a material field as a box \nfld = binary((lbnz.x - 8) * (9 - lbnz.x)) * \\\n      binary((lbnz.y - 3) * (4 - lbnz.y)) * \\\n      binary((lbnz.z - 3) * (4 - lbnz.z))\n\n# construct a constant steady wind\nwind = lbnz.one, lbnz.zero, lbnz.zero\n\n# transport value by wind\ndef derivitive(t, clouds):\n    return - lbnz.upwind(wind, clouds)\n\n# integrate the system with rk4\npred = odeint(derivitive, fld, th.arange(0, 7, 1 / 100), method='rk4')\n```\n\n### UNet, ResUNet and variations\n\n```python\nfrom leibniz.unet import UNet\nfrom leibniz.nn.layer.hyperbolic import HyperBottleneck\nfrom leibniz.nn.activation import CappingRelu\n\nunet = UNet(6, 1, normalizor='batch', spatial=(32, 64), layers=5, ratio=-1,\n            vblks=[4, 4, 4, 4, 4], hblks=[1, 1, 1, 1, 1],\n            scales=[-1, -1, -1, -1, -1], factors=[1, 1, 1, 1, 1],\n            block=HyperBottleneck, relu=CappingRelu(), final_normalized=False)\n```\n\nWe provide a ResUNet implementation, which is a UNet variation can insert ResNet blocks between layers.\nThe supported ResNet blocks are include\n* Pure ResNet: Basic, Bottleneck block\n* SENet variations: Basic, Bottleneck block\n* Hyperbolic variations: Basic, Bottleneck block\n\nWe support 1d, 2d, 3d UNet.\n\nnormalizor are include:\n* batch: BatchNorm\n* layer: LayerNorm\n* instance: InstanceNorm\n\nOther hyperparameters are include:\n* spatial: the sizes of the spatial dimentions\n* ratio: the ratio to decide the intial number of channels into the UNet\n* vblks: how many vertical blocks is inserted between two layers\n* hblks: how many horizontal blocks is inserted in the skip connections\n* scales: scale factors(power-2-based) on the spatial dimentions\n* factors: expand or shrink factors(power-2-based) on the channels\n* final_normalized: wheather to scale to final result between 0 to 1\n\n### Piecewise Linear normalizor\n\nPiecewise Linear normalizor provide an learnable monotonic peicewise linear functions and its inverse fucntion.\nThe API is shown as below\n\n```python\n\nfrom leibniz.nn.normalizor import PWLNormalizor\n\n# on 3 channels, given 128 segmented pieces, and assuming the input data have a zero mean and 1.0 std\npwln = PWLNormalizor(3, 128, mean=0.0, std=1.0)\n\nnormed = pwln(input)\noutput = pwln.inverse(normed)\n```\n\nHow to release\n---------------\n\n```bash\npython3 setup.py sdist bdist_wheel\npython3 -m twine upload dist/*\n\ngit tag va.b.c master\ngit push origin va.b.c\n```\n\nContributors\n------------\n\n* Mingli Yuan ([Mountain](https://github.com/mountain))\n* Xiang Pan ([Panpanx](https://github.com/Panpanx))\n* Yi Liu ([YiLiu](https://github.com/YiLiu-Lly))\n\nAcknowledge\n-----------\n\nWe included source code with minor changes from [torchdiffeq](https://github.com/rtqichen/torchdiffeq) by Ricky Chen,\nbecause of two purpose:\n1. package torchdiffeq is not indexed by pypi\n2. package torchdiffeq is very convenient and mandatory\n\nAll our contribution is based on Ricky's Neural ODE paper (NIPS 2018) and his package.\n\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaiyunapp%2Fleibniz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaiyunapp%2Fleibniz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaiyunapp%2Fleibniz/lists"}