defog-adapt 0.1.0__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.
- defog_adapt/__init__.py +17 -0
- defog_adapt/core/__init__.py +208 -0
- defog_adapt/core/adapter.py +785 -0
- defog_adapt/core/callbacks.py +1470 -0
- defog_adapt/core/constraint.py +148 -0
- defog_adapt/core/data.py +457 -0
- defog_adapt/core/domain.py +202 -0
- defog_adapt/core/energy.py +124 -0
- defog_adapt/core/features.py +418 -0
- defog_adapt/core/feynman_kac.py +276 -0
- defog_adapt/core/layers.py +391 -0
- defog_adapt/core/loss.py +179 -0
- defog_adapt/core/model.py +1280 -0
- defog_adapt/core/noise.py +290 -0
- defog_adapt/core/property_head.py +372 -0
- defog_adapt/core/rate_matrix.py +429 -0
- defog_adapt/core/rl.py +1103 -0
- defog_adapt/core/sampler.py +379 -0
- defog_adapt/core/size_distribution.py +762 -0
- defog_adapt/core/spectrum.py +248 -0
- defog_adapt/core/time_distortion.py +119 -0
- defog_adapt/core/transformer.py +228 -0
- defog_adapt/data/__init__.py +45 -0
- defog_adapt/data/_paths.py +30 -0
- defog_adapt/data/chembl_reference.py +142 -0
- defog_adapt/data/moses_reference.py +407 -0
- defog_adapt/data/vocabulary.py +137 -0
- defog_adapt/data/zinc_reference.py +433 -0
- defog_adapt/domains/__init__.py +40 -0
- defog_adapt/domains/molecule.py +917 -0
- defog_adapt/presets.py +166 -0
- defog_adapt-0.1.0.dist-info/METADATA +361 -0
- defog_adapt-0.1.0.dist-info/RECORD +36 -0
- defog_adapt-0.1.0.dist-info/WHEEL +4 -0
- defog_adapt-0.1.0.dist-info/licenses/LICENSE +21 -0
- defog_adapt-0.1.0.dist-info/licenses/NOTICE +41 -0
defog_adapt/__init__.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""defog-adapt: frozen-base adapters, Feynman-Kac steering and RL fine-tuning for DeFoG.
|
|
2
|
+
|
|
3
|
+
The public API lives in the sub-packages:
|
|
4
|
+
|
|
5
|
+
* :mod:`defog_adapt.core` the model, samplers, adapters, steering, RL, size models
|
|
6
|
+
* :mod:`defog_adapt.domains` molecules (needs RDKit: ``pip install "defog-adapt[chem]"``)
|
|
7
|
+
* :mod:`defog_adapt.data` reference splits (ZINC250k, MOSES) and vocabularies
|
|
8
|
+
* :mod:`defog_adapt.presets` the recorded recipes, as plain data
|
|
9
|
+
"""
|
|
10
|
+
from importlib.metadata import PackageNotFoundError, version as _version
|
|
11
|
+
|
|
12
|
+
try:
|
|
13
|
+
__version__ = _version("defog-adapt")
|
|
14
|
+
except PackageNotFoundError: # a source tree that was never installed
|
|
15
|
+
__version__ = "0.0.0+unknown"
|
|
16
|
+
|
|
17
|
+
__all__ = ["__version__"]
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"""
|
|
2
|
+
DeFoG Core Module - Clean, reusable discrete flow matching for graph generation.
|
|
3
|
+
|
|
4
|
+
This module provides the core DeFoG model functionality with explicit interfaces,
|
|
5
|
+
decoupled from Hydra configuration, for use in external projects.
|
|
6
|
+
|
|
7
|
+
Quick Start:
|
|
8
|
+
>>> from defog_adapt.core import DeFoGModel
|
|
9
|
+
>>> import pytorch_lightning as pl
|
|
10
|
+
>>> from torch_geometric.loader import DataLoader
|
|
11
|
+
>>>
|
|
12
|
+
>>> # Create model from dataloader (auto-infers dimensions)
|
|
13
|
+
>>> loader = DataLoader(dataset, batch_size=32)
|
|
14
|
+
>>> model = DeFoGModel.from_dataloader(loader)
|
|
15
|
+
>>>
|
|
16
|
+
>>> # Train
|
|
17
|
+
>>> trainer = pl.Trainer(max_epochs=100)
|
|
18
|
+
>>> trainer.fit(model, train_dataloaders=loader)
|
|
19
|
+
>>>
|
|
20
|
+
>>> # Sample
|
|
21
|
+
>>> samples = model.sample(num_samples=100)
|
|
22
|
+
|
|
23
|
+
Main Classes:
|
|
24
|
+
DeFoGModel: Main LightningModule for training and sampling
|
|
25
|
+
PlaceHolder: Container for graph tensors (X, E, y)
|
|
26
|
+
LimitDistribution: Noise/limit distribution specification
|
|
27
|
+
RateMatrixDesigner: CTMC rate matrix computation
|
|
28
|
+
TimeDistorter: Time distortion for variable step sizes
|
|
29
|
+
GraphTransformer: Neural network architecture
|
|
30
|
+
ExtraFeatures: RRWP and cycle features
|
|
31
|
+
|
|
32
|
+
Utility Functions:
|
|
33
|
+
to_dense: Convert PyG batch to dense tensors
|
|
34
|
+
dense_to_pyg: Convert dense tensors to PyG Data objects
|
|
35
|
+
compute_dataset_statistics: Analyze dataloader for model configuration
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
from .model import DeFoGModel
|
|
39
|
+
from .callbacks import (
|
|
40
|
+
TrainingMonitorCallback,
|
|
41
|
+
SampleVisualizationCallback,
|
|
42
|
+
EMACallback,
|
|
43
|
+
BestValLossCheckpoint,
|
|
44
|
+
PerLinkTimer,
|
|
45
|
+
)
|
|
46
|
+
from .domain import GraphDomain, GenericGraphDomain, generation_metrics
|
|
47
|
+
from .data import (
|
|
48
|
+
PlaceHolder,
|
|
49
|
+
to_dense,
|
|
50
|
+
dense_to_pyg,
|
|
51
|
+
DistributionNodes,
|
|
52
|
+
compute_dataset_statistics,
|
|
53
|
+
encode_no_edge,
|
|
54
|
+
symmetrize_edges,
|
|
55
|
+
)
|
|
56
|
+
from .noise import (
|
|
57
|
+
LimitDistribution,
|
|
58
|
+
sample_noise,
|
|
59
|
+
sample_from_probs,
|
|
60
|
+
)
|
|
61
|
+
from .size_distribution import (
|
|
62
|
+
SizeDistribution,
|
|
63
|
+
EmpiricalSizeDistribution,
|
|
64
|
+
FixedSizeDistribution,
|
|
65
|
+
ExplicitSizeDistribution,
|
|
66
|
+
CategoricalSizeDistribution,
|
|
67
|
+
ConditionalSizeDistribution,
|
|
68
|
+
LearnedSizeDistribution,
|
|
69
|
+
SizeBranch,
|
|
70
|
+
ComposedSizeDistribution,
|
|
71
|
+
)
|
|
72
|
+
from .rate_matrix import RateMatrixDesigner
|
|
73
|
+
from .sampler import Sampler, InpaintingSampler, AdaptedSampler
|
|
74
|
+
from .adapter import (
|
|
75
|
+
Modulation,
|
|
76
|
+
CrossAttentionAdapter,
|
|
77
|
+
AdaLNAdapter, # the research fork's name: an alias of the same class
|
|
78
|
+
FingerprintEncoder,
|
|
79
|
+
NodeConditionCrossAttention,
|
|
80
|
+
ConditionBranch,
|
|
81
|
+
AdapterComposition,
|
|
82
|
+
AdapterModule,
|
|
83
|
+
)
|
|
84
|
+
from .constraint import Constraint, SubgraphConstraint
|
|
85
|
+
from .energy import MoleculePropertyEnergy, StandardisedEnergy
|
|
86
|
+
from .feynman_kac import FeynmanKacSampler, predict_clean
|
|
87
|
+
from .property_head import PropertyHead, LearnedPropertyEnergy, fit_property_head, fit_size_model
|
|
88
|
+
from .spectrum import Band, SpectrumEnergy, band_masses
|
|
89
|
+
from .rl import (
|
|
90
|
+
RLTrainerBase,
|
|
91
|
+
GDPOTrainer,
|
|
92
|
+
AdapterGDPOTrainer,
|
|
93
|
+
SanityReward,
|
|
94
|
+
PropertyMatchReward,
|
|
95
|
+
WeightedSanityPropertyReward,
|
|
96
|
+
HeadPropertyMatchReward,
|
|
97
|
+
head_predict_batch,
|
|
98
|
+
make_condition_sampler,
|
|
99
|
+
RolloutSampler,
|
|
100
|
+
RolloutBuffer,
|
|
101
|
+
eager_logprob,
|
|
102
|
+
kl_clean,
|
|
103
|
+
group_advantage,
|
|
104
|
+
EMA,
|
|
105
|
+
)
|
|
106
|
+
from .time_distortion import TimeDistorter
|
|
107
|
+
from .transformer import GraphTransformer
|
|
108
|
+
from .features import ExtraFeatures, RRWPFeatures
|
|
109
|
+
from .loss import TrainLoss, compute_loss_components
|
|
110
|
+
from .layers import XEyTransformerLayer, NodeEdgeBlock, timestep_embedding
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
__all__ = [
|
|
114
|
+
# Main model
|
|
115
|
+
"DeFoGModel",
|
|
116
|
+
# Callbacks
|
|
117
|
+
"TrainingMonitorCallback",
|
|
118
|
+
"SampleVisualizationCallback",
|
|
119
|
+
"EMACallback",
|
|
120
|
+
"BestValLossCheckpoint",
|
|
121
|
+
"PerLinkTimer",
|
|
122
|
+
# Graph-domain adapters (decode / visualize / evaluate)
|
|
123
|
+
"GraphDomain",
|
|
124
|
+
"GenericGraphDomain",
|
|
125
|
+
"generation_metrics",
|
|
126
|
+
# Data utilities
|
|
127
|
+
"PlaceHolder",
|
|
128
|
+
"to_dense",
|
|
129
|
+
"dense_to_pyg",
|
|
130
|
+
"DistributionNodes",
|
|
131
|
+
"compute_dataset_statistics",
|
|
132
|
+
"encode_no_edge",
|
|
133
|
+
"symmetrize_edges",
|
|
134
|
+
# Size distributions
|
|
135
|
+
"SizeDistribution",
|
|
136
|
+
"EmpiricalSizeDistribution",
|
|
137
|
+
"FixedSizeDistribution",
|
|
138
|
+
"ExplicitSizeDistribution",
|
|
139
|
+
"CategoricalSizeDistribution",
|
|
140
|
+
"ConditionalSizeDistribution",
|
|
141
|
+
"LearnedSizeDistribution",
|
|
142
|
+
"SizeBranch",
|
|
143
|
+
"ComposedSizeDistribution",
|
|
144
|
+
# Noise distribution
|
|
145
|
+
"LimitDistribution",
|
|
146
|
+
"sample_noise",
|
|
147
|
+
"sample_from_probs",
|
|
148
|
+
# Rate matrix
|
|
149
|
+
"RateMatrixDesigner",
|
|
150
|
+
# Sampling orchestration
|
|
151
|
+
"Sampler",
|
|
152
|
+
"InpaintingSampler",
|
|
153
|
+
"AdaptedSampler",
|
|
154
|
+
"Modulation",
|
|
155
|
+
"CrossAttentionAdapter",
|
|
156
|
+
"AdaLNAdapter",
|
|
157
|
+
"FingerprintEncoder",
|
|
158
|
+
"NodeConditionCrossAttention",
|
|
159
|
+
"ConditionBranch",
|
|
160
|
+
"AdapterComposition",
|
|
161
|
+
"AdapterModule",
|
|
162
|
+
# Constraints (inpainting)
|
|
163
|
+
"Constraint",
|
|
164
|
+
"SubgraphConstraint",
|
|
165
|
+
# Feynman-Kac steering: energies, property heads, sampler (arXiv:2601.10403)
|
|
166
|
+
"MoleculePropertyEnergy",
|
|
167
|
+
"StandardisedEnergy",
|
|
168
|
+
"PropertyHead",
|
|
169
|
+
"fit_property_head",
|
|
170
|
+
"fit_size_model",
|
|
171
|
+
"LearnedPropertyEnergy",
|
|
172
|
+
"FeynmanKacSampler",
|
|
173
|
+
"predict_clean",
|
|
174
|
+
# Vibrational-spectrum steering
|
|
175
|
+
"Band",
|
|
176
|
+
"SpectrumEnergy",
|
|
177
|
+
"band_masses",
|
|
178
|
+
# GDPO reinforcement-learning fine-tuning (arXiv:2402.16302)
|
|
179
|
+
"RLTrainerBase",
|
|
180
|
+
"GDPOTrainer",
|
|
181
|
+
"AdapterGDPOTrainer",
|
|
182
|
+
"SanityReward",
|
|
183
|
+
"PropertyMatchReward",
|
|
184
|
+
"WeightedSanityPropertyReward",
|
|
185
|
+
"HeadPropertyMatchReward",
|
|
186
|
+
"head_predict_batch",
|
|
187
|
+
"make_condition_sampler",
|
|
188
|
+
"RolloutSampler",
|
|
189
|
+
"RolloutBuffer",
|
|
190
|
+
"eager_logprob",
|
|
191
|
+
"kl_clean",
|
|
192
|
+
"group_advantage",
|
|
193
|
+
"EMA",
|
|
194
|
+
# Time distortion
|
|
195
|
+
"TimeDistorter",
|
|
196
|
+
# Neural network
|
|
197
|
+
"GraphTransformer",
|
|
198
|
+
"XEyTransformerLayer",
|
|
199
|
+
"NodeEdgeBlock",
|
|
200
|
+
"timestep_embedding",
|
|
201
|
+
# Features
|
|
202
|
+
"ExtraFeatures",
|
|
203
|
+
"RRWPFeatures",
|
|
204
|
+
# Loss
|
|
205
|
+
"TrainLoss",
|
|
206
|
+
"compute_loss_components",
|
|
207
|
+
]
|
|
208
|
+
|