Skip to content

Refactor BL use GH Copliot to remove the j index - #742

Open
Benjamin Went (MetBenjaminWent) wants to merge 99 commits into
MetOffice:mainfrom
MetBenjaminWent:remove_j_bdy
Open

Benjamin Went (MetBenjaminWent) wants to merge 99 commits into
MetOffice:mainfrom
MetBenjaminWent:remove_j_bdy

Conversation

@MetBenjaminWent

@MetBenjaminWent Benjamin Went (MetBenjaminWent) commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

NOTE TO REVIEWERS

#630 is on trunk and duplication has been removed

PR Summary

As tasked by Chris, use primarily GitHub Copilot to remove the j index in the boundary layer, otherwise retaining source structure, and KGOs.

Prompts and chat sessions are provided below. An Agent was NOT used.
Changes were done file by file, limiting the AI to changing the declarations first, changing the arrays second, then removing redundant loops like the already completed hand coded changes, updating the member arrays of the types bl_diag and wtrac in the same ways, and rolling these back out where they are used.
These were run through the GCC and CCE compilers on the EXs (and AZ), where further changes like where explicit reshapes (copies) where required by routines, or where some implicit reshapes worked.
Finally testing of the OMP developer, and all groups have ensured that these are safe changes to the source.

Also update related Transmute scripts as required.

Run Name Caliper(s) Min Mean Max
base_3n_1T_run1.txt: bl.explicit 4.95282 8.90869 12.853
base_3n_1T_run1.txt: jules.explicit 2.27495 8.22317 15.3209
base_3n_2T_run1.txt: bl.explicit 5.40472 8.5564 13.2783
base_3n_2T_run1.txt: jules.explicit 3.48294 9.56117 18.4192
base_3n_4T_run1.txt: bl.explicit 5.6069 8.5565 12.711
base_3n_4T_run1.txt: jules.explicit 5.78934 12.84618 22.7939
rem_j_bl_3n_1T_run1.txt: bl.explicit 4.96861 8.75009 12.8666
rem_j_bl_3n_1T_run1.txt: jules.explicit 2.42308 8.16398 15.7664
rem_j_bl_3n_2T_run1.txt: bl.explicit 5.37101 8.62736 13.1822
rem_j_bl_3n_2T_run1.txt: jules.explicit 3.49058 9.53386 18.2896
rem_j_bl_3n_4T_run1.txt: bl.explicit 5.82512 9.1024 12.7284
rem_j_bl_3n_4T_run1.txt: jules.explicit 5.87091 12.89366 22.8291
Run Name Caliper(s) Min Mean Max
base_3n_1T_run1.txt: bl.implicit 5.06775 6.82803 8.14612
base_3n_1T_run1.txt: jules.implicit 0.29729 0.54804 1.0899
base_3n_2T_run1.txt: bl.implicit 5.42046 7.35816 8.67137
base_3n_2T_run1.txt: jules.implicit 0.33778 0.66742 1.30464
base_3n_4T_run1.txt: bl.implicit 6.89634 7.80355 8.56602
base_3n_4T_run1.txt: jules.implicit 0.43222 0.81804 1.61717
rem_j_up_3n_2T_run3.txt: bl.implicit 4.91703 6.63539 7.76888
rem_j_up_3n_2T_run3.txt: jules.implicit 0.29359 0.59511 1.17034
rem_j_up_3n_4T_run2.txt: bl.implicit 8.95805 10.05515 10.6433
rem_j_up_3n_4T_run2.txt: jules.implicit 0.37803 0.63062 1.17148
rem_j_up_3n_4T_run3.txt: bl.implicit 5.44311 6.91269 8.09716
rem_j_up_3n_4T_run3.txt: jules.implicit 0.39793 0.67905 1.34144

Sci/Tech Reviewer: Hacka Fett (@christophermaynard)
Code Reviewer: Ed Hone (@EdHone)

Umbrella #106
Issue: #724

