Skip to content

Commit

Permalink
Merge pull request #103 from xylar/update-to-0.2.0
Browse files Browse the repository at this point in the history
Update to v0.2.0
  • Loading branch information
xylar authored Aug 1, 2023
2 parents 10d95b2 + 844896a commit 8670689
Show file tree
Hide file tree
Showing 16 changed files with 999 additions and 61 deletions.
1 change: 1 addition & 0 deletions deploy/albany_supported.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ chicoma-cpu, gnu, mpich
chrysalis, gnu, openmpi
compy, gnu, openmpi
pm-cpu, gnu, mpich
morpheus, gnu, openmpi
127 changes: 100 additions & 27 deletions deploy/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
import os
import platform
import shutil
import socket
import stat
import subprocess
from configparser import ConfigParser
from typing import Dict

import progressbar
from jinja2 import Template
from mache import MachineInfo, discover_machine
from mache import MachineInfo
from mache import discover_machine as mache_discover_machine
from mache.spack import get_spack_script, make_spack_env
from mache.version import __version__ as mache_version
from shared import (
check_call,
get_conda_base,
Expand Down Expand Up @@ -186,18 +187,14 @@ def get_env_setup(args, config, machine, compiler, mpi, env_type, source_path,
else:
config.set('deploy', 'albany', 'None')

if args.with_netlib_lapack:
lib_suffix = f'{lib_suffix}_netlib_lapack'
else:
config.set('deploy', 'lapack', 'None')

if args.with_petsc:
lib_suffix = f'{lib_suffix}_petsc'
logger.info('Turning off OpenMP because it doesn\'t work well '
'with PETSc')
args.without_openmp = True
else:
config.set('deploy', 'petsc', 'None')
config.set('deploy', 'lapack', 'None')

activ_suffix = f'{activ_suffix}{lib_suffix}'

Expand Down Expand Up @@ -290,7 +287,7 @@ def build_conda_env(config, env_type, recreate, mpi, conda_mpi, version,

for package in ['esmf', 'geometric_features', 'jigsaw', 'jigsawpy',
'mache', 'mpas_tools', 'netcdf_c', 'netcdf_fortran',
'otps', 'pnetcdf', 'scorpio']:
'otps', 'parallelio', 'pnetcdf']:
replacements[package] = config.get('deploy', package)

spec_file = template.render(**replacements)
Expand Down Expand Up @@ -366,6 +363,12 @@ def get_env_vars(machine, compiler, mpilib):
f'export I_MPI_F77=ifort\n' \
f'export I_MPI_F90=ifort\n'

if machine.startswith('conda'):
# we're using parallelio so we don't have ADIOS support
env_vars = \
f'{env_vars}' \
f'export HAVE_ADIOS=false\n'

if platform.system() == 'Linux' and machine.startswith('conda'):
env_vars = \
f'{env_vars}' \
Expand All @@ -392,8 +395,9 @@ def get_env_vars(machine, compiler, mpilib):
return env_vars


def build_spack_env(config, update_spack, machine, compiler, mpi, spack_env,
spack_base, spack_template_path, env_vars, tmpdir, logger):
def build_spack_env(config, update_spack, machine, compiler, mpi, # noqa: C901
spack_env, spack_base, spack_template_path, env_vars,
tmpdir, logger):

albany = config.get('deploy', 'albany')
cmake = config.get('deploy', 'cmake')
Expand All @@ -402,12 +406,12 @@ def build_spack_env(config, update_spack, machine, compiler, mpi, spack_env,
petsc = config.get('deploy', 'petsc')
scorpio = config.get('deploy', 'scorpio')

spack_branch_base = f'{spack_base}/spack_for_mache_{mache_version}'
spack_branch_base = f'{spack_base}/{spack_env}'

specs = list()

if cmake != 'None':
specs.append(f'cmake "@{cmake}"')
specs.append(f'"cmake@{cmake}"')

e3sm_hdf5_netcdf = config.getboolean('deploy', 'use_e3sm_hdf5_netcdf')
if not e3sm_hdf5_netcdf:
Expand All @@ -416,39 +420,58 @@ def build_spack_env(config, update_spack, machine, compiler, mpi, spack_env,
netcdf_fortran = config.get('deploy', 'netcdf_fortran')
pnetcdf = config.get('deploy', 'pnetcdf')
specs.extend([
f'hdf5@{hdf5}+cxx+fortran+hl+mpi+shared',
f'netcdf-c@{netcdf_c}+mpi~parallel-netcdf',
f'netcdf-fortran@{netcdf_fortran}',
f'parallel-netcdf@{pnetcdf}+cxx+fortran'])
f'"hdf5@{hdf5}+cxx+fortran+hl+mpi+shared"',
f'"netcdf-c@{netcdf_c}+mpi~parallel-netcdf"',
f'"netcdf-fortran@{netcdf_fortran}"',
f'"parallel-netcdf@{pnetcdf}+cxx+fortran"'])

if esmf != 'None':
specs.append(f'esmf@{esmf}+mpi+netcdf~pio+pnetcdf')
specs.append(f'"esmf@{esmf}+mpi+netcdf~pnetcdf~external-parallelio"')
if lapack != 'None':
specs.append(f'netlib-lapack@{lapack}')
specs.append(f'"netlib-lapack@{lapack}"')
include_e3sm_lapack = False
else:
include_e3sm_lapack = True
if petsc != 'None':
specs.append(f'petsc@{petsc}+mpi+batch')
specs.append(f'"petsc@{petsc}+mpi+batch"')

custom_spack = ''
if scorpio != 'None':
specs.append(
f'scorpio@{scorpio}+pnetcdf~timing+internal-timing~tools+malloc')
f'"scorpio'
f'@{scorpio}+pnetcdf~timing+internal-timing~tools+malloc"')
# make sure scorpio, not esmf, libraries are linked
lib_path = f'{spack_branch_base}/var/spack/environments/' \
f'{spack_env}/.spack-env/view/lib'
scorpio_lib_path = '$(spack find --format "{prefix}" scorpio)'
custom_spack = \
f'{custom_spack}' \
f'ln -sfn {scorpio_lib_path}/lib/libpioc.a {lib_path}\n' \
f'ln -sfn {scorpio_lib_path}/lib/libpiof.a {lib_path}\n'

if albany != 'None':
specs.append(f'albany@{albany}+mpas')
specs.append(f'"albany@{albany}+mpas"')

yaml_template: str | None = None
template_path = f'{spack_template_path}/{machine}_{compiler}_{mpi}.yaml'
if os.path.exists(template_path):
yaml_template = template_path

if machine is not None:
here = os.path.abspath(os.path.dirname(__file__))
machine_config = os.path.join(here, '..', 'polaris', 'machines',
f'{machine}.cfg')
else:
machine_config = None

if update_spack:
make_spack_env(spack_path=spack_branch_base, env_name=spack_env,
spack_specs=specs, compiler=compiler, mpi=mpi,
machine=machine,
machine=machine, config_file=machine_config,
include_e3sm_lapack=include_e3sm_lapack,
include_e3sm_hdf5_netcdf=e3sm_hdf5_netcdf,
yaml_template=yaml_template, tmpdir=tmpdir)
yaml_template=yaml_template, tmpdir=tmpdir,
custom_spack=custom_spack)

