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>
70 lines
1.9 KiB
Python
70 lines
1.9 KiB
Python
"""
|
|
Generate history.json from trial directories.
|
|
|
|
For older substudies that don't have history.json,
|
|
reconstruct it from individual trial results.json files.
|
|
"""
|
|
|
|
from pathlib import Path
|
|
import json
|
|
import sys
|
|
|
|
|
|
def generate_history(substudy_dir: Path) -> list:
|
|
"""Generate history from trial directories."""
|
|
substudy_dir = Path(substudy_dir)
|
|
trial_dirs = sorted(substudy_dir.glob('trial_*'))
|
|
|
|
history = []
|
|
|
|
for trial_dir in trial_dirs:
|
|
results_file = trial_dir / 'results.json'
|
|
|
|
if not results_file.exists():
|
|
print(f"Warning: No results.json in {trial_dir.name}")
|
|
continue
|
|
|
|
with open(results_file, 'r') as f:
|
|
trial_data = json.load(f)
|
|
|
|
# Extract trial number from directory name
|
|
trial_num = int(trial_dir.name.split('_')[-1])
|
|
|
|
# Create history entry
|
|
history_entry = {
|
|
'trial_number': trial_num,
|
|
'timestamp': trial_data.get('timestamp', ''),
|
|
'design_variables': trial_data.get('design_variables', {}),
|
|
'objectives': trial_data.get('objectives', {}),
|
|
'constraints': trial_data.get('constraints', {}),
|
|
'total_objective': trial_data.get('total_objective', 0.0)
|
|
}
|
|
|
|
history.append(history_entry)
|
|
|
|
# Sort by trial number
|
|
history.sort(key=lambda x: x['trial_number'])
|
|
|
|
return history
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if len(sys.argv) < 2:
|
|
print("Usage: python generate_history_from_trials.py <substudy_directory>")
|
|
sys.exit(1)
|
|
|
|
substudy_path = Path(sys.argv[1])
|
|
|
|
print(f"Generating history.json from trials in: {substudy_path}")
|
|
|
|
history = generate_history(substudy_path)
|
|
|
|
print(f"Generated {len(history)} history entries")
|
|
|
|
# Save history.json
|
|
history_file = substudy_path / 'history.json'
|
|
with open(history_file, 'w') as f:
|
|
json.dump(history, f, indent=2)
|
|
|
|
print(f"Saved: {history_file}")
|