DHDRL commited on
Commit
d54c0be
·
verified ·
1 Parent(s): 56f0345

Update mems_adaptive_inspection_env_curriculum_v5_SOFT_RESET_STABLE.py

Browse files
mems_adaptive_inspection_env_curriculum_v5_SOFT_RESET_STABLE.py CHANGED
@@ -173,15 +173,11 @@ class InspectionConfig:
173
  miss_penalty: float = 200.0
174
  max_steps: Optional[int] = 2200
175
  # Belief-lite parameters
176
- prior_belief: float = 0.12 # Higher baseline (was 0.03)
177
  belief_update_radius: int = 3
178
  belief_increase_rate: float = 0.3
179
- belief_decrease_rate: float = 0.05 # Slower decay (was 0.2)
180
- belief_floor: float = 0.005 # CHANGED: was 0.02 — must allow belief to drop below
181
- # rational termination threshold of ~0.01
182
- # (P < inspection_cost / defect_catch_value = 1/99 ≈ 0.01)
183
- # A floor of 0.02 mathematically prevented EV from going negative,
184
- # making rational termination impossible.
185
  real_data_path: Optional[str] = None
186
  preload_wafers: int = 0
187
  image_size: int = 64
@@ -193,7 +189,7 @@ class InspectionConfig:
193
  # Default False — preserves original behavior for validation and baseline training
194
  economic_randomization: bool = False
195
  clean_episode_ratio: float = 0.7 # 70% clean, 30% varied when randomization enabled
196
- cost_range: tuple = (0.8, 1.2) # Narrow range avoids distribution shock
197
  budget_range: tuple = (0.9, 1.1) # ±10% budget variation
198
 
199
  def __post_init__(self):
@@ -238,11 +234,10 @@ class ResolutionAgnosticInspectionEnv(gym.Env):
238
  self.current_budget = self.config.inspection_budget
239
  self.wafer_radius_mm = self.config.wafer_diameter_mm / 2.0
240
 
241
- # Soft reset mode for production optimization
242
  self.soft_reset_enabled = self.config.soft_reset
243
 
244
  # EARLY TERMINATION: The terminate action is the last discrete action (N²)
245
- # It must remain UNMASKED in your policy network's action mask.
246
  # The spatial action_mask (grid_size × grid_size) covers only inspection cells;
247
  # terminate lives outside that spatial mask and must be explicitly kept available.
248
  self.terminate_action = self.config.grid_size * self.config.grid_size
@@ -275,7 +270,6 @@ class ResolutionAgnosticInspectionEnv(gym.Env):
275
  self._init_persistent_tensors()
276
 
277
  def _init_persistent_tensors(self):
278
- """Pre-allocate tensors that will be reused in soft reset mode"""
279
  self.wafer_map = np.zeros((self.current_grid_size, self.current_grid_size), dtype=np.int8)
280
  self.belief_map = np.full((self.current_grid_size, self.current_grid_size),
281
  self.config.prior_belief, dtype=np.float32)
@@ -300,7 +294,6 @@ class ResolutionAgnosticInspectionEnv(gym.Env):
300
  self._init_belief_gpu_cache()
301
 
302
  def _init_belief_gpu_cache(self):
303
- """Persistent GPU buffers for belief updates (no per-step allocation)."""
304
  grid_size = self.current_grid_size
305
 
306
  self._belief_gpu = torch.zeros(
@@ -352,7 +345,6 @@ class ResolutionAgnosticInspectionEnv(gym.Env):
352
  # action_space: grid_size² spatial actions + 1 terminate action
353
  # NOTE for policy implementors: when building your action mask tensor, do:
354
  # full_mask = torch.cat([spatial_mask.flatten(), torch.ones(1, dtype=torch.bool)])
355
- # The terminate action must NEVER be masked out.
356
  self.action_space = spaces.Discrete(self.config.grid_size * self.config.grid_size + 1)
357
 
358
  def _check_reset_invariants(self):
 
173
  miss_penalty: float = 200.0
174
  max_steps: Optional[int] = 2200
175
  # Belief-lite parameters
176
+ prior_belief: float = 0.12
177
  belief_update_radius: int = 3
178
  belief_increase_rate: float = 0.3
179
+ belief_decrease_rate: float = 0.05
180
+ belief_floor: float = 0.005
 
 
 
 
181
  real_data_path: Optional[str] = None
182
  preload_wafers: int = 0
183
  image_size: int = 64
 
189
  # Default False — preserves original behavior for validation and baseline training
190
  economic_randomization: bool = False
191
  clean_episode_ratio: float = 0.7 # 70% clean, 30% varied when randomization enabled
192
+ cost_range: tuple = (0.8, 1.2) # Narrow range to avoid distribution shock
193
  budget_range: tuple = (0.9, 1.1) # ±10% budget variation
194
 
195
  def __post_init__(self):
 
234
  self.current_budget = self.config.inspection_budget
235
  self.wafer_radius_mm = self.config.wafer_diameter_mm / 2.0
236
 
 
237
  self.soft_reset_enabled = self.config.soft_reset
238
 
239
  # EARLY TERMINATION: The terminate action is the last discrete action (N²)
240
+ # It must remain unmasked in your policy network's action mask.
241
  # The spatial action_mask (grid_size × grid_size) covers only inspection cells;
242
  # terminate lives outside that spatial mask and must be explicitly kept available.
243
  self.terminate_action = self.config.grid_size * self.config.grid_size
 
270
  self._init_persistent_tensors()
271
 
272
  def _init_persistent_tensors(self):
 
273
  self.wafer_map = np.zeros((self.current_grid_size, self.current_grid_size), dtype=np.int8)
274
  self.belief_map = np.full((self.current_grid_size, self.current_grid_size),
275
  self.config.prior_belief, dtype=np.float32)
 
294
  self._init_belief_gpu_cache()
295
 
296
  def _init_belief_gpu_cache(self):
 
297
  grid_size = self.current_grid_size
298
 
299
  self._belief_gpu = torch.zeros(
 
345
  # action_space: grid_size² spatial actions + 1 terminate action
346
  # NOTE for policy implementors: when building your action mask tensor, do:
347
  # full_mask = torch.cat([spatial_mask.flatten(), torch.ones(1, dtype=torch.bool)])
 
348
  self.action_space = spaces.Discrete(self.config.grid_size * self.config.grid_size + 1)
349
 
350
  def _check_reset_invariants(self):