Skip to main content

A neural adjoint method implementation

Project description

MM-Neural-Adjoint

A Python package implementing neural adjoint methods, specifically designed for predicting the geometries of metamaterials. This implementation is based on the work from BDIMNNA (Benchmarking Deep Inverse Models over time, and the Neural-Adjoint method), published in NeurIPS 2020 by Simiao Ren, Willie J. Padilla and Jordan Malof.

About

This package focuses on the Neural Adjoint (NA) method for inverse design of metamaterials. It provides a streamlined implementation specifically optimized for metamaterial geometry prediction tasks, building upon the benchmarking work done in the original BDIMNNA repository.

Installation

This package supports different hardware configurations including CPU, Apple Silicon (M1/M2), and NVIDIA GPUs. Choose the appropriate installation method based on your hardware:

Basic Installation (CPU/Apple Silicon)

pip install MM-neural-adjoint

Usage

Basic Usage

Here's a simple example of how to use the package:

from mm_neural_adjoint import NANetwork, ConvModel, LinModel
import torch
from torch.utils.data import DataLoader, TensorDataset

# Initialize the model
geometry_size = 8  # Input size (geometry parameters)
spectrum_size = 300  # Output size (spectrum parameters)

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

# This can be any well defined torch model.
model = LinModel(geometry_size, spectrum_size)

model = NANetwork(
    model=model
    device=device
)

model.train(
    epochs=100,
    train_loader=train_loader,
    val_loader=val_loader
)

MLflow Integration

The package uses MLflow for experiment tracking and model management. By default, MLflow data is stored in a local SQLite database (mlflow.db). Here's how to use MLflow features:

import mlflow
from mm_neural_adjoint import NANetwork

# Set a custom experiment name
model = NANetwork(
    model=model,
    device=device,
    mlflow_exp_name="my_experiment"  # Custom experiment name
)

# Training will automatically log:
# - Training loss
# - Validation loss
# - Best validation loss
# - Total training time
# - Model parameters
model.train(
    epochs=100,
    train_loader=train_loader,
    val_loader=val_loader
)

# View MLflow UI
# Run this command in your terminal:
# mlflow ui

MLflow Features

  1. Automatic Logging:

    • Training metrics (loss, validation loss)
    • Model parameters
    • Training duration
    • Model checkpoints
  2. Experiment Organization:

    • Each training run is tracked as a separate experiment
    • Experiments are named using timestamps by default
    • Custom experiment names can be set during model initialization
  3. Model Checkpoints:

    • Best models are automatically saved
    • Checkpoints are stored in the checkpoints/ directory
    • MLflow tracks the relationship between metrics and checkpoints
  4. Viewing Results:

    # Start MLflow UI
    mlflow ui --backend-store-uri sqlite:///mlflow.db
    
    # Access the UI at http://localhost:5000
    
  5. Custom Logging:

    # Add custom metrics during training
    with mlflow.start_run():
        mlflow.log_param("learning_rate", 0.001)
        mlflow.log_metric("custom_metric", value)
    

Requirements

  • Python >= 3.10
  • PyTorch >= 2.6.0
  • NumPy >= 2.2.4
  • Pandas >= 2.2.3
  • tqdm >= 4.67.1
  • MLflow >= 2.21.3
  • scikit-learn >= 1.4.0

Examples

The package includes several example notebooks in the examples/ directory:

  • examples/example1.ipynb: Basic usage and training
  • examples/example2.ipynb: Advanced features and customization

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

This package is based on the Neural Adjoint implementation from the BDIMNNA repository by Benson Ren et al. We thank the original authors for their foundational work in developing and benchmarking the Neural Adjoint method.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mm_neural_adjoint-0.1.19.tar.gz (420.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mm_neural_adjoint-0.1.19-py2.py3-none-any.whl (12.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file mm_neural_adjoint-0.1.19.tar.gz.

File metadata

  • Download URL: mm_neural_adjoint-0.1.19.tar.gz
  • Upload date:
  • Size: 420.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for mm_neural_adjoint-0.1.19.tar.gz
Algorithm Hash digest
SHA256 f4020abd1614c0458ab1be81066bbd4e049caf372d13ff5632a27cac4bab9899
MD5 3051ad6a21e6d35a28555719b809c37e
BLAKE2b-256 c7f5fedfb3b5a80e266c972a6bfab6dcdfbce8276d05eb26d3ae450c81e4f131

See more details on using hashes here.

File details

Details for the file mm_neural_adjoint-0.1.19-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for mm_neural_adjoint-0.1.19-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2fcd6ed40f6cceaea048ae0424541bfce9fba9ce5f2a26e6c46bcb029d4995f2
MD5 3341552fd6a6b1c1a8d924e21167c8fc
BLAKE2b-256 0496b765459f2c201789090154fea0b75b5c2f5f2e470ffea6a49112625199cf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page