BREAKING CHANGE: Module paths have been reorganized for better maintainability. Backwards compatibility aliases with deprecation warnings are provided. New Structure: - core/ - Optimization runners (runner, intelligent_optimizer, etc.) - processors/ - Data processing - surrogates/ - Neural network surrogates - nx/ - NX/Nastran integration (solver, updater, session_manager) - study/ - Study management (creator, wizard, state, reset) - reporting/ - Reports and analysis (visualizer, report_generator) - config/ - Configuration management (manager, builder) - utils/ - Utilities (logger, auto_doc, etc.) - future/ - Research/experimental code Migration: - ~200 import changes across 125 files - All __init__.py files use lazy loading to avoid circular imports - Backwards compatibility layer supports old import paths with warnings - All existing functionality preserved To migrate existing code: OLD: from optimization_engine.nx_solver import NXSolver NEW: from optimization_engine.nx.solver import NXSolver OLD: from optimization_engine.runner import OptimizationRunner NEW: from optimization_engine.core.runner import OptimizationRunner 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
"""Test neural surrogate integration."""
|
|
|
|
import time
|
|
from optimization_engine.processors.surrogates.neural_surrogate import create_surrogate_for_study
|
|
|
|
print("Testing Neural Surrogate Integration")
|
|
print("=" * 60)
|
|
|
|
# Create surrogate with auto-detection
|
|
surrogate = create_surrogate_for_study()
|
|
|
|
if surrogate is None:
|
|
print("ERROR: Failed to create surrogate")
|
|
exit(1)
|
|
|
|
print(f"Surrogate created successfully!")
|
|
print(f" Device: {surrogate.device}")
|
|
print(f" Nodes: {surrogate.num_nodes}")
|
|
print(f" Model val_loss: {surrogate.best_val_loss:.4f}")
|
|
|
|
# Test prediction
|
|
test_params = {
|
|
"beam_half_core_thickness": 7.0,
|
|
"beam_face_thickness": 3.0,
|
|
"holes_diameter": 40.0,
|
|
"hole_count": 10.0
|
|
}
|
|
|
|
print(f"\nTest prediction with params: {test_params}")
|
|
results = surrogate.predict(test_params)
|
|
|
|
print(f"\nResults:")
|
|
print(f" Max displacement: {results['max_displacement']:.6f} mm")
|
|
print(f" Max stress: {results['max_stress']:.2f} (approx)")
|
|
print(f" Inference time: {results['inference_time_ms']:.2f} ms")
|
|
|
|
# Speed test
|
|
n = 100
|
|
start = time.time()
|
|
for _ in range(n):
|
|
surrogate.predict(test_params)
|
|
elapsed = time.time() - start
|
|
|
|
print(f"\nSpeed test: {n} predictions in {elapsed:.3f}s")
|
|
print(f" Average: {elapsed/n*1000:.2f} ms per prediction")
|
|
|
|
# Compare with FEA expectation
|
|
# From training data, typical max_displacement is ~0.02-0.03 mm
|
|
print(f"\nExpected range (from training data):")
|
|
print(f" Max displacement: ~0.02-0.03 mm")
|
|
print(f" Max stress: ~200-300 MPa")
|
|
|
|
stats = surrogate.get_statistics()
|
|
print(f"\nStatistics:")
|
|
print(f" Total predictions: {stats['total_predictions']}")
|
|
print(f" Average time: {stats['average_time_ms']:.2f} ms")
|
|
|
|
print("\nNeural surrogate test PASSED!")
|