-
Notifications
You must be signed in to change notification settings - Fork 25
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
cpe in ce #257
Closed
Closed
cpe in ce #257
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright 2024 Swiss National Supercomputing Centre (CSCS/ETH Zurich) | ||
# ReFrame Project Developers. See the top-level LICENSE file for details. | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
import reframe as rfm | ||
import reframe.utility.typecheck as typ | ||
|
||
|
||
class ContainerEngineMixinCPE(rfm.RegressionMixin): | ||
#: The container image to use. | ||
#: | ||
#: :default: ``required`` | ||
container_image = variable(str) | ||
|
||
#: The working directory of the container. | ||
#: | ||
#: Setting to `None` will not set any workdir for the container | ||
#: | ||
#: :default: ``'/rfm_workdir/'`` | ||
container_workdir = variable(str, type(None), value='/rfm_workdir') | ||
|
||
#: A list of the container mounts following the <src dir>:<target dir> | ||
#: convention. | ||
#: The test stage directory is always mounted on `/rfm_workdir`. | ||
#: | ||
#: :default: ``[]`` | ||
container_mounts = variable(typ.List[str], value=[]) | ||
|
||
#: A dictionary of key/values to pass to the container environment. | ||
#: | ||
#: :default: ``{}`` | ||
container_env_key_values = variable(typ.Dict[str, str], value={}) | ||
|
||
#: A dictionary of tables to pass to the container environment. | ||
#: For each key, a dictionary of key/value pairs is given. | ||
#: | ||
#: :default: ``{}`` | ||
container_env_table= variable(typ.Dict[str, typ.Dict[str, str]], value={}) | ||
|
||
@run_before('compile') | ||
def create_env_file(self): | ||
mounts = ',\n'.join(f'"{m}"' for m in self.container_mounts) | ||
toml_lines = [ | ||
f'image = "{self.container_image}"', | ||
f'mounts = [', | ||
f'"{self.stagedir}:/rfm_workdir",', | ||
f'"{self.stagedir}:{self.stagedir}",', | ||
mounts, | ||
f']', | ||
] | ||
toml_lines += [f'workdir = "{self.stagedir}"'] | ||
|
||
for k, v in self.container_env_key_values.items(): | ||
toml_lines.append(f'{k} = "{v}"') | ||
|
||
for table_name, values in self.container_env_table.items(): | ||
if values: | ||
toml_lines.append(f'[{table_name}]') | ||
for k, v in values.items(): | ||
toml_lines.append(f'{k} = "{v}"') | ||
|
||
self.env_file = f'{self.stagedir}/rfm_env.toml' | ||
with open(self.env_file, 'w') as f: | ||
f.write('\n'.join(l for l in toml_lines if l)) | ||
|
||
@run_before('compile') | ||
def set_sbatch(self): | ||
self.build_job.options += [f'--environment={self.env_file}'] | ||
|
||
@run_before('run') | ||
def set_container_engine_env_launcher_options(self): | ||
self.job.options += [f'--environment={self.env_file}'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed on slack, I am not sure we need to have a special class for this. I think we can re-use the container engine mixin and make it pass the options in both compilation and run scripts