# remove ESMC/ESMF include files that interfere with MPAS time keeping
include_path = f'{spack_branch_base}/var/spack/environments/' \
Expand All @@ -461,7 +484,7 @@ def build_spack_env(config, update_spack, machine, compiler, mpi, spack_env,

spack_script = get_spack_script(
spack_path=spack_branch_base, env_name=spack_env, compiler=compiler,
mpi=mpi, shell='sh', machine=machine,
mpi=mpi, shell='sh', machine=machine, config_file=machine_config,
include_e3sm_lapack=include_e3sm_lapack,
include_e3sm_hdf5_netcdf=e3sm_hdf5_netcdf,
yaml_template=yaml_template)
Expand Down Expand Up @@ -804,6 +827,57 @@ def check_supported(library, machine, compiler, mpi, source_path):
f'on {machine}')


def safe_rmtree(path):
try:
shutil.rmtree(path)
except OSError:
pass


def discover_machine(quiet=False):
"""
Figure out the machine from the host name
Parameters
----------
quiet : bool, optional
Whether to print warnings if the machine name is ambiguous
Returns
-------
machine : str
The name of the current machine
"""
machine = mache_discover_machine(quiet=quiet)
if machine is None:
possible_hosts = get_possible_hosts()
hostname = socket.gethostname()
for possible_machine, hostname_contains in possible_hosts.items():
if hostname_contains in hostname:
machine = possible_machine
break
return machine


def get_possible_hosts():
here = os.path.abspath(os.path.dirname(__file__))
files = sorted(glob.glob(os.path.join(
here, '..', 'polaris', 'machines', '*.cfg')))

possible_hosts = dict()
for filename in files:
machine = os.path.splitext(os.path.split(filename)[1])[0]
config = ConfigParser()
config.read(filename)
if config.has_section('discovery') and \
config.has_option('discovery', 'hostname_contains'):
hostname_contains = config.get('discovery',
'hostname_contains')
possible_hosts[machine] = hostname_contains

return possible_hosts


def main(): # noqa: C901
args = parse_args(bootstrap=True)

Expand All @@ -828,7 +902,7 @@ def main(): # noqa: C901
else:
machine = args.machine

