refactor: Reorganize code structure and create tests directory
- Consolidate surrogates module to processors/surrogates/ - Move ensemble_surrogate.py to proper location - Add deprecation shim for old import path - Create tests/ directory with pytest structure - Move test files from archive/test_scripts/ - Add conftest.py with shared fixtures 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
58
tests/unit/test_neural_surrogate.py
Normal file
58
tests/unit/test_neural_surrogate.py
Normal file
@@ -0,0 +1,58 @@
|
||||
"""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!")
|
||||
Reference in New Issue
Block a user