#!/bin/bash
# Phase 6: ML/AI Augmentation Prerequisites Verification Script
# Verifies acceleration module, ffmpeg, and Python ML dependencies
set -e
echo "π Phase 6: ML/AI Augmentation Prerequisites Check"
echo "=================================================="
# Check if we're in the right directory
if [ ! -f "server.config.json" ]; then
echo "β Error: Must run from Phys-MCP root directory"
exit 1
fi
# Check acceleration module
echo "π Checking acceleration module..."
if [ -f "packages/python-worker/accel.py" ]; then
echo "β
Acceleration module found"
# Test device detection
cd packages/python-worker
python3 -c "
import accel
try:
device = accel.get_device()
print(f'β
Device detection working: {device}')
if device != 'cpu':
print(f'π GPU acceleration available: {device}')
else:
print('π» CPU fallback available')
except Exception as e:
print(f'β οΈ Device detection issue: {e}')
print('π» Will use CPU fallback')
"
cd ../..
else
echo "β Acceleration module not found at packages/python-worker/accel.py"
exit 1
fi
# Check ffmpeg for video encoding
echo "π¬ Checking ffmpeg..."
if command -v ffmpeg >/dev/null 2>&1; then
echo "β
ffmpeg found: $(ffmpeg -version | head -n1)"
# Check for required encoders
if ffmpeg -encoders 2>/dev/null | grep -q libx264; then
echo "β
H.264 encoder (libx264) available"
else
echo "β οΈ H.264 encoder not available - MP4 export may fail"
fi
if ffmpeg -encoders 2>/dev/null | grep -q libvpx-vp9; then
echo "β
VP9 encoder (libvpx-vp9) available"
else
echo "β οΈ VP9 encoder not available - WebM export may fail"
fi
else
echo "β ffmpeg not found - video animations will not work"
echo " Install with: apt install ffmpeg (Linux) or brew install ffmpeg (macOS)"
exit 1
fi
# Check Python ML dependencies
echo "π§ Checking Python ML dependencies..."
# Core ML dependencies
python3 -c "
import sys
missing = []
optional_missing = []
# Required dependencies
try:
import torch
print('β
PyTorch found:', torch.__version__)
# Check device availability
if torch.cuda.is_available():
print(f'π CUDA available: {torch.cuda.device_count()} device(s)')
elif hasattr(torch.backends, 'mps') and torch.backends.mps.is_available():
print('π MPS (Apple Silicon) available')
else:
print('π» GPU not available, will use CPU')
except ImportError:
missing.append('torch')
try:
import torchvision
print('β
TorchVision found:', torchvision.__version__)
except ImportError:
missing.append('torchvision')
try:
import sklearn
print('β
Scikit-learn found:', sklearn.__version__)
except ImportError:
missing.append('scikit-learn')
try:
import matplotlib
print('β
Matplotlib found:', matplotlib.__version__)
except ImportError:
missing.append('matplotlib')
try:
import sympy
print('β
SymPy found:', sympy.__version__)
except ImportError:
missing.append('sympy')
try:
import trimesh
print('β
Trimesh found (from Phase 5):', trimesh.__version__)
except ImportError:
missing.append('trimesh')
# Optional dependencies
try:
import pysr
print('β
PySR found:', pysr.__version__)
except ImportError:
optional_missing.append('pysr')
try:
import deepxde
print('β
DeepXDE found:', deepxde.__version__)
except ImportError:
optional_missing.append('deepxde')
if missing:
print('β Missing required dependencies:', ', '.join(missing))
print(' Install with: pip install', ' '.join(missing))
sys.exit(1)
if optional_missing:
print('β οΈ Missing optional dependencies:', ', '.join(optional_missing))
print(' For full functionality, install with: pip install', ' '.join(optional_missing))
print(' Note: PySR requires Julia; DeepXDE provides advanced PINN features')
print('β
All required ML dependencies satisfied')
"
if [ $? -ne 0 ]; then
echo "β Python dependency check failed"
exit 1
fi
# Check existing Phase 5 components
echo "π¨ Checking Phase 5 integration..."
if [ -f "packages/tools-plot/src/handlers.ts" ]; then
if grep -q "plot_type.*volume_3d\|animation\|interactive" packages/tools-plot/src/handlers.ts; then
echo "β
Phase 5 advanced visualization tools found"
else
echo "β οΈ Phase 5 tools may not be fully integrated"
fi
else
echo "β Phase 5 plot handlers not found"
exit 1
fi
echo ""
echo "π Phase 6 Prerequisites Check Complete!"
echo "β
Acceleration module ready"
echo "β
Video encoding (ffmpeg) ready"
echo "β
ML dependencies satisfied"
echo "β
Phase 5 integration confirmed"
echo ""
echo "Ready to implement Phase 6: ML/AI Augmentation! π"