defog-adapt 0.1.0__tar.gz
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-0.1.0/.gitignore +35 -0
- defog_adapt-0.1.0/CHANGELOG.md +77 -0
- defog_adapt-0.1.0/CITATION.cff +26 -0
- defog_adapt-0.1.0/CLAUDE.md +114 -0
- defog_adapt-0.1.0/CONTRIBUTING.md +77 -0
- defog_adapt-0.1.0/LICENSE +21 -0
- defog_adapt-0.1.0/NOTICE +41 -0
- defog_adapt-0.1.0/PKG-INFO +361 -0
- defog_adapt-0.1.0/README.md +321 -0
- defog_adapt-0.1.0/SECURITY.md +21 -0
- defog_adapt-0.1.0/docs/about/citation-and-licence.md +22 -0
- defog_adapt-0.1.0/docs/about/contributing.md +40 -0
- defog_adapt-0.1.0/docs/about/limits.md +29 -0
- defog_adapt-0.1.0/docs/about/results-and-caveats.md +242 -0
- defog_adapt-0.1.0/docs/assets/banner/README.md +49 -0
- defog_adapt-0.1.0/docs/assets/banner/banner.gif +0 -0
- defog_adapt-0.1.0/docs/assets/banner/banner.py +400 -0
- defog_adapt-0.1.0/docs/assets/banner/candidates.py +49 -0
- defog_adapt-0.1.0/docs/assets/banner/molecules.py +163 -0
- defog_adapt-0.1.0/docs/assets/banner/record_trajectories.py +316 -0
- defog_adapt-0.1.0/docs/assets/banner/render_banner.py +162 -0
- defog_adapt-0.1.0/docs/assets/banner/trajectory.json +1 -0
- defog_adapt-0.1.0/docs/assets/diagrams/README.md +45 -0
- defog_adapt-0.1.0/docs/assets/diagrams/adapter-modulation.svg +2284 -0
- defog_adapt-0.1.0/docs/assets/diagrams/feynman-kac.svg +4457 -0
- defog_adapt-0.1.0/docs/assets/diagrams/recorded-pipeline.svg +3724 -0
- defog_adapt-0.1.0/docs/assets/diagrams/src/adapter_modulation.py +74 -0
- defog_adapt-0.1.0/docs/assets/diagrams/src/feynman_kac.py +98 -0
- defog_adapt-0.1.0/docs/assets/diagrams/src/publish.py +56 -0
- defog_adapt-0.1.0/docs/assets/diagrams/src/recorded_pipeline.py +111 -0
- defog_adapt-0.1.0/docs/assets/diagrams/src/steering_roles.py +107 -0
- defog_adapt-0.1.0/docs/assets/diagrams/src/vocab.py +321 -0
- defog_adapt-0.1.0/docs/assets/diagrams/steering-roles.svg +1385 -0
- defog_adapt-0.1.0/docs/assets/results_logp.json +198 -0
- defog_adapt-0.1.0/docs/assets/results_logp.png +0 -0
- defog_adapt-0.1.0/docs/assets/results_logp.py +157 -0
- defog_adapt-0.1.0/docs/assets/results_logp_dark.png +0 -0
- defog_adapt-0.1.0/docs/concepts/adapters.md +169 -0
- defog_adapt-0.1.0/docs/concepts/index.md +98 -0
- defog_adapt-0.1.0/docs/concepts/rl.md +156 -0
- defog_adapt-0.1.0/docs/concepts/steering.md +175 -0
- defog_adapt-0.1.0/docs/getting-started.md +46 -0
- defog_adapt-0.1.0/docs/guides/steer-toward-a-target.md +205 -0
- defog_adapt-0.1.0/docs/guides/steer_toward_a_target.py +128 -0
- defog_adapt-0.1.0/docs/guides/train-an-adapter.md +201 -0
- defog_adapt-0.1.0/docs/guides/train-an-unconditional-base.md +176 -0
- defog_adapt-0.1.0/docs/guides/train_an_adapter.py +171 -0
- defog_adapt-0.1.0/docs/guides/train_an_unconditional_base.py +141 -0
- defog_adapt-0.1.0/docs/index.md +65 -0
- defog_adapt-0.1.0/docs/reference/main-classes.md +89 -0
- defog_adapt-0.1.0/docs/reference/migration.md +108 -0
- defog_adapt-0.1.0/docs/reference/recipes.md +79 -0
- defog_adapt-0.1.0/docs/stylesheets/extra.css +5 -0
- defog_adapt-0.1.0/examples/README.md +11 -0
- defog_adapt-0.1.0/examples/_common.py +328 -0
- defog_adapt-0.1.0/examples/adapter_rl_finetune__zinc.py +577 -0
- defog_adapt-0.1.0/examples/adapter_training__zinc.py +378 -0
- defog_adapt-0.1.0/examples/compare_arms__zinc.py +442 -0
- defog_adapt-0.1.0/examples/fit_property_head__zinc.py +215 -0
- defog_adapt-0.1.0/examples/quickstart_cpu.py +182 -0
- defog_adapt-0.1.0/examples/rl_sanity__zinc.py +298 -0
- defog_adapt-0.1.0/examples/steer_zinc.py +345 -0
- defog_adapt-0.1.0/examples/training__e1.py +504 -0
- defog_adapt-0.1.0/mkdocs.yml +102 -0
- defog_adapt-0.1.0/pyproject.toml +146 -0
- defog_adapt-0.1.0/src/defog_adapt/__init__.py +17 -0
- defog_adapt-0.1.0/src/defog_adapt/core/__init__.py +208 -0
- defog_adapt-0.1.0/src/defog_adapt/core/adapter.py +785 -0
- defog_adapt-0.1.0/src/defog_adapt/core/callbacks.py +1470 -0
- defog_adapt-0.1.0/src/defog_adapt/core/constraint.py +148 -0
- defog_adapt-0.1.0/src/defog_adapt/core/data.py +457 -0
- defog_adapt-0.1.0/src/defog_adapt/core/domain.py +202 -0
- defog_adapt-0.1.0/src/defog_adapt/core/energy.py +124 -0
- defog_adapt-0.1.0/src/defog_adapt/core/features.py +418 -0
- defog_adapt-0.1.0/src/defog_adapt/core/feynman_kac.py +276 -0
- defog_adapt-0.1.0/src/defog_adapt/core/layers.py +391 -0
- defog_adapt-0.1.0/src/defog_adapt/core/loss.py +179 -0
- defog_adapt-0.1.0/src/defog_adapt/core/model.py +1280 -0
- defog_adapt-0.1.0/src/defog_adapt/core/noise.py +290 -0
- defog_adapt-0.1.0/src/defog_adapt/core/property_head.py +372 -0
- defog_adapt-0.1.0/src/defog_adapt/core/rate_matrix.py +429 -0
- defog_adapt-0.1.0/src/defog_adapt/core/rl.py +1103 -0
- defog_adapt-0.1.0/src/defog_adapt/core/sampler.py +379 -0
- defog_adapt-0.1.0/src/defog_adapt/core/size_distribution.py +762 -0
- defog_adapt-0.1.0/src/defog_adapt/core/spectrum.py +248 -0
- defog_adapt-0.1.0/src/defog_adapt/core/time_distortion.py +119 -0
- defog_adapt-0.1.0/src/defog_adapt/core/transformer.py +228 -0
- defog_adapt-0.1.0/src/defog_adapt/data/__init__.py +45 -0
- defog_adapt-0.1.0/src/defog_adapt/data/_paths.py +30 -0
- defog_adapt-0.1.0/src/defog_adapt/data/chembl_reference.py +142 -0
- defog_adapt-0.1.0/src/defog_adapt/data/moses_reference.py +407 -0
- defog_adapt-0.1.0/src/defog_adapt/data/vocabulary.py +137 -0
- defog_adapt-0.1.0/src/defog_adapt/data/zinc_reference.py +433 -0
- defog_adapt-0.1.0/src/defog_adapt/domains/__init__.py +40 -0
- defog_adapt-0.1.0/src/defog_adapt/domains/molecule.py +917 -0
- defog_adapt-0.1.0/src/defog_adapt/presets.py +166 -0
- defog_adapt-0.1.0/tests/_gdpo_frozen.py +577 -0
- defog_adapt-0.1.0/tests/_snippets.py +41 -0
- defog_adapt-0.1.0/tests/_tutorials.py +107 -0
- defog_adapt-0.1.0/tests/conftest.py +285 -0
- defog_adapt-0.1.0/tests/parity/cases.py +362 -0
- defog_adapt-0.1.0/tests/parity/generate_golden.py +50 -0
- defog_adapt-0.1.0/tests/parity/golden/golden.json +329 -0
- defog_adapt-0.1.0/tests/parity/test_parity.py +88 -0
- defog_adapt-0.1.0/tests/test_accumulation_plan.py +81 -0
- defog_adapt-0.1.0/tests/test_adapter.py +944 -0
- defog_adapt-0.1.0/tests/test_adapter_module.py +126 -0
- defog_adapt-0.1.0/tests/test_adapter_name.py +43 -0
- defog_adapt-0.1.0/tests/test_best_val_loss_checkpoint.py +118 -0
- defog_adapt-0.1.0/tests/test_callbacks.py +459 -0
- defog_adapt-0.1.0/tests/test_ci_config.py +135 -0
- defog_adapt-0.1.0/tests/test_compare_arms.py +403 -0
- defog_adapt-0.1.0/tests/test_conditioning.py +427 -0
- defog_adapt-0.1.0/tests/test_data.py +363 -0
- defog_adapt-0.1.0/tests/test_data_paths.py +79 -0
- defog_adapt-0.1.0/tests/test_diagrams.py +171 -0
- defog_adapt-0.1.0/tests/test_docs.py +252 -0
- defog_adapt-0.1.0/tests/test_docs_site.py +322 -0
- defog_adapt-0.1.0/tests/test_domain_viz.py +214 -0
- defog_adapt-0.1.0/tests/test_end_to_end_condition.py +213 -0
- defog_adapt-0.1.0/tests/test_energy.py +155 -0
- defog_adapt-0.1.0/tests/test_examples.py +167 -0
- defog_adapt-0.1.0/tests/test_features.py +169 -0
- defog_adapt-0.1.0/tests/test_feynman_kac.py +250 -0
- defog_adapt-0.1.0/tests/test_fk_resampling.py +83 -0
- defog_adapt-0.1.0/tests/test_import_hygiene.py +89 -0
- defog_adapt-0.1.0/tests/test_inpainting.py +291 -0
- defog_adapt-0.1.0/tests/test_layers.py +267 -0
- defog_adapt-0.1.0/tests/test_loss.py +221 -0
- defog_adapt-0.1.0/tests/test_model.py +377 -0
- defog_adapt-0.1.0/tests/test_molecular_features.py +133 -0
- defog_adapt-0.1.0/tests/test_molecular_metrics.py +92 -0
- defog_adapt-0.1.0/tests/test_morgan_condition.py +93 -0
- defog_adapt-0.1.0/tests/test_moses_reference.py +274 -0
- defog_adapt-0.1.0/tests/test_no_private_references.py +139 -0
- defog_adapt-0.1.0/tests/test_noise.py +330 -0
- defog_adapt-0.1.0/tests/test_per_link_timer.py +31 -0
- defog_adapt-0.1.0/tests/test_presets.py +160 -0
- defog_adapt-0.1.0/tests/test_prob_blending.py +183 -0
- defog_adapt-0.1.0/tests/test_property_head.py +101 -0
- defog_adapt-0.1.0/tests/test_pypi_readme.py +117 -0
- defog_adapt-0.1.0/tests/test_rate_matrix.py +194 -0
- defog_adapt-0.1.0/tests/test_readme_quickstart.py +62 -0
- defog_adapt-0.1.0/tests/test_recipes.py +234 -0
- defog_adapt-0.1.0/tests/test_release_metadata.py +68 -0
- defog_adapt-0.1.0/tests/test_results_figure.py +245 -0
- defog_adapt-0.1.0/tests/test_resume.py +118 -0
- defog_adapt-0.1.0/tests/test_rl.py +587 -0
- defog_adapt-0.1.0/tests/test_rl_parity.py +200 -0
- defog_adapt-0.1.0/tests/test_sanity_reward.py +148 -0
- defog_adapt-0.1.0/tests/test_size_distribution.py +544 -0
- defog_adapt-0.1.0/tests/test_spectrum.py +254 -0
- defog_adapt-0.1.0/tests/test_steer_tutorial.py +114 -0
- defog_adapt-0.1.0/tests/test_time_distortion.py +148 -0
- defog_adapt-0.1.0/tests/test_transformer.py +180 -0
- defog_adapt-0.1.0/tests/test_tutorial_chain.py +151 -0
- defog_adapt-0.1.0/tests/test_tutorial_pages.py +80 -0
- defog_adapt-0.1.0/tests/test_tutorial_settings.py +145 -0
- defog_adapt-0.1.0/tests/test_tutorial_style.py +65 -0
- defog_adapt-0.1.0/tests/test_vocabulary.py +202 -0
- defog_adapt-0.1.0/tests/test_weighted_reward.py +148 -0
- defog_adapt-0.1.0/tests/test_zinc_reference.py +349 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
.eggs/
|
|
6
|
+
build/
|
|
7
|
+
dist/
|
|
8
|
+
.pytest_cache/
|
|
9
|
+
.coverage
|
|
10
|
+
htmlcov/
|
|
11
|
+
|
|
12
|
+
# Environments
|
|
13
|
+
.venv/
|
|
14
|
+
.venv*/
|
|
15
|
+
venv/
|
|
16
|
+
|
|
17
|
+
# Local working area (scratch output, logs); never committed
|
|
18
|
+
.work/
|
|
19
|
+
|
|
20
|
+
# The built documentation site (`mkdocs build`)
|
|
21
|
+
/site/
|
|
22
|
+
|
|
23
|
+
# Figure documents that the diagram build writes beside its scripts (the scripts are the source)
|
|
24
|
+
/docs/assets/diagrams/src/*.vectorcraft
|
|
25
|
+
|
|
26
|
+
# Never commit weights, datasets or experiment output. Checkpoints are not distributed with the
|
|
27
|
+
# package; the parity tests read them from $DEFOG_ADAPT_CKPTS.
|
|
28
|
+
*.ckpt
|
|
29
|
+
*.pt
|
|
30
|
+
*.pth
|
|
31
|
+
*.safetensors
|
|
32
|
+
/data/
|
|
33
|
+
/ckpts/
|
|
34
|
+
results/
|
|
35
|
+
.DS_Store
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (2026-11-26)
|
|
4
|
+
|
|
5
|
+
First release: a standalone port of the `defog/` package of a research fork of
|
|
6
|
+
[DeFoG](https://arxiv.org/abs/2410.04263), keeping only features with a recorded positive result.
|
|
7
|
+
Import name `defog_adapt`. Code only: no model weights ship.
|
|
8
|
+
|
|
9
|
+
### Included
|
|
10
|
+
|
|
11
|
+
- **Frozen-base adapters**: `CrossAttentionAdapter` (gated FiLM, node-to-condition cross-attention, Fourier bands on
|
|
12
|
+
the condition, an encoder for high-dimensional conditions), `AdapterModule`, `AdapterComposition`
|
|
13
|
+
(product or mean of probability-space marginals), `AdaptedSampler`.
|
|
14
|
+
- **Learned node counts**: `LearnedSizeDistribution`, `ComposedSizeDistribution`, `fit_size_model`.
|
|
15
|
+
- **Feynman-Kac steering**: `FeynmanKacSampler` (with `trace`), `StandardisedEnergy`, `MoleculePropertyEnergy`,
|
|
16
|
+
`LearnedPropertyEnergy`, `PropertyHead`, `fit_property_head`.
|
|
17
|
+
- **GDPO fine-tuning**: `GDPOTrainer`, `AdapterGDPOTrainer` and the rewards that were used with them
|
|
18
|
+
(`SanityReward`, `PropertyMatchReward`, `HeadPropertyMatchReward`, `WeightedSanityPropertyReward`).
|
|
19
|
+
- **Inpainting** (`InpaintingSampler`, `SubgraphConstraint`) and a **spectrum energy** (`SpectrumEnergy`,
|
|
20
|
+
`Band`): thin evidence, see `docs/about/results-and-caveats.md`.
|
|
21
|
+
- **Molecules**: encode and decode, validity and distribution metrics, `morgan_condition`, kekulized
|
|
22
|
+
representations, and reference-split loaders for ZINC250k, MOSES and ChEMBL.
|
|
23
|
+
- `defog_adapt.presets`: the recorded recipes as plain data.
|
|
24
|
+
- `examples/`: a CPU quickstart, PyComex recipes (E1 base training, optionally end to end on a property and, with
|
|
25
|
+
`MICRO_BATCH_SIZE`, with the recorded batch accumulated on a 24 GB GPU; structural RL, adapter training, adapter RL), the property-head script, `steer_zinc.py` (the assembly) and `compare_arms__zinc.py` (the
|
|
26
|
+
comparison behind the README's results figure).
|
|
27
|
+
- `docs/`: the documentation, built as a Material for MkDocs site: concepts (adapters, steering, RL), guides, reference
|
|
28
|
+
(main classes, recipes, migration) and about (limits, results and caveats, contributing, citation). Four diagrams
|
|
29
|
+
(`docs/assets/diagrams/`) show the recorded pipeline, how an adapter plugs in, Feynman-Kac steering, and what a steered
|
|
30
|
+
run needs and what is optional in it; they are schematic, drawn from scripts, and their text is outlines so that they
|
|
31
|
+
need no font. The three guides are tutorials, each around one runnable script in `docs/guides/` that is shown in short
|
|
32
|
+
steps and in full at the bottom of its page. "Train an unconditional base" trains a small base on your own SMILES, with
|
|
33
|
+
an optional RL cleanup; "Train an adapter" labels the graphs by the decoded graph, builds, trains and checks an adapter,
|
|
34
|
+
and fits the size model and the property head; "Steer toward a target" runs the adapter alone, then adds a size model
|
|
35
|
+
and Feynman-Kac steering. They write out the recorded settings and explain each one, and the code is wrapped for the
|
|
36
|
+
code window (no line over 88 characters, a call with four or more arguments one per line). A test runs the three scripts
|
|
37
|
+
one after the other on tiny data, so that the files each writes are the ones the next loads.
|
|
38
|
+
- The five-way logP comparison behind the README figure, trained and measured in this repository: the unconditional base, a
|
|
39
|
+
model trained end to end, a FiLM adapter, a cross-attention adapter and Feynman-Kac on top of it, on the held-out test split
|
|
40
|
+
over three seeds (`docs/about/results-and-caveats.md`; `docs/assets/results_logp.json` holds the data and
|
|
41
|
+
`docs/assets/results_logp.py` draws it, in a light and a dark variant).
|
|
42
|
+
- `docs/assets/banner/`: the animated README banner (one recorded sampler run, base alone and then with a logP
|
|
43
|
+
adapter, from the same noise), its recorded trajectory and the scripts that made it.
|
|
44
|
+
- The README opens with installation, the results figure (`docs/assets/results_logp.py`) and a self-contained
|
|
45
|
+
quickstart that runs on a CPU after `pip install` (and is executed by `tests/test_readme_quickstart.py`), and
|
|
46
|
+
has a BibTeX block and badges. `CONTRIBUTING.md` and `SECURITY.md` are new.
|
|
47
|
+
- One extra, `chem` (RDKit). pandas, psutil and nvidia-ml-py are core dependencies; the contributor tools are a
|
|
48
|
+
`dev` dependency group; PyComex, which the recipes need, is installed separately because it caps numpy below 2.
|
|
49
|
+
|
|
50
|
+
### Changed relative to the research fork
|
|
51
|
+
|
|
52
|
+
- Import name `defog` to `defog_adapt`; experiment helpers now live in `defog_adapt.domains.molecule`.
|
|
53
|
+
- `AdaLNAdapter` is now `CrossAttentionAdapter`, the name of the recorded architecture. The old name is an alias of
|
|
54
|
+
the same class, so fork code and every adapter checkpoint (which stores no class name) keep working.
|
|
55
|
+
- Trainer defaults are the recorded recipes, and `AdapterGDPOTrainer(rollout_weight=...)` is **required**.
|
|
56
|
+
- Only probability-space guidance blending remains (rate-space blending was numerically broken above weight 1).
|
|
57
|
+
- `MoleculeDomain.encode` encodes an aromatic core in Kekule form when the vocabulary is kekulized.
|
|
58
|
+
- The library no longer selects a matplotlib backend at import time or leaks a pyplot figure per epoch.
|
|
59
|
+
- Reference data is read from `$DEFOG_ADAPT_HOME` or a per-user cache and is never downloaded silently.
|
|
60
|
+
- `defog_adapt.__version__` is read from the installed metadata.
|
|
61
|
+
|
|
62
|
+
### Removed relative to the research fork
|
|
63
|
+
|
|
64
|
+
Features with a null, negative, superseded or untried result: the other RL estimators (RAM, DAM, NFT), credit
|
|
65
|
+
assignment, distribution-fidelity penalties, the guidance family and its samplers, autoguidance, the refinement
|
|
66
|
+
sampler, the spectrum condition encoder, interior adapters, Feynman-Kac rejuvenation and beta schedules, and the
|
|
67
|
+
GuacaMol reference loader. The complete list, with reasons, is in `docs/reference/migration.md`. Checkpoints that need a
|
|
68
|
+
removed feature raise an error that says so instead of loading a different model.
|
|
69
|
+
|
|
70
|
+
### Verified
|
|
71
|
+
|
|
72
|
+
- A golden-output parity test runs real checkpoints through the sampling, adapter, Feynman-Kac and RL code and
|
|
73
|
+
matches the research package bit for bit.
|
|
74
|
+
- The unit suite passes with every dependency at its tested minimum (Python 3.10, torch 2.1, PyG 2.3, Lightning
|
|
75
|
+
2.4, numpy 1.23) and on current releases.
|
|
76
|
+
- Every recipe runs end to end in its smoke configuration, on PyComex 0.13.1 and 0.29.
|
|
77
|
+
- A wheel and sdist build, pass `twine check`, install into a clean environment and import.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use defog-adapt, please cite it, and cite the DeFoG paper it builds on."
|
|
3
|
+
title: "defog-adapt"
|
|
4
|
+
type: software
|
|
5
|
+
authors:
|
|
6
|
+
- family-names: Teufel
|
|
7
|
+
given-names: Jonas
|
|
8
|
+
license: MIT
|
|
9
|
+
repository-code: "https://github.com/aimat-lab/defog-adapt"
|
|
10
|
+
version: "0.1.0"
|
|
11
|
+
date-released: "2026-11-26"
|
|
12
|
+
references:
|
|
13
|
+
- type: conference-paper
|
|
14
|
+
title: "DeFoG: Discrete Flow Matching for Graph Generation"
|
|
15
|
+
authors:
|
|
16
|
+
- family-names: Qin
|
|
17
|
+
given-names: Yiming
|
|
18
|
+
- family-names: Madeira
|
|
19
|
+
given-names: Manuel
|
|
20
|
+
- family-names: Thanou
|
|
21
|
+
given-names: Dorina
|
|
22
|
+
- family-names: Frossard
|
|
23
|
+
given-names: Pascal
|
|
24
|
+
collection-title: "International Conference on Machine Learning (ICML), PMLR 267"
|
|
25
|
+
year: 2025
|
|
26
|
+
url: "https://arxiv.org/abs/2410.04263"
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
Guidance for working in this repository.
|
|
4
|
+
|
|
5
|
+
## What this is
|
|
6
|
+
|
|
7
|
+
`defog-adapt` (import `defog_adapt`) is a standalone, PyPI-targeted port of the `defog/` package of a
|
|
8
|
+
research fork of DeFoG (discrete flow matching for graph generation). It keeps **only features with
|
|
9
|
+
a recorded positive result**; null, negative, superseded and untried features were left out on
|
|
10
|
+
purpose. Do not re-add a feature without evidence that it works, and say what the evidence is.
|
|
11
|
+
|
|
12
|
+
## Layout
|
|
13
|
+
|
|
14
|
+
- `src/defog_adapt/core/` base model, adapters, samplers, Feynman-Kac steering, energies, RL, size models
|
|
15
|
+
- `src/defog_adapt/domains/molecule.py` RDKit decode/encode/metrics (needs the `chem` extra)
|
|
16
|
+
- `src/defog_adapt/data/` reference-split loaders (ZINC250k, MOSES, ChEMBL) and vocabularies
|
|
17
|
+
- `src/defog_adapt/presets.py` the recorded recipes as plain data (every value has its evidence in a comment)
|
|
18
|
+
- `tests/` CPU-only unit tests; `tests/parity/` opt-in comparison against golden outputs of the research repo;
|
|
19
|
+
`tests/test_recipes.py` opt-in smoke runs of every recipe
|
|
20
|
+
- `examples/` the quickstart, the PyComex recipes (optional `recipes` extra) and `steer_zinc.py`, the assembly
|
|
21
|
+
- `docs/` the documentation: Home and Getting started, `concepts/` (overview, adapters, steering, RL), `guides/`,
|
|
22
|
+
`reference/` (main classes, recipes, migration) and `about/` (limits, results and caveats, contributing, citation)
|
|
23
|
+
- `mkdocs.yml` the documentation site (Material for MkDocs). Every page of `docs/` is in its nav, and code on its pages is
|
|
24
|
+
included from the README, `docs/concepts/adapters.md` and the three tutorial scripts in `docs/guides/`
|
|
25
|
+
(`train_an_unconditional_base.py`, `train_an_adapter.py`, `steer_toward_a_target.py`: the one copy of a tutorial's code,
|
|
26
|
+
shown in pieces by section and in full at the end of its page) by `--8<--` markers, never copied
|
|
27
|
+
|
|
28
|
+
## Commands
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
uv venv --python 3.12 .venv && uv pip install -e ".[chem]" --group dev # CPU torch first: see the README
|
|
32
|
+
OMP_NUM_THREADS=2 .venv/bin/python -m pytest -n 8 # unit tests, no network, ~30 s
|
|
33
|
+
DEFOG_ADAPT_CKPTS=/path/to/ckpts .venv/bin/python -m pytest -m parity # parity gate (local only)
|
|
34
|
+
DEFOG_ADAPT_HOME=/path/to/data DEFOG_ADAPT_CKPTS=/path/to/ckpts .venv/bin/python -m pytest tests/test_recipes.py
|
|
35
|
+
uv pip install --group docs && mkdocs build --strict # the documentation site: no PyTorch needed
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Without `OMP_NUM_THREADS=2` the suite takes many times longer: tiny tensors across every core thrash. The
|
|
39
|
+
recipes need PyComex (`pip install pycomex`), which caps `numpy<2`, so run them in an environment of their own.
|
|
40
|
+
|
|
41
|
+
## Rules
|
|
42
|
+
|
|
43
|
+
- **Parity gate.** After every change to a ported module, the parity tests must still match the golden
|
|
44
|
+
outputs bit for bit. Run it on a `git archive` snapshot, not the working tree (the library imports lazily).
|
|
45
|
+
Any drift must be understood, not tolerated.
|
|
46
|
+
- **Checkpoint compatibility.** Every config key present in existing checkpoints stays accepted; removed
|
|
47
|
+
features accept only their neutral value and otherwise raise a clear error.
|
|
48
|
+
- **Test your tests.** Every new test is checked against a deliberately broken implementation, **after**
|
|
49
|
+
asserting that the unbroken one passes (a failing baseline makes every "caught" meaningless). Mutate the
|
|
50
|
+
code under test, not the test. A test that cannot fail is not a test; this found more than one vacuous one.
|
|
51
|
+
- **Examples must run.** A recipe that is not run has already rotted. Keep `tests/test_recipes.py` green when
|
|
52
|
+
the library API changes, and assert on a recipe's own output, not on PyComex's banner (it varies by version).
|
|
53
|
+
- **Documentation is tested.** `tests/test_docs.py` parses every code block (an include is expanded first), checks every
|
|
54
|
+
`defog_adapt` import in one and every link and anchor. The tutorials are tested by `tests/test_tutorial_*.py` (and
|
|
55
|
+
`test_steer_tutorial.py`): the structure of each page, every written-out setting against its preset and its table, the
|
|
56
|
+
three scripts run one after the other on tiny data, and the style of the code (no line over 88 characters, a call with
|
|
57
|
+
four or more arguments one per line). Every number on `docs/about/results-and-caveats.md` needs a source and its protocol.
|
|
58
|
+
- **The site is the documentation.** Every page of `docs/` is in the nav of `mkdocs.yml`, and a number on any page has
|
|
59
|
+
the same source as on `docs/about/results-and-caveats.md`. `mkdocs build --strict` (group `docs`, no PyTorch) and
|
|
60
|
+
`tests/test_docs_site.py` guard the nav, the exclusions, the includes and the config. Keep the config portable (no
|
|
61
|
+
hooks, no plugin beyond search, publish through the Pages artifact flow, never `gh-deploy`): Material for MkDocs
|
|
62
|
+
ends on 2027-05-05 and its successor reads the same file. Publishing is dormant until the repository is public.
|
|
63
|
+
- **No network and no local data in unit tests.** Reference-split tests pass `download=False`.
|
|
64
|
+
- **Never commit** checkpoints, datasets, experiment output, cluster or account names, job IDs, local paths, or
|
|
65
|
+
the names of sibling projects. `tests/test_no_private_references.py` fails on the generic patterns (paths,
|
|
66
|
+
scheduler commands, job numbers, addresses) everywhere. The SPECIFIC names (a published list of private names is
|
|
67
|
+
itself a leak) are read from a file named by `DEFOG_ADAPT_PRIVATE_PATTERNS`, one regex per line, that the
|
|
68
|
+
maintainer keeps OUTSIDE the repository; set it when running the suite locally. Before publishing a history,
|
|
69
|
+
scan **every commit**, not just the tip: the intermediate commits of a port are where leaks hide.
|
|
70
|
+
- **Dependency floors are tested**, not guessed: the suite passes with every dependency at its minimum on
|
|
71
|
+
Python 3.10. Change a floor only by running it.
|
|
72
|
+
- **The PyPI page is the README, with its relative paths made absolute at build time** (hatch-fancy-pypi-readme, the rules
|
|
73
|
+
in `pyproject.toml`); the README in the repository keeps them relative. `tests/test_pypi_readme.py` builds the wheel and
|
|
74
|
+
checks the description it carries. A new kind of path in the README (a reference-style link, say) needs a rule.
|
|
75
|
+
- Commits and pushes to the working branch need no go-ahead. Releasing does: tags, PyPI uploads, making the repository
|
|
76
|
+
public, merging a pull request.
|
|
77
|
+
|
|
78
|
+
## Releasing
|
|
79
|
+
|
|
80
|
+
Nothing publishes by accident. A pushed `v*` tag runs `.github/workflows/release.yml`, which builds the sdist and the
|
|
81
|
+
wheel, checks them with `twine check` and keeps them as the `dist` artifact of the run; a manual run of the workflow does
|
|
82
|
+
the same and nothing more, so it is the dry run. There is no TestPyPI step: only a PyPI account exists. To release (every
|
|
83
|
+
step that publishes needs the maintainer's go-ahead):
|
|
84
|
+
|
|
85
|
+
1. Set `version` in `pyproject.toml` and `CITATION.cff` (with its `date-released`) and date the top entry of
|
|
86
|
+
`CHANGELOG.md`; `tests/test_release_metadata.py` checks that they agree.
|
|
87
|
+
2. Run the gates: the unit suite, the minimum-versions job in CI, the parity gate and `tests/test_recipes.py`.
|
|
88
|
+
3. Merge to `main`, wait for CI, then push the tag `v<version>` on that commit.
|
|
89
|
+
4. Upload what the tag's run built, so that PyPI gets the files CI checked: `gh run download <run-id> -n dist -D dist`,
|
|
90
|
+
then `uv publish dist/*`, which reads the maintainer's PyPI token from `UV_PUBLISH_TOKEN`. (The first upload of a
|
|
91
|
+
project needs an account-wide token, because a project-scoped one cannot exist yet: scope it to the project after.)
|
|
92
|
+
5. Look at the project page on PyPI, and install the release into a clean environment.
|
|
93
|
+
|
|
94
|
+
PyPI **Trusted Publishing** is the alternative to the token, and the job `publish-pypi` of the workflow is for it. It is
|
|
95
|
+
dormant: it runs only when the repository variable `PYPI_TRUSTED_PUBLISHING` is `true`. Set it up once, on the maintainer's
|
|
96
|
+
side: on PyPI add a *trusted publisher* for the project `defog-adapt` (this repository, workflow `release.yml`,
|
|
97
|
+
environment `pypi`), create the GitHub environment `pypi` with a required reviewer (possible for a public repository on
|
|
98
|
+
the free plan), and set the variable. From then on a tag push builds, waits for the reviewer and publishes, and the token
|
|
99
|
+
can be deleted.
|
|
100
|
+
|
|
101
|
+
## Behaviour notes that matter
|
|
102
|
+
|
|
103
|
+
- Molecules must be **kekulized**: the aromatic bond class is lossy (118 of 120 hard validity failures on the
|
|
104
|
+
aromatic MOSES base were kekulization errors).
|
|
105
|
+
- A graph stores **no formal charge**: the property of a source SMILES and of the decoded graph differ by up to
|
|
106
|
+
1.6 logP. Every recorded result labelled by the decoded graph (`property_from="decoded"`), and the adapter, head
|
|
107
|
+
and size model must agree.
|
|
108
|
+
- **Feynman-Kac `beta` is dimensionless only through `StandardisedEnergy`.** At `beta` 20 it is the largest lever
|
|
109
|
+
measured, at a cost in diversity; a starved `beta` (2.5) made it look useless. Read `FeynmanKacSampler.trace`.
|
|
110
|
+
- **Do not read a re-packaged checkpoint's stored hyperparameters as its training configuration.** The adapter base
|
|
111
|
+
is weight-identical to the two-round RL model and carries the E1 recipe; its file stores defaults.
|
|
112
|
+
- RL: `rollout_weight` must be the deployed guidance weight; one round for adapters; probe many fixed targets and
|
|
113
|
+
always compute the true property beside the selection metric.
|
|
114
|
+
- Gains from RL and from Feynman-Kac do not add.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Contributing to defog-adapt
|
|
2
|
+
|
|
3
|
+
Issues and pull requests are welcome. This page explains the one rule that is specific to this project, how to run
|
|
4
|
+
the checks, and what they guard.
|
|
5
|
+
|
|
6
|
+
## The scope rule: only features with a recorded positive result
|
|
7
|
+
|
|
8
|
+
`defog-adapt` deliberately contains **only features that have a recorded positive result**. Things that were tried
|
|
9
|
+
and came out null, negative or superseded are left out on purpose; the list, with the reasons, is in
|
|
10
|
+
[`docs/reference/migration.md`](docs/reference/migration.md#what-was-removed). So a new feature has to arrive with its evidence: the
|
|
11
|
+
protocol, the numbers and their run-to-run noise. Say in the pull request what the evidence is, and add the number
|
|
12
|
+
to [`docs/about/results-and-caveats.md`](docs/about/results-and-caveats.md) with its source. Bug fixes, documentation and tests need no such evidence.
|
|
13
|
+
|
|
14
|
+
## Setting up
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
git clone https://github.com/aimat-lab/defog-adapt && cd defog-adapt
|
|
18
|
+
uv venv --python 3.12 .venv && uv pip install -e ".[chem]" --group dev # CPU PyTorch first if you have no GPU
|
|
19
|
+
OMP_NUM_THREADS=2 .venv/bin/python -m pytest -n 8 # the unit suite: no network, about 30 s
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
With plain pip (25.1 or newer), `pip install -e ".[chem]" --group dev` and `pytest` do the same. `chem` is the only
|
|
23
|
+
extra; the contributor tools are the `dev` dependency group. Keep `OMP_NUM_THREADS=2`: without it the suite takes
|
|
24
|
+
many times longer, because tiny tensors spread across every core thrash.
|
|
25
|
+
|
|
26
|
+
Two checks are opt-in because they need the research checkpoints and data. `tests/parity` runs real checkpoints
|
|
27
|
+
through the library and compares them with golden outputs from the research package; it is the release gate.
|
|
28
|
+
`tests/test_recipes.py` runs every recipe in `examples/` end to end (these also need PyComex, which caps numpy below
|
|
29
|
+
2, so give them an environment of their own and `pip install pycomex` there):
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
DEFOG_ADAPT_CKPTS=/path/to/ckpts python -m pytest -m parity
|
|
33
|
+
DEFOG_ADAPT_HOME=/path/to/data DEFOG_ADAPT_CKPTS=/path/to/ckpts python -m pytest tests/test_recipes.py
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## The documentation site
|
|
37
|
+
|
|
38
|
+
The documentation is a [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/) site
|
|
39
|
+
(`mkdocs.yml` and the pages under `docs/`). It has a dependency group of its own and needs no PyTorch:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
uv pip install --group docs
|
|
43
|
+
mkdocs serve # a live preview at http://127.0.0.1:8000
|
|
44
|
+
mkdocs build --strict # what CI runs: a broken link, a missing snippet or a page that is not in the nav fails it
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The build prints a notice about MkDocs 2.0; set `NO_MKDOCS_2_WARNING=1` to hide it. Every page of `docs/` is part of the
|
|
48
|
+
site (the nav is in `mkdocs.yml`; `exclude_docs` leaves out only the scripts and data that build the banner and the
|
|
49
|
+
figure). Code on the site pages is included from the README and from `docs/concepts/adapters.md` with `--8<--` markers,
|
|
50
|
+
so that there is one tested copy: keep the markers where they are when you edit that code. Nothing is published yet, because GitHub Pages needs a public repository.
|
|
51
|
+
|
|
52
|
+
## Rules the checks enforce
|
|
53
|
+
|
|
54
|
+
- **Test your tests.** Check every new test against a deliberately broken implementation, after asserting that the
|
|
55
|
+
unbroken one passes. Break the code under test, not the test. A test that cannot fail is not a test.
|
|
56
|
+
- **Examples must run.** A recipe or a README snippet that is not run has already rotted. The README quickstart is
|
|
57
|
+
executed by `tests/test_readme_quickstart.py`; keep it, and `tests/test_recipes.py`, green when the API changes.
|
|
58
|
+
- **Documentation is tested.** `tests/test_docs.py` parses every code block, checks every `defog_adapt` import in one,
|
|
59
|
+
and resolves every link and anchor, every snippet include, every GitHub link to this repository and every
|
|
60
|
+
`python examples/...` command. `tests/test_docs_site.py` and `mkdocs build --strict` check the site. Every number on
|
|
61
|
+
`docs/about/results-and-caveats.md` needs a source and its protocol.
|
|
62
|
+
- **Checkpoint compatibility.** Every config key present in existing checkpoints stays accepted; a removed feature
|
|
63
|
+
accepts only its neutral value and otherwise raises a clear error.
|
|
64
|
+
- **Dependency floors are tested, not guessed.** The suite passes with every dependency at its minimum on Python
|
|
65
|
+
3.10; change a floor only by running it.
|
|
66
|
+
- **No network and no local data in unit tests.**
|
|
67
|
+
- **Never commit** checkpoints, datasets, experiment output, cluster or account names, job IDs or local paths.
|
|
68
|
+
`tests/test_no_private_references.py` fails on the generic patterns.
|
|
69
|
+
|
|
70
|
+
[`CLAUDE.md`](CLAUDE.md) has the code layout and the same conventions, written for anyone (or any tool) working in
|
|
71
|
+
the repository.
|
|
72
|
+
|
|
73
|
+
## Pull requests
|
|
74
|
+
|
|
75
|
+
Keep the pull request to one change. Run the unit suite, say what you changed and why, and update the documentation
|
|
76
|
+
and [`CHANGELOG.md`](CHANGELOG.md) where the change is visible to users. Security problems go to
|
|
77
|
+
[`SECURITY.md`](SECURITY.md), not to a public issue.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Copyright (c) 2026 Jonas Teufel <jonseb1998@gmail.com>
|
|
2
|
+
Copyright (c) 2012-2025 Manuel Madeira, Yiming Qin
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
5
|
+
a copy of this software and associated documentation files (the
|
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
10
|
+
the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be
|
|
13
|
+
included in all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
defog_adapt-0.1.0/NOTICE
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
defog-adapt
|
|
2
|
+
Copyright (c) 2026 Jonas Teufel
|
|
3
|
+
|
|
4
|
+
This package is derived from DeFoG (Discrete Flow Matching for Graph Generation):
|
|
5
|
+
|
|
6
|
+
Yiming Qin, Manuel Madeira, Dorina Thanou, Pascal Frossard.
|
|
7
|
+
"DeFoG: Discrete Flow Matching for Graph Generation." ICML 2025.
|
|
8
|
+
https://arxiv.org/abs/2410.04263
|
|
9
|
+
https://github.com/qym7/DeFoG
|
|
10
|
+
|
|
11
|
+
The base model (graph transformer, noise distributions, rate-matrix construction, time
|
|
12
|
+
distortion, RRWP features) follows the upstream implementation, which is MIT licensed
|
|
13
|
+
(Copyright (c) 2012-2025 Manuel Madeira, Yiming Qin; see LICENSE). The upstream notice is
|
|
14
|
+
retained as required.
|
|
15
|
+
|
|
16
|
+
Provenance. The code in this package was ported from a research fork of DeFoG (commit
|
|
17
|
+
68637b5 of that fork), keeping only the features that have a recorded positive result there.
|
|
18
|
+
Features that were tried and failed, came out null, or were never tried are not included.
|
|
19
|
+
Frozen-base adapters, Feynman-Kac steering, GDPO reinforcement-learning fine-tuning, learned
|
|
20
|
+
size conditioning and the molecular domain code were added in that fork.
|
|
21
|
+
|
|
22
|
+
Methods used in this package, and the papers they come from (titles and authors as listed on
|
|
23
|
+
arXiv):
|
|
24
|
+
|
|
25
|
+
DeFoG: Discrete Flow Matching for Graph Generation (base model)
|
|
26
|
+
Qin, Madeira, Thanou, Frossard. arXiv:2410.04263
|
|
27
|
+
Discrete Feynman-Kac Correctors (Feynman-Kac / SMC steering)
|
|
28
|
+
Hasan, Ohanesian, Gazizov, Bengio, Aspuru-Guzik,
|
|
29
|
+
Bondesan, Skreta, Neklyudov. arXiv:2601.10403
|
|
30
|
+
Graph Diffusion Policy Optimization (GDPO reinforcement-learning fine-tuning)
|
|
31
|
+
Liu, Du, Pang, Li, Lin, Chen. arXiv:2402.16302
|
|
32
|
+
Fourier Features Let Networks Learn High Frequency Functions in Low Dimensional
|
|
33
|
+
Domains (Fourier condition bands in the adapter)
|
|
34
|
+
Tancik, Srinivasan, Mildenhall, Fridovich-Keil, Raghavan,
|
|
35
|
+
Singhal, Ramamoorthi, Barron, Ng. arXiv:2006.10739
|
|
36
|
+
Classifier-free graph diffusion for molecular property targeting (FreeGress; the
|
|
37
|
+
node-count conditioning idea and the property-targeting evaluation protocol)
|
|
38
|
+
Ninniri, Podda, Bacciu. arXiv:2312.17397
|
|
39
|
+
|
|
40
|
+
The implementations here are independent adaptations to DeFoG's categorical outputs, not the
|
|
41
|
+
authors' code. Any error in them is this package's.
|