Conversation
66b59af to
578dd37
Compare
391f039 to
99121cf
Compare
2df8bd1 to
cf6039c
Compare
* Update atom pair utilities and Scaler * Move utility to pair helpers * lint --------- Co-authored-by: Pol <pfebrer96@gmail.com>
HaoZeke
left a comment
There was a problem hiding this comment.
This is two new experimental architectures plus a pile of core mutations (scaler, composition, loss, eval, SPACE). It cannot land in this shape.
The package-level breakage is in src/metatrain/utils/additive/remove.py: it imports metatrain.experimental.edge_composition, which imports elearn. elearn is not on PyPI and is not a metatrain extra. That is why tests dies at conftest collection (ModuleNotFoundError: No module named 'elearn') and why docs die the same way. A core util cannot import an experimental architecture.
src/metatrain/utils/loss.py has the same layering leak. MatrixLoss.compute imports graph2mat and experimental.graph2mat, then hardcodes matrix_name = "hamiltonian". Loss functions in utils/ have to stay architecture-agnostic.
tox.ini is also just wrong. [testenv:mace-tests] now changedirs into experimental/edge_composition/tests/, and [testenv:edge-composition-tests] points at experimental/dpa3/tests/. There is no graph2mat-tests env at all.
On the experimental lifecycle (docs/src/dev-docs/architecture-life-cycle.rst):
graph2mathas noArchitectureTests/TorchscriptTests. The only test (tests/test_transforms.py) reads/home/febrer/COSMO_disk/.../scfbench_main_100.zip.MetaGraph2Mat.exportisNotImplementedError(model.py:614). JIT is a listed experimental requirement.pyproject.tomlhas nograph2matextra (graph2matis on PyPI 0.0.13;e3nnandsphericart-torchare also imported at module level).edge-compositionextras list onlysphericart-torch. The model importselearnandfeatomic.torchat the top ofmodel.py.CODEOWNERSis untouched. ChangelogUnreleasedis empty. Contributor checklist is all[ ].
The core side-effects look like debug leftovers, not a reviewable contract:
composition/model.pycomments outdensify_atomic_basis_dataset_infoand the eval-mode sparsify, and leavesif not self.training: ....composition/trainer.pycomments outatomic_basis_transform.experimental/space/model.pystops skippingmtt::aux::outputs.additive/remove.pyhasif True or isinstance(...)/if False and not isinstance(...).
experimental.graph2mat as a wrapper around a featurizer is a reasonable experiment. The PR description already says the target type is made up, export is unfinished, GPU is untested, and this might stay a draft until Joe's PET matrix path exists. That is fine as a branch. It is not fine as a merge into main.
What I would do:
- Revert every change under
src/metatrain/{cli,composition,scaler,utils,experimental/space}andtox.iniexcept things that have their own PR and tests (theatom_pairhelpers maybe). - Split
edge_compositionout. It is a second architecture and it currently poisons the default import graph. - Give
graph2matthe usual experimental skeleton: extra, CODEOWNERS, tox + architecture-tests job,ArchitectureTests+TorchscriptTestson an in-repo fixture, workingexport(), no star import, no MACE copy-paste leftovers (model.py:46,restarterror string,cutoff = 80.999 + i * 0.03). - Keep
MatrixLoss/Blocks2Matrixinsideexperimental.graph2matuntil they do not namehamiltonian.
I did not run the suite. The GitHub checks are already red on lint, docs, tests, and every architecture job, and the collection error above is enough.
Not approving this.
| from metatomic.torch import System | ||
|
|
||
| from metatrain.experimental.edge_composition.utils.samples import match_samples | ||
| from metatrain.experimental.edge_composition import EdgeCompositionModel |
There was a problem hiding this comment.
This is the collection killer. utils.additive is imported from the default test path, so this pulls experimental.edge_composition (and elearn, which is not on PyPI) into every mtt install. Core utils cannot depend on an experimental architecture.
| # against transform-densified targets, so force train mode for the evaluation. | ||
| was_training = additive_model.training | ||
| additive_model.train(True) | ||
| if True or isinstance(additive_model, EdgeCompositionModel): |
There was a problem hiding this comment.
if True or isinstance(...) and the matching if False and not isinstance(...) below look like debug leftovers. They also flip the train/eval contract that the comment two lines down is still describing.
| ) | ||
|
|
||
| model = extra_data["model"] | ||
| matrix_name = "hamiltonian" |
There was a problem hiding this comment.
utils.loss.MatrixLoss importing experimental.graph2mat and hardcoding matrix_name = "hamiltonian" is not a public loss API. Keep this inside the architecture until it can name an arbitrary matrix target.
| pytest-cov | ||
| extras = mace | ||
| changedir = src/metatrain/experimental/mace/tests/ | ||
| changedir = src/metatrain/experimental/edge_composition/tests/ |
There was a problem hiding this comment.
mace-tests now runs edge_composition tests (and the new edge-composition-tests env changedirs into dpa3/tests/). Restore the MACE env and add a real graph2mat-tests one.
| # checkpoints portable across every architecture: standalone training | ||
| # and training embedded in e.g. PET both produce the same layout. | ||
| dense_dataset_info = densify_atomic_basis_dataset_info(dataset_info) | ||
| dense_dataset_info = dataset_info # densify_atomic_basis_dataset_info(dataset_info) |
There was a problem hiding this comment.
| return model | ||
|
|
||
| def export(self, metadata: Optional[ModelMetadata] = None) -> AtomisticModel: | ||
| raise NotImplementedError("Export not implemented yet for MetaGraph2Mat") |
There was a problem hiding this comment.
Experimental gate in architecture-life-cycle.rst is JIT / export(). A NotImplementedError here means this is not an experimental architecture yet, it is a training-only prototype. Same file still says "Interface of MACE for metatrain" and uses leftover i in cutoff=80.999 + i * 0.03.
| dataset, targets_info, _ = get_dataset( | ||
| { | ||
| "systems": { | ||
| "read_from": "/home/febrer/COSMO_disk/COSMO/tests/mtt_pair_targets/atom/spherical/scfbench_main_100.zip", |
There was a problem hiding this comment.
This is not a CI test. Point it at something in tests/resources/ (there is already a scfbench_2_bidirectional_edges.zip in this PR) or drop it until there is an in-repo fixture. Also missing ArchitectureTests / TorchscriptTests.
| from typing import Any, Dict, List, Literal, Optional | ||
|
|
||
| import torch | ||
| from elearn.interface.metatensor.couple import couple_tensor_blocks |
There was a problem hiding this comment.
elearn is not on PyPI. Experimental criterion 6 is "pip-installable, public URL". Even then this architecture does not belong in the same PR as graph2mat, and it must not be imported from utils/.
| # remaining outputs (main outputs) | ||
| for output_name in outputs.keys(): | ||
| if output_name == "feature" or output_name.startswith("mtt::aux::"): | ||
| if output_name == "feature": #or output_name.startswith("mtt::aux::"): |
There was a problem hiding this comment.
Unrelated SPACE change: mtt::aux:: outputs will now leak into return_dict. Leave SPACE alone in this PR.
|
I will track progress in pfebrer#15. Anyway this will probably end up being a hook #1209 instead of a full architecture |
From the creators of
experimental.mace...This one is quite experimental and I'm not sure it will ever aim at being stable, let's see.
What it is useful for
This architecture predicts sparse matrices in spherical basis from the output of any model.
Implementation
The idea of the architecture is simple enough: it takes any architecture in metatrain, asks for a spherical per-atom output, and then applies graph2mat on top of it. This is basically what I had in mind when I developed
graph2mat, so I'm very happy thatmetatrainstandardizes everything in a way that implementing this is "trivial" (you know, once you have spent a whole year in COSMO 😆).The architecture supports multiple matrix targets, and for each target a separate graph is built, since different matrices can have different sparsity patterns. As a consequence of this, the graph used to construct each matrix is not shared by the base (featurizer) model. E.g. the base model can have a higher/lower/adaptive cutoff for neighbors, or even not have a graph at all.
The main point of friction with
metatrainis thatgraph2matworks with a completely flattened array as the batch (due to the sparsity/raggedness of the target), whilemetatrainin general is more suited for uniform targets (e.g. the supportedTargetInfos). For now I solved the problem by using aDiskDatasetthat makesmetatrainhappy, but then converting tograph2matbatch in a callable of the collate function.I tested this with
soap_bpnn,PETandMACEand it is working fine.Future perspective
There is a case for thinking that the architecture is unnecessary, since one can just add
graph2matas a head in the architectures where it makes sense. However, I think it is good to first test things in this experimental architecture because things are probably going to change fast.There are also architectures for which other approaches are probably much more efficient and using graph2mat for matrices would make things unnecessarily complex. For example, @jwa7 is working on a more native way of doing this in PET.
Still, since
graph2matis very modular and easy to modify, it is nice to have it to quickly test new approaches before moving into modifying the other architectures (non-goal of metatrain, I know haha).Things missing.
For a proof of concept, I made up a target type (
basis) that allows me to play with things. This will be changed to adapt to the target type that Joe is using in his PET implementation, since after all forgraph2matthe target type is just a tool to trickmetatraininto allowing its running. Therefore, this PR is likely to stay as a draft until Joe finishes his implementation.Generating inputs
The architecture requires mainly two non-trivial inputs: the disk dataset and the basis specification. Both will be creatable using
graph2mattools, although the disk dataset will be general enough that it could be generated with whatever other tool.To test it
[not tested on GPU, will test soon!]
The architecture can be tested with this subset of 100 QM9 structures: https://drive.google.com/file/d/1gV4QP4ZwW_BDXdSe0K-UPvu2G3NPg2Nt/view?usp=sharing, which contains the
density_matrix,hamiltonian,energy_density_matrixandoverlap.Then run
mtt trainwith the typical options yaml:With the
qm9_basis.yamlfile containing the basis specification:Hope you think this is nice, and looking forward to having this one merged :)
Contributor (creator of pull-request) checklist
experimentalorstablefolder. See the[docs/src/dev-docs/architecture-life-cycle.rst](Architecture life cycle)
document for requirements.
src/metatrain/experimental/<architecture_name>.github/workflow/architecture-tests.yml)optional-dependenciessection in thepyproject.tomlReviewer checklist
New experimental architectures
tests.
TorchScript <https://pytorch.org/docs/stable/jit.html>_.__maintainers__and theCODEOWNERSfilePyPI, a public git repository or another public URL with a repository is acceptable.
New stable architectures
file.
PyPI.
metatrain, includinglogging and model save locations.
📚 Documentation preview 📚: https://metatrain--979.org.readthedocs.build/en/979/