e3sm_machine = machine is not None
known_machine = machine is not None

if machine is None and not args.conda_env_only:
if platform.system() == 'Linux':
Expand Down Expand Up @@ -899,7 +973,7 @@ def main(): # noqa: C901

if args.spack_base is not None:
spack_base = args.spack_base
elif e3sm_machine and compiler is not None:
elif known_machine and compiler is not None:
spack_base = get_spack_base(args.spack_base, config)
else:
spack_base = None
Expand Down Expand Up @@ -969,7 +1043,6 @@ def main(): # noqa: C901
check_env(script_filename, conda_env_name, logger)

if env_type == 'release' and not (args.with_albany or
args.with_netlib_lapack or
args.with_petsc):
# make a symlink to the activation script
link = os.path.join(activ_path,
Expand Down
7 changes: 5 additions & 2 deletions deploy/conda-dev-spec.template
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ otps={{ otps }}
progressbar2
pyamg>=4.2.2
pyproj
pyremap>=0.0.16,<0.1.0
pyremap>=1.0.0,<2.0.0
ruamel.yaml
requests
scipy>=1.8.0
Expand Down Expand Up @@ -59,7 +59,7 @@ fortran-compiler
libnetcdf={{ netcdf_c }}={{ mpi_prefix }}_*
netcdf-fortran={{ netcdf_fortran }}={{ mpi_prefix }}_*
libpnetcdf={{ pnetcdf }}={{ mpi_prefix }}_*
scorpio={{ scorpio }}={{ mpi_prefix }}_*
parallelio={{ parallelio }}={{ mpi_prefix }}_*
m4
make
{{ mpi }}
Expand All @@ -76,3 +76,6 @@ sphinx_rtd_theme
myst-parser
sphinx-multiversion
rst-to-myst

# Visualization
ncview
23 changes: 12 additions & 11 deletions deploy/default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,31 @@ recreate = False
suffix =

# the python version
python = 3.10
python = 3.11

# the MPI version (nompi, mpich or openmpi)
mpi = nompi

# versions of conda packages
geometric_features = 1.0.1
geometric_features = 1.2.0
jigsaw = 0.9.14
jigsawpy = 0.3.3
mache = 1.14.0
mpas_tools = 0.18.0
mache = 1.16.0
mpas_tools = 0.21.0
otps = 2021.10
parallelio = 2.6.0

# versions of conda or spack packages (depending on machine type)
esmf = 8.2.0
netcdf_c = 4.8.1
netcdf_fortran = 4.6
pnetcdf = 1.12.2
scorpio = 1.3.2
esmf = 8.4.2
netcdf_c = 4.9.2
netcdf_fortran = 4.6.1
pnetcdf = 1.12.3

# versions of spack packages
albany = develop
# cmake newer than 3.23.0 needed for Trilinos
cmake = 3.23.0:
hdf5 = 1.12.1
hdf5 = 1.14.1
lapack = 3.9.1
petsc = 3.16.1
petsc = 3.19.1
scorpio = 1.4.1
1 change: 0 additions & 1 deletion deploy/petsc_supported.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ chicoma-cpu, gnu, mpich
chrysalis, intel, openmpi
chrysalis, gnu, openmpi
compy, intel, impi
compy, gnu, openmpi
pm-cpu, gnu, mpich
15 changes: 4 additions & 11 deletions deploy/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,10 @@ def parse_args(bootstrap):
action='store_true',
help="Whether to include albany in the spack "
"environment.")
parser.add_argument("--with_netlib_lapack", dest="with_netlib_lapack",
action='store_true',
help="Whether to include Netlib-LAPACK in the spack "
"environment.")
parser.add_argument("--with_petsc", dest="with_petsc",
action='store_true',
help="Whether to include PETSc in the spack "
"environment.")
help="Whether to include PETSc and Netlib-LAPACK in "
"the spack environment.")
parser.add_argument("--without_openmp", dest="without_openmp",
action='store_true',
help="If this flag is included, OPENMP=false will "
Expand Down Expand Up @@ -177,19 +173,16 @@ def install_mambaforge(conda_base, activate_base, logger):
check_call(command, logger=logger)
os.remove(mambaforge)

backup_bashrc()

print('Doing initial setup\n')
commands = f'{activate_base} && ' \
f'conda config --add channels conda-forge && ' \
f'conda config --set channel_priority strict && ' \
f'mamba update -y "mamba>1.3.1" "conda>=23.1.0" && ' \
f'mamba update -y --all && ' \
f'mamba init'
f'mamba init --no-user'

check_call(commands, logger=logger)

restore_bashrc()


def backup_bashrc():
home_dir = os.path.expanduser('~')
Expand Down
Loading

0 comments on commit 8670689

Please sign in to comment.