Skip to content

Unit test fixes - #1089

Merged
JunoRavin merged 42 commits into
mainfrom
gk_unit_test_fix
Aug 5, 2026
Merged

Unit test fixes#1089
JunoRavin merged 42 commits into
mainfrom
gk_unit_test_fix

Conversation

@Antoinehoff

@Antoinehoff Antoinehoff commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

We fix a few failing unit tests on CPU and GPU. We also clean unused code in the GK app.

Core fixes (GPU fail)

ctest_array_ops

  • cu_array_copy_range_to_range_diff_range_dim was failing on GPU because the deflated range is not providing the inverted indexer which is needed by the GPU code of this test.

ctest_dg_array_mask

  • The global_max variable (on host) is passed by reference in the reduction that uses the device array. We now do the reduction with the host array to get the global_max.

ctest_tensor_field_ops

  • The copy of a pointer address from host to device was not working because the data that was pointed was living on the host. We just fix that by copying the host pointer to device data with ->on_dev.

Vlasov fix (GPU fail)

ctest_dg_em_vars

We import the fix present in kitp-hamil-vlasov branch.

  • The components of the gkyl_dg_mu_op_range in the GPU part of the test were not set correctly (0 everywhere instead of 0,1, and 2 like in the CPU code).
  • The tensor 2x and 3x p=2 tests were commented our for CPU but not for GPU.

GK fixes

ctest_fem_parproj

  • The p=2 Dirichlet BC case is protected with an assert. We comment this case now for CPU and GPU.

ctest_dg_gyrokinetic_kern_tm

  • The value 0 was used as a collisionless enum but this corresponds to GKYL_GK_COLLISIONLESS_NONE which returns a NULL updater and fails the test. We now pass GKYL_GK_COLLISIONLESS_ES.

ctest_gyrokinetic_cross_prim_moms_bgk

  • The BGK cross-primitive-moments kernel was rewritten in commit bcc40b7 (Oct 14 2025, "Modify the BGK app to have the same structure as the LBO app…") and so the result changes slightly. We update the expected M2 moment value from 2.83391995e9 to 2.86262992e9.

ctest_mom_gyrokinetic

  • Only the M2 check line 887 fails typically M2[0] computed = 172.5525 vs expected 172.3291. This seems to be a consequence of the change of bmag representation. We update the reference values stored in m2Correct line 855.

ctest_rescale_ghost_jacf

  • This updater is not used anymore. We just remove it and the associated kernels at gyrokinetic/ker/inflate_surf.

ctest_gk_geometry_tok

  • Missing null position map for ASDEX tests (3 and 4).
  • For the elliptical and straight cylinder tests, some surface node had a small negative value in the argument of the square root in the dphidhteta (~-1e-7) so we propose here to clamp the argument of the square root though this could make some bug silent.
  • Finally the cylinder test was out of date in terms of the new geometry convention.

ctest_bc_twistshift

ctest_dg_interpolate (Stellar nvcc fail)

  • This test failed on stellar with nvcc because of a wrong memory access when computing the magnetic field amplitude.

