Skip to content

Commit

Permalink
Spack package for UM (#131)
Browse files Browse the repository at this point in the history
* Add a site-dependent keyword config file

* Add a package for um

* Add more versions. Specify openmpi dependency.

* Specify gcom dependency. Let gcom specify openmpi dependency. Install the correct directory tree.
  • Loading branch information
penguian authored Aug 6, 2024
1 parent 8388104 commit d69e984
Show file tree
Hide file tree
Showing 6 changed files with 381 additions and 3 deletions.
147 changes: 147 additions & 0 deletions packages/fcm/etc/nci-gadi/keyword.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# From gadi.nci.org.au:/g/data/hr22/apps/etc/fcm/access/keyword.cfg
location{primary}[admin] = file:///g/data/access/access-svn/UM_Admin
location{primary}[admin_br] = file:///g/data/access/access-svn/UM_Admin/branches
location{primary}[admin_dev] = file:///g/data/access/access-svn/UM_Admin/branches/dev
location{primary}[admin_tags] = file:///g/data/access/access-svn/UM_Admin/tags
location{primary}[admin_tr] = file:///g/data/access/access-svn/UM_Admin/trunk
location{primary}[cice] = file:///g/data/access/access-svn/cice
location{primary}[cice_br] = file:///g/data/access/access-svn/cice/branches
location{primary}[cice_tr] = file:///g/data/access/access-svn/cice/trunk
location{primary}[gcom] = file:///g/data/access/access-svn/GCOM
location{primary}[gcom_br] = file:///g/data/access/access-svn/GCOM/branches
location{primary}[gcom_dev] = file:///g/data/access/access-svn/GCOM/branches/dev
location{primary}[gcom_tags] = file:///g/data/access/access-svn/GCOM/tags
location{primary}[gcom_tr] = file:///g/data/access/access-svn/GCOM/trunk
location{primary}[ghui] = file:///g/data/access/access-svn/ghui
location{primary}[ghui_br] = file:///g/data/access/access-svn/ghui/branches
location{primary}[ghui_tags] = file:///g/data/access/access-svn/ghui/tags
location{primary}[ghui_tr] = file:///g/data/access/access-svn/ghui/trunk
location{primary}[jules] = file:///g/data/access/access-svn/jules
location{primary}[jules_br] = file:///g/data/access/access-svn/jules/branches
location{primary}[jules_dev] = file:///g/data/access/access-svn/jules/branches/dev
location{primary}[jules_tags] = file:///g/data/access/access-svn/jules/tags
location{primary}[jules_tr] = file:///g/data/access/access-svn/jules/trunk
location{primary}[nemo] = file:///g/data/access/access-svn/nemo
location{primary}[nemo_br] = file:///g/data/access/access-svn/nemo/branches
location{primary}[nemo_tr] = file:///g/data/access/access-svn/nemo/trunk
location{primary}[ops] = file:///g/data/access/access-svn/ops
location{primary}[um] = file:///g/data/access/access-svn/um
location{primary}[um_br] = file:///g/data/access/access-svn/um/branches
location{primary}[um_dev] = file:///g/data/access/access-svn/um/branches/dev
location{primary}[um_tags] = file:///g/data/access/access-svn/um/tags
location{primary}[um_tr] = file:///g/data/access/access-svn/um/trunk
location{primary}[umui] = file:///g/data/access/access-svn/umui
location{primary}[umui_br] = file:///g/data/access/access-svn/umui/branches
location{primary}[umui_tags] = file:///g/data/access/access-svn/umui/tags
location{primary}[umui_tr] = file:///g/data/access/access-svn/umui/trunk
location{primary}[var] = file:///g/data/access/access-svn/var
revision[gcom:] = 36
revision[um:] = 9135
revision[um:vn6.3] = 37
# From gadi.nci.org.au:/g/data/hr22/apps/etc/fcm/mosrs/keyword.cfg
location{primary}[ancil.x] = https://code.metoffice.gov.uk/svn/ancil/main
location{primary}[ancil.xm] = file:///g/data/ki32/mosrs/ancil/main
location{primary}[ancil_ants.x] = https://code.metoffice.gov.uk/svn/ancil/ants
location{primary}[ancil_ants.xm] = file:///g/data/ki32/mosrs/ancil/ants
location{primary}[ancil_contrib.x] = https://code.metoffice.gov.uk/svn/ancil/contrib
location{primary}[ancil_contrib.xm] = file:///g/data/ki32/mosrs/ancil/contrib
location{primary}[ancil_data.x] = https://code.metoffice.gov.uk/svn/ancil/data
location{primary}[ancil_data.xm] = file:///g/data/ki32/mosrs/ancil/data
location{primary}[casim.x] = https://code.metoffice.gov.uk/svn/monc/casim
location{primary}[casim.xm] = file:///g/data/ki32/mosrs/casim/casim
location{primary}[cice.x] = https://code.metoffice.gov.uk/svn/cice/main
location{primary}[cice.xm] = file:///g/data/ki32/mosrs/cice/main
location{primary}[da.x] = https://code.metoffice.gov.uk/svn/da
location{primary}[da.xm] = file:///g/data/ki32/mosrs/da
location{primary}[da_aodsetup.x] = https://code.metoffice.gov.uk/svn/da/AODSetup_namelists
location{primary}[da_aodsetup.xm] = file:///g/data/ki32/mosrs/da/AODSetup_namelists
location{primary}[da_assoccntl.x] = https://code.metoffice.gov.uk/svn/da/Assoccntl
location{primary}[da_assoccntl.xm] = file:///g/data/ki32/mosrs/da/Assoccntl
location{primary}[da_covppxref.x] = https://code.metoffice.gov.uk/svn/da/Cov_PPXref
location{primary}[da_covppxref.xm] = file:///g/data/ki32/mosrs/da/Cov_PPXref
location{primary}[da_elements.x] = https://code.metoffice.gov.uk/svn/da/Elements
location{primary}[da_elements.xm] = file:///g/data/ki32/mosrs/da/Elements
location{primary}[da_eotdlocalisation.x] = https://code.metoffice.gov.uk/svn/da/EOTD_localisation
location{primary}[da_eotdlocalisation.xm] = file:///g/data/ki32/mosrs/da/EOTD_localisation
location{primary}[da_gpsrocoeffs.x] = https://code.metoffice.gov.uk/svn/da/GPSRO_coeffs
location{primary}[da_gpsrocoeffs.xm] = file:///g/data/ki32/mosrs/da/GPSRO_coeffs
location{primary}[da_groundgpsbiases.x] = https://code.metoffice.gov.uk/svn/da/GroundGPS_biases
location{primary}[da_groundgpsbiases.xm] = file:///g/data/ki32/mosrs/da/GroundGPS_biases
location{primary}[da_hloswindnamelist.x] = https://code.metoffice.gov.uk/svn/da/HLOSwind_namelist
location{primary}[da_hloswindnamelist.xm] = file:///g/data/ki32/mosrs/da/HLOSwind_namelist
location{primary}[da_rttov11coeffs.x] = https://code.metoffice.gov.uk/svn/da/RTTOV11_coeffs
location{primary}[da_rttov11coeffs.xm] = file:///g/data/ki32/mosrs/da/RTTOV11_coeffs
location{primary}[da_rttov12coeffs.x] = https://code.metoffice.gov.uk/svn/da/RTTOV12_coeffs
location{primary}[da_rttov12coeffs.xm] = file:///g/data/ki32/mosrs/da/RTTOV12_coeffs
location{primary}[da_rttov7coeffs.x] = https://code.metoffice.gov.uk/svn/da/RTTOV7_coeffs
location{primary}[da_rttov7coeffs.xm] = file:///g/data/ki32/mosrs/da/RTTOV7_coeffs
location{primary}[da_satradbiases.x] = https://code.metoffice.gov.uk/svn/da/SatRad_biases
location{primary}[da_satradbiases.xm] = file:///g/data/ki32/mosrs/da/SatRad_biases
location{primary}[da_satradcoeffs.x] = https://code.metoffice.gov.uk/svn/da/SatRad_coeffs
location{primary}[da_satradcoeffs.xm] = file:///g/data/ki32/mosrs/da/SatRad_coeffs
location{primary}[da_satwindnamelists.x] = https://code.metoffice.gov.uk/svn/da/Satwind_namelists
location{primary}[da_satwindnamelists.xm] = file:///g/data/ki32/mosrs/da/Satwind_namelists
location{primary}[da_scatwindcoeffs.x] = https://code.metoffice.gov.uk/svn/da/Scatwind_coeffs
location{primary}[da_scatwindcoeffs.xm] = file:///g/data/ki32/mosrs/da/Scatwind_coeffs
location{primary}[da_sondecoeffs.x] = https://code.metoffice.gov.uk/svn/da/Sonde_coeffs
location{primary}[da_sondecoeffs.xm] = file:///g/data/ki32/mosrs/da/Sonde_coeffs
location{primary}[da_stationlists.x] = https://code.metoffice.gov.uk/svn/da/StationLists
location{primary}[da_stationlists.xm] = file:///g/data/ki32/mosrs/da/StationLists
location{primary}[da_vargrid.x] = https://code.metoffice.gov.uk/svn/da/VarGrid
location{primary}[da_vargrid.xm] = file:///g/data/ki32/mosrs/da/VarGrid
location{primary}[da_varpfbl.x] = https://code.metoffice.gov.uk/svn/da/Var_PFBL
location{primary}[da_varpfbl.xm] = file:///g/data/ki32/mosrs/da/Var_PFBL
location{primary}[da_varppxref.x] = https://code.metoffice.gov.uk/svn/da/Var_PPXref
location{primary}[da_varppxref.xm] = file:///g/data/ki32/mosrs/da/Var_PPXref
location{primary}[da_varppxrefem.x] = https://code.metoffice.gov.uk/svn/da/Var_PPXref_EM
location{primary}[da_varppxrefem.xm] = file:///g/data/ki32/mosrs/da/Var_PPXref_EM
location{primary}[da_vartransform.x] = https://code.metoffice.gov.uk/svn/da/Var_Transform
location{primary}[da_vartransform.xm] = file:///g/data/ki32/mosrs/da/Var_Transform
location{primary}[gcom.x] = https://code.metoffice.gov.uk/svn/gcom/main
location{primary}[gcom.xm] = file:///g/data/ki32/mosrs/gcom/main
location{primary}[jules.x] = https://code.metoffice.gov.uk/svn/jules/main
location{primary}[jules.xm] = file:///g/data/ki32/mosrs/jules/main
location{primary}[lfric.x] = https://code.metoffice.gov.uk/svn/lfric/LFRic
location{primary}[lfric.xm] = file:///g/data/ki32/mosrs/lfric/LFRic
location{primary}[lfric_apps.x] = https://code.metoffice.gov.uk/svn/lfric_apps/main
location{primary}[lfric_apps.xm] = file:///g/data/ki32/mosrs/lfric_apps/main
location{primary}[lfric_gpl_utils.x] = https://code.metoffice.gov.uk/svn/lfric/GPL-utilities
location{primary}[lfric_gpl_utils.xm] = file:///g/data/ki32/mosrs/lfric/GPL-utilities
location{primary}[moci.x] = https://code.metoffice.gov.uk/svn/moci/main
location{primary}[moci.xm] = file:///g/data/ki32/mosrs/moci/main
location{primary}[mule.x] = https://code.metoffice.gov.uk/svn/um/mule
location{primary}[mule.xm] = file:///g/data/ki32/mosrs/um/mule
location{primary}[ops.x] = https://code.metoffice.gov.uk/svn/ops/main
location{primary}[ops.xm] = file:///g/data/ki32/mosrs/ops/main
location{primary}[rmedtoolbox.x] = https://code.metoffice.gov.uk/svn/rmedtoolbox/main
location{primary}[rmedtoolbox.xm] = file:///g/data/ki32/mosrs/rmedtoolbox/main
location{primary}[shumlib.x] = https://code.metoffice.gov.uk/svn/utils/shumlib
location{primary}[shumlib.xm] = file:///g/data/ki32/mosrs/utils/shumlib
location{primary}[socrates.x] = https://code.metoffice.gov.uk/svn/socrates/main
location{primary}[socrates.xm] = file:///g/data/ki32/mosrs/socrates/main
location{primary}[surf.x] = https://code.metoffice.gov.uk/svn/surf/main
location{primary}[surf.xm] = file:///g/data/ki32/mosrs/surf/main
location{primary}[trui.x] = https://code.metoffice.gov.uk/svn/trui/main
location{primary}[trui.xm] = file:///g/data/ki32/mosrs/trui/main
location{primary}[ukca.x] = https://code.metoffice.gov.uk/svn/ukca/main
location{primary}[ukca.xm] = file:///g/data/ki32/mosrs/ukca/main
location{primary}[um.x] = https://code.metoffice.gov.uk/svn/um/main
location{primary}[um.xm] = file:///g/data/ki32/mosrs/um/main
location{primary}[um_aux.x] = https://code.metoffice.gov.uk/svn/um/aux
location{primary}[um_aux.xm] = file:///g/data/ki32/mosrs/um/aux
location{primary}[um_doc.x] = https://code.metoffice.gov.uk/svn/um/doc
location{primary}[um_meta.x] = https://code.metoffice.gov.uk/svn/um/meta
location{primary}[um_meta.xm] = file:///g/data/ki32/mosrs/um/meta
location{primary}[utils.x] = https://code.metoffice.gov.uk/svn/utils
location{primary}[utils.xm] = file:///g/data/ki32/mosrs/utils
location{primary}[var.x] = https://code.metoffice.gov.uk/svn/var/main
location{primary}[var.xm] = file:///g/data/ki32/mosrs/var/main
location{primary}[varpy.x] = https://code.metoffice.gov.uk/svn/varpy/main
location{primary}[varpy.xm] = file:///g/data/ki32/mosrs/varpy/main
location{primary}[ver.x] = https://code.metoffice.gov.uk/svn/ver/main
location{primary}[ver.xm] = file:///g/data/ki32/mosrs/ver/main
location{primary}[verpy.x] = https://code.metoffice.gov.uk/svn/ver/verpy
location{primary}[verpy.xm] = file:///g/data/ki32/mosrs/ver/verpy
# From gadi.nci.org.au:/g/data/hr22/apps/etc/fcm/nemo/keyword.cfg
location{primary}[nemo.x] = https://code.metoffice.gov.uk/svn/nemo
location{primary}[nemo.xm] = file:///g/data/ki32/mosrs/nemo
11 changes: 10 additions & 1 deletion packages/fcm/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@ class Fcm(Package):

homepage = "https://github.com/metomi/fcm"

maintainers = ["scottwales"]
maintainers("scottwales", "penguian")

version(
"2021.05.0",
sha256="b4178b488470aa391f29b46d19bd6395ace42ea06cb9678cabbd4604b46f56cd",
)

variant("site", default="none", description="Site to use for keyword configuration",
values=("none", "nci-gadi"), multi=False)

def url_for_version(self, version):
return "https://github.com/metomi/fcm/archive/refs/tags/{0}.tar.gz".format(version)

def install(self, spec, prefix):
install_tree(".", prefix)
site = spec.variants["site"].value
if site != "none":
mkdirp(prefix.etc)
install(
join_path(self.package_dir, "etc", site, "keyword.cfg"),
join_path(prefix.etc, "fcm"))
12 changes: 10 additions & 2 deletions packages/gcom/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,25 @@ class Gcom(Package):
homepage = "https://code.metoffice.gov.uk/trac/gcom"
svn = "file:///g/data/ki32/mosrs/gcom/main/trunk"

maintainers = ["scottwales"]
maintainers("scottwales", "paulleopardi")

# See 'fcm kp fcm:gcom.xm' for release versions
version("7.8", revision=1147)
version("7.9", revision=1166)
version("8.0", revision=1181)
version("8.1", revision=1215)
version("8.2", revision=1251)
version("8.3", revision=1288)

variant("mpi", default=True, description="Build with MPI")

depends_on("fcm", type="build")
depends_on("mpi", when="+mpi")
depends_on("mpi", when="+mpi", type=("build", "link", "run"))
# For the default MPI version for NCI, see (e.g.)
# https://code.metoffice.gov.uk/trac/gcom/browser/main/trunk/rose-stem/site/nci/suite.rc
# For cherry picking virtual dependencies, see
# https://github.com/spack/spack/releases/tag/v0.21.0 Feature 4
depends_on("[email protected]:", when="+mpi^[virtuals=mpi] openmpi", type=("build", "link", "run"))

def install(self, spec, prefix):
fcm = which("fcm")
Expand Down
11 changes: 11 additions & 0 deletions packages/um/fcm-make.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# From fcm:[email protected]/rose-stem/app/fcm_make_um/file/fcm-make.cfg
use = $prebuild

include = $config_root_path/fcm-make/$platform_config_dir/um-$config_type-$optimisation_level.cfg$config_revision

extract.location{diff}[um] = $um_sources
extract.location{diff}[ukca] = $ukca_sources
extract.location{diff}[shumlib] = $shumlib_sources
extract.location{diff}[casim] = $casim_sources
extract.location{diff}[jules] = $jules_sources
extract.location{diff}[socrates] = $socrates_sources
151 changes: 151 additions & 0 deletions packages/um/package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# Copyright 2013-2023 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# Copyright 2024 ACCESS-NRI
# Based on https://github.com/nci/spack-repo/blob/main/packages/um/package.py
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

import configparser
from spack.package import *

class Um(Package):
"""
UM is a numerical weather prediction and climate modelling software package.
"""

homepage = "https://code.metoffice.gov.uk/trac/um"
svn = "file:///g/data/ki32/mosrs/um/main/trunk"

# See 'fcm kp fcm:um.xm' for release versions
version("13.0", revision=111272, preferred=True)
version("13.1", revision=114076)
version("13.2", revision=116723)
version("13.3", revision=118802)
version("13.4", revision=120750)
version("13.5", revision=123226)
version("13.6", revision=124981)

maintainers("penguian")

variant("optim", default="safe", description="Optimization level",
values=("debug", "high", "rigorous", "safe"), multi=False)
variant("platform", default="nci-x86-ifort", description="Site platform",
values=("nci-x86-ifort", "vm-x86-gnu"), multi=False)


depends_on("fcm", type="build")
# For GCOM versions, see
# https://code.metoffice.gov.uk/trac/gcom/wiki/Gcom_meto_installed_versions
depends_on("[email protected]", when="@:13.0", type=("build", "link"))
depends_on("[email protected]", when="@13.1", type=("build", "link"))
depends_on("[email protected]", when="@13.2", type=("build", "link"))
depends_on("[email protected]", when="@13.3", type=("build", "link"))
depends_on("[email protected]", when="@13.4", type=("build", "link"))
depends_on("[email protected]:", when="@13.5:", type=("build", "link"))
depends_on("eccodes +fortran +netcdf", type=("build", "link", "run"))
depends_on("[email protected]", type=("build", "link", "run"))

phases = ["build", "install"]

# The dependency name and the ld_flags from
# the FCM config for each library configured via FCM.
_lib_cfg = {
"DR_HOOK": {
"dep_name": "drhook",
"fcm_ld_flags": "-ldrhook"},
"eccodes": {
"dep_name": "eccodes",
"fcm_ld_flags": "-leccodes_f90 -leccodes"},
"netcdf": {
"dep_name": "netcdf-fortran",
"fcm_ld_flags": "-lnetcdff -lnetcdf"}}


def _get_linker_args(self, spec, fcm_libname):
"""
Return the linker flags corresponding to fcm_libname,
a library name configured via FCM.
"""
dep_name = self._lib_cfg[fcm_libname]["dep_name"]
ld_flags = [
spec[dep_name].libs.ld_flags,
self._lib_cfg[fcm_libname]["fcm_ld_flags"]]
# The reason for the explicit -rpath is:
# https://github.com/ACCESS-NRI/spack_packages/issues/14#issuecomment-1653651447
rpaths = ["-Wl,-rpath=" + d for d in spec[dep_name].libs.directories]

# Both ld_flags and rpaths are lists of strings.
return " ".join(ld_flags + rpaths)


def setup_build_environment(self, env):
"""
Set environment variables to their required values.
"""
spec = self.spec
env.prepend_path("PATH", spec["fcm"].prefix.bin)
ideps = ["eccodes", "gcom", "netcdf-fortran"]
incs = [spec[d].prefix.include for d in ideps]
for ipath in incs:
env.prepend_path("CPATH", ipath)
# The gcom library does not contain shared objects and
# therefore must be statically linked.
env.prepend_path("LIBRARY_PATH", spec["gcom"].prefix.lib)

# Use rose-app.conf to set config options.
config = configparser.ConfigParser()
config.read(join_path(self.package_dir, "rose-app.conf"))
# Modify the config as per points 8 and 9 of
# https://metomi.github.io/rose/2019.01.8/html/api/configuration/rose-configuration-format.html
for key in config["env"]:
if len(key) > 0 and key[0] != '!':
value = config["env"][key].replace("\n=", "\n")
env.set(key, value)

# Override some specific environment variables
env.set("optimisation_level", spec.variants["optim"].value)
env.set("platform_config_dir", spec.variants["platform"].value)
env.set("um_rev", f"vn{spec.version}")
components = ["casim", "jules", "shumlib", "socrates", "ukca"]
for comp in components:
env.set(f"{comp}_rev", f"um{spec.version}")
for fcm_libname in ["eccodes", "netcdf"]:
linker_args = self._get_linker_args(spec, fcm_libname)
env.set(f"ldflags_{fcm_libname}_on", linker_args)


def _build_dir(self):
"""
Return the build directory.
"""
return join_path(self.stage.source_path, "..", "spack-build")


def build(self, spec, prefix):
"""
Use FCM to build the executables.
"""
config_file = join_path(self.package_dir, "fcm-make.cfg")
build_dir = self._build_dir()
mkdirp(build_dir)
fcm = which("fcm")
fcm("make",
"--new",
f"--config-file={config_file}",
f"--directory={build_dir}",
"--jobs=4")


def install(self, spec, prefix):
"""
Install executables and accompanying files into the prefix directory,
according to the directory structure of EXEC_DIR, as described in (e.g.)
https://code.metoffice.gov.uk/trac/roses-u/browser/b/y/3/9/5/trunk/meta/rose-meta.conf
"""
for um_exe in ["atmos", "recon"]:
bin_dir = join_path(f"build-{um_exe}", "bin")
build_bin_dir = join_path(self._build_dir(), bin_dir)
install_bin_dir = join_path(prefix, bin_dir)
mkdirp(install_bin_dir)
install_tree(build_bin_dir, install_bin_dir)
Loading

0 comments on commit d69e984

Please sign in to comment.