Skip to content

Add covfie binary field map loaders#2335

Merged
sethrj merged 6 commits into
celeritas-project:developfrom
rahmans1:pr/covfie-field-import
Mar 30, 2026
Merged

Add covfie binary field map loaders#2335
sethrj merged 6 commits into
celeritas-project:developfrom
rahmans1:pr/covfie-field-import

Conversation

@rahmans1

@rahmans1 rahmans1 commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

Title

Add covfie binary field map loaders

Description

Add load_covfie_cart_field and load_covfie_rz_field free functions that deserialize covfie binary files into CartMapFieldInput and
RZMapFieldInput.

  • Use a deserialization_interp_t typedef to document that stateless covfie interpolation backends (linear, nearest_neighbour, etc.) produce identical binary formats, so the choice is arbitrary for deserialization
  • Assume native Celeritas units with no conversion applied
  • Add CovfieCartImportTest (2x3x4 grid) and CovfieRZImportTest (2x3 grid) that generate small covfie binaries at test time with analytic field values, then verify grid dimensions, affine-recovered bounds, and stride ordering

This PR is AI-assisted (Claude Code, claude-opus-4-6). Follows from discussion in #2298

Sakib Rahman added 2 commits March 26, 2026 13:38
Add load_covfie_cart_field and load_covfie_rz_field free functions that
deserialize covfie binary files into CartMapFieldInput and RZMapFieldInput.
The loaders use a deserialization_interp_t typedef to make explicit that
stateless covfie backends (linear, nearest_neighbour, etc.) produce
identical binary formats. No unit conversion is applied; values are
assumed to be in native Celeritas units.

Prompt: "Add functions to load 3D Cartesian and 2D RZ cylindrical magnetic
field maps from covfie binary files into Celeritas field input structs"

Assisted-by: Claude Code (claude-opus-4-6)
Add CovfieCartImportTest and CovfieRZImportTest that generate small
covfie binary files at test time (2x3x4 Cartesian, 2x3 RZ) with
analytic field values, then verify that the loaders correctly recover
grid dimensions, bounds from the affine transform, and field values
at known indices to confirm stride ordering.

Prompt: "Add unit tests for the covfie binary field map loaders using
small generated test files with known analytic field values"

Assisted-by: Claude Code (claude-opus-4-6)
@rahmans1
rahmans1 requested a review from sethrj March 26, 2026 18:52
@rahmans1 rahmans1 added enhancement New feature or request ai-assisted Generated/refactored substantially with agentic/LLM AI tools labels Mar 26, 2026
@codecov

codecov Bot commented Mar 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.85714% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.19%. Comparing base (8874128) to head (1c4f6fd).
⚠️ Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
src/celeritas/field/LoadCovfieField.covfie.cc 92.85% 1 Missing and 5 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2335      +/-   ##
===========================================
- Coverage    87.20%   87.19%   -0.01%     
===========================================
  Files         1373     1374       +1     
  Lines        43581    43678      +97     
  Branches     13785    13394     -391     
===========================================
+ Hits         38005    38086      +81     
+ Misses        4535     4362     -173     
- Partials      1041     1230     +189     
Files with missing lines Coverage Δ
src/celeritas/field/LoadCovfieField.covfie.cc 92.85% <92.85%> (ø)

... and 116 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Mar 26, 2026

Copy link
Copy Markdown

Test summary

 5 617 files   9 101 suites   20m 1s ⏱️
 2 246 tests  2 205 ✅  41 💤 0 ❌
31 747 runs  31 627 ✅ 120 💤 0 ❌

Results for commit 1c4f6fd.

♻️ This comment has been updated with latest results.

@sethrj
sethrj marked this pull request as ready for review March 27, 2026 05:43
@sethrj
sethrj requested a review from esseivaju as a code owner March 27, 2026 05:43

@sethrj sethrj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks a bunch for splitting this up! Made it much easier to review. I have a few fixes that should be easy for copilot to address ;)

Comment thread src/celeritas/field/LoadCovfieField.covfie.cc Outdated
Comment thread src/celeritas/field/LoadCovfieField.covfie.cc Outdated
Comment thread src/celeritas/field/LoadCovfieField.hh
Comment thread test/celeritas/field/Fields.test.cc Outdated
Comment thread test/celeritas/field/Fields.test.cc
Sakib Rahman added 3 commits March 30, 2026 13:36
Extract repeated axis-grid recovery into an anonymous from_affine
helper. Remove unnecessary static_casts (float-to-double widening,
size_t in strided_view.at). Guard declarations with
CELERITAS_USE_COVFIE and provide inline CELER_NOT_CONFIGURED stubs
so downstream code compiles without covfie.

Prompt: "Address PR review: refactor axis grid extraction into a
from_affine helper, remove unnecessary casts, add not-configured
stubs for non-covfie builds"

Assisted-by: Claude Code (claude-opus-4-6)
Move write_cart_covfie and write_rz_covfie from Fields.test.cc into
CovfieTestField.hh and CovfieTestField.covfie.cc, conditionally built
when covfie is enabled. Provide inline CELER_NOT_CONFIGURED stubs for
non-covfie builds so disabled tests still compile.

Prompt: "Move covfie test field construction to a separate header and
source file that gets conditionally built into the test library"

