{ "info": { "author": "Data Analysis Center", "author_email": "akoriagin@nes.ru", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Intended Audience :: Science/Research", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Scientific/Engineering" ], "description": "[![License](https://img.shields.io/github/license/analysiscenter/pydens.svg)](https://www.apache.org/licenses/LICENSE-2.0)\n[![Python](https://img.shields.io/badge/python-3.5-blue.svg)](https://python.org)\n[![PyTorch](https://img.shields.io/badge/PyTorch-1.7-orange.svg)](https://pytorch.org)\n[![Run Status](https://api.shippable.com/projects/5d2deaa02900de000646cdf7/badge?branch=master)](https://app.shippable.com/github/analysiscenter/pydens)\n\n# PyDEns\n\n**PyDEns** is a framework for solving Ordinary and Partial Differential Equations (ODEs & PDEs) using neural networks. With **PyDEns** one can solve\n - PDEs & ODEs from a large family including [heat-equation](https://en.wikipedia.org/wiki/Heat_equation), [poisson equation](https://en.wikipedia.org/wiki/Poisson%27s_equation) and [wave-equation](https://en.wikipedia.org/wiki/Wave_equation)\n - parametric families of PDEs\n - PDEs with trainable coefficients.\n\nThis page outlines main capabilities of **PyDEns**. To get an in-depth understanding we suggest you to also read [the tutorial](https://github.com/analysiscenter/pydens/blob/master/tutorials/0.%20Theory.ipynb).\n\n## Getting started with **PyDEns**: solving common PDEs\nLet's solve poisson equation\n\n

\n\n

\n\n\nusing simple feed-forward neural network. Let's start by importing `Solver`-class along with other needed libraries:\n\n```python\nfrom pydens import Solver, NumpySampler\nimport numpy as np\nimport torch\n\n```\n\nYou can now set up a **PyDEns**-model for solving the task at hand. For this you need to supply the equation into a `Solver`-instance. Note the use of differentiation token `D`:\n\n```python\n# Define the equation as a callable.\ndef pde(f, x, y):\n return D(D(f, x), x) + D(D(f, y), y) - 5 * torch.sin(np.pi * (x + y))\n\n# Supply the equation, initial condition, the number of variables (`ndims`)\n# and the configration of neural network in Solver-instance.\nsolver = Solver(equation=pde, ndims=2, boundary_condition=1,\n layout='fa fa fa f', activation='Tanh', units=[10, 12, 15, 1])\n\n```\n\nNote that we defined the architecture of the neural network by supplying `layout`, `activation` and `units` parameters. Here `layout` configures the sequence of layers: `fa fa fa f` stands for `f`ully connected architecture with four layers and three `a`ctivations. In its turn, `units` and `activation` cotrol the number of units in dense layers and activation-function. When defining neural network this way use [`ConvBlock`](https://analysiscenter.github.io/batchflow/api/batchflow.models.torch.layers.html?highlight=baseconvblock#batchflow.models.torch.layers.BaseConvBlock) from [`BatchFlow`](https://github.com/analysiscenter/batchflow).\n\nIt's time to run the optimization procedure\n\n```python\nsolver.fit(batch_size=100, niters=1500)\n```\nin a fraction of second we've got a mesh-free approximation of the solution on **[0, 1]X[0, 1]**-square:\n\n

\n\n

\n\n## Going deeper into **PyDEns**-capabilities\n**PyDEns** allows to do much more than just solve common PDEs: it also deals with (i) parametric families of PDEs and (ii) PDEs with trainable coefficients.\n\n### Solving parametric families of PDEs\nConsider a *family* of ordinary differential equations\n\n

\n\n

\n\nClearly, the solution is a **sin** wave with a phase parametrized by \u03f5:\n\n

\n\n

\n\nSolving this problem is just as easy as solving common PDEs. You only need to introduce parameter `e` in the equation and supply the number of parameters (`nparams`) into a `Solver`-instance:\n\n```python\ndef odeparam(f, x, e):\n return D(f, x) - e * np.pi * torch.cos(e * np.pi * x)\n\n# One for argument, one for parameter\ns = NumpySampler('uniform') & NumpySampler('uniform', low=1, high=5)\n\nsolver = Solver(equation=odeparam, ndims=1, nparams=1, initial_condition=1)\nsolver.fit(batch_size=1000, sampler=s, niters=5000, lr=0.01)\n# solving the whole family takes no more than a couple of seconds!\n```\n\nCheck out the result:\n\n

\n\n

\n\n### Solving PDEs with trainable coefficients\n\nWith **PyDEns** things can get even more interesting! Assume that the *initial state of the system is unknown and yet to be determined*:\n\n

\n\n

\n\nOf course, without additional information, [the problem is undefined](https://en.wikipedia.org/wiki/Initial_value_problem). To make things better, let's fix the state of the system at some other point:\n\n

\n\n

\n\nSetting this problem requires a [slightly more complex configuring](https://github.com/analysiscenter/pydens/blob/master/tutorials/PDE_solving.ipynb). Note the use of `V`-token, that stands for trainable variable, in the initial condition of the problem. Also pay attention to the additional constraint supplied into the `Solver` instance. This constraint binds the final solution to zero at `t=0.5`:\n\n```python\ndef odevar(u, t):\n return D(u, t) - 2 * np.pi * torch.cos(2 * np.pi * t)\ndef initial(*args):\n return V('init', data=torch.Tensor([3.0]))\n\nsolver = Solver(odevar, ndims=1, initial_condition=initial,\n constraints=lambda u, t: u(torch.tensor([0.5])))\n```\nWhen tackling this problem, `pydens` will not only solve the equation, but also adjust the variable (initial condition) to satisfy the additional constraint.\nHence, model-fitting comes in two parts now: (i) solving the equation and (ii) adjusting initial condition to satisfy the additional constraint. Inbetween\nthe steps we need to freeze layers of the network to adjust only the adjustable variable:\n\n```python\nsolver.fit(batch_size=150, niters=100, lr=0.05)\nsolver.model.freeze_layers(['fc1', 'fc2', 'fc3'], ['log_scale'])\nsolver.fit(batch_size=150, niters=100, lr=0.05)\n```\n\nCheck out the results:\n\n

\n\n

\n\n## Installation\n\nFirst of all, you have to manually install [pytorch](https://pytorch.org/get-started/locally/),\nas you might need a certain version or a specific build for CPU / GPU.\n\n### Stable python package\n\nWith modern [pipenv](https://docs.pipenv.org/)\n```\npipenv install pydens\n```\n\nWith old-fashioned [pip](https://pip.pypa.io/en/stable/)\n```\npip3 install pydens\n```\n\n### Development version\n\n```\npipenv install git+https://github.com/analysiscenter/pydens.git\n```\n\n```\npip3 install git+https://github.com/analysiscenter/pydens.git\n```\n\n### Installation as a project repository:\n\nDo not forget to use the flag ``--recursive`` to make sure that ``BatchFlow`` submodule is also cloned.\n\n```\ngit clone --recursive https://github.com/analysiscenter/pydens.git\n```\n\nIn this case you need to manually install the dependencies.\n\n\n## Citing PyDEns\n\nPlease cite **PyDEns** if it helps your research.\n\n```\nRoman Khudorozhkov, Sergey Tsimfer, Alexander Koryagin. PyDEns framework for solving differential equations with deep learning. 2019.\n```\n\n```\n@misc{pydens_2019,\n author = {Khudorozhkov R. and Tsimfer S. and Koryagin. A.},\n title = {PyDEns framework for solving differential equations with deep learning},\n year = 2019\n}\n```\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/analysiscenter/pydens.git", "keywords": "", "license": "Apache License 2.0", "maintainer": "", "maintainer_email": "", "name": "pydens", "package_url": "https://pypi.org/project/pydens/", "platform": "any", "project_url": "https://pypi.org/project/pydens/", "project_urls": { "Homepage": "https://github.com/analysiscenter/pydens.git" }, "release_url": "https://pypi.org/project/pydens/1.0.2/", "requires_dist": [ "numpy (>=1.10)", "dill (>=0.2.7)", "tqdm (>=4.19.7)", "scipy (>=0.19.1)", "scikit-image (>=0.13.1)", "numba (>=0.42)" ], "requires_python": "", "summary": "Framework for solving differential equations with deep learning", "version": "1.0.2", "yanked": false, "yanked_reason": null }, "last_serial": 12635064, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "34ea7b34fb725d06320a256464926776", "sha256": "89e6ab43d54a7870ffb4af4536ce3c5c2d3b931d74df04146686a7dc2c2693b5" }, "downloads": -1, "filename": "pydens-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "34ea7b34fb725d06320a256464926776", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 22578, "upload_time": "2019-08-26T11:14:11", "upload_time_iso_8601": "2019-08-26T11:14:11.194032Z", "url": "https://files.pythonhosted.org/packages/17/3f/22631fcf48545d12715b0e75cc27a4170f133e5463153c106fb1d438dcfd/pydens-0.1.0-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "4352d160096a1f57abed3d72547c201d", "sha256": "5e9c7a55496de35369c9b386860cd67a8ca37d85ec9a34ad7679d531e96cdbfe" }, "downloads": -1, "filename": "pydens-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "4352d160096a1f57abed3d72547c201d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 278808, "upload_time": "2019-10-02T11:59:25", "upload_time_iso_8601": "2019-10-02T11:59:25.945494Z", "url": "https://files.pythonhosted.org/packages/af/c5/8d53a4cf059b0fd1cc47275d67a9b571a6ba6fb1afde822eda16776b28fe/pydens-0.1.1-py3-none-any.whl", "yanked": false, "yanked_reason": null } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "a6aaa37a5b94f03a0f756c2ea7ba8d25", "sha256": "925db8c47752c7bcbee8ac1cc7d986004106b42d0577bd3ce667aae15714ef31" }, "downloads": -1, "filename": "pydens-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "a6aaa37a5b94f03a0f756c2ea7ba8d25", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 281003, "upload_time": "2019-10-23T12:44:18", "upload_time_iso_8601": "2019-10-23T12:44:18.478786Z", "url": "https://files.pythonhosted.org/packages/ad/4b/a5b23a20dfbc0fa8c0999fa77c00381cd6cf60051e975d3b39593743c3a3/pydens-0.1.2-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "39e588bb07d40f826aa6a7d8af2aecc7", "sha256": "ad7963e608b7dd0083a7c7f8c0f7910adc976045f3d4de74428fb181e9a53432" }, "downloads": -1, "filename": "pydens-0.1.2.tar.gz", "has_sig": false, "md5_digest": "39e588bb07d40f826aa6a7d8af2aecc7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 205793, "upload_time": "2019-10-23T12:44:21", "upload_time_iso_8601": "2019-10-23T12:44:21.425727Z", "url": "https://files.pythonhosted.org/packages/1f/34/f3bcdb1746b440311e7f446455c925164ba80afb6ce1ebe7c1b16ecf97fd/pydens-0.1.2.tar.gz", "yanked": false, "yanked_reason": null } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "411a49a02fdb777a93a974b98e70de73", "sha256": "87130c1e3f31f8bbe7011ad40cd1b8c9430b3b291c99c02f55f1705c1e915bfa" }, "downloads": -1, "filename": "pydens-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "411a49a02fdb777a93a974b98e70de73", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 15941, "upload_time": "2022-01-20T15:09:51", "upload_time_iso_8601": "2022-01-20T15:09:51.464463Z", "url": "https://files.pythonhosted.org/packages/e0/a6/17dd0a21a4b6d284abd89d89975e62340c607431f2c1d19ae3cecacb97d9/pydens-1.0.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "6b7bbe499a70abeae830cbb0666874aa", "sha256": "58bb844638cfc8821da684381015057eb25403bc57ccdf74e1f125d35e5f6d2f" }, "downloads": -1, "filename": "pydens-1.0.0.tar.gz", "has_sig": false, "md5_digest": "6b7bbe499a70abeae830cbb0666874aa", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17847, "upload_time": "2022-01-20T15:09:52", "upload_time_iso_8601": "2022-01-20T15:09:52.553548Z", "url": "https://files.pythonhosted.org/packages/5d/5c/39cd18159fed1cf32a8a67d2c22a3faf7253840c3a83009c3e5f14731182/pydens-1.0.0.tar.gz", "yanked": false, "yanked_reason": null } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "01c7a8a308d69c223755ccb5125398e2", "sha256": "700f0e8a0dc5c7d15152b5b56527a9cd3eba9cbdfd6b747ddecc0caea480481d" }, "downloads": -1, "filename": "pydens-1.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "01c7a8a308d69c223755ccb5125398e2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 296027, "upload_time": "2022-01-20T17:15:30", "upload_time_iso_8601": "2022-01-20T17:15:30.575476Z", "url": "https://files.pythonhosted.org/packages/9c/a2/66d01173f12ebf62dd0f78ad3153a16d6387c24b207cd89bc42649345161/pydens-1.0.2-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "6952340425551769472003c5f7fce9f0", "sha256": "dc62c781ff9d73e964b75ec05639072a9d9ab36353dbd880459cdc53a790596a" }, "downloads": -1, "filename": "pydens-1.0.2.tar.gz", "has_sig": false, "md5_digest": "6952340425551769472003c5f7fce9f0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 247595, "upload_time": "2022-01-20T17:15:32", "upload_time_iso_8601": "2022-01-20T17:15:32.054007Z", "url": "https://files.pythonhosted.org/packages/00/4d/def97d3f465c5a714e34c2446aa51b182d6e1944594567aa1beb9437be68/pydens-1.0.2.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "01c7a8a308d69c223755ccb5125398e2", "sha256": "700f0e8a0dc5c7d15152b5b56527a9cd3eba9cbdfd6b747ddecc0caea480481d" }, "downloads": -1, "filename": "pydens-1.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "01c7a8a308d69c223755ccb5125398e2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 296027, "upload_time": "2022-01-20T17:15:30", "upload_time_iso_8601": "2022-01-20T17:15:30.575476Z", "url": "https://files.pythonhosted.org/packages/9c/a2/66d01173f12ebf62dd0f78ad3153a16d6387c24b207cd89bc42649345161/pydens-1.0.2-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "6952340425551769472003c5f7fce9f0", "sha256": "dc62c781ff9d73e964b75ec05639072a9d9ab36353dbd880459cdc53a790596a" }, "downloads": -1, "filename": "pydens-1.0.2.tar.gz", "has_sig": false, "md5_digest": "6952340425551769472003c5f7fce9f0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 247595, "upload_time": "2022-01-20T17:15:32", "upload_time_iso_8601": "2022-01-20T17:15:32.054007Z", "url": "https://files.pythonhosted.org/packages/00/4d/def97d3f465c5a714e34c2446aa51b182d6e1944594567aa1beb9437be68/pydens-1.0.2.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }