Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nested compiler install #302

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions lib/ramble/ramble/application_types/spack.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ def _long_print(self):

def _software_install_requested_compilers(self, workspace):
"""Install compilers an application uses"""

# See if we cached this already, and if so return
env_path = self.expander.env_path
if not env_path:
raise ApplicationError('Ramble env_path is set to None.')
logger.msg('Installing compilers')

cache_tupl = ('spack-compilers', env_path)
if workspace.check_cache(cache_tupl):
Expand All @@ -101,13 +101,30 @@ def _software_install_requested_compilers(self, workspace):

app_context = self.expander.expand_var_name(self.keywords.env_name)

compilers_to_install = set()
root_compilers = []
for pkg_name in workspace.software_environments.get_env_packages(app_context):
pkg_spec = workspace.software_environments.get_spec(pkg_name)
if 'compiler' in pkg_spec:
logger.msg('Installing compilers')
logger.debug(f'Compilers: {pkg_spec["compiler"]}')
comp_spec = workspace.software_environments.get_spec(pkg_spec['compiler'])
self.spack_runner.install_compiler(comp_spec['spack_spec'])
if pkg_spec['compiler'] not in compilers_to_install:
logger.debug(f' Adding root compiler: {pkg_spec["compiler"]}')
compilers_to_install.add(pkg_spec['compiler'])
root_compilers.append(pkg_spec['compiler'])

dep_compilers = []
for comp_name in root_compilers:
cur_spec = workspace.software_environments.get_spec(comp_name)
while 'compiler' in cur_spec and cur_spec['compiler'] not in compilers_to_install:
compilers_to_install.add(cur_spec['compiler'])
dep_compilers.append(cur_spec['compiler'])
logger.debug(f' Adding dependency compiler: {cur_spec["compiler"]}')
cur_spec = workspace.software_environments.get_spec(cur_spec['compiler'])

# Install all compilers, starting with deps:
for comp_pkg in reversed(root_compilers + dep_compilers):
spec_str = workspace.software_environments.get_spec_string(comp_pkg)
logger.debug(f'Installing compiler: {comp_pkg}')
self.spack_runner.install_compiler(spec_str)

except ramble.spack_runner.RunnerError as e:
logger.die(e)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Copyright 2022-2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.

import os
import glob

import pytest

import ramble.filters
import ramble.pipeline
import ramble.workspace
import ramble.config
import ramble.software_environments
from ramble.main import RambleCommand
from ramble.test.dry_run_helpers import search_files_for_string


# everything here uses the mock_workspace_path
pytestmark = pytest.mark.usefixtures('mutable_config',
'mutable_mock_workspace_path')

workspace = RambleCommand('workspace')


def test_nested_compilers_are_installed(mutable_config, mutable_mock_workspace_path, capsys):
test_config = """
ramble:
variables:
mpi_command: 'mpirun -n {n_ranks} -ppn {processes_per_node}'
batch_submit: 'batch_submit {execute_experiment}'
processes_per_node: '10'
n_ranks: '{processes_per_node}*{n_nodes}'
n_threads: '1'
applications:
wrfv4:
workloads:
CONUS_12km:
experiments:
test{n_nodes}_{env_name}:
variables:
n_nodes: '1'
spack:
concretized: true
packages:
gcc8:
spack_spec: [email protected]
gcc9:
spack_spec: [email protected]
compiler: gcc8
gcc10:
spack_spec: [email protected]
compiler: gcc9
intel:
spack_spec: [email protected]
compiler: gcc10
wrf:
spack_spec: [email protected] build_type=dm+sm compile_type=em_real nesting=basic ~chem ~pnetcdf
compiler: gcc10
environments:
wrfv4:
packages:
- wrf
- intel
"""

setup_type = ramble.pipeline.pipelines.setup
setup_cls = ramble.pipeline.pipeline_class(setup_type)
filters = ramble.filters.Filters()

workspace_name = 'test_nested_compilers_are_installed'
with ramble.workspace.create(workspace_name) as ws:
ws.write()

config_path = os.path.join(ws.config_dir, ramble.workspace.config_file_name)

with open(config_path, 'w+') as f:
f.write(test_config)

ws.dry_run = True
ws._re_read()

setup_pipeline = setup_cls(ws, filters)
setup_pipeline.run()

gcc8_str = "[email protected]"
gcc9_str = "[email protected]"
gcc10_str = "[email protected]"

out_files = glob.glob(os.path.join(ws.log_dir, '**', '*.out'), recursive=True)

assert search_files_for_string(out_files, gcc8_str) is True
assert search_files_for_string(out_files, gcc9_str) is True
assert search_files_for_string(out_files, gcc10_str) is True