Code Quality Checklist

  • I have performed a self-review of my own code
  • My code follows the project's style guidelines
  • Comments have been included that aid understanding and enhance the readability of the code
  • My changes generate no new warnings
  • All automated checks in the CI pipeline have completed successfully

Testing

  • I have tested this change locally, using the LFRic Apps rose-stem suite
  • If any tests fail (rose-stem or CI) the reason is understood and acceptable (e.g. kgo changes)
  • I have added tests to cover new functionality as appropriate (e.g. system tests, unit tests, etc.)
  • Any new tests have been assigned an appropriate amount of compute resource and have been allocated to an appropriate testing group (i.e. the developer tests are for jobs which use a small amount of compute resource and complete in a matter of minutes)

trac.log

Test Suite Results - lfric_apps - remove_j_bdy2/run34

Suite Information

Item Value
Suite Name remove_j_bdy2/run34
Suite User benjamin.went
Workflow Start 2026-10-01T09:26:58
Groups Run ex1a_omp_developer
Dependency Reference Main Like
casim MetOffice/casim@2026.07.1 True
jules MetOffice/jules@c22aeea True
lfric_apps MetBenjaminWent/lfric_apps@remove_j_bdy False
lfric_core MetOffice/lfric_core@220a00c True
moci MetOffice/moci@2026.07.1 True
SimSys_Scripts MetOffice/SimSys_Scripts@77a5166 True
socrates MetOffice/socrates@2026.07.1 True
socrates-spectral MetOffice/socrates-spectral@2026.07.1 True
ukca MetOffice/ukca@c372b36 True

Task Information

✅ succeeded tasks - 51

Test Suite Results - lfric_apps - remove_j_bdy2/run26

Suite Information

Item Value
Suite Name remove_j_bdy2/run26
Suite User benjamin.went
Workflow Start 2026-09-01T13:05:07
Groups Run ex1a_omp_developer
Dependency Reference Main Like
casim MetOffice/casim@2026.07.1 True
jules MetOffice/jules@2026.07.1 True
lfric_apps MetBenjaminWent/lfric_apps@remove_j_bdy False
lfric_core MetOffice/lfric_core@60fc29a True
moci MetOffice/moci@2026.07.1 True
SimSys_Scripts MetOffice/SimSys_Scripts@77a5166 True
socrates MetOffice/socrates@2026.07.1 True
socrates-spectral MetOffice/socrates-spectral@2026.07.1 True
ukca MetOffice/ukca@9fc2b6d True

Task Information

✅ succeeded tasks - 51

Test Suite Results - lfric_apps - remove_j_bdy2/run35

Suite Information

Item Value
Suite Name remove_j_bdy2/run35
Suite User benjamin.went
Workflow Start 2026-10-01T10:03:43
Groups Run all
Dependency Reference Main Like
casim MetOffice/casim@2026.07.1 True
jules MetOffice/jules@c22aeea True
lfric_apps MetBenjaminWent/lfric_apps@remove_j_bdy False
lfric_core MetOffice/lfric_core@220a00c True
moci MetOffice/moci@2026.07.1 True
SimSys_Scripts MetOffice/SimSys_Scripts@77a5166 True
socrates MetOffice/socrates@2026.07.1 True
socrates-spectral MetOffice/socrates-spectral@2026.07.1 True
ukca MetOffice/ukca@c372b36 True

Task Information

✅ succeeded tasks - 1598

Security Considerations

  • I have reviewed my changes for potential security issues
  • Sensitive data is properly handled (if applicable)
  • Authentication and authorisation are properly implemented (if applicable)

Performance Impact

  • Performance of the code has been considered and, if applicable, suitable performance measurements have been conducted

AI Assistance and Attribution

  • The majority of the content of this change has been produced with the assistance of Generative AI tool name (e.g., Met Office Github Copilot Enterprise, Github Copilot Personal, ChatGPT GPT-4, etc) and I have followed the Simulation Systems AI policy (including attribution labels). An Agent was NOT used in this development, only licenced VS code GH Copilot chat prompts, using Auto at first, or Claude Sonate for specific changes.