Assisted-by: Claude Code (claude-opus-4-6)
Replace inline covfie includes and helper functions with the
CovfieTestField and LoadCovfieField headers included at the top of
the file. Covfie import tests now compile in both covfie and
non-covfie builds, skipped via DISABLED_ prefix when covfie is off.

Prompt: "Remove mid-file covfie includes from test file and make
tests compile without covfie using DISABLED prefix"

Assisted-by: Claude Code (claude-opus-4-6)
@rahmans1

Copy link
Copy Markdown
Contributor Author

@sethrj Tried to address the previous comments. Let me know if anything else is needed. The tests still pass after refactoring.

ctest -R "Fields" --output-on-failure -V
UpdateCTestConfiguration  from :/home/srahman1/celeritas-dd4hep/celeritas-covfie/build/DartConfiguration.tcl
Parse Config file:/home/srahman1/celeritas-dd4hep/celeritas-covfie/build/DartConfiguration.tcl
UpdateCTestConfiguration  from :/home/srahman1/celeritas-dd4hep/celeritas-covfie/build/DartConfiguration.tcl
Parse Config file:/home/srahman1/celeritas-dd4hep/celeritas-covfie/build/DartConfiguration.tcl
Test project /home/srahman1/celeritas-dd4hep/celeritas-covfie/build
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 241
    Start 241: celeritas/field/Fields

241: Test command: /home/srahman1/celeritas-dd4hep/celeritas-covfie/build/test/celeritas/field_Fields
241: Working Directory: /home/srahman1/celeritas-dd4hep/celeritas-covfie/build/test/celeritas
241: Environment variables:
241:  CELER_LOG=warning
241:  CELER_LOG_LOCAL=warning
241:  CELER_DISABLE_PARALLEL=1
241: Test timeout computed to be: 1500
241: Celeritas version 0.7+6347c547
241: [==========] Running 9 tests from 8 test suites.
241: [----------] Global test environment set-up.
241: [----------] 1 test from UniformZFieldTest
241: [ RUN      ] UniformZFieldTest.all
241: [       OK ] UniformZFieldTest.all (0 ms)
241: [----------] 1 test from UniformZFieldTest (0 ms total)
241:
241: [----------] 1 test from UniformFieldTest
241: [ RUN      ] UniformFieldTest.all
241: [       OK ] UniformFieldTest.all (0 ms)
241: [----------] 1 test from UniformFieldTest (0 ms total)
241:
241: [----------] 1 test from CMSParameterizedFieldTest
241: [ RUN      ] CMSParameterizedFieldTest.all
241: [       OK ] CMSParameterizedFieldTest.all (0 ms)
241: [----------] 1 test from CMSParameterizedFieldTest (0 ms total)
241:
241: [----------] 1 test from RZMapFieldTest
241: [ RUN      ] RZMapFieldTest.all
241: /home/srahman1/celeritas-dd4hep/celeritas-covfie/src/celeritas/field/RZMapFieldInputIO.json.cc:90: warning: No units given in RZ field input: assuming CGS for length (cm) and SI for strength (T)
241: [       OK ] RZMapFieldTest.all (0 ms)
241: [----------] 1 test from RZMapFieldTest (1 ms total)
241:
241: [----------] 1 test from CylMapFieldTest
241: [ RUN      ] CylMapFieldTest.all
241: [       OK ] CylMapFieldTest.all (0 ms)
241: [----------] 1 test from CylMapFieldTest (0 ms total)
241:
241: [----------] 1 test from CovfieCartImportTest
241: [ RUN      ] CovfieCartImportTest.load_2x3x4
241: [       OK ] CovfieCartImportTest.load_2x3x4 (0 ms)
241: [----------] 1 test from CovfieCartImportTest (0 ms total)
241:
241: [----------] 1 test from CovfieRZImportTest
241: [ RUN      ] CovfieRZImportTest.load_2x3
241: [       OK ] CovfieRZImportTest.load_2x3 (0 ms)
241: [----------] 1 test from CovfieRZImportTest (0 ms total)
241:
241: [----------] 2 tests from CartMapFieldTest
241: [ RUN      ] CartMapFieldTest.host
241: [       OK ] CartMapFieldTest.host (20 ms)
241: [ RUN      ] CartMapFieldTest.device
241: [       OK ] CartMapFieldTest.device (99 ms)
241: [----------] 2 tests from CartMapFieldTest (119 ms total)
241:
241: [----------] Global test environment tear-down
241: [==========] 9 tests from 8 test suites ran. (121 ms total)
241: [  PASSED  ] 9 tests.
241: /home/srahman1/celeritas-dd4hep/celeritas-covfie/build/test/celeritas/field_Fields: tests PASSED
1/1 Test #241: celeritas/field/Fields ...........   Passed    0.37 sec

The following tests passed:
        celeritas/field/Fields

100% tests passed, 0 tests failed out of 1

Label Time Summary:
gpu     =   0.37 sec*proc (1 test)
unit    =   0.37 sec*proc (1 test)

Total Test time (real) =   0.38 sec

@sethrj sethrj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perfect! Thank you.

@sethrj
sethrj enabled auto-merge (squash) March 30, 2026 18:01
@sethrj
sethrj merged commit d62dcb5 into celeritas-project:develop Mar 30, 2026
77 of 79 checks passed
@rahmans1
rahmans1 deleted the pr/covfie-field-import branch April 16, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted Generated/refactored substantially with agentic/LLM AI tools enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants