Thank you for your interest in contributing to the Cognitive Computing package! This document provides guidelines and instructions for contributing.
- Code of Conduct
- How Can I Contribute?
- Development Setup
- Development Process
- Code Style Guidelines
- Testing Guidelines
- Documentation Guidelines
- Pull Request Process
- Project Structure
- Adding New Features
- Release Process
This project adheres to a Code of Conduct that all contributors are expected to follow:
- Be respectful and inclusive: Welcome newcomers and treat everyone with respect
- Be patient: Remember that everyone was new once
- Be constructive: Provide helpful feedback and suggestions
- Be collaborative: Work together to solve problems
- Be mindful: Consider how your contributions affect others
Report bugs by opening a new issue with:
- A clear, descriptive title
- Steps to reproduce the issue
- Expected vs actual behavior
- Your environment details (OS, Python version, package version)
- Code snippets or error messages
Enhancement suggestions are welcome! Open an issue with:
- Use case description
- Proposed solution
- Alternative solutions considered
- Mockups or examples if applicable
- Fix bugs (look for issues labeled
bug) - Implement new features (check issues labeled
enhancement) - Improve performance
- Add new cognitive computing paradigms
- Fix typos or clarify existing docs
- Add examples and tutorials
- Improve API documentation
- Translate documentation
- Increase test coverage
- Add edge case tests
- Improve test performance
- Add integration tests
# Fork the repository on GitHub, then:
git clone https://github.com/YOUR_USERNAME/cognitive-computing.git
cd cognitive-computing
git remote add upstream https://github.com/cognitive-computing/cognitive-computing.git# Create virtual environment
python -m venv venv
# Activate it
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate# Install in editable mode with all dependencies
pip install -e ".[dev,viz]"
# Install pre-commit hooks
pre-commit install# Update main branch
git checkout main
git pull upstream main
# Create feature branch
git checkout -b feature/your-feature-name- Write clean, documented code
- Follow the style guidelines
- Add tests for new functionality
- Update documentation as needed
# Run all tests
pytest
# Run specific test file
pytest tests/test_sdm/test_core.py
# Run with coverage
pytest --cov=cognitive_computing --cov-report=html
# Run only fast tests
pytest -m "not slow"# Format code with black
black cognitive_computing tests
# Check linting
flake8 cognitive_computing tests
# Type checking
mypy cognitive_computing
# Run all checks
make check # If Makefile is available# Build documentation locally
cd docs
make html
# View at docs/_build/html/index.htmlWe follow PEP 8 with these tools:
- Black for formatting (line length: 88)
- Flake8 for linting
- MyPy for type checking
# Standard library
import os
import sys
from typing import List, Optional
# Third-party
import numpy as np
import matplotlib.pyplot as plt
# Local imports
from cognitive_computing.common.base import CognitiveMemoryUse NumPy-style docstrings:
def compute_similarity(pattern1: np.ndarray, pattern2: np.ndarray) -> float:
"""
Compute similarity between two binary patterns.
Parameters
----------
pattern1 : np.ndarray
First binary pattern
pattern2 : np.ndarray
Second binary pattern
Returns
-------
float
Similarity score between 0 and 1
Examples
--------
>>> p1 = np.array([1, 0, 1, 0])
>>> p2 = np.array([1, 0, 0, 1])
>>> compute_similarity(p1, p2)
0.5
"""Always use type hints:
from typing import List, Optional, Tuple, Union
def process_data(
data: np.ndarray,
threshold: float = 0.5,
return_indices: bool = False
) -> Union[np.ndarray, Tuple[np.ndarray, List[int]]]:
...class NewDecoder(AddressDecoder):
"""One-line summary.
Longer description of the decoder and its purpose.
Parameters
----------
config : DecoderConfig
Configuration parameters
Attributes
----------
some_attribute : type
Description
"""
def __init__(self, config: DecoderConfig):
super().__init__(config)
self._private_attribute = None
def public_method(self) -> None:
"""Public methods have docstrings."""
pass
def _private_method(self) -> None:
# Private methods use comments
pass- Classes:
CamelCase - Functions/Methods:
snake_case - Constants:
UPPER_CASE - Private:
_leading_underscore
import pytest
import numpy as np
from cognitive_computing.sdm import SDM
class TestSDMFeature:
"""Group related tests in classes."""
@pytest.fixture
def sample_sdm(self):
"""Provide test fixture."""
return SDM(SDMConfig(dimension=256))
def test_basic_functionality(self, sample_sdm):
"""Test names should be descriptive."""
# Arrange
pattern = np.random.randint(0, 2, 256)
# Act
sample_sdm.store(pattern, pattern)
# Assert
recalled = sample_sdm.recall(pattern)
assert np.array_equal(recalled, pattern)
def test_edge_case(self):
"""Test edge cases and error conditions."""
with pytest.raises(ValueError, match="Invalid dimension"):
SDM(SDMConfig(dimension=0))- All new features must have tests
- Maintain or increase code coverage (aim for >90%)
- Include both unit and integration tests
- Test edge cases and error conditions
- Use meaningful test names
@pytest.mark.slow
def test_large_scale_performance():
"""Mark slow tests that can be skipped."""
# Test with large parameters
pass
@pytest.mark.benchmark
def test_operation_speed(benchmark):
"""Use pytest-benchmark for performance tests."""
result = benchmark(function_to_test, arg1, arg2)- All public APIs must have docstrings
- Complex algorithms should have explanatory comments
- Mathematical formulas should include references
When adding new features:
- Update relevant
.mdfiles indocs/ - Add examples to example scripts
- Update the README if needed
- Add to API reference
def new_feature(data: np.ndarray) -> np.ndarray:
"""
Short description of the feature.
Longer explanation of what the feature does, why it's useful,
and any important details users should know.
.. math::
f(x) = \\sum_{i=1}^{n} x_i^2
Parameters
----------
data : np.ndarray
Description of the parameter
Returns
-------
np.ndarray
Description of the return value
See Also
--------
related_function : Brief description
References
----------
.. [1] Author, "Paper Title," Journal, 2023.
Examples
--------
>>> data = np.array([1, 2, 3, 4])
>>> result = new_feature(data)
>>> print(result)
[1 4 9 16]
"""- All tests pass locally
- Code follows style guidelines
- Documentation is updated
- Commit messages are clear
- Branch is up to date with main
Title Format: [TYPE] Brief description
Types:
[FEAT]- New feature[FIX]- Bug fix[DOCS]- Documentation only[TEST]- Test only[PERF]- Performance improvement[REFACTOR]- Code refactoring
Description Template:
## Description
Brief description of changes
## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
## Testing
- [ ] All tests pass
- [ ] New tests added
- [ ] Coverage maintained/increased
## Checklist
- [ ] Code follows style guidelines
- [ ] Self-review completed
- [ ] Documentation updated
- [ ] No new warnings- Respond to feedback constructively
- Make requested changes
- Re-request review when ready
- Delete your feature branch
- Update your local main branch
- Celebrate! 🎉
Understanding the project structure helps when contributing:
cognitive-computing/
├── cognitive_computing/
│ ├── common/ # Shared base classes
│ ├── sdm/ # Sparse Distributed Memory
│ ├── hrr/ # Holographic Reduced Representations (future)
│ ├── vsa/ # Vector Symbolic Architectures (future)
│ └── hdc/ # Hyperdimensional Computing (future)
├── tests/ # Test suite
├── docs/ # Documentation
├── examples/ # Example scripts
└── benchmarks/ # Performance benchmarks
- Create file:
cognitive_computing/sdm/decoders/new_decoder.py - Implement the decoder:
from cognitive_computing.sdm.address_decoder import AddressDecoder
class NewDecoder(AddressDecoder):
def decode(self, address: np.ndarray) -> np.ndarray:
# Implementation
pass- Add tests:
tests/test_sdm/test_new_decoder.py - Update
__init__.pyto export the decoder - Add documentation and examples
- Create new module:
cognitive_computing/new_paradigm/ - Implement base classes following existing patterns
- Add comprehensive tests
- Create documentation
- Add examples
We follow Semantic Versioning:
- MAJOR: Incompatible API changes
- MINOR: New functionality (backwards compatible)
- PATCH: Bug fixes (backwards compatible)
- Update version in
cognitive_computing/version.py - Update CHANGELOG.md
- Run full test suite
- Build and test documentation
- Create release PR
- Tag release after merge
- Build and upload to PyPI
- Check existing issues and PRs
- Read the documentation
- Ask questions in issues (label:
question) - Join discussions in the community
Contributors are recognized in:
- The AUTHORS file
- Release notes
- Project documentation
Thank you for contributing to Cognitive Computing! Your efforts help advance the field of brain-inspired computing.