Repository navigation
feat: custom float precision in the C writer (closes #22) - #34
Merged
Merged
Conversation
ASE's default 8-decimal output truncates positions, breaking hash-equality of Atoms across a write (issue #22). The pure-Python writer already accepted a `format_dict`; the C path raised `ValueError`. Add `extxyz_write_ll_fmt(fp, nat, info, arrays, fmt_i, fmt_f, fmt_b, fmt_s)` (any NULL -> compiled-in default) and make `extxyz_write_ll` a thin wrapper, so the existing ABI (used by the Fortran bindings and standalone lib) is unchanged. The formats apply to the per-atom data columns, matching the pure-Python writer's per-type `format_dict` (keyed R/I/S/L). Threaded through `cextxyz.write_frame_dicts` and `core.write_dicts`; the C-writer ValueError is gone, so `write_dicts(..., format_dict={'R': '%.16g'})` now works on both backends. Exported in _extxyz.def for Windows. Tests: high-precision format round-trips (<1e-12) and beats the default (~1e-9); default output byte-identical; no ValueError. Core + ase-extxyz suites and `leaks` clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
ASE's default 8-decimal extxyz output truncates positions, which breaks hash-equality of
Atomsbefore/after a write (#22, and the linked abcd issue). The pure-Python writer already honored aformat_dict, but the C writer rejected it:Now it works on both backends, and a high-precision format round-trips:
%16.8f%.16gHow (ABI-safe)
extxyz_write_ll's signature is used by the Fortran bindings and the standalone lib, so I didn't change it. Instead:extxyz_write_ll_fmt(fp, nat, info, arrays, fmt_i, fmt_f, fmt_b, fmt_s)— any formatNULLfalls back to the compiled-in default (FLOAT_FMTetc.).extxyz_write_llbecomes a one-line wrapper calling it with all-NULL.format_dict(keyedR/I/S/L); info-line values keep default formatting (the pure-Python writer is the same).cextxyz.write_frame_dicts→core.write_dicts; the C-pathValueErroris removed. Exported in_extxyz.deffor Windows.Verification
tests/test_write_precision.py(rtol=0): custom precision round-trips < 1e-12 and strictly beats the default; default output is byte-identical to before; noValueError.leaksclean.Closes #22.
🤖 Generated with Claude Code