Skip to content

5 add fab build script - #6

Open
Joerg Henrichs (hiker) wants to merge 6 commits into
MetOffice:mainfrom
hiker:5_add_fab_build_script
Open

5 add fab build script#6
Joerg Henrichs (hiker) wants to merge 6 commits into
MetOffice:mainfrom
hiker:5_add_fab_build_script

Conversation

@hiker

@hiker Joerg Henrichs (hiker) commented Jul 30, 2026

Copy link
Copy Markdown

PR Summary

Add a FAB-based build script for MONC.

Code Reviewer: Sam Clarke-Green (@t00sa)

This PR adds a simple FAB build script.

Linked issue:
MetOffice/fab#588
(for now there is a work-around in place by duplicating a single file).

Code Quality Checklist

(Some checks are automatically carried out via the CI pipeline)

  • 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

Testing

So far, no testing has been done of the binary.

Security Considerations

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

Performance Impact

  • [N/A] Performance of the code has been considered and, if applicable, suitable performance measurements have been conducted

AI Assistance and Attribution

N/A

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

@github-actions github-actions Bot added the cla-signed The CLA has been signed as part of this PR - added by GA label Jul 30, 2026
@hiker

Copy link
Copy Markdown
Author

This seems to work for a simple build with gfortran now (debug, safe, and high compilation mode). I have added settings for other compilers (intel classic+llvm, cray) based on the existing settings in fcm-make, and a setup for nvidia (based on LFRic). The latter will very likely not work. Note that I could not even test build any other compiler except GNU.

Note that for now I had to duplicate one file (monc_driver.F90). I have it locally working without the duplication, but it needs an update to Fab (I am waiting for feedback from the UKMO which implementation they prefer). For testing and progressing the initial Fab build, this will work for now, once we have the next Fab release done, we can remove the duplication again.

I need help from a dev here. I don't know how the casim/socrates integration would work at all - I have command line flags added to disable these integrations (which is the default, i.e. it will use the corresponding stub files), but with the integration, likely additional flags will be required (i.e. is casim etc. linked in as library?? Search path for these, ...).

@hiker

Copy link
Copy Markdown
Author

Fab PR MetOffice/fab#592 submitted, which will allow us to copy a single file (and remove the duplicated file again once it is merged).

@t00sa

Copy link
Copy Markdown
Collaborator

I've hit a problem with my testing and I'm not sure if it's something I've done or a problem with the LFRic software stack!

If I run the ./fab_monc.py script, it successfully grabs and pre-processes the source but when it analyses the code, it fails with lots of KeyErrors, e.g.

error parsing file 'fab/fab-workspace/monc-debug-gfortran/build_output/components/set_consistent_lowbc/src/set_consistent_lowbc.f90':
unhandled error '<class 'KeyError'>' in fab/fab-workspace/monc-debug-gfortran/build_output/components/set_consistent_lowbc/src/set_consistent_lowbc.f90
'End_Program_Stmt'

If I run with my own install of fab and alter the code to generate a traceback, I get a stack trace that points to a problem in fparser:

