### Install Documentation Dependencies
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/documentation.md
Install the necessary Python dependencies to build the documentation locally.
```bash
pip install '.[docs]'
```
--------------------------------
### Install Pre-Commit Hooks
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/environment.md
Install pre-commit hooks to ensure code quality and consistency. These hooks run automatically before each commit.
```bash
pre-commit install
```
--------------------------------
### Install Project Dependencies
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/environment.md
Install all project dependencies using pip. Use the `.[dev]` option to include development-specific dependencies.
```bash
pip install -e .
```
```bash
pip install -e '.[dev]'
```
--------------------------------
### Install Anemoi via Repository
Source: https://github.com/ecmwf/anemoi/blob/main/README.md
Clone the repository and perform an editable installation of the dependencies.
```bash
$ git clone https://github.com/ecmwf/anemoi-transform.git
$ cd anemoi-transform
$ pip install -e
```
--------------------------------
### Example Build Output
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/documentation.md
Terminal output indicating a successful Sphinx build process.
```text
Running Sphinx v8.1.3
loading translations [en]... done
[...]
writing additional pages... search done
dumping search index in English (code: en)... done
dumping object inventory... done
build succeeded, 1 warning.
```
--------------------------------
### Install Anemoi via PyPI
Source: https://github.com/ecmwf/anemoi/blob/main/README.md
Install individual Anemoi packages directly from the Python Package Index.
```bash
$ pip install anemoi-transform
```
--------------------------------
### Install Anemoi Package
Source: https://github.com/ecmwf/anemoi/blob/main/docs/getting-started/installing.md
Use this command to install any Anemoi package from PyPI. Replace `{package}` with the specific package name, such as `datasets` or `training`.
```bash
pip install anemoi-{package}
```
--------------------------------
### Install Testing Dependencies
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/testing.md
Installs the necessary dependencies for running Anemoi tests, including optional testing packages.
```bash
pip install -e .[test]
```
--------------------------------
### Module Docstring Example
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/documentation.md
Standard format for module-level docstrings following the NumPy style.
```python
"""
Module for building and managing reduced Gaussian grid nodes.
This module provides functionality to create and manipulate nodes based on
ECMWF's reduced Gaussian grid system, supporting both original and octahedral
grid types.
"""
```
--------------------------------
### Run Pre-Commit Hooks on All Files
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/environment.md
Run pre-commit hooks on all files in the repository to verify the installation and check for any code quality issues.
```bash
pre-commit run --all-files
```
--------------------------------
### Function Docstring Format
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/documentation.md
Functions should include parameters, return types, and usage examples.
```python
def get_coordinates(self) -> torch.Tensor:
"""Get the coordinates of the nodes.
Returns
-------
torch.Tensor
A tensor of shape (num_nodes, 2) containing the latitude and longitude
coordinates in radians.
Examples
--------
>>> nodes = ReducedGaussianGridNodes("O640", "data")
>>> coords = nodes.get_coordinates()
>>> print(coords.shape)
torch.Size([6599680, 2])
"""
```
--------------------------------
### Install GitHub Token in .env
Source: https://github.com/ecmwf/anemoi/blob/main/tools/README.md
Add your GitHub token to the .env file to authenticate API requests. Ensure the token has 'repo' scope for repository access.
```shell
GITHUB_TOKEN=xxxxx
```
--------------------------------
### Conventional Commits Examples
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/guidelines.md
Examples of commit message formats following Conventional Commits guidelines, including type, scope, and breaking change indicators.
```text
feat(training): add new loss function
```
```text
fix(graphs): resolve node indexing bug
```
```text
docs(readme): update installation steps
```
```text
feat(models)!: change model input format
```
```text
refactor!: restructure project layout
```
--------------------------------
### Example Test Structure with Pytest
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/testing.md
Demonstrates a basic test structure using pytest, including testing normal input and handling expected exceptions for edge cases.
```python
import pytest
from anemoi.training import SomeFeature
def test_some_feature_normal_input():
feature = SomeFeature()
result = feature.process(normal_input)
assert result == expected_output
def test_some_feature_edge_case():
feature = SomeFeature()
with pytest.raises(ValueError):
feature.process(invalid_input)
```
--------------------------------
### Referencing Issues in Commit Messages
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/guidelines.md
Example of how to reference a relevant issue number within a commit message.
```text
fix: resolve data loading issue #123
```
--------------------------------
### Run Integration Tests with Slow Flag
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/testing.md
Executes integration tests, including those marked as slow-running, using the --slow flag. This example is specific to anemoi-training.
```bash
pytest training/tests/integration/ --slow
```
--------------------------------
### Define Pytest Fixtures
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/testing.md
Utilize fixtures to manage setup and teardown of common test data or objects required by test functions.
```python
@pytest.fixture
def sample_dataset():
# Create and return a sample dataset
pass
def test_data_loading(sample_dataset):
# Use the sample_dataset fixture in your test
pass
```
--------------------------------
### Build Documentation Locally
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/documentation.md
Navigate to the docs directory and execute the make command to generate HTML documentation.
```bash
cd docs
make html
```
--------------------------------
### Serve Documentation Locally
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/documentation.md
Serve the generated HTML files using a local Python HTTP server.
```bash
cd docs/_build/html
python -m http.server
```
--------------------------------
### Open Local Documentation
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/documentation.md
Commands to open the generated index.html file in a web browser based on the operating system.
```bash
open docs/_build/html/index.html # macOS
xdg-open docs/_build/html/index.html # Linux
start docs/_build/html/index.html # Windows
```
--------------------------------
### Private Method Documentation
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/documentation.md
Basic documentation is required for private methods, including exception details.
```python
def _validate_grid(self) -> None:
"""Validate the grid identifier format.
Raises
------
ValueError
If grid identifier doesn't match expected format
"""
```
--------------------------------
### Property Docstring Format
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/documentation.md
Properties require concise documentation.
```python
@property
def num_nodes(self) -> int:
"""Number of nodes in the grid."""
return len(self.coordinates)
```
--------------------------------
### Build the Test Suite
Source: https://github.com/ecmwf/anemoi/blob/main/tests/system-level/README.md
Builds the anemoi_test suite in the specified output directory.
```bash
./build.sh -s OUTPUT_ROOT_SUITE=desired-output-dir
```
--------------------------------
### Load Suite Definition to Ecflow Server
Source: https://github.com/ecmwf/anemoi/blob/main/tests/system-level/README.md
Loads the generated suite definition file into the ecflow server.
```bash
ecflow_client --load={USER}.def
```
--------------------------------
### Test Configuration Changes
Source: https://github.com/ecmwf/anemoi/blob/main/tests/system-level/README.md
Builds the suite using a specific branch of the anemoi repository to test configuration modifications.
```bash
./build.sh -s OUTPUT_ROOT_SUITE=$SCRATCH/workdir anemoi_branch=name-of-your-branch
```
--------------------------------
### Type Hinting and Documentation
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/documentation.md
Combine docstrings with type hints to improve code clarity and error detection.
```python
def register_nodes(
self, graph: HeteroData, attrs_config: dict[str, dict] | None = None
) -> HeteroData:
"""Register nodes in the graph with optional attributes.
Parameters
----------
graph : HeteroData
The graph to add nodes to
attrs_config : dict[str, dict] | None
Configuration for node attributes
Returns
-------
HeteroData
The updated graph with new nodes
"""
```
--------------------------------
### Update Training Configurations
Source: https://github.com/ecmwf/anemoi/blob/main/tests/system-level/README.md
Updates training config files in the system-level tests folder using a helper script from anemoi-training.
```bash
python training/tests/integration/scripts/update_slt_configs.py PATH_TO_YOUR_ANEMOI_REPO
```
--------------------------------
### Configure Additional Build Options
Source: https://github.com/ecmwf/anemoi/blob/main/tests/system-level/README.md
Overrides default build options such as the anemoi-datasets branch.
```bash
./build.sh -s OUTPUT_ROOT_SUITE=$SCRATCH/workdir anemoi_datasets_branch=name-of-your-branch
```
--------------------------------
### Verify Upstream Remote Configuration
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/environment.md
Verify that the upstream remote has been configured correctly to prevent pushes. This command shows the fetch and push URLs for all remotes.
```bash
git remote -v
```
--------------------------------
### Run Specific Unit Test File
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/testing.md
Executes unit tests located in a specific file.
```bash
pytest tests/unit/test_specific_feature.py
```
--------------------------------
### Cross-Reference Documentation
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/documentation.md
Use specific syntax to link to internal sections or external documentation.
```python
"""
Process nodes in the graph.
See Also
--------
:ref:`graphs-post-processor` : Documentation about post-processing nodes
`PyG Documentation `_ : External docs
anemoi.graphs.nodes.TriNodes : Reference to another class
"""
```
--------------------------------
### Run All Unit Tests
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/testing.md
Executes all unit tests in the Anemoi project using pytest.
```bash
pytest
```
--------------------------------
### Documentation Standards
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/documentation.md
Standardized formats for documenting Python classes, functions, properties, and private methods within the Anemoi codebase.
```APIDOC
## Python Documentation Standards
### Class Docstrings
Classes should include a summary, attributes list, methods list, and notes section.
### Function Docstrings
Functions should include a summary, parameters, return values, and usage examples.
### Property Docstrings
Properties should have concise, clear descriptions.
### Type Hints
Combine docstrings with Python type hints for improved clarity and error checking.
### Private Methods
Even private methods (prefixed with _) require basic documentation, including any exceptions raised.
### Cross-Referencing
Use :ref:`section-name` for internal links and `Title `_ for external documentation.
```
--------------------------------
### Class Docstring Format
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/documentation.md
Classes require detailed docstrings including attributes, methods, and notes sections.
```python
class ReducedGaussianGridNodes:
"""Nodes from a reduced gaussian grid.
A gaussian grid is a latitude/longitude grid. The spacing of the latitudes
is not regular. However, the spacing of the lines of latitude is
symmetrical about the Equator.
Attributes
----------
grid : str
The reduced gaussian grid identifier (e.g., 'O640')
name : str
Unique identifier for the nodes in the graph
Methods
-------
get_coordinates()
Get the lat-lon coordinates of the nodes.
register_nodes(graph, name)
Register the nodes in the graph.
Notes
-----
The grid identifier format follows ECMWF conventions:
- 'N' prefix for original reduced Gaussian grid
- 'O' prefix for octahedral reduced Gaussian grid
- Number indicates latitude lines between pole and equator
For example, 'O640' represents an octahedral grid with 640
latitude lines between pole and equator.
"""
```
--------------------------------
### Run Tests Locally
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/guidelines.md
Execute all tests using pytest before submitting pull requests to ensure code correctness.
```bash
pytest
```
--------------------------------
### Mark Slow Integration Tests
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/testing.md
Apply the slow marker to integration tests to allow selective execution during test runs.
```python
@pytest.mark.slow
def test_long():
pass
```
--------------------------------
### Measure Test Coverage
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/testing.md
Execute tests with coverage reporting enabled using the pytest-cov plugin.
```bash
pytest --cov=anemoi_training
```
--------------------------------
### Parametrize Pytest Tests
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/testing.md
Use the parametrize decorator to execute the same test function with multiple input and expected output pairs.
```python
@pytest.mark.parametrize(
"input,expected",
[
(2, 4),
(3, 9),
(4, 16),
],
)
def test_square(input, expected):
assert square(input) == expected
```
--------------------------------
### Prevent Accidental Pushes to Upstream
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/environment.md
Configure the upstream remote to prevent accidental pushes. This ensures you can fetch updates but not push directly to the original repository.
```bash
git remote set-url --push upstream no_push
```
--------------------------------
### Mock External Dependencies
Source: https://github.com/ecmwf/anemoi/blob/main/docs/contributing/testing.md
Use pytest-mock to patch external functions or objects, such as API calls, to isolate test logic.
```python
def test_api_call(mocker):
mock_response = mocker.Mock()
mock_response.json.return_value = {"data": "mocked"}
mocker.patch("requests.get", return_value=mock_response)
result = my_api_function()
assert result == "mocked"
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.