Skip to content

Feature/singularity support#64

Open
lucas-ebi wants to merge 14 commits into
developfrom
feature/singularity-support
Open

Feature/singularity support#64
lucas-ebi wants to merge 14 commits into
developfrom
feature/singularity-support

Conversation

@lucas-ebi
Copy link
Copy Markdown
Contributor

This pull request adds support for running remote jobs inside a Singularity container in the RcsbDpUtility and RunRemote modules. It introduces configuration options and logic to enable or disable containerization, specify images and bind paths, and avoid unnecessary container usage for pure Python jobs. The main changes can be grouped as follows:

Singularity container integration:

  • Added Singularity-related configuration and state variables (__use_singularity, __singularity_image, __singularity_bind_paths, __partition) to RcsbDpUtility and initialized them from config files. Provided setters for these options. ([[1]](https://github.com/wwPDB/py-wwpdb_utils_dp/pull/64/files#diff-2e2869b065e067698eb47b67f09dfb23c80c48f00226941f5dea3c8587cb6e7dR433-R444), [[2]](https://github.com/wwPDB/py-wwpdb_utils_dp/pull/64/files#diff-2e2869b065e067698eb47b67f09dfb23c80c48f00226941f5dea3c8587cb6e7dR496-R528), [[3]](https://github.com/wwPDB/py-wwpdb_utils_dp/pull/64/files#diff-2e2869b065e067698eb47b67f09dfb23c80c48f00226941f5dea3c8587cb6e7dR537-R554))
  • Updated __run in RcsbDpUtility to pass Singularity options to RunRemote, and added logic to only use Singularity if the command is not purely Python-based. ([[1]](https://github.com/wwPDB/py-wwpdb_utils_dp/pull/64/files#diff-2e2869b065e067698eb47b67f09dfb23c80c48f00226941f5dea3c8587cb6e7dR5050-R5089), [[2]](https://github.com/wwPDB/py-wwpdb_utils_dp/pull/64/files#diff-2e2869b065e067698eb47b67f09dfb23c80c48f00226941f5dea3c8587cb6e7dR5103-R5106))
  • In RunRemote, added parameters and logic to wrap commands using Singularity, including detection of nested containers and construction of bind mounts and environment variables. ([[1]](https://github.com/wwPDB/py-wwpdb_utils_dp/pull/64/files#diff-0bec41aa508ed1c2af5339f02d9075f7c749d732fee45898b42a3b13e832edd0R47-R50), [[2]](https://github.com/wwPDB/py-wwpdb_utils_dp/pull/64/files#diff-0bec41aa508ed1c2af5339f02d9075f7c749d732fee45898b42a3b13e832edd0R61-R76), [[3]](https://github.com/wwPDB/py-wwpdb_utils_dp/pull/64/files#diff-0bec41aa508ed1c2af5339f02d9075f7c749d732fee45898b42a3b13e832edd0R166-R216), [[4]](https://github.com/wwPDB/py-wwpdb_utils_dp/pull/64/files#diff-0bec41aa508ed1c2af5339f02d9075f7c749d732fee45898b42a3b13e832edd0R235-R238))

Partition and SLURM integration:

  • Added support for specifying the SLURM partition (queue) for job submission, either via parameter or configuration, defaulting to "standard" if not set. (F75435fbL45R44, [wwpdb/utils/dp/RunRemote.pyR61-R76](https://github.com/wwPDB/py-wwpdb_utils_dp/pull/64/files#diff-0bec41aa508ed1c2af5339f02d9075f7c749d732fee45898b42a3b13e832edd0R61-R76))

Python job detection:

  • Implemented __commandOnlyCallsPythonScripts in RcsbDpUtility to detect if a command only runs Python scripts, allowing the system to skip containerization for such jobs. ([wwpdb/utils/dp/RcsbDpUtility.pyR5050-R5089](https://github.com/wwPDB/py-wwpdb_utils_dp/pull/64/files#diff-2e2869b065e067698eb47b67f09dfb23c80c48f00226941f5dea3c8587cb6e7dR5050-R5089))

Command-line interface enhancements:

  • Extended the RunRemote CLI with options for Singularity usage, image selection, and bind paths. ([[1]](https://github.com/wwPDB/py-wwpdb_utils_dp/pull/64/files#diff-0bec41aa508ed1c2af5339f02d9075f7c749d732fee45898b42a3b13e832edd0R276-R287), [[2]](https://github.com/wwPDB/py-wwpdb_utils_dp/pull/64/files#diff-0bec41aa508ed1c2af5339f02d9075f7c749d732fee45898b42a3b13e832edd0R297-R299))

Other improvements:

  • Added re import for regex matching in Python job detection. ([wwpdb/utils/dp/RcsbDpUtility.pyR153](https://github.com/wwPDB/py-wwpdb_utils_dp/pull/64/files#diff-2e2869b065e067698eb47b67f09dfb23c80c48f00226941f5dea3c8587cb6e7dR153))
  • Ensured environment variables are exported in SLURM jobs for correct container detection. ([wwpdb/utils/dp/RunRemote.pyR144-R155](https://github.com/wwPDB/py-wwpdb_utils_dp/pull/64/files#diff-0bec41aa508ed1c2af5339f02d9075f7c749d732fee45898b42a3b13e832edd0R144-R155))

These changes enable flexible and configurable use of Singularity containers for remote job execution, improving compatibility and reproducibility for heterogeneous compute environments.

- Add use_singularity, singularity_image, and singularity_bind_paths parameters
- Implement _wrap_with_singularity() method to execute commands inside container
- Automatically bind necessary paths (onedep_root, log_dir, run_dir, /tmp)
- Support custom bind paths via singularity_bind_paths parameter
- Set required environment variables (WWPDB_SITE_ID, WWPDB_SITE_LOC, ONEDEP_PATH)
- Add CLI arguments for Singularity options
- Default image: /nfs/public/services/onedep_gpfs/docker-tools/onedep-builder_rocky8.sif

This enables running tools built for Rocky Linux 8 on RedHat 9 cluster nodes.
- Add use_singularity, singularity_image, and singularity_bind_paths instance variables
- Implement setUseSingularity(), setSingularityImage(), and setSingularityBindPaths() methods
- Update __run() method to pass Singularity parameters to RunRemote
- Enables all RcsbDpUtility operations to run inside Singularity containers when enabled

Works together with RunRemote Singularity support for RedHat 9 migration.
- Add __getSingularity() method to read Singularity settings from ConfigInfo
- Call __getSingularity() in __init__ to auto-configure from site-config
- Supports use_singularity, singularity_image, and singularity_bind_paths config keys
- No code changes needed in calling code - Singularity is enabled automatically via configuration

This allows enabling Singularity site-wide by adding to site.cfg:
  use_singularity = true
  singularity_image = /path/to/image.sif  (optional)
  singularity_bind_paths = /path1,/path2  (optional)
- Detect if already running inside a Singularity container
- Skip container wrapping when SINGULARITY_CONTAINER or SINGULARITY_NAME env vars are set
- Prevents container-in-container issues when jobs spawn sub-jobs

This handles the case where:
1. Job A runs in Singularity container on SLURM
2. Job A spawns Job B and submits it to SLURM
3. Job B would be wrapped in Singularity again (nested)
4. Now Job B detects it's already in a container and skips wrapping
- Remove hardcoded default path from RunRemote.__init__
- Singularity image path must be provided via singularity_image parameter
- Or set via site.cfg configuration: singularity_image = /path/to/image.sif
- This ensures paths are always configuration-driven, never hardcoded
- Only use TOP_WWPDB_SITE_CONFIG_DIR from config for bind mounts.
- Do not fall back to ONEDEP_PATH or any hardcoded path.
- Ensures cross-site compatibility and restores original wwPDB environment standards.
At runtime, inspect the shebang of every executable invoked in the
shell command.  If all of them are Python scripts, bypass the
container (the host Python works fine without it).  ELF binaries
and mixed commands still run inside the container as before.
Extend __commandOnlyCallsPythonScripts to recognise bare python/python3
invocations (e.g. python -m wwpdb.apps.validation) in addition to
absolute paths with Python shebangs.  Shell builtins and variable
assignments are skipped.

Pass PYTHON=/usr/bin/python3 into the Singularity container so that
env.sh (which now uses ${PYTHON:-python3}) calls the container system
python for ConfigInfoShellExec.py instead of tools-rhel-9/bin/python3
which requires glibc 2.34.
@lucas-ebi lucas-ebi requested review from epeisach and wmorellato April 2, 2026 14:59
@epeisach
Copy link
Copy Markdown
Contributor

epeisach commented Apr 4, 2026

You should fix the auto test errors...
pyllint is complaining for instance...
************* Module dp.RunRemote
wwpdb/utils/dp/RunRemote.py:49:8: W0621: Redefining name 'singularity_bind_paths' from outer scope (line 284) (redefined-outer-name)

Route all remote workflow jobs through Singularity when enabled now that the Rocky 8 toolchain is active. Remove the forced container PYTHON override so env.sh owns interpreter selection.
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.

2 participants