Thank you for your interest in contributing to the Spintronics library! This document provides guidelines and information for contributors.
- Getting Started
- Development Setup
- Code Guidelines
- Physics Guidelines
- Testing
- Pull Request Process
- Code of Conduct
- Rust 1.70.0 or later
- Git
- Basic knowledge of condensed matter physics (for physics-related contributions)
git clone https://github.com/cool-japan/spintronics.git
cd spintronics
cargo build
cargo test# Run all tests
cargo test
# Run tests with all features
cargo test --all-features
# Run specific test module
cargo test material::ferromagnet
# Run tests with output
cargo test -- --nocaptureWe enforce code quality with clippy and rustfmt:
# Check formatting
cargo fmt --all -- --check
# Run clippy (with warnings as errors)
cargo clippy --all-features -- -D warnings
# Auto-format code
cargo fmt --allcargo doc --no-deps --all-features --open- Physics First: Always validate against physical intuition and experimental data
- Type Safety: Use Rust's type system to prevent unphysical states
- Performance: Profile before optimizing; correctness > speed
- Simplicity: Prefer simple solutions over clever ones
- Follow standard Rust naming conventions:
snake_casefor functions and variablesCamelCasefor types and traitsSCREAMING_SNAKE_CASEfor constants
- Use meaningful variable names that reflect physics (e.g.,
magnetization,spin_current) - Prefer explicit types in public APIs
- Document all public items with
///doc comments
- Implement
Defaultfor types with sensible defaults - Implement
Displayfor types that users might print - Use builder pattern for complex configuration
- Prefer
&selfmethods over consuming methods where possible - Return
Result<T, E>instead of panicking
/// Ferromagnetic material properties
///
/// # Example
/// ```
/// use spintronics::material::Ferromagnet;
///
/// let yig = Ferromagnet::yig();
/// println!("Damping: {}", yig.damping());
/// ```
#[derive(Debug, Clone)]
pub struct Ferromagnet {
/// Gilbert damping constant (dimensionless)
pub alpha: f64,
// ... other fields
}
impl Default for Ferromagnet {
fn default() -> Self {
Self::yig()
}
}Every physics function should include:
- LaTeX equations in doc comments where applicable
- Physical units clearly specified in brackets (e.g.,
[A/m],[J/m³]) - References to relevant papers
- Physical interpretation explaining the meaning
Example:
/// Calculate the effective field from anisotropy
///
/// The uniaxial anisotropy field is given by:
///
/// $$
/// \mathbf{H}_{\text{ani}} = \frac{2K}{\mu_0 M_s} (\mathbf{m} \cdot \hat{n}) \hat{n}
/// $$
///
/// # Arguments
/// * `magnetization` - Normalized magnetization direction
/// * `k` - Anisotropy constant [J/m³]
/// * `ms` - Saturation magnetization [A/m]
/// * `easy_axis` - Easy axis direction (normalized)
///
/// # Returns
/// Effective anisotropy field [A/m]
///
/// # References
/// - Kittel, "Introduction to Solid State Physics", Ch. 15
pub fn anisotropy_field(/* ... */) -> Vector3<f64> {
// ...
}- Use constants from
crate::constantsmodule - Include NIST reference values with appropriate precision
- Document the physical meaning of each constant
- Compare results with published experimental data
- Include validation tests that check against known results
- Document any approximations or limitations
- Unit Tests: Test individual functions in isolation
- Integration Tests: Test module interactions
- Doc Tests: Ensure examples in documentation work
- Physics Validation: Compare with experimental/theoretical results
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_physical_quantity() {
let material = Ferromagnet::yig();
let result = material.some_calculation();
// Use appropriate tolerances for floating point
assert!((result - expected).abs() < 1e-10);
}
#[test]
fn test_against_experiment() {
// Reference: Saitoh et al., APL 88, 182509 (2006)
let expected_voltage = 1.0e-6; // 1 μV
let calculated = spin_pumping_voltage(/* ... */);
// Within 10% of experimental value
assert!((calculated - expected_voltage).abs() / expected_voltage < 0.1);
}
}- Ensure all tests pass:
cargo test --all-features - Run clippy with no warnings:
cargo clippy --all-features -- -D warnings - Format code:
cargo fmt --all - Update documentation if needed
- Add tests for new functionality
Include in your PR description:
- What: Brief description of changes
- Why: Motivation and context
- How: Technical approach (if non-obvious)
- Testing: How you tested the changes
- References: Any relevant papers or resources
- PRs require at least one approving review
- All CI checks must pass
- Address reviewer feedback constructively
- Squash commits before merging (if requested)
- Be respectful and inclusive
- Focus on constructive feedback
- Accept criticism gracefully
- Prioritize the project's best interests
Report unacceptable behavior by opening an issue or contacting the maintainers directly.
- Open a GitHub issue for bugs or feature requests
- Start a GitHub discussion for questions
- Check existing issues before creating new ones
Thank you for contributing to Spintronics!