bfflearn 0.1.0.dev1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bff/__init__.py +30 -0
- bff/bayes/__init__.py +11 -0
- bff/bayes/gaussian_process.py +285 -0
- bff/bayes/kernels.py +71 -0
- bff/bayes/learning.py +484 -0
- bff/bayes/likelihoods.py +142 -0
- bff/bayes/posterior.py +62 -0
- bff/bayes/priors.py +179 -0
- bff/bayes/results.py +327 -0
- bff/bayes/utils.py +333 -0
- bff/cli.py +254 -0
- bff/data.py +93 -0
- bff/domain/__init__.py +12 -0
- bff/domain/bias.py +149 -0
- bff/domain/specs.py +347 -0
- bff/domain/trainset.py +201 -0
- bff/io/__init__.py +12 -0
- bff/io/colvars.py +186 -0
- bff/io/commands.py +20 -0
- bff/io/cp2k.py +330 -0
- bff/io/logs.py +213 -0
- bff/io/mdp.py +98 -0
- bff/io/plumed.py +184 -0
- bff/io/progress.py +74 -0
- bff/io/schedulers.py +118 -0
- bff/io/utils.py +208 -0
- bff/mcmc/__init__.py +3 -0
- bff/mcmc/convergence.py +168 -0
- bff/mcmc/proposal.py +254 -0
- bff/mcmc/sampler.py +481 -0
- bff/plotting.py +362 -0
- bff/qoi/__init__.py +9 -0
- bff/qoi/analysis.py +209 -0
- bff/qoi/data.py +169 -0
- bff/qoi/hbonds.py +255 -0
- bff/qoi/rdf.py +108 -0
- bff/qoi/routines.py +272 -0
- bff/tools.py +168 -0
- bff/topology.py +581 -0
- bff/workflows/__init__.py +0 -0
- bff/workflows/configs.py +1147 -0
- bff/workflows/learn.py +77 -0
- bff/workflows/md.py +326 -0
- bff/workflows/prepare.py +788 -0
- bff/workflows/qoi.py +260 -0
- bff/workflows/runsims.py +620 -0
- bff/workflows/simulate.py +28 -0
- bff/workflows/train.py +69 -0
- bff/workflows/validate.py +29 -0
- bfflearn-0.1.0.dev1.dist-info/METADATA +913 -0
- bfflearn-0.1.0.dev1.dist-info/RECORD +55 -0
- bfflearn-0.1.0.dev1.dist-info/WHEEL +5 -0
- bfflearn-0.1.0.dev1.dist-info/entry_points.txt +2 -0
- bfflearn-0.1.0.dev1.dist-info/licenses/LICENSE +674 -0
- bfflearn-0.1.0.dev1.dist-info/top_level.txt +1 -0
bff/workflows/train.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""Workflow entry point for surrogate training."""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Union
|
|
6
|
+
|
|
7
|
+
from ..io.logs import Logger
|
|
8
|
+
from ..qoi.data import QoIDataset
|
|
9
|
+
from .configs import TrainConfig
|
|
10
|
+
|
|
11
|
+
PathLike = Union[str, Path]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _load_datasets(config: TrainConfig) -> tuple[QoIDataset, ...]:
|
|
15
|
+
datasets: list[QoIDataset] = []
|
|
16
|
+
for dataset_config in config.datasets:
|
|
17
|
+
dataset = QoIDataset.load(dataset_config.fn_data)
|
|
18
|
+
dataset.nuisance = dataset_config.nuisance
|
|
19
|
+
datasets.append(dataset)
|
|
20
|
+
return tuple(datasets)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _dataset_options(
|
|
24
|
+
config: TrainConfig,
|
|
25
|
+
) -> tuple[dict[str, Path | None], dict[str, object], dict[str, float]]:
|
|
26
|
+
model_paths = {dataset.name: dataset.fn_model for dataset in config.datasets}
|
|
27
|
+
y_means = {dataset.name: dataset.mean for dataset in config.datasets}
|
|
28
|
+
observation_scales = {
|
|
29
|
+
dataset.name: dataset.observation_scale for dataset in config.datasets
|
|
30
|
+
}
|
|
31
|
+
return model_paths, y_means, observation_scales
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def main(fn_config: PathLike) -> None:
|
|
35
|
+
try:
|
|
36
|
+
from ..bayes.learning import train_surrogates
|
|
37
|
+
except ModuleNotFoundError as exc:
|
|
38
|
+
if exc.name == "torch":
|
|
39
|
+
raise RuntimeError(
|
|
40
|
+
"PyTorch is required for 'bff train'. Install a CPU or CUDA "
|
|
41
|
+
"build of PyTorch first."
|
|
42
|
+
) from exc
|
|
43
|
+
raise
|
|
44
|
+
|
|
45
|
+
config = TrainConfig.load(fn_config)
|
|
46
|
+
logger = Logger("BFF", str(config.log), mode="w")
|
|
47
|
+
datasets = _load_datasets(config)
|
|
48
|
+
model_paths, y_means, observation_scales = _dataset_options(config)
|
|
49
|
+
|
|
50
|
+
config.training.model_dir.mkdir(parents=True, exist_ok=True)
|
|
51
|
+
|
|
52
|
+
train_surrogates(
|
|
53
|
+
datasets,
|
|
54
|
+
y_means=y_means,
|
|
55
|
+
observation_scales=observation_scales,
|
|
56
|
+
model_paths=model_paths,
|
|
57
|
+
reuse_models=config.training.reuse_models,
|
|
58
|
+
n_hyper_max=config.training.n_hyper_max,
|
|
59
|
+
committee_size=config.training.committee_size,
|
|
60
|
+
test_fraction=config.training.test_fraction,
|
|
61
|
+
device=config.training.device,
|
|
62
|
+
logger=logger,
|
|
63
|
+
**config.training.opt_kwargs,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
if __name__ == "__main__":
|
|
68
|
+
fn_config = sys.argv[1]
|
|
69
|
+
main(fn_config)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Workflow entry point for posterior-sample validation campaigns."""
|
|
2
|
+
|
|
3
|
+
from ..io.logs import Logger
|
|
4
|
+
from .configs import ValidateConfig
|
|
5
|
+
from .runsims import (
|
|
6
|
+
load_parameter_samples,
|
|
7
|
+
print_validate_summary,
|
|
8
|
+
run_campaign,
|
|
9
|
+
stage_campaign,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main(fn_config: str) -> None:
|
|
14
|
+
"""Run a validation campaign for provided force-field parameter samples."""
|
|
15
|
+
config = ValidateConfig.load(fn_config)
|
|
16
|
+
parameter_samples = load_parameter_samples(config.parameters, config.specs)
|
|
17
|
+
|
|
18
|
+
fn_specs, systems = stage_campaign(config, fn_specs=config.specs)
|
|
19
|
+
assert fn_specs is not None
|
|
20
|
+
|
|
21
|
+
logger = Logger("validate")
|
|
22
|
+
print_validate_summary(config, fn_specs, len(parameter_samples), logger)
|
|
23
|
+
run_campaign(
|
|
24
|
+
config=config,
|
|
25
|
+
fn_specs=fn_specs,
|
|
26
|
+
systems=systems,
|
|
27
|
+
parameter_samples=parameter_samples,
|
|
28
|
+
logger=logger,
|
|
29
|
+
)
|