Documentation

  • Where appropriate I have updated documentation related to this change and confirmed that it builds correctly

PSyclone Approval

  • If you have edited any PSyclone-related code (e.g. PSyKAl-lite, Kernel interface, optimisation scripts, LFRic data structure code) then please contact the HPC Optimisation Team

Sci/Tech Review

  • I understand this area of code and the changes being added
  • The proposed changes correspond to the pull request description
  • Documentation is sufficient (do documentation papers need updating)
  • Sufficient testing has been completed

(Please alert the code reviewer via a tag when you have approved the SR)

Code Review

  • All dependencies have been resolved
  • Related Issues have been properly linked and addressed
  • CLA compliance has been confirmed
  • Code quality standards have been met
  • Tests are adequate and have passed
  • Documentation is complete and accurate
  • Security considerations have been addressed
  • Performance impact is acceptable

…rides for mphys_kernel_mod to use the correct one
…ns list.

Possibly a wider options fix needs to be rolled in with this ticket......
…ions. Depricate old methods, and better align script with existing methods
…tions by accident, needed for raising jules_exp_kernel_mod into local. Also needed pure call option which is a minor extra, and makes the script more flexible
…locally 2D, call to surf_couple_explicit okay with reshape, formatting changes
@github-actions github-actions Bot added the cla-modified The CLA has been modified as part of this PR - added by GA label Sep 29, 2026
@Adrian-Lock

Adrian Lock (Adrian-Lock) commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Benjamin Went (@MetBenjaminWent), what's your planned timing for this PR, noting you've not put a milestone? There are significant changes planned for the Autumn 2026 release, with a lot of new routines coming into the BL directory from the UM under #734, plus #752 [sorry, this PR had a type/brain freeze in the original!] making some minor changes. Would you rerun GH Copilot once vn3.3 is released and look to get this in shortly thereafter?

@MetBenjaminWent

Copy link
Copy Markdown
Contributor Author

Benjamin Went (Benjamin Went (@MetBenjaminWent)), what's your planned timing for this PR, noting you've not put a milestone? There are significant changes planned for the Autumn 2026 release, with a lot of new routines coming into the BL directory from the UM under #734, plus #128 making some minor changes. Would you rerun GH Copilot once vn3.3 is released and look to get this in shortly thereafter?

Hi Adrian, appologies for not putting a milestone, I was just aiming for the next release, or when the reviews are completed for this PR.
If that's really going to conflict with other work, I'm happy to try and mitigate that.
I could wait with this PR until after the release, but much preferably we could try and get ahead of that and get our branches synced up, such as merging yours here, or we just update our respective branches with whaterver is one trunk. This way both make the release.

@MetBenjaminWent

Benjamin Went (MetBenjaminWent) commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Benjamin Went (Benjamin Went (Benjamin Went (@MetBenjaminWent))), what's your planned timing for this PR, noting you've not put a milestone? There are significant changes planned for the Autumn 2026 release, with a lot of new routines coming into the BL directory from the UM under #734, plus #128 making some minor changes. Would you rerun GH Copilot once vn3.3 is released and look to get this in shortly thereafter?

Hi Adrian, appologies for not putting a milestone, I was just aiming for the next release, or when the reviews are completed for this PR. If that's really going to conflict with other work, I'm happy to try and mitigate that. I could wait with this PR until after the release, but much preferably we could try and get ahead of that and get our branches synced up, such as merging yours here, or we just update our respective branches with whaterver is one trunk. This way both make the release.

I've had a quick chat with Chris for how we can manage these together. We also need to think about a Transmute script for the new domain kernel in #734, and do some similar work as to #106 there too.

@iboutle iboutle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just one comment below.

Regarding merging with other tickets, I think that should be possible as part of the current release

Comment thread interfaces/jules_interface/source/kernel/jules_exp_kernel_mod.F90 Outdated
This was referenced Sep 29, 2026