manauref and others added 19 commits July 3, 2026 15:30
… given in the input file. Add sample regression test (gkylcas 16cfe76398a327fa8617ed162509585f0c6c6f47).
…up. We should make it so that omega_H is only computed if the field evolves. Passive eqn object is clearly not ready as the result is not as expected.
…x2v passive advection reg test. Tried using TS BCs in passive advection but I think there's a memory bug, need to switch to cluster with valgrind.
…oken its use in bc_twistshift. Also, I think there was a bug in find_cell all along, though I don't know if it was ever triggered. Fix this bug, and adjust a tolerance in twistshift to make it work with the recently added epsilon in rect_grid_find_cell. Unit tests pass. There's still an issue with passive advection using TS BCs because the solution quickly becomes NaNs.
… show that the shift at the lower boundary is OK, but the shift at the upper boundary (which -1 times the lower shift) produces NaNs.
… integrals of bc_twistshift, it was causing NaNs in the fig14 scenario. Fix boundary kernel selection in gk_collisionless_passive_flux. Now the passive advection test with TS BCs looks as expected.
…uadratic q has issues near the upper radial boundary. We'll examine this in a unit test setting, and try it with TCV geo.
… delete or simplify this in the future, but it already reproduces the checkerboard pattern seen in the simulation.
…in the shift across a single cell is equal or greater to the length of the domain along y. I tried to add support for this sort of scenario but didn't succeed. I'll try again in the future. For now we must increase resolution along y, reduce shear or increase Ly so this doesn't happen. Add accepted results to CBC unit test.
…n TS BC updater. The previous approach looked in periodic copies of the domain independently for each point, but this could give different periodic copies for 2-4 points that are meant to define a subcell integral, leading to error. So now we look for the correct periodic copy only once (for a given donor-target pair) and pass that to be used for looking for intersections. This fixes some checkerboarding seen in the CBC geo with Nx cells. All other unit tests continue to pass (I had to generate new cbc accepted results, but I confirmed visually that for Nx=32 the difference was machine precision.
…eger. This explains a mysterious shift we were seeing when structures crossed the IMP.
…ddress, this makes it easier to call it from python. Rename num_cell_ variables in tcv reg tests so that they use Nx like all other reg tests (makes it easier to automate changes to them).
… resolutions to speed up the test. Rename "anal" to "ana" for obvious reasons.
…ation because the unit test computes sometimes ~1e-7 negative values that make it fail.
@Antoinehoff Antoinehoff changed the title Gk and other unit test fixes Core and GK unit test fixes Jul 31, 2026
@Antoinehoff
Antoinehoff requested a review from JunoRavin July 31, 2026 14:11
… host pointer to data to a device pointer to data was not correct because it was the pointer to host data and not the pointer to device data that was copied. Hence, this make the code fails when the GPU tries to access that data through the address that was copied 😵‍💫
@Antoinehoff
Antoinehoff requested a review from johnson452 July 31, 2026 14:52
…(one because of precision adjustment, the other because of unused misallocated array)

@manauref manauref left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

approving, but please check if rescale_ghost_jacf has some associated gkylcas/maxima code, and delete that too

@manauref

manauref commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

we also have to be mindful that GK depends on some code in vlasov/ (and maybe moments too), so that to get proper coverage we need the unit tests to be clean for vlasov/ too.

@Antoinehoff

Copy link
Copy Markdown
Collaborator Author

approving, but please check if rescale_ghost_jacf has some associated gkylcas/maxima code, and delete that too

I see that the kernels used are in gyrokinetic/ker/inflate_surf_kernels.h and these seem to be unused in the rest of the code. I will remove them.

@Antoinehoff Antoinehoff changed the title Core and GK unit test fixes Unit test fixes Aug 4, 2026
@Antoinehoff

Copy link
Copy Markdown
Collaborator Author

we also have to be mindful that GK depends on some code in vlasov/ (and maybe moments too), so that to get proper coverage we need the unit tests to be clean for vlasov/ too.

The version of the code proposed by this PR is passing all unit tests on both CPU and GPU except:

==================== gkeyll unit test summary ====================
Total: 126   Passed: 119   Failed: 7
Failed tests:
  moments: ctest_wv_vacuum_einstein_conformal
  moments: ctest_wv_vacuum_einstein
  moments: ctest_wv_gr_mhd_tetrad
  moments: ctest_wv_gr_mhd
  gyrokinetic: ctest_bc_twistshift

@JunoRavin
JunoRavin merged commit 8a8d514 into main Aug 5, 2026
1 check passed
@JunoRavin
JunoRavin deleted the gk_unit_test_fix branch August 5, 2026 20:27
@Antoinehoff
Antoinehoff restored the gk_unit_test_fix branch September 1, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants