From 7bdb74f93b3304b1eb5733d089c2e06ecfb2d324 Mon Sep 17 00:00:00 2001 From: Anto01 Date: Wed, 7 Jan 2026 09:01:37 -0500 Subject: [PATCH] refactor: Reorganize code structure and create tests directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- .../processors/surrogates/__init__.py | 12 +++++++ .../surrogates/ensemble_surrogate.py | 0 optimization_engine/surrogates/__init__.py | 27 ++++++++++------ tests/conftest.py | 32 +++++++++++++++++++ .../unit}/test_adaptive_characterization.py | 0 .../unit}/test_neural_surrogate.py | 0 .../unit}/test_nn_surrogate.py | 0 .../unit}/test_parametric_surrogate.py | 0 .../unit}/test_training_data_export.py | 0 9 files changed, 61 insertions(+), 10 deletions(-) rename optimization_engine/{ => processors}/surrogates/ensemble_surrogate.py (100%) create mode 100644 tests/conftest.py rename {archive/test_scripts => tests/unit}/test_adaptive_characterization.py (100%) rename {archive/test_scripts => tests/unit}/test_neural_surrogate.py (100%) rename {archive/test_scripts => tests/unit}/test_nn_surrogate.py (100%) rename {archive/test_scripts => tests/unit}/test_parametric_surrogate.py (100%) rename {archive/test_scripts => tests/unit}/test_training_data_export.py (100%) diff --git a/optimization_engine/processors/surrogates/__init__.py b/optimization_engine/processors/surrogates/__init__.py index 7bc1f673..09ccbdfa 100644 --- a/optimization_engine/processors/surrogates/__init__.py +++ b/optimization_engine/processors/surrogates/__init__.py @@ -59,6 +59,15 @@ def __getattr__(name): elif name == 'create_exporter_from_config': from .training_data_exporter import create_exporter_from_config return create_exporter_from_config + elif name == 'EnsembleSurrogate': + from .ensemble_surrogate import EnsembleSurrogate + return EnsembleSurrogate + elif name == 'OODDetector': + from .ensemble_surrogate import OODDetector + return OODDetector + elif name == 'create_and_train_ensemble': + from .ensemble_surrogate import create_and_train_ensemble + return create_and_train_ensemble raise AttributeError(f"module 'optimization_engine.processors.surrogates' has no attribute '{name}'") @@ -76,4 +85,7 @@ __all__ = [ 'AutoTrainer', 'TrainingDataExporter', 'create_exporter_from_config', + 'EnsembleSurrogate', + 'OODDetector', + 'create_and_train_ensemble', ] diff --git a/optimization_engine/surrogates/ensemble_surrogate.py b/optimization_engine/processors/surrogates/ensemble_surrogate.py similarity index 100% rename from optimization_engine/surrogates/ensemble_surrogate.py rename to optimization_engine/processors/surrogates/ensemble_surrogate.py diff --git a/optimization_engine/surrogates/__init__.py b/optimization_engine/surrogates/__init__.py index 52622c1f..09199726 100644 --- a/optimization_engine/surrogates/__init__.py +++ b/optimization_engine/surrogates/__init__.py @@ -1,19 +1,26 @@ """ -Surrogate models for FEA acceleration. +DEPRECATED: This module has been moved to optimization_engine.processors.surrogates -Available surrogates: -- EnsembleSurrogate: Multiple MLPs with uncertainty quantification -- OODDetector: Out-of-distribution detection +Please update your imports: + from optimization_engine.processors.surrogates import EnsembleSurrogate + +This module will be removed in a future version. """ -from .ensemble_surrogate import ( +import warnings + +warnings.warn( + "optimization_engine.surrogates is deprecated. " + "Use optimization_engine.processors.surrogates instead.", + DeprecationWarning, + stacklevel=2 +) + +# Redirect imports +from optimization_engine.processors.surrogates import ( EnsembleSurrogate, OODDetector, create_and_train_ensemble ) -__all__ = [ - 'EnsembleSurrogate', - 'OODDetector', - 'create_and_train_ensemble' -] +__all__ = ['EnsembleSurrogate', 'OODDetector', 'create_and_train_ensemble'] diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..68911509 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,32 @@ +""" +Pytest configuration and shared fixtures for Atomizer tests. +""" + +import pytest +import sys +from pathlib import Path + +# Add project root to path +sys.path.insert(0, str(Path(__file__).parent.parent)) + +@pytest.fixture +def sample_study_dir(tmp_path): + """Create a temporary study directory structure.""" + study = tmp_path / "test_study" + (study / "1_setup").mkdir(parents=True) + (study / "2_iterations").mkdir() + (study / "3_results").mkdir() + return study + +@pytest.fixture +def sample_config(): + """Sample optimization config for testing.""" + return { + "study_name": "test_study", + "design_variables": [ + {"name": "param1", "lower": 0, "upper": 10, "type": "continuous"} + ], + "objectives": [ + {"name": "minimize_mass", "direction": "minimize"} + ] + } diff --git a/archive/test_scripts/test_adaptive_characterization.py b/tests/unit/test_adaptive_characterization.py similarity index 100% rename from archive/test_scripts/test_adaptive_characterization.py rename to tests/unit/test_adaptive_characterization.py diff --git a/archive/test_scripts/test_neural_surrogate.py b/tests/unit/test_neural_surrogate.py similarity index 100% rename from archive/test_scripts/test_neural_surrogate.py rename to tests/unit/test_neural_surrogate.py diff --git a/archive/test_scripts/test_nn_surrogate.py b/tests/unit/test_nn_surrogate.py similarity index 100% rename from archive/test_scripts/test_nn_surrogate.py rename to tests/unit/test_nn_surrogate.py diff --git a/archive/test_scripts/test_parametric_surrogate.py b/tests/unit/test_parametric_surrogate.py similarity index 100% rename from archive/test_scripts/test_parametric_surrogate.py rename to tests/unit/test_parametric_surrogate.py diff --git a/archive/test_scripts/test_training_data_export.py b/tests/unit/test_training_data_export.py similarity index 100% rename from archive/test_scripts/test_training_data_export.py rename to tests/unit/test_training_data_export.py