Skip to content

Commit 3b4f97b

Browse files
committed
Clean-up (Phase 5): exceptions, logging, schedule checks, dead code, docstrings
- Validation asserts raise TypeError/ValueError/RuntimeError. - Importing fes_ml no longer configures logging (NullHandler only); config_logger() prints the banner and no longer hides other loggers by default. Examples call config_logger(). - The lambda schedule is checked before any state is built. - Remove commented-out code; reuse _remove_constraints in Sire; sets for membership tests; cache the water check in _apply_hmr; fix docstrings that contradicted the code; module docstrings.
1 parent 5098151 commit 3b4f97b

31 files changed

Lines changed: 221 additions & 101 deletions

‎CHANGELOG.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ All notable changes to fes-ml are listed here.
66

77
### Changed
88

9+
- **Importing fes-ml no longer configures logging** or prints the banner. Call
10+
`fes_ml.config_logger()` in scripts to print progress messages; it no longer hides other
11+
packages' messages unless `FES_ML_FILTER_LOGGERS=1`.
12+
- Invalid arguments raise `TypeError`, `ValueError` or `RuntimeError` instead of `AssertionError`
13+
(asserts are removed under `python -O`).
14+
- The λ schedule is checked before any state is built: empty schedules, rows of different lengths,
15+
non-numeric or non-finite values and windows with only `None` raise `ValueError`; values outside
16+
[0, 1] warn.
917
- **Sire, OpenFF, EMLE and the ML packages are optional.** `import fes_ml` needs only OpenMM, NumPy
1018
and networkx; each strategy or modification imports its packages when used and says what to
1119
install if they are missing. A missing package now raises when the feature is used, not on import.

‎README.md‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,19 +225,21 @@ The customizable options can be found [here](https://github.com/openforcefield/o
225225

226226
## Logging Settings
227227

228-
By default, fes-ml logs messages at the `INFO` level, showing informative messages about overall progress without detailed debugging information. You can control the logging verbosity by setting the `FES_ML_LOG_LEVEL` environment variable:
228+
Importing fes-ml does not configure logging, so it does not change your application's log output. To print fes-ml's progress messages in a script, call `config_logger()` once:
229229

230-
```bash
231-
export FES_ML_LOG_LEVEL="DEBUG"
230+
```python
231+
from fes_ml import config_logger
232+
233+
config_logger()
232234
```
233235

234-
To include log messages from packages other than fes-ml, set the `FES_ML_FILTER_LOGGERS` variable to 0:
236+
You can control the logging verbosity by setting the `FES_ML_LOG_LEVEL` environment variable (default `INFO`):
235237

236238
```bash
237-
export FES_ML_FILTER_LOGGERS=0
239+
export FES_ML_LOG_LEVEL="DEBUG"
238240
```
239241

240-
By default, this variable is set to 1, filtering out log messages from other packages.
242+
To show only fes-ml's messages and hide those of other packages, set `FES_ML_FILTER_LOGGERS=1`.
241243

242244
For debugging purposes, you can report the energy decomposition of each alchemical state before and after the alchemical modification by setting the `FES_ML_LOG_DEVEL` variable to 1:
243245

‎examples/openff_strategy/benzene_mm_sol_openff.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
import openff.units as offunit
1717
import openmm.unit as unit
1818

19+
from fes_ml import config_logger
1920
from fes_ml.fes import FES
2021

22+
config_logger() # print fes-ml's progress messages
23+
2124
# Set up the alchemical modifications
2225
n_ChargeScaling = 5
2326
n_LJSoftCore = 11

‎examples/openff_strategy/mts_benchmark/ml/run_fes.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import openmm.app as app
2424
import openmm.unit as unit
2525

26-
from fes_ml import FES, MTS
26+
from fes_ml import FES, MTS, config_logger
27+
28+
config_logger() # print fes-ml's progress messages
2729

2830
if len(sys.argv) != 3:
2931
raise ValueError("must pass script and window as positional arguments")

‎examples/openff_strategy/mts_benchmark/ml_mts/run_fes.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import openmm.app as app
77
import openmm.unit as unit
88

9-
from fes_ml import FES, MTS
9+
from fes_ml import FES, MTS, config_logger
10+
11+
config_logger() # print fes-ml's progress messages
1012

1113
if len(sys.argv) != 3:
1214
raise ValueError("must pass script and window as positional arguments")

‎examples/openff_strategy/mts_benchmark/mm/run_fes.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import openmm.app as app
2424
import openmm.unit as unit
2525

26-
from fes_ml import FES, MTS
26+
from fes_ml import FES, MTS, config_logger
27+
28+
config_logger() # print fes-ml's progress messages
2729

2830
if len(sys.argv) != 3:
2931
raise ValueError("must pass script and window as positional arguments")

‎examples/openff_strategy/openff_system_creation.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
import openmm.app as app
2525
import openmm.unit as unit
2626

27-
from fes_ml import FES, MTS
27+
from fes_ml import FES, MTS, config_logger
28+
29+
config_logger() # print fes-ml's progress messages
2830

2931
if len(sys.argv) == 1:
3032
raise ValueError("must pass window as positional arguments")

‎examples/openff_strategy/performance_benchmark_emle_aev.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
import openmm.app as app
1515
import openmm.unit as unit
1616

17-
from fes_ml import FES
17+
from fes_ml import FES, config_logger
18+
19+
config_logger() # print fes-ml's progress messages
1820

1921
if len(sys.argv) == 1:
2022
raise ValueError("must pass window as positional arguments")

‎examples/openff_strategy/run_scripts/create_run_system.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import openmm.app as app
1010
import openmm.unit as unit
1111

12-
from fes_ml import FES, MTS
12+
from fes_ml import FES, MTS, config_logger
13+
14+
config_logger() # print fes-ml's progress messages
1315

1416
logger = logging.getLogger(__name__)
1517

‎examples/sire_strategy/benzene_ml_mm_gas.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
if __name__ == "__main__":
1313
import numpy as np
1414

15+
from fes_ml import config_logger
1516
from fes_ml.fes import FES
1617
from fes_ml.utils import plot_lambda_schedule
1718

19+
config_logger() # print fes-ml's progress messages
20+
1821
# Set up the alchemical modifications
1922
n_MLInterpolation = 11
2023
interpolate_windows = np.linspace(1.0, 0.0, n_MLInterpolation)

0 commit comments

Comments
 (0)