TensorForceField serialization - #178
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #178 +/- ##
==========================================
+ Coverage 81.40% 81.47% +0.07%
==========================================
Files 56 57 +1
Lines 5070 5097 +27
==========================================
+ Hits 4127 4153 +26
- Misses 943 944 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
6f1d9a4 to
3d38e67
Compare
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The new module contains non-functional dead code (_Tensor and the sparse helpers) and the exceptions serialization path is entirely untested.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
This PR adds JSON serialization support for TensorForceField (closing #168). It introduces a new tyff/_serialization.py module providing dump_*/load_* functions that convert a TensorForceField (and its nested TensorPotential and TensorVSites) to and from plain Python dicts suitable for json.dump/json.load, handling tensors, units, OpenFF PotentialKeys, and exceptions. A new test module exercises round-trip serialization for a basic water force field and a virtual-site force field.
Changes:
- New
tyff/_serialization.pywith helpers to encode/decode tensors, units, potential keys, and exceptions, plus top-leveldump_tensor_force_field/load_tensor_force_field. - New
tyff/_tests/test_serialization.pywith a field-by-field comparison helper and two round-trip tests (basic and virtual sites).
| File | Description |
|---|---|
| tyff/_serialization.py | Adds dump/load functions for TensorForceField, TensorPotential, and TensorVSites, plus tensor/exception encoding helpers (includes some unused _Tensor/sparse helpers). |
| tyff/_tests/test_serialization.py | Adds round-trip serialization tests and a compare_tensor_force_fields helper (does not compare exceptions). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.


Closes #168