Skip to content

[BUG] MemmapDataset crashes on target variants (energy/<variant>) + non_conservative_stress/<variant> dangerously skips process_non_conservative_stress() #1188

Description

@zyxwwxyz

Summary

Training on a MemmapDataset with a variant target (e.g. energy/pbe) fails at the first batch with:

invalid parameter: 'energy/pbe' is not a valid label name

The identical target definition trains fine when the data is read from an ASE-readable .xyz file. The issue should be isolated to MemmapDataset.__getitem__, which builds the metatensor property Labels from the raw target name and does not strip the /<variant> suffix.

Is this a wanted behaviour or a bug worth correcting?

Expected behavior

Training runs correctly with /<variant> suffix

Actual behavior

mtt stops with error

invalid parameter: 'energy/pbe' is not a valid label name

Version

2026.2.1

Steps to reproduce

from metatensor.torch import Labels

# What `MemmapDataset.__getitem__` currently does:

Labels.range("energy/pbeu".replace("mtt::", ""), 1)
-> RuntimeError: invalid parameter: 'energy/pbeu' is not a valid label name

# What `target_info.py` / the ASE reader do (works):

tk = "energy/pbeu"
Labels.range((tk.split("/")[0] if "/" in tk else tk).replace("mtt::", ""), 1)  # OK -> "energy"

Further information, files, and links

Suggested fix:

properties=Labels.range(
-            target_key.replace("mtt::", ""), target_array.shape[-1]
+            (target_key.split("/")[0] if "/" in target_key else target_key).replace(
+                "mtt::", ""
+            ),
+            target_array.shape[-1],
         ),

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions