-
-
Notifications
You must be signed in to change notification settings - Fork 144
added script to build docker/singularity images #703
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
Open
SubhadityaMukherjee
wants to merge
1
commit into
openml:master
Choose a base branch
from
SubhadityaMukherjee:contribute_minor_changes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 hidden or 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 |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ my_* | |
| __pycache__ | ||
| .python-version | ||
| venv/ | ||
| .venv/ | ||
|
|
||
| # editors/IDEs | ||
| .idea/ | ||
|
|
||
This file contains hidden or 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,104 @@ | ||
| """ | ||
| This script can be used to build all/selected docker/singularity images. | ||
| 0. Load your virtual environment like you would when using AMLB. | ||
| 1. Run the script with the required mode: | ||
| python build_images.py -m docker | ||
| python build_images.py -m singularity | ||
|
|
||
| 2. To delete files forcefully, add the --force flag. This is optional but recommended in case you change something. | ||
| python build_images.py -m singularity --force | ||
|
|
||
| 3. To specify frameworks, use the -f flag with a comma-separated list: | ||
| python build_images.py -m docker -f autosklearn,flaml,gama --force | ||
|
|
||
| 4. If no frameworks are specified, the script will act on all available frameworks. | ||
|
|
||
| """ | ||
|
|
||
| import os | ||
| import argparse | ||
| import pathlib | ||
| from pathlib import Path | ||
| from typing import List, Optional | ||
|
|
||
|
|
||
| def delete_singularity_files( | ||
| directory: pathlib.Path, frameworks: Optional[List[str]] = None | ||
| ) -> None: | ||
| """Deletes Singularity-related files from the specified directory.""" | ||
| for root, _, files in os.walk(directory): | ||
| for file in files: | ||
| if file == "Singularityfile" or file.endswith(".sif"): | ||
| file_path = Path(root) / file | ||
|
|
||
| if frameworks and not any( | ||
| framework in file_path.name.lower() for framework in frameworks | ||
| ): | ||
| continue | ||
|
|
||
| try: | ||
| file_path.unlink() | ||
| print(f"Deleted: {file_path}") | ||
| except Exception as e: | ||
| print(f"Error deleting {file_path}: {e}") | ||
|
|
||
|
|
||
| def parse_arguments() -> argparse.Namespace: | ||
| """Parses command-line arguments.""" | ||
| parser = argparse.ArgumentParser( | ||
| description="Script to manage Docker and Singularity frameworks." | ||
| ) | ||
| parser.add_argument( | ||
| "-m", "--mode", help="Docker or singularity", type=str, required=True | ||
| ) | ||
| parser.add_argument( | ||
| "--force", help="Delete singularity/docker files.", action="store_true" | ||
| ) | ||
| parser.add_argument( | ||
| "-f", | ||
| "--frameworks", | ||
| help="Comma-separated list of frameworks to act on.", | ||
| type=str, | ||
| ) | ||
| return parser.parse_args() | ||
|
|
||
|
|
||
| def get_frameworks(framework_dir: Path, user_input: Optional[str]) -> List[str]: | ||
| """Gets the list of frameworks based on user input or directory listing.""" | ||
| if user_input: | ||
| frameworks = [framework.lower().strip() for framework in user_input.split(",")] | ||
| print(f"Running for given frameworks - {frameworks}") | ||
| else: | ||
| frameworks = [ | ||
| framework.lower() | ||
| for framework in os.listdir(framework_dir) | ||
| if "__" not in framework | ||
| ] | ||
| print(f"Running for all frameworks - {frameworks}") | ||
| return frameworks | ||
|
|
||
|
|
||
| def main() -> None: | ||
| args = parse_arguments() | ||
| framework_dir = Path("../frameworks/") | ||
| mode = args.mode.lower().strip() | ||
| frameworks = get_frameworks(framework_dir, args.frameworks) | ||
|
|
||
| if mode == "docker" and args.force: | ||
| print("Deleting frameworks from Docker") | ||
| for framework in frameworks: | ||
| os.system(f"docker rmi $(docker images 'automlbenchmark/{framework}')") | ||
|
|
||
| elif mode == "singularity" and args.force: | ||
| print("Deleting frameworks from Singularity") | ||
| delete_singularity_files(directory=framework_dir, frameworks=frameworks) | ||
|
|
||
| for framework in frameworks: | ||
| print(f"Setting up {framework}") | ||
| os.system( | ||
| f"yes | python ../runbenchmark.py {framework} openml/t/3812 --mode {mode} --setup only" | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.