jflows-md 0.5.3__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.
jflows_md/__init__.py ADDED
@@ -0,0 +1,121 @@
1
+ """Mixed-domain molecular companions for :mod:`jflows`."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ import subprocess
7
+ from importlib import import_module
8
+ from importlib.metadata import (
9
+ PackageNotFoundError as _PackageNotFoundError,
10
+ distributions as _distributions,
11
+ version as _package_version,
12
+ )
13
+ from shutil import which
14
+
15
+
16
+ __all__ = [
17
+ "__version__",
18
+ "backend",
19
+ "Mixed_Identity",
20
+ "Mixed_NSF",
21
+ "Molecular_Bundle",
22
+ "Molecular_Potential",
23
+ "Molecular_Source",
24
+ "annealed_importance_sampling",
25
+ "available_bundles",
26
+ "boltzmann_identity",
27
+ "boltzmann_forward_KLX_G",
28
+ "boltzmann_forward_KLXX_G",
29
+ "mixed_mala",
30
+ "mixed_quench_and_temper",
31
+ "potential_space_smc",
32
+ "sequential_monte_carlo",
33
+ "train_forward_KLX_G",
34
+ "train_forward_KLXX_G",
35
+ ]
36
+
37
+
38
+ def backend():
39
+ """Print the JAX and OpenMM accelerator configuration."""
40
+ from jflows import backend as jax_backend
41
+
42
+ jax_backend()
43
+
44
+ try:
45
+ openmm_version = _package_version("openmm")
46
+ except _PackageNotFoundError:
47
+ print("OpenMM: not installed")
48
+ print("OpenMM GPU backend: unavailable")
49
+ return
50
+
51
+ print(f"OpenMM {openmm_version}")
52
+ installed = {
53
+ item.metadata["Name"].lower().replace("_", "-").replace(".", "-"): item.version
54
+ for item in _distributions()
55
+ if item.metadata.get("Name")
56
+ }
57
+ cuda_visible = os.environ.get("CUDA_VISIBLE_DEVICES") not in ("", "-1")
58
+ cuda_available = cuda_visible and which("nvidia-smi") and subprocess.run(
59
+ ["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"],
60
+ stdout=subprocess.DEVNULL,
61
+ stderr=subprocess.DEVNULL,
62
+ ).returncode == 0
63
+ hip_visible = os.environ.get("ROCR_VISIBLE_DEVICES") not in ("", "-1")
64
+ hip_available = hip_visible and which("rocm-smi") and subprocess.run(
65
+ ["rocm-smi", "--showproductname"],
66
+ stdout=subprocess.DEVNULL,
67
+ stderr=subprocess.DEVNULL,
68
+ ).returncode == 0
69
+
70
+ gpu = []
71
+ for name, plugin_version in sorted(installed.items()):
72
+ if name.startswith("openmm-cuda-"):
73
+ label = f"CUDA {name.removeprefix('openmm-cuda-')} ({plugin_version})"
74
+ available = cuda_available
75
+ elif name.startswith("openmm-hip-"):
76
+ label = f"HIP {name.removeprefix('openmm-hip-')} ({plugin_version})"
77
+ available = hip_available
78
+ else:
79
+ continue
80
+ if plugin_version != openmm_version:
81
+ state = f"version mismatch with OpenMM {openmm_version}"
82
+ elif available:
83
+ state = "available"
84
+ else:
85
+ state = "installed, accelerator unavailable"
86
+ gpu.append(f"{label} — {state}")
87
+
88
+ print(f"OpenMM GPU backend: {'; '.join(gpu) if gpu else 'unavailable'}")
89
+
90
+
91
+ _EXPORTS = {
92
+ "Mixed_Identity": (".flow", "Mixed_Identity"),
93
+ "Mixed_NSF": (".flow", "Mixed_NSF"),
94
+ "Molecular_Bundle": (".system", "Molecular_Bundle"),
95
+ "Molecular_Potential": (".potential", "Molecular_Potential"),
96
+ "Molecular_Source": (".source", "Molecular_Source"),
97
+ "annealed_importance_sampling": (
98
+ ".utils",
99
+ "annealed_importance_sampling",
100
+ ),
101
+ "available_bundles": (".system", "available_bundles"),
102
+ "boltzmann_identity": (".boltzmann", "boltzmann_identity"),
103
+ "boltzmann_forward_KLX_G": (".boltzmann", "boltzmann_forward_KLX_G"),
104
+ "boltzmann_forward_KLXX_G": (".boltzmann", "boltzmann_forward_KLXX_G"),
105
+ "mixed_mala": (".utils", "mixed_mala"),
106
+ "mixed_quench_and_temper": (".utils", "mixed_quench_and_temper"),
107
+ "potential_space_smc": (".utils", "potential_space_smc"),
108
+ "sequential_monte_carlo": (".utils", "sequential_monte_carlo"),
109
+ "train_forward_KLX_G": (".train", "train_forward_KLX_G"),
110
+ "train_forward_KLXX_G": (".train", "train_forward_KLXX_G"),
111
+ "__version__": (".version", "__version__"),
112
+ }
113
+
114
+
115
+ def __getattr__(name: str):
116
+ if name not in _EXPORTS:
117
+ raise AttributeError(name)
118
+ module_name, attribute = _EXPORTS[name]
119
+ value = getattr(import_module(module_name, __name__), attribute)
120
+ globals()[name] = value
121
+ return value
jflows_md/artifacts.py ADDED
@@ -0,0 +1,19 @@
1
+ """Medium-level molecular artifacts use the generic jflows format."""
2
+
3
+ from jflows.artifacts import (
4
+ load_flow,
5
+ load_history,
6
+ load_samples,
7
+ save_flow,
8
+ save_history,
9
+ save_samples,
10
+ )
11
+
12
+ __all__ = [
13
+ "load_flow",
14
+ "load_history",
15
+ "load_samples",
16
+ "save_flow",
17
+ "save_history",
18
+ "save_samples",
19
+ ]