@Adrian-Lock Adrian Lock (Adrian-Lock) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Other than noting the clashes with the other PRs that did make the code review deadline, #734 and #752, this is fine.


! profile fields from level 0 upwards
real(r_um), dimension(seg_len,1,0:1) :: p_theta_levels, q, qcl, qcf
real(r_um), dimension(seg_len,0:1) :: p_theta_levels, q, qcl, qcf

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.

On line 720 several arrays are declared to be the same size. p_theta_levels is passed to buoy_tq on line 1412. The dummy argument declaration in buoy_tq.h (lines 19-21) is declared of size 0:bl_levels+1 in the last dimension, whereas the remaining dummy args are tdims_l%k_start:bl_levels. all the arrays are declared the same size in this file. Co-Pilot/Claude say this is benign but whilst changing this file it may as well be corrected, so that p_theta_levels is declared ,0:2 , with the other args 0:1 to match the dummy args.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wonder if another caller of buoy_tq needs that extra level? I can have a look to see if the +1 can be removed simply.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is probably a hangover from the UM - the bl_levels+1 index of p is unused in buoy_tq, so it could just be dimensioned as bl_levels there. p_theta_levels passed in from bl_exp_kernel is dimensioned to nlayers, but we will always have bl_levels <= nlayers so this should be okay.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Cool, thanks for the context Ian, I'll get it removed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

+1 level removed in buoy_tq, testing in prog

integer(i_um), dimension(seg_len) :: lcbase0, ccb0, cct0

! Temporary 3D buffers (j=1) for legacy PC2 routine interface.
real(r_um), dimension(seg_len,1,nlayers) :: qcf_latest_pc2, &

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.

These 5 arrays are all unused and should be removed.

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.

qcf_latest_pc2, qcf_earliest_pc2, cff_earliest_pc2, cff_latest_pc2, cf_latest_pc2 lines 419 to 421

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed

real(r_um) :: res_factor(row_length, rows) ! dry deposition coeff.
real(r_um) :: rhokh_1(row_length) ! surface exchange coeff.
real(r_um) :: res_factor(row_length) ! dry deposition coeff.
real(r_um) :: f_field(row_length, rows, bl_levels) ! tracer flux from tr_mix

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.

array f_field is now unused (spotted by Co-Pilot/Claude) so it could be deleted, or is it replaced by f_field_1D, in which case why just keep f_field and use that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed duplicate arrays for redundant copies back - updated naming of copy arrays from _1D to _bl

real(r_um) :: f_field_1D(row_length, bl_levels) ! tracer flux from tr_mix
real(r_um) :: surf_dep_flux(row_length, rows) ! surf. deposition flux from
! tr_mix
real(r_um) :: surf_dep_flux_1D(row_length) ! surf. deposition flux from

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.

Same comment for surf_dep_flux

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same as above

@@ -786,7 +784,7 @@ subroutine bdy_expl2 ( &
! NTPAR restricted below BL_LEVELS
i_wt, &
! Water tracer loop counter
il, jl ! LOCAL indexes for land index loops
il ! LOCAL index for land index loops

integer, parameter :: j = 1 ! Array dimension, LFRic Parameter

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.

I think this declaration for j can be removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed, also for other routines where it had persisited, along with it's uses further on.

@github-actions github-actions Bot removed the cla-modified The CLA has been modified as part of this PR - added by GA label Oct 1, 2026

@christophermaynard Hacka Fett (christophermaynard) 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.

Claude/Co-Pilot assisted in reviewing these changes, I asked it for a summary, which was useful. I asked if there were any bugs in the changes, it found quite a few problems but not bugs. Some, Ian had already found. It found dead/unused code, and a potential memory issue. I reviewed all these in person and agreed with analysis. These change requests have all been completed. I have scanned the diffs for all 26 files. I spotted one left over integer. paramter :: j = 1 by eye, but Claude had already flagged it! I understand all the changes, have looked at all the code and can pass the PR for Sci/Tech.

This branch has not been deployed

No deployments
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.

6 participants