Skip to content

Conversation

SimoneBendazzoli93
Copy link
Collaborator

fixes #114

@SimoneBendazzoli93 SimoneBendazzoli93 self-assigned this Sep 25, 2025
@Copilot Copilot AI review requested due to automatic review settings September 25, 2025 02:01
@brainless-bot
Copy link
Contributor

brainless-bot bot commented Sep 25, 2025

🤖 Code Formatting Reminder

Hello there! 👋 It looks like the code in this pull request might benefit from some formatting improvements.
Fix the issues locally or use our auto format action by commenting /format on this PR!

Code style: black

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds Singularity container support as an alternative to Docker for running BraTS algorithms, addressing issue #114. The implementation allows users to switch between Docker and Singularity backends via an environment variable or method parameter.

  • Implements Singularity container runtime functionality alongside existing Docker support
  • Adds backend selection mechanism through environment variable or explicit parameter
  • Updates all algorithm inference methods to support the new backend parameter

Reviewed Changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
brats/core/singularity.py New module implementing Singularity container execution logic
brats/core/brats_algorithm.py Updated to dispatch between Docker and Singularity backends
brats/constants.py Added Backends enum for backend type definitions
brats/core/segmentation_algorithms.py Added backend parameter support to inference methods
brats/core/missing_mri_algorithms.py Added backend parameter support to inference methods
brats/core/inpainting_algorithms.py Added backend parameter support to inference methods
pyproject.toml Added spython dependency for Singularity support
tests/core/test_singularity.py Comprehensive test suite for Singularity functionality
README.md Updated documentation with Singularity installation instructions

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@neuronflow
Copy link
Contributor

/format

@brainless-bot
Copy link
Contributor

brainless-bot bot commented Sep 25, 2025

🤖 I will now format your code with black. Check the status here.

Copy link
Contributor

@neuronflow neuronflow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README.md also needs adjustments :)

please have a look at co-pilot comments and ensure tests are passing :)

@neuronflow neuronflow marked this pull request as draft September 25, 2025 02:08
@neuronflow
Copy link
Contributor

please mark as ready for review once @MarcelRosier and me should review :)

@SimoneBendazzoli93 SimoneBendazzoli93 marked this pull request as ready for review September 25, 2025 08:20
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 5 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

force_cpu: bool,
internal_external_name_map: Optional[Dict[str, str]] = None,
):
"""Run a docker container for the provided algorithm.
Copy link
Preview

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring incorrectly states 'Run a docker container' when this function actually runs a Singularity container. This should be updated to reflect the correct container technology.

Suggested change
"""Run a docker container for the provided algorithm.
"""Run a Singularity container for the provided algorithm.

Copilot uses AI. Check for mistakes.

image = _ensure_image(image=algorithm.run_args.docker_image)

additional_files_path = _get_additional_files_path(algorithm)
print(f"Additional files path: {additional_files_path}")
Copy link
Preview

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This debug print statement should be replaced with a proper logger call for consistency with the rest of the codebase. Use logger.debug(f'Additional files path: {additional_files_path}') instead.

Suggested change
print(f"Additional files path: {additional_files_path}")
logger.debug(f"Additional files path: {additional_files_path}")

Copilot uses AI. Check for mistakes.

executor = Client.run(
image,
options=options,
args=["infer", *command_args.split(" "), *extra_args],
Copy link
Preview

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splitting command_args by spaces can break arguments that contain spaces (e.g., file paths with spaces). This could cause incorrect argument parsing. Consider using a more robust argument parsing approach or ensure command_args is already properly tokenized.

Copilot uses AI. Check for mistakes.

Comment on lines +134 to +135
log_file (Optional[Path | str], optional): Save logs to this file. Defaults to None.
backend (str, optional): Backend to use for inference. Defaults to "docker".
Copy link
Preview

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The docstring formatting is inconsistent. Line 134 has a period at the end while line 135 doesn't. For consistency, both lines should either have periods or not have them.

Copilot uses AI. Check for mistakes.

cuda_devices=self.cuda_devices,
force_cpu=self.force_cpu,
)

Copy link
Preview

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This extra blank line is unnecessary and reduces code readability. Remove the empty line after the runner() function call.

Suggested change

Copilot uses AI. Check for mistakes.

inputs: dict[str, Path | str],
output_file: Path | str,
log_file: Optional[Path | str] = None,
backend: str = "docker",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the Backend enum as type and default value? Would be cleaner IMO

data_folder: Path | str,
output_folder: Path | str,
log_file: Optional[Path | str] = None,
backend: str = "docker",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

mask: Path | str,
output_file: Path | str,
log_file: Optional[Path | str] = None,
backend: Optional[str] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for all algorithm classes: use the enum

backend (str, optional): Backend to use for inference. Defaults to "docker".
"""
if backend is None:
backend_env = os.environ.get("BRATS_ORCHESTRATOR_BACKEND")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no difference but prettier: backend = os.environ.get("BRATS_ORCHESTRATOR_BACKEND", "docker")

# ensure output folder exists
output_path.mkdir(parents=True, exist_ok=True)

volume_mappings = _get_volume_mappings_mlcube(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will only work for algorithms up to 2024. In 2025 mlcube was not used anymore, see the difference here

_sanity_check_output(
data_path=data_path,
output_path=output_path,
container_output="",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for debugging its really helpful to pass the actual output. always logging it on info lvl as done rn seems a bit excessive

Copy link
Contributor

@neuronflow neuronflow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Copilot's and @MarcelRosier's comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] singularity support
3 participants