File size: 9,037 Bytes
a1a1fbf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# Contributing to NeuralOperator

We welcome new contributions to the library! Our mission for NeuralOperator is to provide access to well-documented, robust implementations of neural operator methods from foundations to the cutting edge. The library is primarily intended for methods that directly relate to operator learning: new architectures, meta-algorithms, training methods and benchmark datasets. We are also interested in integrating interactive examples that showcase operator learning in action on small sample problems.

If your work provides one of the above, we would be thrilled to integrate it into the library. Otherwise, if your work simply relies on a version of the NeuralOperator codebase, we recommend publishing your code separately using a procedure outlined below.

Thank you for contributing to NeuralOperator! Your contributions help make this library better for the entire scientific machine learning community.


## Table of Contents

- [Development Setup](#development-setup)
- [Development Workflow](#development-workflow)
- [Development Guidelines](#development-guidelines)
- [Adding a New Model or Layer](#adding-a-new-model-or-layer)
- [Getting Help](#getting-help)
- [Publishing Code Built on the Library](#publishing-code-built-on-the-library)
- [License](#license)

 

## Development Setup

### 1. Fork and Clone the Repository

1. **Fork the repository** on GitHub by clicking the "Fork" button

2. **Clone the library and connect your fork**:
   ```bash
   git clone https://github.com/neuraloperator/neuraloperator.git
   cd neuraloperator
   git remote rename origin upstream
   git remote add origin https://github.com/<YOUR_GIT_NAME>/neuraloperator.git
   git remote -v
   ```
   This should show:
   ```
   origin  https://github.com/<YOUR_GIT_NAME>/neuraloperator.git (fetch)
   origin  https://github.com/<YOUR_GIT_NAME>/neuraloperator.git (push)
   upstream        https://github.com/neuraloperator/neuraloperator.git (fetch)
   upstream        https://github.com/neuraloperator/neuraloperator.git (push)
   ```

### 2. Set Up Development Environment

1. **Create a virtual environment**:
   ```bash
   python -m venv venv
   source venv/bin/activate  # On Windows: venv\Scripts\activate
   ```

2. **Install development dependencies**:
   ```bash
   pip install -e .[dev]
   # OR
   pip install neuraloperator[dev]
   ```


&nbsp;

## Development Workflow

### 1. Create a Branch and Make Changes

```bash
# Create and switch to a new branch
git checkout -b feature/your-feature-name

# Make your changes
# ... edit files ...

# Stage and commit your changes
git add .
git commit -m "Add: brief description of your changes

- More detailed explanation of what you changed
- Why you made these changes
- Any relevant context"

# Push to your fork
git push -u origin feature/your-feature-name
```

### 2. Write Tests

**Always add tests for new functionality!**

- **For models**: Add tests in `neuralop/models/tests/test_your_model.py`
- **For layers**: Add tests in `neuralop/layers/tests/test_your_layer.py`
- **For utilities**: Add tests in the appropriate test directory

**Example test structure:**
```python
import pytest
import torch
from neuralop.models import YourModel

class TestYourModel:
    def test_forward_pass(self):
        model = YourModel(...)
        x = torch.randn(1, 3, 32, 32)
        output = model(x)
        assert output.shape == expected_shape
    
    def test_gradient_flow(self):
        # Test that gradients flow properly
        pass
```

### 3. Run Tests and Quality Checks

```bash
# Run all tests
pytest neuralop

# Run tests with verbose output
pytest neuralop -v

# Run specific test file
pytest neuralop/models/tests/test_your_model.py

# Format code
black .
```

### 4. Submit a Pull Request

Go to your fork on GitHub and click "Compare & pull request". 

Ensure your PR description clearly communicates what you have changed or added.

&nbsp;

## Development Guidelines

### Code Style
- **Follow PEP 8** style guidelines for Python code
- **Use meaningful names** for variables, functions, and classes
- **Write clear docstrings** using NumPy docstring format
- **Add type hints** where appropriate

### Code Formatting
Before submitting, ensure your code follows our style guide:

```bash
# Format with black
black .
```

Validate every update made by the ``black`` command

### Testing Requirements
- **All new code must have tests**
- **Run the full test suite** before submitting PRs
- **Use descriptive test names** that explain what is being tested
- **Test both normal operation and edge cases**
- **Aim for complete code coverage** for new functionality

### Documentation Standards
- **Update relevant documentation** when adding new features
- **Include clear examples** in docstrings
- **Add interactive examples** to the `examples/` directory when possible
- **Follow existing documentation style** and format
- **Include paper references** and mathematical formulations when relevant

### Building Documentation
The HTML documentation is built using Sphinx:

```bash
cd doc
make html
```

This builds the docs in `./doc/build/html`. Note that documentation requires additional dependencies from `./doc/requirements_doc.txt`.

To view documentation locally:
```bash
cd doc/build/html
python -m http.server 8000
# Visit http://localhost:8000
```

### Git Best Practices
- **Write clear, descriptive commit messages**
- **Keep commits focused and atomic** (one logical change per commit)
- **Rebase your branch** on main before submitting PRs
- **Use conventional commit format** when possible (feat:, fix:, docs:, etc.)

&nbsp;

## Adding a New Model or Layer

We welcome various types of contributions:

- **Bug fixes** - Report and fix bugs
- **New features** - Add new models, layers, or datasets
- **Examples** - Create new examples or improve existing ones
- **Performance** - Optimize existing code

### Adding a New Neural Operator Model

To add a new neural operator model:

1. **Create a new file** in `neuralop/models/your_model.py`
2. **Implement the model** as a subclass of `BaseModel`
3. **Add comprehensive tests** in `neuralop/models/tests/test_your_model.py`
4. **Update imports** in the appropriate `__init__.py` files
5. **Add documentation** with examples and mathematical formulations

**Example structure:**
```python
from neuralop.models import BaseModel

class YourModel(BaseModel):
    """Your model docstring here."""
    
    def __init__(self, ...):
        super().__init__()
        # Your implementation
    
    def forward(self, x):
        # Your forward pass
        return x
```

### Adding a New Layer

To add a new layer:

1. **Create a new file** in `neuralop/layers/your_layer.py`
2. **Ensure the layer** is a subclass of `torch.nn.Module`
3. **Add comprehensive tests** in `neuralop/layers/tests/test_your_layer.py`
4. **Update imports** in the appropriate `__init__.py` files

> **💡 Pro Tip**: For bonus points, add an interactive example featuring your new method to `./examples`. This helps both us and you: the simpler it is for new users to understand and adapt your method, the more visibility it will get!

&nbsp;

## Getting Help

### Before Asking for Help
1. **Check the documentation** and existing issues
2. **Search GitHub issues** for similar problems
3. **Provide a minimal reproducible example**
4. **Include error messages** and stack traces
5. **Specify your environment** (OS, Python version, PyTorch version)

### Contact Methods
- **GitHub Issues**: Create an issue for bugs or feature requests
- **GitHub Discussions**: Use for questions and ideas
- **Documentation**: Check the [official documentation](https://neuraloperator.github.io/)

&nbsp;

## Publishing Code Built on the Library

If you plan to use `neuralop` as the base of a project, we suggest the following workflow:

### 1. Set Up Clean Environment
```bash
python -m venv my_project_env
source my_project_env/bin/activate
```

### 2. Install NeuralOperator

**Option A: Latest PyPI release**
```bash
pip install neuralop
```

**Option B: From specific commit (for latest features)**
```bash
# Find commit hash from GitHub commit history
pip install git+https://github.com/neuraloperator/neuraloperator.git@<COMMIT_HASH>
```

### 3. Subclass Functionality

Create your own models by subclassing:

```python
from neuralop.models import FNO

class MyCustomFNO(FNO):
    def __init__(self, custom_param, **kwargs):
        super().__init__(**kwargs)
        self.custom_param = custom_param
        # Add your custom layers here
    
    def forward(self, x):
        # Preprocessing
        x = self.custom_preprocessing(x)
        
        # Use the base FNO forward pass
        x = super().forward(x)
        
        # Postprocessing
        x = self.custom_postprocessing(x)
        
        return x
```

&nbsp;

---

## License

By contributing to NeuralOperator, you agree that your contributions will be licensed as described in the `LICENSE` file in the root directory of this source tree.