Traceback (most recent call last):
  File "$SPACK/python-3.14.5-ow2igu4da6z3nm22hrm7mqqm6sb3addf/lib/python3.14/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
                    ~~~~^^^^^^^^^^^^^^^
  File "$SPACK/python-3.14.5-ow2igu4da6z3nm22hrm7mqqm6sb3addf/lib/python3.14/multiprocessing/pool.py", line 48, in mapstar
    return list(map(*args))
  File "/var/tmp/persistent/sam.clarke/Development/fab/source/fab/parse/fortran_common.py", line 112, in run
    node_tree = self._parse_file(fpath=fpath)
  File "/var/tmp/persistent/sam.clarke/Development/fab/source/fab/parse/fortran_common.py", line 147, in _parse_file
    tree = self.f2008_parser(reader)
  File "$SPACK/py-fparser-0.2.4-hbpwaho34bxaaqrhs7zgsopo3dujkuhz/lib/python3.14/site-packages/fparser/two/Fortran2003.py", line 361, in __new__
    return Base.__new__(cls, string, _deepcopy=_deepcopy)
           ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "$SPACK/py-fparser-0.2.4-hbpwaho34bxaaqrhs7zgsopo3dujkuhz/lib/python3.14/site-packages/fparser/two/utils.py", line 470, in __new__
    result = cls.match(string)
  File "$SPACK/py-fparser-0.2.4-hbpwaho34bxaaqrhs7zgsopo3dujkuhz/lib/python3.14/site-packages/fparser/two/Fortran2003.py", line 421, in match
    result = BlockBase.match(Main_Program0, [], None, reader)
  File "$SPACK/py-fparser-0.2.4-hbpwaho34bxaaqrhs7zgsopo3dujkuhz/lib/python3.14/site-packages/fparser/two/utils.py", line 695, in match
    obj = startcls(reader)
  File "$SPACK/py-fparser-0.2.4-hbpwaho34bxaaqrhs7zgsopo3dujkuhz/lib/python3.14/site-packages/fparser/two/utils.py", line 470, in __new__
    result = cls.match(string)
  File "$SPACK/py-fparser-0.2.4-hbpwaho34bxaaqrhs7zgsopo3dujkuhz/lib/python3.14/site-packages/fparser/two/Fortran2003.py", line 11116, in match
    result = BlockBase.match(
        None,
    ...<2 lines>...
        reader,
    )
  File "$SPACK/py-fparser-0.2.4-hbpwaho34bxaaqrhs7zgsopo3dujkuhz/lib/python3.14/site-packages/fparser/two/utils.py", line 730, in match
    endcls_all = tuple([endcls] + endcls.subclasses[endcls.__name__])
                                  ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
KeyError: 'End_Program_Stmt'

My environment includes fparser 0.24, fab 2.2.0, clang 20.1, gcc 12.2.0, and MPICH 4.3.2.

@hiker

Copy link
Copy Markdown
Author

No idea what is happening :( I did notice that the logging was not set up correctly, hopefully that's the reason why the stack trace wasn't shown (there is an issue that Fab does not abort on analysis errors).

  1. I've tested it with py 3.14 (which I usually don't use), and it worked fine with me.
  2. I've tested fparser 0.2.1/2/3/4 (just in case that an unexpected version was actually used), all could parse that file just fine.

Two questions:

  1. Can you run `fparser2 fab/fab-workspace/monc-debug-gfortran/build_output/components/set_consistent_lowbc/src/set_consistent_lowbc.f90', and see if this creates an error? It's strange that fparser complains about missing end_program_statement, since as far as I an see there is no program statement there at all, why would it search for an end??
  2. Just in case, can you give me your preprocessed file? And update the branch, clean the fab-workspace, run again, and send me the full log file? Maybe I can spot something there??

@hiker

Copy link
Copy Markdown
Author

Dang, I accidentally pushed an update that requires a change to Fab as part of my logging fix :(

I've created a new branch fab_for_monc in Fab, which contains this PR (and will allow us to test anything else that might be required).

@t00sa

Copy link
Copy Markdown
Collaborator

Matthew thinks he has seen something similar before and has suggested that it might be a problem with the pre-processing. I'll do a bit of investigating and let you know how I get on

@hiker

Copy link
Copy Markdown
Author

Matthew thinks he has seen something similar before and has suggested that it might be a problem with the pre-processing. I'll do a bit of investigating and let you know how I get on

Yes, that's why I also wanted the log file and the preprocessed file. It might be that the pre-processed files have line markers (though they should be accepted in fparser 0.2.4, but 0.2.2 and earlier they would trigger an error).

Check environment flags - so far I have made no real progress in removing them (due to request to stay compatible with existing builds) - though iirc only actual compiler flags should be picked up ($FC, $CC, $LD, $FFLAGS, $CFLAGS, $LDFLAGS)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The CLA has been signed as part of this PR - added by GA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants