Code Structure

Understanding and maintaining the code structure is crucial for sustainable development of Anemoi Graphs. This guide outlines best practices for contributing to the codebase.

Subclassing for New Features

When creating a new feature, the recommended practice is to subclass existing base classes rather than modifying them directly. This approach preserves functionality for other users while allowing for customization.

Example:

In anemoi/graphs/nodes/builder.py, the BaseNodeBuilder class serves as a foundation to define new sets of nodes. New node builders should subclass this base class.

File Organization

When developing multiple new functions for a feature:

  1. Create a new file in the folder (e.g., edges/builder/<new_edge_builder>.py) to avoid confusion with base functions.

  2. Group related functionality together for better organization and maintainability.

Version Control Best Practices

  1. Always use pre-commit hooks to ensure code quality and consistency.

  2. Never commit directly to the develop branch.

  3. Create a new branch for your feature or bug fix, e.g., feature/<feature_name> or bugfix/<bug_name>.

  4. Submit a Pull Request from your branch to develop for peer review and testing.

Code Style and Documentation

  1. Follow PEP 8 guidelines for Python code style, the pre-commit hooks will help enforce this.

  2. Write clear, concise docstrings for all classes and functions using the Numpy style.

  3. Use type hints to improve code readability and catch potential errors.

  4. Add inline comments for complex logic or algorithms.

Testing

  1. Write unit tests for new features using pytest.

  2. Ensure all existing tests pass before submitting a Pull Request.

  3. Aim for high test coverage, especially for critical functionality.

Performance Considerations

  1. Profile your code to identify performance bottlenecks.

  2. Optimize critical paths and frequently called functions.

  3. Consider using vectorized operations when working with large datasets.

By following these guidelines, you’ll contribute to a maintainable and robust codebase for Anemoi Graphs.