Skip to content

Write each row of the NEP training report once for both the standard output and loss.out - #1813

Merged
brucefan1983 merged 2 commits into
masterfrom
refactor/nep-report-row
Oct 5, 2026
Merged

brucefan1983 merged 2 commits into
masterfrom
refactor/nep-report-row

Conversation

@erhart1

@erhart1 erhart1 commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fitness::report_error in src/main_nep/fitness.cu wrote every row of the training report twice, once with printf to the standard output and once with fprintf to loss.out. The NEP, charge-model and TNEP branches each held the format string and the argument list in two identical copies, and a column added to one copy had to be added to the other by hand.

This PR replaces the duplicated calls with one lambda, write_row, that takes a FILE* and is called once with stdout and once with fid_loss_out. It holds the three model branches and writes the energy-difference columns within the branch of the potential models, which are the only models that accept lambda_d. The format strings and the order of the columns are unchanged.

Testing

No test is added, since the output is unchanged. Baseline and candidate nep were built from master and from this branch with -DDEBUG, and run on the same inputs with a test set and three report rows each: NEP, charge_mode 1, charge_mode 2, charge_vdw, vdw, TNEP dipole and TNEP polarizability models, the potential models with and without lambda_d. loss.out is byte-identical in all 10 cases, and the standard output differs only in the two lines that report the wall-clock time. An independent run of 28 cases, which adds model_type 3, runs without a test set and a restart from nep.restart, gave the same result.

pytest -m "not slow" on tests_pytest/test_ediff_loss.py and tests_pytest/test_nep_train_outputs.py: 87 passed. git-clang-format reports no changes. The full tests_regression suite was not run.

Fitness::report_error writes a report row to the standard output and to
loss.out through one lambda that takes a FILE*, instead of two copies of
each format string and argument list per model branch.
@erhart1
erhart1 requested a review from brucefan1983 as a code owner October 4, 2026 18:52
@erhart1 erhart1 self-assigned this Oct 4, 2026
@erhart1

erhart1 commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author

@brucefan1983 this is a refactor of the code for writing the loss row to both stdout and loss.out. This is part of preparing the code for additional models.

@brucefan1983 brucefan1983 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good refactoring

@brucefan1983
brucefan1983 merged commit fa10fb0 into master Oct 5, 2026
2 checks passed
@brucefan1983
brucefan1983 deleted the refactor/nep-report-row branch October 5, 2026 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants