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

Replace check_max function with resourceLimits directive #3037

Merged
merged 22 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ee2241a
Replace check_max with resourceLimits
jfy133 Jun 25, 2024
ce49bad
Update CHANGELOG.md
jfy133 Jun 25, 2024
c8abbef
Code alignment, and try to get test to run on GHA Actions runner
jfy133 Jun 25, 2024
044fc1d
Remove default basic resource limits in template (should be set by us…
jfy133 Jul 1, 2024
528a207
Add a basic set of resource limits in test configs, matching GithubAc…
jfy133 Jul 1, 2024
936802f
Bump minimum NXF version to allow resourceLimits
jfy133 Jul 1, 2024
06a1dbe
Add linting check for now deprecated params
jfy133 Jul 1, 2024
47abfc2
Add linting check for check_ params and continue removing from everyw…
jfy133 Jul 1, 2024
2e690d9
Merge branch 'dev' into deprecate-cehck_max_function
jfy133 Sep 4, 2024
736d5e8
Removes all remaining references to max_* params
jfy133 Sep 4, 2024
5563360
[automated] Fix code linting
nf-core-bot Sep 4, 2024
6633769
Fix linting fail
jfy133 Sep 4, 2024
d819232
Fix schema error
jfy133 Sep 4, 2024
f3138fc
Merge branch 'deprecate-cehck_max_function' of github.com:jfy133/nf-c…
jfy133 Sep 4, 2024
5599039
add tests back
mirpedrol Sep 16, 2024
e87478d
Merge branch 'dev' of https://github.com/nf-core/tools into deprecate…
mirpedrol Sep 16, 2024
c568ce9
more pytest fixing
mirpedrol Sep 16, 2024
17dc0bc
change order of profiles used for CI
mirpedrol Sep 19, 2024
482c40b
Merge branch 'dev' into deprecate-cehck_max_function
mirpedrol Sep 19, 2024
c494c26
update nextflow version on CI
mirpedrol Sep 19, 2024
2c0d2f6
configs are included after profiles
mirpedrol Sep 19, 2024
d2959ed
reduce memory in test profile
mirpedrol Sep 19, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/create-lint-wf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
strategy:
matrix:
NXF_VER:
- "23.10.0"
- "24.04.2"
- "latest-everything"
steps:
- name: go to subdirectory and change nextflow workdir
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/create-test-wf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
strategy:
matrix:
NXF_VER:
- "23.10.0"
- "24.04.2"
- "latest-everything"
steps:
- name: go to working directory
Expand Down Expand Up @@ -75,7 +75,7 @@ jobs:
pwd
# echo content of current directory
ls -la
nextflow run nf-core-testpipeline -profile test,self_hosted_runner --outdir ./results
nextflow run nf-core-testpipeline -profile self_hosted_runner,test --outdir ./results

- name: Upload log file artifact
if: ${{ always() }}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
- add option to exclude tower.yml from pipeline template ([#3134](https://github.com/nf-core/tools/pull/3134))
- run nf-core lint `--release` on PRs to master ([#3148](https://github.com/nf-core/tools/pull/3148))
- Add tests to ensure all files are part of a template customisation group and all groups are tested ([#3099](https://github.com/nf-core/tools/pull/3099))
- Replaces the old custom `check_max()` function with the Nextflow native `resourceLimits` directive ([#3037](https://github.com/nf-core/tools/pull/3037))
- Fixed release announcement hashtags for Mastodon ([#3099](https://github.com/nf-core/tools/pull/3176))

### Linting
Expand Down
2 changes: 1 addition & 1 deletion nf_core/pipeline-template/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
strategy:
matrix:
NXF_VER:
- "23.10.0"
- "24.04.2"
- "latest-everything"
steps:
- name: Check out pipeline code
Expand Down
2 changes: 1 addition & 1 deletion nf_core/pipeline-template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
[![Cite with Zenodo](http://img.shields.io/badge/DOI-10.5281/zenodo.XXXXXXX-1073c8?labelColor=000000)](https://doi.org/10.5281/zenodo.XXXXXXX)
[![nf-test](https://img.shields.io/badge/unit_tests-nf--test-337ab7.svg)](https://www.nf-test.com)

[![Nextflow](https://img.shields.io/badge/nextflow%20DSL2-%E2%89%A523.10.0-23aa62.svg)](https://www.nextflow.io/)
[![Nextflow](https://img.shields.io/badge/nextflow%20DSL2-%E2%89%A524.04.2-23aa62.svg)](https://www.nextflow.io/)
[![run with conda](http://img.shields.io/badge/run%20with-conda-3EB049?labelColor=000000&logo=anaconda)](https://docs.conda.io/en/latest/)
[![run with docker](https://img.shields.io/badge/run%20with-docker-0db7ed?labelColor=000000&logo=docker)](https://www.docker.com/)
[![run with singularity](https://img.shields.io/badge/run%20with-singularity-1d355c.svg?labelColor=000000)](https://sylabs.io/docs/)
Expand Down
34 changes: 17 additions & 17 deletions nf_core/pipeline-template/conf/base.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
process {

// TODO nf-core: Check the defaults for all processes
cpus = { check_max( 1 * task.attempt, 'cpus' ) }
memory = { check_max( 6.GB * task.attempt, 'memory' ) }
time = { check_max( 4.h * task.attempt, 'time' ) }
cpus = { 1 * task.attempt }
memory = { 6.GB * task.attempt }
time = { 4.h * task.attempt }

errorStrategy = { task.exitStatus in ((130..145) + 104) ? 'retry' : 'finish' }
maxRetries = 1
Expand All @@ -27,30 +27,30 @@ process {
// TODO nf-core: Customise requirements for specific processes.
// See https://www.nextflow.io/docs/latest/config.html#config-process-selectors
withLabel:process_single {
cpus = { check_max( 1 , 'cpus' ) }
memory = { check_max( 6.GB * task.attempt, 'memory' ) }
time = { check_max( 4.h * task.attempt, 'time' ) }
cpus = { 1 }
memory = { 6.GB * task.attempt }
time = { 4.h * task.attempt }
}
withLabel:process_low {
cpus = { check_max( 2 * task.attempt, 'cpus' ) }
memory = { check_max( 12.GB * task.attempt, 'memory' ) }
time = { check_max( 4.h * task.attempt, 'time' ) }
cpus = { 2 * task.attempt }
memory = { 12.GB * task.attempt }
time = { 4.h * task.attempt }
}
withLabel:process_medium {
cpus = { check_max( 6 * task.attempt, 'cpus' ) }
memory = { check_max( 36.GB * task.attempt, 'memory' ) }
time = { check_max( 8.h * task.attempt, 'time' ) }
cpus = { 6 * task.attempt }
memory = { 36.GB * task.attempt }
time = { 8.h * task.attempt }
}
withLabel:process_high {
cpus = { check_max( 12 * task.attempt, 'cpus' ) }
memory = { check_max( 72.GB * task.attempt, 'memory' ) }
time = { check_max( 16.h * task.attempt, 'time' ) }
cpus = { 12 * task.attempt }
memory = { 72.GB * task.attempt }
time = { 16.h * task.attempt }
}
withLabel:process_long {
time = { check_max( 20.h * task.attempt, 'time' ) }
time = { 20.h * task.attempt }
}
withLabel:process_high_memory {
memory = { check_max( 200.GB * task.attempt, 'memory' ) }
memory = { 200.GB * task.attempt }
}
withLabel:error_ignore {
errorStrategy = 'ignore'
Expand Down
13 changes: 8 additions & 5 deletions nf_core/pipeline-template/conf/test.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@
----------------------------------------------------------------------------------------
*/

process {
resourceLimits = [
cpus: 4,
memory: '15.GB',
time: '1.h'
]
}

params {
config_profile_name = 'Test profile'
config_profile_description = 'Minimal test dataset to check pipeline function'

// Limit resources so that this can run on GitHub Actions
max_cpus = 2
max_memory = '6.GB'
max_time = '6.h'

// Input data
// TODO nf-core: Specify the paths to your test data on nf-core/test-datasets
// TODO nf-core: Give any required params for the test so that command line flags are not needed
Expand Down
71 changes: 17 additions & 54 deletions nf_core/pipeline-template/nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ params {
config_profile_url = null
{%- endif %}

// Max resource options
// Defaults only, expecting to be overwritten
max_memory = '128.GB'
max_cpus = 16
max_time = '240.h'

{%- if nf_schema %}
// Schema validation default options
validate_params = true
Expand All @@ -82,21 +76,6 @@ process {
maxErrors = '-1'
}
{% endif %}
{% if nf_core_configs -%}
// Load nf-core custom profiles from different Institutions
try {
includeConfig "${params.custom_config_base}/nfcore_custom.config"
} catch (Exception e) {
System.err.println("WARNING: Could not load nf-core/config profiles: ${params.custom_config_base}/nfcore_custom.config")
}

// Load {{ name }} custom profiles from different institutions.
try {
includeConfig "${params.custom_config_base}/pipeline/{{ short_name }}.config"
} catch (Exception e) {
System.err.println("WARNING: Could not load nf-core/config/{{ short_name }} profiles: ${params.custom_config_base}/pipeline/{{ short_name }}.config")
}
{% endif -%}

profiles {
debug {
Expand Down Expand Up @@ -205,6 +184,22 @@ profiles {
{%- endif %}
}

{% if nf_core_configs -%}
// Load nf-core custom profiles from different Institutions
try {
includeConfig "${params.custom_config_base}/nfcore_custom.config"
} catch (Exception e) {
System.err.println("WARNING: Could not load nf-core/config profiles: ${params.custom_config_base}/nfcore_custom.config")
}

// Load {{ name }} custom profiles from different institutions.
try {
includeConfig "${params.custom_config_base}/pipeline/{{ short_name }}.config"
} catch (Exception e) {
System.err.println("WARNING: Could not load nf-core/config/{{ short_name }} profiles: ${params.custom_config_base}/pipeline/{{ short_name }}.config")
}
{% endif -%}

// Set default registry for Apptainer, Docker, Podman, Charliecloud and Singularity independent of -profile
// Will not be used unless Apptainer / Docker / Podman / Charliecloud / Singularity are enabled
// Set to your registry if you have a mirror of containers
Expand Down Expand Up @@ -271,7 +266,7 @@ manifest {
homePage = 'https://github.com/{{ name }}'
description = """{{ description }}"""
mainScript = 'main.nf'
nextflowVersion = '!>=23.10.0'
nextflowVersion = '!>=24.04.2'
version = '{{ version }}'
doi = ''
}
Expand Down Expand Up @@ -318,35 +313,3 @@ validation {
// Load modules.config for DSL2 module specific options
includeConfig 'conf/modules.config'
{% endif %}
// Function to ensure that resource requirements don't go beyond
// a maximum limit
def check_max(obj, type) {
if (type == 'memory') {
try {
if (obj.compareTo(params.max_memory as nextflow.util.MemoryUnit) == 1)
return params.max_memory as nextflow.util.MemoryUnit
else
return obj
} catch (all) {
println " ### ERROR ### Max memory '${params.max_memory}' is not valid! Using default value: $obj"
return obj
}
} else if (type == 'time') {
try {
if (obj.compareTo(params.max_time as nextflow.util.Duration) == 1)
return params.max_time as nextflow.util.Duration
else
return obj
} catch (all) {
println " ### ERROR ### Max time '${params.max_time}' is not valid! Using default value: $obj"
return obj
}
} else if (type == 'cpus') {
try {
return Math.min( obj, params.max_cpus as int )
} catch (all) {
println " ### ERROR ### Max cpus '${params.max_cpus}' is not valid! Using default value: $obj"
return obj
}
}
}
38 changes: 0 additions & 38 deletions nf_core/pipeline-template/nextflow_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,41 +136,6 @@
}
},
{%- endif %}
"max_job_request_options": {
"title": "Max job request options",
"type": "object",
"fa_icon": "fab fa-acquisitions-incorporated",
"description": "Set the top limit for requested resources for any single job.",
"help_text": "If you are running on a smaller system, a pipeline step requesting more resources than are available may cause the Nextflow to stop the run with an error. These options allow you to cap the maximum resources requested by any single job so that the pipeline will run on your system.\n\nNote that you can not _increase_ the resources requested by any job using these options. For that you will need your own configuration file. See [the nf-core website](https://nf-co.re/usage/configuration) for details.",
"properties": {
"max_cpus": {
"type": "integer",
"description": "Maximum number of CPUs that can be requested for any single job.",
"default": 16,
"fa_icon": "fas fa-microchip",
"hidden": true,
"help_text": "Use to set an upper-limit for the CPU requirement for each process. Should be an integer e.g. `--max_cpus 1`"
},
"max_memory": {
"type": "string",
"description": "Maximum amount of memory that can be requested for any single job.",
"default": "128.GB",
"fa_icon": "fas fa-memory",
"pattern": "^\\d+(\\.\\d+)?\\.?\\s*(K|M|G|T)?B$",
"hidden": true,
"help_text": "Use to set an upper-limit for the memory requirement for each process. Should be a string in the format integer-unit e.g. `--max_memory '8.GB'`"
},
"max_time": {
"type": "string",
"description": "Maximum amount of time that can be requested for any single job.",
"default": "240.h",
"fa_icon": "far fa-clock",
"pattern": "^(\\d+\\.?\\s*(s|m|h|d|day)\\s*)+$",
"hidden": true,
"help_text": "Use to set an upper-limit for the time requirement for each process. Should be a string in the format integer-unit e.g. `--max_time '2.h'`"
}
}
},
"generic_options": {
"title": "Generic options",
"type": "object",
Expand Down Expand Up @@ -278,9 +243,6 @@
{% if nf_core_configs %}{
"$ref": "#/$defs/institutional_config_options"
},{% endif %}
{
"$ref": "#/$defs/max_job_request_options"
},
{
"$ref": "#/$defs/generic_options"
}
Expand Down
14 changes: 13 additions & 1 deletion nf_core/pipelines/lint/nextflow_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def nextflow_config(self) -> Dict[str, List[str]]:
* ``params.nf_required_version``: The old method for specifying the minimum Nextflow version. Replaced by ``manifest.nextflowVersion``
* ``params.container``: The old method for specifying the dockerhub container address. Replaced by ``process.container``
* ``igenomesIgnore``: Changed to ``igenomes_ignore``
* ``params.max_cpus``: Old method of specifying the maximum number of CPUs a process can request. Replaced by native Nextflow `resourceLimits`directive in config files.
* ``params.max_memory``: Old method of specifying the maximum number of memory can request. Replaced by native Nextflow `resourceLimits`directive.
* ``params.max_time``: Old method of specifying the maximum number of CPUs can request. Replaced by native Nextflow `resourceLimits`directive.

.. tip:: The ``snake_case`` convention should now be used when defining pipeline parameters

Expand Down Expand Up @@ -146,7 +149,13 @@ def nextflow_config(self) -> Dict[str, List[str]]:
["params.input"],
]
# Throw a warning if these are missing
config_warn = [["manifest.mainScript"], ["timeline.file"], ["trace.file"], ["report.file"], ["dag.file"]]
config_warn = [
["manifest.mainScript"],
["timeline.file"],
["trace.file"],
["report.file"],
["dag.file"],
]
# Old depreciated vars - fail if present
config_fail_ifdefined = [
"params.nf_required_version",
Expand All @@ -155,6 +164,9 @@ def nextflow_config(self) -> Dict[str, List[str]]:
"params.igenomesIgnore",
"params.name",
"params.enable_conda",
"params.max_cpus",
"params.max_memory",
"params.max_time",
]

# Lint for plugins
Expand Down
2 changes: 1 addition & 1 deletion nf_core/pipelines/lint/readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def readme(self):

if "nextflow_badge" not in ignore_configs:
# Check that there is a readme badge showing the minimum required version of Nextflow
# [![Nextflow](https://img.shields.io/badge/nextflow%20DSL2-%E2%89%A523.10.0-23aa62.svg)](https://www.nextflow.io/)
# [![Nextflow](https://img.shields.io/badge/nextflow%20DSL2-%E2%89%A524.04.2-23aa62.svg)](https://www.nextflow.io/)
# and that it has the correct version
nf_badge_re = r"\[!\[Nextflow\]\(https://img\.shields\.io/badge/nextflow%20DSL2-!?(?:%E2%89%A5|%3E%3D)([\d\.]+)-23aa62\.svg\)\]\(https://www\.nextflow\.io/\)"
match = re.search(nf_badge_re, content)
Expand Down
Loading
Loading