-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
134 lines (112 loc) · 4.54 KB
/
Copy pathrun.py
File metadata and controls
134 lines (112 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
"""Run locking-parameter optimization with mpBAX.
Usage:
# Approach 1 (F=always, R=configurable):
python run.py --approach 1
# Approach 2 (R=always, inner loop):
python run.py --approach 2
# Custom retrain frequency (approach 1):
python run.py --approach 1 --retrain-every 5
"""
import argparse
import tempfile
import numpy as np
from mpbax.core.model import DummyModel
from engine import LockingEngine
from algorithm import LockingAlgorithm
from oracles import LockingOracle
from sko.PSO import PSO
from PSOoptimizer import *
def main():
# parser = argparse.ArgumentParser(description='Locking-parameter optimization')
# parser.add_argument('--approach', type=int, default=1, choices=[1, 2],
# help='Optimization approach (1 or 2)')
# parser.add_argument('--retrain-every', type=int, default=3,
# help='Retrain frequency for approach 1 (default: 3)')
# parser.add_argument('--inner-steps', type=int, default=10,
# help='Inner loop steps for approach 2 (default: 10)')
# parser.add_argument('--max-loops', type=int, default=10,
# help='Maximum optimization loops (default: 10)')
# parser.add_argument('--input-dim', type=int, default=4,
# help='Design parameter dimensionality (default: 4)')
# parser.add_argument('--checkpoint-dir', type=str, default=None,
# help='Checkpoint directory (default: temp dir)')
# args = parser.parse_args()
# # Create oracle and algorithm instances
# oracle = LockingOracle(use_surrogate_init=True, noise_scale=0.01)
# algo = LockingAlgorithm
# # Build config programmatically (instance-based for oracle, class for algorithm)
# checkpoint_dir = args.checkpoint_dir or tempfile.mkdtemp(prefix='ligo_')
# config = {
# 'seed': 42,
# 'max_loops': args.max_loops,
# 'optimization': {
# 'approach': args.approach,
# 'retrain_every': args.retrain_every,
# },
# 'checkpoint': {
# 'dir': checkpoint_dir,
# 'freq': 1,
# },
# 'training': {
# 'mode': 'finetune',
# 'checkpoint_mode': 'final',
# },
# 'oracles': [{
# 'name': 'locking',
# 'input_dim': args.input_dim,
# 'n_initial': 200,
# 'function': {'class': oracle}, # Callable class instance
# 'model': {'class': DummyModel},
# }],
# 'algorithm': {
# 'class': LockingAlgorithm,
# 'params': {
# 'input_dims': [args.input_dim],
# 'n_propose': 5,
# 'n_candidates': 500,
# 'approach': args.approach,
# 'inner_steps': args.inner_steps,
# },
# },
# }
# # Print config summary
# print("=" * 60)
# print("Cavity Optimization")
# print("=" * 60)
# print(f" Approach: {args.approach}")
# if args.approach == 1:
# print(f" Retrain every: {args.retrain_every} loops (R switch)")
# print(f" Finetune: always (F=always true)")
# else:
# print(f" Inner steps: {args.inner_steps} (F switch in algorithm)")
# print(f" Retrain: always (R=always true)")
# print(f" Design dim: {args.input_dim}")
# print(f" Max loops: {args.max_loops}")
# print(f" Checkpoint: {checkpoint_dir}")
# print("=" * 60)
# # Create engine and link oracle to it
# # Run optimization
# # Print final results
# print("\n" + "=" * 60)
# print("Optimization complete!")
# print("=" * 60)
# # Show best result from accumulated data
# X, Y = engine.data_handlers[0].get_data()
# if X is not None and Y is not None:
# # Y contains L* (locking params). Compute objectives.
# from utils.calc import calc_objective
# objectives = calc_objective(X, Y)
# best_idx = np.argmin(objectives)
# print(f"\n Best objective: {objectives[best_idx]:.6f}")
# print(f" Best D: {X[best_idx]}")
# print(f" Best L*: {Y[best_idx]}")
# print(f" Total simulations: {engine.evaluators[0].get_eval_count()}")
# print("=" * 60)
start_ETM_Roc = 5
end_ETM_Roc = 20
start_ITM_Roc = 5
end_ITM_Roc = 20
pso = PSO(func=main_wrapper_PSO_sim, n_dim=3, pop=300, max_iter=1000, lb=[start_ITM_Roc, start_ETM_Roc], ub=[end_ITM_Roc, end_ETM_Roc], w=0.9, c1=1.2, c2=1.8, verbose=True)
print("test")
if __name__ == '__main__':
main()