Context
During PR review of #149 (mkdocs documentation), the silent-failure-hunter
agent flagged three bare except: blocks inside calibration optimization
closures. These are pre-existing bugs not introduced by the PR, but they
hide real errors (including the broken wrapper method names that went
undetected for months).
Related: #146 (unit tests), #149 (docs PR)
Problem / Current Behaviour
Three opt_fun closures in Calibration catch every exception type
(including KeyboardInterrupt, SystemExit, MemoryError), silently
set error = np.nan, and return fail = 1 to the optimizer. During
hours-long calibration runs, any programming error produces garbage
results with zero diagnostic output.
Affected locations
| File |
Symbol |
Notes |
| `src/Hapi/calibration.py:~269` |
`run_calibration.opt_fun` |
Bare `except:` |
| `src/Hapi/calibration.py:~415` |
`FW1Calibration.opt_fun` |
Bare `except:` |
| `src/Hapi/calibration.py:~550` |
`lumpedCalibration.opt_fun` |
Bare `except:` |
Steps to Reproduce
```python
If any model evaluation raises an error (e.g., wrong array shape),
the optimizer silently receives NaN and continues for hours.
from Hapi.calibration import Calibration
... setup calibration with a typo in parameter bounds ...
Calibration runs to completion but every iteration returned NaN.
No error, no traceback, no indication of root cause.
```
Proposed Solution
```python
Minimum fix: catch Exception (not bare except), log the error
except Exception as e:
logger.warning(f"Model evaluation failed: {e}")
error = np.nan
g = []
fail = 1
```
Ideally, distinguish between expected numerical failures (which the
optimizer should handle) and programming errors (which should halt).
Out of Scope
- Refactoring the optimization loop itself
- Changing the Harmony Search algorithm interface
Effort Estimate
Size: `S`
Rationale: Mechanical replacement of 3 bare except blocks with
`except Exception as e:` plus a log statement.
Definition of Done
Context
During PR review of #149 (mkdocs documentation), the silent-failure-hunter
agent flagged three bare
except:blocks inside calibration optimizationclosures. These are pre-existing bugs not introduced by the PR, but they
hide real errors (including the broken wrapper method names that went
undetected for months).
Related: #146 (unit tests), #149 (docs PR)
Problem / Current Behaviour
Three
opt_funclosures inCalibrationcatch every exception type(including
KeyboardInterrupt,SystemExit,MemoryError), silentlyset
error = np.nan, and returnfail = 1to the optimizer. Duringhours-long calibration runs, any programming error produces garbage
results with zero diagnostic output.
Affected locations
Steps to Reproduce
```python
If any model evaluation raises an error (e.g., wrong array shape),
the optimizer silently receives NaN and continues for hours.
from Hapi.calibration import Calibration
... setup calibration with a typo in parameter bounds ...
Calibration runs to completion but every iteration returned NaN.
No error, no traceback, no indication of root cause.
```
Proposed Solution
```python
Minimum fix: catch Exception (not bare except), log the error
except Exception as e:
logger.warning(f"Model evaluation failed: {e}")
error = np.nan
g = []
fail = 1
```
Ideally, distinguish between expected numerical failures (which the
optimizer should handle) and programming errors (which should halt).
Out of Scope
Effort Estimate
Size: `S`
Rationale: Mechanical replacement of 3 bare except blocks with
`except Exception as e:` plus a log statement.
Definition of Done