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

Fix 2d output arrays with format tag #2010

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

vjaganat90
Copy link

The issue is when we print 2d_output arrays which have "format" tag

touch filename.txt
cwltool --cachedir foo output_2D_file_format.cwl

("Error collecting output for parameter 'output_array': output_2D_file_format.cwl:14:3: list indices must
                                                                                        be integers or
                                                                                        slices, not str",
                                                                                        {})

The crux of the issue is aslist function, only promotes scalars to 1d arrays. Arbitrary JS can return an arbitrary json, format handling code needs to handle arbitrary json (not just scalars or 1d arrays which is done through aslist function).

With this fix the output should be something like this

jaganathv2$ touch filename.txt
jaganathv2$ cwltool --cachedir foo output_2D_file_format.cwl
INFO /Users/jaganathv2/mambaforge/envs/cwt/bin/cwltool 3.1.20220628170239.dev281+g57619ffd
INFO Resolved 'output_2D_file_format.cwl' to 'file:///Users/jaganathv2/Code/WIC/cwltool/tests/output_2D_file_format.cwl'
INFO [job output_2D_file_format.cwl] Output of job will be cached in /Users/jaganathv2/Code/WIC/cwltool/tests/foo/585a1a734523fb1e13030642dc26ad4a
INFO [job output_2D_file_format.cwl] /Users/jaganathv2/Code/WIC/cwltool/tests/foo/585a1a734523fb1e13030642dc26ad4a$ true
INFO [job output_2D_file_format.cwl] completed success
{
    "output_array": [
        [
            {
                "class": "File",
                "location": "file:///Users/jaganathv2/Code/WIC/cwltool/tests/filename.txt",
                "format": "file:///Users/jaganathv2/Code/WIC/cwltool/tests/output_2D_file_format.cwl#some_format",
                "basename": "filename.txt",
                "size": 0,
                "checksum": "sha1$da39a3ee5e6b4b0d3255bfef95601890afd80709",
                "path": "/Users/jaganathv2/Code/WIC/cwltool/tests/filename.txt"
            },
            {
                "class": "File",
                "location": "file:///Users/jaganathv2/Code/WIC/cwltool/tests/filename.txt",
                "format": "file:///Users/jaganathv2/Code/WIC/cwltool/tests/output_2D_file_format.cwl#some_format",
                "basename": "filename.txt",
                "size": 0,
                "checksum": "sha1$da39a3ee5e6b4b0d3255bfef95601890afd80709",
                "path": "/Users/jaganathv2/Code/WIC/cwltool/tests/filename.txt"
            }
        ],
        [
            {
                "class": "File",
                "location": "file:///Users/jaganathv2/Code/WIC/cwltool/tests/filename.txt",
                "format": "file:///Users/jaganathv2/Code/WIC/cwltool/tests/output_2D_file_format.cwl#some_format",
                "basename": "filename.txt",
                "size": 0,
                "checksum": "sha1$da39a3ee5e6b4b0d3255bfef95601890afd80709",
                "path": "/Users/jaganathv2/Code/WIC/cwltool/tests/filename.txt"
            },
            {
                "class": "File",
                "location": "file:///Users/jaganathv2/Code/WIC/cwltool/tests/filename.txt",
                "format": "file:///Users/jaganathv2/Code/WIC/cwltool/tests/output_2D_file_format.cwl#some_format",
                "basename": "filename.txt",
                "size": 0,
                "checksum": "sha1$da39a3ee5e6b4b0d3255bfef95601890afd80709",
                "path": "/Users/jaganathv2/Code/WIC/cwltool/tests/filename.txt"
            }
        ]
    ]
}INFO Final process status is success

Copy link

codecov bot commented Jun 27, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 3 lines in your changes missing coverage. Please review.

Project coverage is 83.84%. Comparing base (71360db) to head (c73137b).

Files Patch % Lines
cwltool/command_line_tool.py 66.66% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2010      +/-   ##
==========================================
+ Coverage   82.87%   83.84%   +0.97%     
==========================================
  Files          46       46              
  Lines        8244     8251       +7     
  Branches     2190     2194       +4     
==========================================
+ Hits         6832     6918      +86     
+ Misses        909      854      -55     
+ Partials      503      479      -24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

cwltool/command_line_tool.py Outdated Show resolved Hide resolved
@vjaganat90 vjaganat90 force-pushed the fix_2dformat branch 2 times, most recently from cb3f616 to 4700f30 Compare July 2, 2024 21:00
tests/test_2D.py Outdated
def test_output_2D_file_format() -> None:
"""A simple test for format tag fix for 2D output arrays."""

Path("filename.txt").touch()
Copy link
Member

@mr-c mr-c Jul 8, 2024

Choose a reason for hiding this comment

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

That creates a file in the current working directory. If you need to create new files, please use the tmp_path Pytest fixture to get a safe directory to write into

https://github.com/common-workflow-language/cwltool/blob/main/tests/test_examples.py#L1263-L1268

tests/test_2D.py Outdated Show resolved Hide resolved
cwltool/command_line_tool.py Outdated Show resolved Hide resolved
tests/test_2D.py Outdated Show resolved Hide resolved
@mr-c
Copy link
Member

mr-c commented Jul 8, 2024

Thank you @vjaganat90 ! I've made a note to turn your example into a new conformance test for CWL: common-workflow-language/cwl-v1.3#31

@vjaganat90
Copy link
Author

@mr-c if the test passes, please have another look.

@vjaganat90 vjaganat90 force-pushed the fix_2dformat branch 3 times, most recently from 7f341eb to 72ffef0 Compare July 10, 2024 14:11
@mr-c mr-c force-pushed the fix_2dformat branch 2 times, most recently from 8b58f87 to 49a244c Compare July 10, 2024 22:22
@mr-c
Copy link
Member

mr-c commented Jul 11, 2024

Okay, the conformance test errors are due to common-workflow-language/cwltest#216

Copy link
Member

@mr-c mr-c left a comment

Choose a reason for hiding this comment

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

This looks good to me; and we should add a version of this as a CWL v1.3 conformance test. Any thoughts @tetron ?

@tetron
Copy link
Member

tetron commented Jul 11, 2024

This looks good to me; and we should add a version of this as a CWL v1.3 conformance test. Any thoughts @tetron ?

Yes, I agree, and I wonder if the spec should have say anything about this behavior as well.

@mr-c
Copy link
Member

mr-c commented Jul 12, 2024

This looks good to me; and we should add a version of this as a CWL v1.3 conformance test. Any thoughts @tetron ?

Yes, I agree, and I wonder if the spec should have say anything about this behavior as well.

Ah, yes, now that I re-read https://www.commonwl.org/v1.2/CommandLineTool.html#CommandInputParameter , it says

format
optional
string | array<string> | Expression
Only valid when type: File or is an array of items: File.

(The quoted text is the same for CWL v1.1 and v1.0)

And yet, the example from this PR is an array of arrays of Files. So maybe this behavior change has to wait for CWL version 1.3?

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.

4 participants