A powerful Python library for micromagnetic simulation analysis and visualization
π Documentation β’ π Getting Started β’ π― Features β’ π‘ Examples
|
|
|
|
|
# Install from PyPI (recommended)
pip install mmpp
# Or install latest development version
pip install git+https://github.com/MateuszZelent/mmpp.git
import mmpp
# π Load simulation data
op = mmpp.MMPP('path/to/simulation.zarr')
# π Single file analysis with auto-selection
result = op[0]
fft_analyzer = result.fft
# π€ Auto-dataset selection (NEW!) - automatically chooses largest m_z dataset
spectrum = fft_analyzer.spectrum() # Uses auto-selection
power_spectrum = fft_analyzer.power() # Uses auto-selection
# π― Or specify dataset explicitly
spectrum = fft_analyzer.spectrum(dset='m_z5-8')
# β‘ Batch processing
batch = op[:] # Get all results
modes = batch.fft.modes.compute_modes(parallel=True) # Auto-selection in batch too
MMPP now includes intelligent dataset auto-selection that automatically chooses the best magnetization dataset for analysis:
# β¨ NEW: Auto-selection API (recommended)
result = op[0]
fft_analyzer = result.fft
# No need to specify dataset - MMPP chooses the largest m_z dataset automatically
spectrum = fft_analyzer.spectrum()
power_spectrum = fft_analyzer.power()
modes = fft_analyzer.modes.compute_modes()
# π Check which dataset was auto-selected
selected_dataset = result.get_largest_m_dataset()
print(f"Auto-selected dataset: {selected_dataset}") # e.g., "m_z5-8"
# π Traditional API still works for manual control
spectrum = fft_analyzer.spectrum(dset='m_z5-8')
Benefits:
- π― Simplified API: No need to remember dataset names
- π Intelligent Selection: Automatically finds the best dataset
- π Backward Compatible: Existing code continues to work
- π Consistent Results: Always uses the dataset with most data points
Process multiple simulation files efficiently:
# π Process all files in a directory
op = mmpp.MMPP('simulation_results/')
batch = op[:]
# β‘ Parallel FFT analysis with auto-selection (NEW!)
modes = batch.fft.modes.compute_modes(parallel=True) # Auto-selects best dataset
# οΏ½ Or specify dataset explicitly for batch operations
modes = batch.fft.modes.compute_modes(dset='m_z5-8', parallel=True)
# π Complete analysis in one call (NEW!)
results = batch.process(parallel=True, max_workers=4) # FFT + mode analysis
print(f"Processed {results['successful']}/{results['total']} files successfully")
Comprehensive frequency domain analysis:
# π€ Auto-selection (NEW!) - Let MMPP choose the best dataset
spectrum = fft_analyzer.spectrum() # Automatically selects largest m_z dataset
power_spectrum = fft_analyzer.power()
frequencies = fft_analyzer.frequencies()
modes = fft_analyzer.modes.compute_modes()
# π― Manual dataset selection (traditional approach)
spectrum = fft_analyzer.spectrum(dset='m_z5-8')
power_spectrum = fft_analyzer.power(dset='m_z5-8')
frequencies = fft_analyzer.frequencies(dset='m_z5-8')
modes = fft_analyzer.modes.compute_modes(dset='m_z5-8')
# π¬ Plot mode visualizations at specific frequency
plot_result = fft_analyzer.plot_modes(frequency=10.5) # Auto-selection
plot_result = fft_analyzer.plot_modes(frequency=10.5, dset='m_z5-8') # Manual
Create stunning plots with built-in themes:
# π Custom styled plots
import mmpp.plotting as mplt
mplt.plot_spectrum(spectrum, style='publication')
# π¨ Interactive visualizations
mplt.interactive_plot(data, colormap='viridis')
# πΎ Export in multiple formats
mplt.save_figure('spectrum.png', dpi=300, format='png')
# Enable parallel processing for batch operations
modes = batch.fft.modes.compute_modes(parallel=True)
# Control number of workers
modes = batch.fft.modes.compute_modes(parallel=True, max_workers=4)
# Let MMPP choose the optimal dataset automatically
spectrum = fft_analyzer.spectrum() # Faster than manual selection
# Process large datasets in chunks to manage memory usage
op = mmpp.MMPP('large_simulation_directory/')
batch_size = 50 # Process 50 results at a time
print(f"Total files: {len(op)}")
for i in range(0, len(op), batch_size):
chunk = op[i:i+batch_size]
results = chunk.process(parallel=True, max_workers=4)
chunk_num = i//batch_size + 1
total_chunks = (len(op) + batch_size - 1) // batch_size
print(f"Chunk {chunk_num}/{total_chunks}: {results['successful']}/{results['total']} successful "
f"({results['computation_time']:.1f}s)")
# Optional: Clear memory or save intermediate results
if results['failed'] > 0:
print(f"β οΈ {results['failed']} files failed in chunk {chunk_num}")
# Load only what you need
result = op[0] # Single result
specific_results = op.find(solver=3, amp_values=0.0022) # Filtered results
Typical performance on a modern system (16GB RAM, 8-core CPU):
Operation | Single File | Batch (10 files) | Parallel Batch |
---|---|---|---|
Load Data | ~0.1s | ~1.0s | ~0.3s |
FFT Analysis | ~2.0s | ~20s | ~5s |
Mode Computation | ~5.0s | ~50s | ~12s |
Performance varies significantly based on dataset size and system specifications.
Resource | Description | Link |
---|---|---|
π Documentation | Complete API reference and tutorials | GitHub Pages |
π Tutorials | Step-by-step guides and examples | Tutorials |
π¬ API Reference | Detailed function documentation | API Docs |
π Getting Started | Quick start guide | Getting Started |
ποΈ PyZFN Library | ZFN file format handling (dependency) | PyZFN by Mathieu Moalic |
# Quick build and serve
./build_docs.sh --serve
# Manual build
cd docs
pip install sphinx sphinx-rtd-theme myst-parser sphinx-autodoc-typehints
sphinx-build -b html . _build
pip install mmpp
git clone https://github.com/MateuszZelent/mmpp.git
cd mmpp
pip install -e ".[dev]"
# Interactive Jupyter support
pip install mmpp[interactive]
# Enhanced plotting capabilities
pip install mmpp[plotting]
# Full development environment
pip install mmpp[dev]
- π Python β₯3.9
- π’ NumPy β₯1.20.0
- πΌ Pandas β₯1.3.0
- π Matplotlib β₯3.5.0
- ποΈ PyZFN - ZFN file format handling (Mathieu Moalic)
- β‘ Zarr - High-performance data storage
- π¨ Rich - Beautiful terminal output
- π TQDM - Progress bars
- πͺ Jupyter Ecosystem (
itables
,IPython
,jupyter
) - π Enhanced Plotting (
cmocean
,seaborn
) - π§ͺ Development Tools (
pytest
,ruff
,mypy
)
- π§ Linux (Ubuntu 18.04+, CentOS 7+, etc.)
- π macOS (10.14+)
- πͺ Windows (10+)
- RAM: 8GB minimum, 16GB+ recommended for large datasets
- Storage: SSD recommended for better I/O performance
- CPU: Multi-core processor recommended for parallel operations
- β Python 3.9 - Minimum supported version
- β Python 3.10 - Fully supported
- β Python 3.11 - Fully supported
β οΈ Python 3.12 - Beta support (some dependencies may vary)
For developers and advanced users, additional documentation is available:
- Complete FFT API Analysis - Detailed technical analysis of FFT functionality
- FFT API Verification - Verification of all FFT examples and methods
- Detailed FFT Analysis - In-depth FFT implementation details
- Performance Optimization - Performance enhancement strategies
- Smart Legend Documentation - Advanced plotting features
- GitHub Pages Setup - Documentation deployment guide
- Workflow Fixes - Development workflow improvements
We welcome contributions! Here's how you can help:
Type | Description | Action |
---|---|---|
π Bug Reports | Found an issue? | Open Issue |
π‘ Feature Requests | Have an idea? | Discussion |
π§ Pull Requests | Want to contribute code? | Contributing Guide |
π Documentation | Improve the docs | Edit on GitHub |
# Fork and clone the repository
git clone https://github.com/MateuszZelent/mmpp.git
cd mmpp
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest tests/
# Check code style
ruff check mmpp/
ruff format --check mmpp/
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with β€οΈ by MateuszZelent
- Powered by the amazing Python scientific computing ecosystem
- PyZFN integration: Utilizes components from PyZFN by Mathieu Moalic for efficient ZFN file handling
- Special thanks to all contributors and users
β Star this repo if you find it useful! β
Report Bug β’ Request Feature β’ Documentation
A: MMPP automatically identifies and selects the largest magnetization dataset (m_z*) in your simulation files. This ensures you're always working with the most comprehensive data available.
A: Yes! The auto-selection feature is backward compatible. You can still specify datasets manually using the dset
parameter in any method.
A: Use the parallel=True
parameter in batch operations:
batch.fft.modes.compute_modes(parallel=True)
A: Make sure you have all dependencies installed:
pip install mmpp[dev] # For full functionality
A: MMPP primarily works with Zarr archives (.zarr) from micromagnetic simulations. The library is optimized for this format's high-performance capabilities.
# Problem: ModuleNotFoundError
# Solution: Install missing dependencies
pip install mmpp[dev]
# Problem: Out of memory errors
# Solution: Process data in chunks or use batch operations
batch_size = 10
for chunk in op.chunks(batch_size):
results = chunk.fft.modes.compute_modes()
# Problem: Slow FFT computation
# Solution: Use parallel processing
modes = batch.fft.modes.compute_modes(parallel=True, max_workers=4)
If you encounter issues:
- Check the Documentation: GitHub Pages
- Search Issues: GitHub Issues
- Ask Questions: GitHub Discussions
- Contact: mateusz.zelent@amu.edu.pl