Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Paddle Toolkit Development Competition No.3】 Paddle 适配 neuralop #1056

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# weights and biases
.wandb/
wandb_api_key.txt

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
*.DS_Store
*.vscode

# C extensions
*.so
*.py~

# Pycharm
.idea

# vim temp files
*.swp

# Sphinx doc
doc/_build/
doc/source/auto_examples/
doc/source/modules/generated/

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
.pytest_cache/

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

#Ipython Notebook
.ipynb_checkpoints
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 NeuralOperator developers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
.. image:: https://img.shields.io/pypi/v/neuraloperator
:target: https://pypi.org/project/neuraloperator/
:alt: PyPI

.. image:: https://github.com/NeuralOperator/neuraloperator/actions/workflows/test.yml/badge.svg
:target: https://github.com/NeuralOperator/neuraloperator/actions/workflows/test.yml


===============
Neural Operator
===============

``neuraloperator`` is a comprehensive library for
learning neural operators in PyTorch.
It is the official implementation for Fourier Neural Operators
and Tensorized Neural Operators.

Unlike regular neural networks, neural operators
enable learning mapping between function spaces, and this library
provides all of the tools to do so on your own data.

NeuralOperators are also resolution invariant,
so your trained operator can be applied on data of any resolution.


Installation
------------

Just clone the repository and install locally (in editable mode so changes in the code are immediately reflected without having to reinstall):

.. code::

git clone https://github.com/NeuralOperator/neuraloperator
cd neuraloperator
pip install -e .
pip install -r requirements.txt

You can also just pip install the library:


.. code::

pip install neuraloperator

Quickstart
----------

After you've installed the library, you can start training operators seemlessly:


.. code-block:: python

from neuralop.models import FNO

operator = FNO(n_modes=(16, 16), hidden_channels=64,
in_channels=3, out_channels=1)

Tensorization is also provided out of the box: you can improve the previous models
by simply using a Tucker Tensorized FNO with just a few parameters:

.. code-block:: python

from neuralop.models import TFNO

operator = TFNO(n_modes=(16, 16), hidden_channels=64,
in_channels=3,
out_channels=1,
factorization='tucker',
implementation='factorized',
rank=0.05)

This will use a Tucker factorization of the weights. The forward pass
will be efficient by contracting directly the inputs with the factors
of the decomposition. The Fourier layers will have 5% of the parameters
of an equivalent, dense Fourier Neural Operator!

Checkout the `documentation <https://neuraloperator.github.io/neuraloperator/dev/index.html>`_ for more!

Using with weights and biases
-----------------------------

Create a file in ``neuraloperator/config`` called ``wandb_api_key.txt`` and paste your Weights and Biases API key there.
You can configure the project you want to use and your username in the main yaml configuration files.

Contributing code
-----------------

All contributions are welcome! So if you spot a bug or even a typo or mistake in
the documentation, please report it, and even better, open a Pull-Request on
`GitHub <https://github.com/neuraloperator/neuraloperator>`_. Before you submit
your changes, you should make sure your code adheres to our style-guide. The
easiest way to do this is with ``black``:

.. code::

pip install black
black .

Running the tests
=================

Testing and documentation are an essential part of this package and all
functions come with uni-tests and documentation. The tests are ran using the
pytest package. First install ``pytest``:

.. code::

pip install pytest

Then to run the test, simply run, in the terminal:

.. code::

pytest -v neuralop

Citing
------

If you use NeuralOperator in an academic paper, please cite [1]_, [2]_::

@misc{li2020fourier,
title={Fourier Neural Operator for Parametric Partial Differential Equations},
author={Zongyi Li and Nikola Kovachki and Kamyar Azizzadenesheli and Burigede Liu and Kaushik Bhattacharya and Andrew Stuart and Anima Anandkumar},
year={2020},
eprint={2010.08895},
archivePrefix={arXiv},
primaryClass={cs.LG}
}

@article{kovachki2021neural,
author = {Nikola B. Kovachki and
Zongyi Li and
Burigede Liu and
Kamyar Azizzadenesheli and
Kaushik Bhattacharya and
Andrew M. Stuart and
Anima Anandkumar},
title = {Neural Operator: Learning Maps Between Function Spaces},
journal = {CoRR},
volume = {abs/2108.08481},
year = {2021},
}


.. [1] Li, Z., Kovachki, N., Azizzadenesheli, K., Liu, B., Bhattacharya, K., Stuart, A., and Anandkumar A., “Fourier Neural Operator for Parametric Partial Differential Equations”, ICLR, 2021. doi:10.48550/arXiv.2010.08895.

.. [2] Kovachki, N., Li, Z., Liu, B., Azizzadenesheli, K., Bhattacharya, K., Stuart, A., and Anandkumar A., “Neural Operator: Learning Maps Between Function Spaces”, JMLR, 2021. doi:10.48550/arXiv.2108.08481.
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
default: &DEFAULT

#General
# For computing compression
n_params_baseline: None
verbose: True
arch: 'tfno2d'

#Distributed computing
distributed:
use_distributed: False
wireup_info: 'mpi'
wireup_store: 'tcp'
model_parallel_size: 2
seed: 666

# FNO related
tfno2d:
data_channels: 3
n_modes_height: 15
n_modes_width: 15
hidden_channels: 24
lifting_channels: 24
projection_channels: 24
n_layers: 5
domain_padding: None
domain_padding_mode: 'one-sided'
fft_norm: 'forward'
norm: 'group_norm'
skip: 'linear'
implementation: 'factorized'
separable: 0
preactivation: 0
half_prec_fourier: False
half_prec_inverse: False
stabilizer: None

use_mlp: 1
mlp:
expansion: 0.5
dropout: 0

factorization: None
rank: 0.05
fixed_rank_modes: None
dropout: 0.0
tensor_lasso_penalty: 0.0
joint_factorization: False

# Optimizer
opt:
n_epochs: 10000
learning_rate: 0.0001
training_loss: 'l2'
weight_decay: 1e-4
amp_autocast: False

scheduler_T_max: 500 # For cosine only, typically take n_epochs
scheduler_patience: 100 # For ReduceLROnPlateau only
scheduler: 'ReduceLROnPlateau' # Or 'CosineAnnealingLR' OR 'ReduceLROnPlateau'
step_size: 60
gamma: 0.5
precision_schedule: None

# Dataset related
data:
folder: '/home/ubuntu/data/burgers/burgers.npz'
batch_size: 16
n_train: 800
test_batch_sizes: [16]
n_tests: [400]
spatial_length: 128
temporal_length: 101

positional_encoding: True
encode_input: False
encode_output: False
include_endpoint: [True, False]

# Patching
patching:
levels: 0
padding: 0
stitching: False

# Weights and biases
wandb:
log: False
name: None # If None, config will be used but you can override it here
group: ""
project: ""
entity: "" # put your username here
sweep: False
log_output: True
log_test_interval: 1
Loading