Skip to content

Conversation

@Stellatsuu
Copy link
Collaborator

@Stellatsuu Stellatsuu commented Oct 8, 2025

I tried to run "bad" jobs with cwltool and it seems that it does not check for conflicts or higher requirements than expected in ResourceRequirement.

So, I've come to this code to validate ResourceRequirements in workflows, related to #27. I tried to make something generic in case we need to implement other Requirements in the future?

However, I'm not entirely sure if this matches with how we want to implement things in the proto, so I'd appreciate any feedback or suggestions.

@Stellatsuu Stellatsuu self-assigned this Oct 8, 2025
@mr-c
Copy link

mr-c commented Oct 8, 2025

@Stellatsuu PRs and/or issues to cwltool are welcome. I'm curious as to how it didn't meet your expectations.

@Stellatsuu Stellatsuu linked an issue Oct 9, 2025 that may be closed by this pull request
3 tasks
@Stellatsuu
Copy link
Collaborator Author

Hi @mr-c,
I just created a discussion on CWL Forum explaining what I'm trying to do: https://cwl.discourse.group/t/how-does-resourcerequirement-work/1019

@Stellatsuu Stellatsuu changed the title Draft: Resource requirements validation Resource requirements validation Oct 15, 2025
@natthan-pigoux
Copy link
Collaborator

natthan-pigoux commented Oct 22, 2025

Thank you @Stellatsuu ! The overall looks good to me.

I have a remark on the testing part. We can probably do something more concise here without adding that many cwl files.

Here is a suggestion which could be extended:

from cwl_utils.parser.cwl_v1_2 import CommandLineTool, Workflow, WorkflowStep, ResourceRequirement
import pytest

from dirac_cwl_proto.execution_hooks.requirement_validator import RequirementError, ResourceRequirementValidator

@pytest.mark.parametrize(
    ("bad_min_max_reqs"),
    [
        ResourceRequirement(coresMin=4, coresMax=2),
        ResourceRequirement(ramMin=2048, ramMax=1024)
    ],
)
def test_bad_min_max_resource_reqs(bad_min_max_reqs):
    """Test wrong min max resource requirements."""
    # test clt:
    clt = CommandLineTool(
        requirements=[bad_min_max_reqs],
        inputs=[],
        outputs=[]
    )
    with pytest.raises(RequirementError):
        ResourceRequirementValidator(cwl_object=clt).validate_requirements()

    # test workflow
    step = WorkflowStep(
        in_=[],
        out=[],
        run=clt
    )
    workflow = Workflow(
        requirements=[],
        steps=[step],
        inputs=[],
        outputs=[]
    )
    with pytest.raises(RequirementError):
        ResourceRequirementValidator(cwl_object=workflow).validate_requirements()

    workflow = Workflow(
        requirements=[bad_min_max_reqs],
        steps=[],
        inputs=[],
        outputs=[]
    )
    with pytest.raises(RequirementError):
        ResourceRequirementValidator(cwl_object=workflow).validate_requirements()

@pytest.mark.parametrize(
    ("global_cores_requirements", "step_cores_requirements"),
    [
        (
            ResourceRequirement(coresMax=2),
            ResourceRequirement(coresMin=4),
        ),
        (
            ResourceRequirement(ramMax=512),
            ResourceRequirement(ramMin=1024),
        ),
    ],
)
def test_bad_global_requirements(global_cores_requirements, step_cores_requirements):
    """Test global requirements conflicts."""
    clt = CommandLineTool(
        inputs=[],
        outputs=[]
    )
    step = WorkflowStep(
        in_=[],
        out=[],
        run=clt,
        requirements=[step_cores_requirements]
    )
    workflow = Workflow(
        requirements=[global_cores_requirements],
        steps=[step],
        inputs=[],
        outputs=[]
    )
    with pytest.raises(RequirementError):
        ResourceRequirementValidator(cwl_object=workflow).validate_requirements()

This is more easily extendable, and it also allows to test the RequirementValidator separately of the job submission.

What do you think?

@Stellatsuu
Copy link
Collaborator Author

Thank you @Stellatsuu ! The overall looks good to me.

I have a remark on the testing part. We can probably do something more concise here without adding that many cwl files.

This is more easily extendable, and it also allows to test the RequirementValidator separately of the job submission.

What do you think?

@natthan-pigoux Thanks, I hadn't thought of that, but it definitely seems like a better approach! I was already realizing that there were a lot of files... I forgot I could test it this way, so I'll give it a try and see if we can apply these tests to cover all cases 😄

Comment on lines 142 to 154
def validate_minmax(min_value, max_value, resource, context):
"""
Check if the resource min_value is higher than the resource max_value.
If so, raise a ValueError.
:param min_value: The current resource min_value.
:param max_value: The current resource max_value.
:param resource: The resource name.
:param context: A context string describing the validation context.
Ex: "Step requirement", "Global requirement", etc.
"""
if min_value and max_value and min_value > max_value:
raise ValueError(f"{resource}Min is higher than {resource}Max in {context}")
Copy link
Owner

Choose a reason for hiding this comment

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

We now know that this should be part of cwl itself.
By the way, now that I am seeing that, I think we should include it to cwl-utils and not cwltool (or may be both).
In this way, this minmax test would be performed when we use save in the Production/Transformation/JobSubmissionModel.
Do you see what I mean?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added a minmax check in cwl-utils : common-workflow-language/cwl-utils@addfebb
When saving a Workflow or CLT with save(), it triggers an error if min > max, I also added a test for that.

But, this will only check the minmax values of a same ResourceRequirement (ex: Workflow RR, Step RR, CLT RR, etc.). I don't think we can check that a Step RR values are not higher than a 'global' Workflow RR values using cwl-utils, I don't really see how to do it right now.

Also, I don't really know how to test the fromDoc() method, so I added the check without any test..

Do you think I should also look to add it to cwltool ? @aldbr

Copy link

@mr-c mr-c Nov 13, 2025

Choose a reason for hiding this comment

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

I don't think we can check that a Step RR values are not higher than a 'global' Workflow RR values using cwl-utils

If there is a step-level ResourceRequirement in requirements, then any ResourceRequirement under the workflow-level hints or requirements would be ignored in CWL v1.0-v1.3; so such a check is unnecessarily and non-sensical

@Stellatsuu
Copy link
Collaborator Author

@aldbr Here's an update for now :

I removed my Validator classes and added everything into SubmissionsModels as asked :

  • Every type of WF (Job, Transformation, Production) goes through the same validation before the model is created.
    - I don't know if I should've included the methods in the SubmissionModel class or if I let them as module helpers outside of it.
    - Once we add every possible check in cwl-utils/cwltool, we'll be able to reduce the validation cases/code and maybe even remove all of it.
    - Should I also add this validation into TransformationSubmissionModel and ProductionSubmissionModel ? I saw we always end up calling JobSubmissionModel, that's why I only implemented it there.
  • In case of a Production, there's a special validation alongside the steps-metadata validation.

As for the implementation in cwl-utils/cwltool, I'm working on it (see: #40 (comment)). I think it would be great to add the minmax check in both codes, what do you think? Do you think I should ask the devs?

@Stellatsuu
Copy link
Collaborator Author

Stellatsuu commented Nov 13, 2025

Open cwl-utils PR: common-workflow-language/cwl-utils#384 --> might be closed due to unnecessary validation (it's mostly auto-generated code)
Open cwl-tool PR: common-workflow-language/cwltool#2179

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.

Resource Requirement minmax validation

5 participants