Skip to content

Provenance Support for cwltool - Single Job Executor - #676

Merged
mr-c merged 338 commits into
masterfrom
provenance
Jul 3, 2018
Merged

mr-c merged 338 commits into
masterfrom
provenance

Conversation

@FarahZKhan

@FarahZKhan FarahZKhan commented Feb 26, 2018 •

Copy link
Copy Markdown
Member
  • make diff_pylint_report is clean
  • Test with toil-cwl-runner, does this break anything?
  • move extra Python dependencies to an extra, add code to remind the user to install them if --provenance is called
  • @mr-c to review type hints
  • remove use of hasattr
  • add raw logs

Comment thread setup.py Outdated
'schema-salad >= 2.6.20170927145003, < 3',
'typing >= 3.5.3',
'six >= 1.8.0',
'prov == 1.5.1'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

needs a trailing comma

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks, Added in new commit.

Comment thread tests/wf/test-prov/model_provRun.py Outdated
@@ -0,0 +1,46 @@

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the directory tests/wf/test-prov should be removed from this PR. You can keep it on another branch for your personal use, if you wish

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks, done just now.

Comment thread cwltool/provenance.py Outdated
pos = nx.nx_agraph.graphviz_layout(provgraph)
nx.draw(provgraph, pos=pos)
write_dot(provgraph, provDot)
check_call(['dot','-Tpng',provDot,'-o',original_path+'/ProvenanceVisualGraph.png'])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mind if I make the graphviz dependency optional? I can make a PR to this PR and you can review it

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We removed this code as it was tricky to get transitive dependencies of nx installed.

Comment thread tests/wf/whale.txt Outdated
@@ -1,3 +1,6 @@
<<<<<<< HEAD
This is whale file for testing revsort.cwl workflow
=======

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

??

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

whale.txt was restored.

Comment thread tests/wf/revsort.cwl Outdated
default:
class: File
location: hello.txt
location: hello.txt

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think it was for the testing purpose, Wanted to see if the workflow paths still work if default is not given.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Okay, you should undo the change.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed in 61797e0

Comment thread output.txt Outdated
@@ -0,0 +1 @@
elif tset elahw si siht

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Probably should be removed from this PR

Comment thread cwltool/job.py Outdated
pass


# type: (bool, bool, bool, Text, **Any) -> None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the line above needs to be removed, or put where it belongs.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

@mr-c mr-c self-assigned this Feb 26, 2018
Comment thread cwltool/workflow.py Outdated
from schema_salad.sourceline import SourceLine, cmap

from .provenance import *
from . import draft2tool, expression

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

replace draft2tool with command_line_tool

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

Comment thread cwltool/job.py Outdated

def _execute(self, runtime, env, rm_tmpdir=True, move_outputs="move"):
def _execute(self, runtime, env, kwargs, document=None, WorkflowRunID=None, ProcessProvActivity=None,reference_locations=None, rm_tmpdir=True, move_outputs="move"):
# type: (List[Text], MutableMapping[Text, Text], bool, Text) -> None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You need to update the type signature to match the changes you made

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

Comment thread cwltool/job.py Outdated
rm_tmpdir=True, move_outputs="move", **kwargs):
def run(self, document=None, WorkflowRunID=None, ProcessProvActivity=None,reference_locations=None, pull_image=True, rm_container=True,
rm_tmpdir=True, move_outputs="move", **kwargs):
# type: (bool, bool, bool, Text, **Any) -> None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

likewise for this type signature as well

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

Comment thread setup.py Outdated
'prov == 1.5.1',
'pathlib == 1.0.1',
'graphviz == 0.8.2',
'uuid == 1.30',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hmm.. this library might not be Python 3 compatible ..

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is a backport of the functionality within the Python 2.5+ standard library, so remove uuid from setup.py and requirements.txt and I bet many more of the tests will pass

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Can we still use it even if removed from setup.py and requirement.txt?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, uuid is part of the Python Standard Library from Python 2.5 and onwards: https://docs.python.org/2/library/uuid.html

Comment thread setup.py
'schema-salad >= 2.6.20170927145003, < 3',
'typing >= 3.5.3',
'six >= 1.8.0',
'prov == 1.5.1',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does prov 1.5.0 work as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It does but there is a bug with datetime() and that might sometimes not record the start and end time of the activity and many more time instances used in quite a few properties.
In addition, if you want to make changes to prov serialization later to have a bundle instead of just one prov file (for example in case of sub-workflows), then prov 1.5.1 is better.

Comment thread setup.py Outdated
'typing >= 3.5.3',
'six >= 1.8.0',
'prov == 1.5.1',
'pathlib == 1.0.1',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

resolved

Comment thread setup.py Outdated
'prov == 1.5.1',
'pathlib == 1.0.1',
'graphviz == 0.8.2',
'pygraphviz == 1.3.1',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are both needed? Only graphviz seems to be used

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

removed pygraphviz

Comment thread setup.py Outdated
'pathlib == 1.0.1',
'graphviz == 0.8.2',
'pygraphviz == 1.3.1',
'Matplotlib == 2.1.2',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This appears to be unused, can it be removed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removed

Comment thread setup.py Outdated
'graphviz == 0.8.2',
'pygraphviz == 1.3.1',
'Matplotlib == 2.1.2',
'pydot == 1.2.4'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Likewise pydot doesn't appear to be used either.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removed

Comment thread setup.py Outdated
'six >= 1.8.0',
'prov == 1.5.1',
'pathlib == 1.0.1',
'graphviz == 0.8.2',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Like other modules, I tried updating this one too to use 0.8.1 instead but the workflow would not run if the version is changed. I am unsure about the underlying reason but can explore further.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Also tried with 0.8 but same results.

Comment thread cwltool/provenance.py Outdated
# This makes later close() a no-op
self.folder = None

def create_ro(tmpPrefix):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Needs a type specification

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Now

def create_researchObject(tmpPrefix  # type: str
             ):

Comment thread cwltool/main.py Outdated
return json.dumps(packed["$graph"][0], indent=4)


def generate_provDoc():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Needs a type specification

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

Comment thread cwltool/executors.py Outdated
if r.outdir:
self.output_dirs.add(r.outdir)
r.run(**kwargs)
if ro:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would suggest creating a separate subclass of JobExecutor here to keep the API simpler and cleaner since the number of changes and if clauses for a single feature is large enough.

Comment thread cwltool/main.py Outdated
document = ProvDocument()
engineUUID=""
activity_workflowRun={} # type: Dict[Text, Any]
defaultStreamHandler = logging.StreamHandler()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Consider reusing defaultStreamHandler from loghandler module

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Apparently I did not need it :). Thanks for indicating. removed in new commits.

Comment thread cwltool/workflow.py Outdated
from ruamel.yaml.comments import CommentedMap, CommentedSeq
from schema_salad.sourceline import SourceLine, cmap

from .provenance import *

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Consider removing this import

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

Comment thread cwltool/provenance.py Outdated
# See ./cwltool/schemas/v1.0/Process.yml
hashmethod = hashlib.sha1

class RO():

@anton-khodak anton-khodak Feb 28, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would suggest using longer names ResearchObject or research_obj instead of RO() and ro everywhere outside the module so they are more meaningful to unfamiliar code users.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks @anton-khodak for the feedback. Definitely makes sense. I'd make the required changes.

Comment thread cwltool/job.py Outdated

if processStatus != "success":
_logger.warning(u"[job %s] completed %s", self.name, processStatus)
if research_obj:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Consider taking the inner blocks if research_obj: out of the if status != success: block to avoid code duplication.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks @psafont, good point. the new commit has resolved this.

@ghost

ghost commented Jun 28, 2018

Copy link
Copy Markdown

The merged version does not write out the primary-job.json in the workflow directory as mentioned in the paper. Thanks!

@mr-c

mr-c commented Jul 1, 2018 •

Copy link
Copy Markdown
Member

I ran this PR against the CWL conformance tests using

for n in $(seq 1 132); do ./run_test.sh RUNNER=cwltool -n${n} EXTRA="--provenance test_${n}"; done

Many tests passed; there are three types of problems so far

Test failed: /home/michael/cwltool/env3/bin/cwltool --provenance test_14 --outdir=/tmp/tmpkkshqorq --quiet v1.0/null-expression1-tool.cwl v1.0/empty.json
Test default usage of Any in expressions.
Returned non-zero
Got workflow error
Traceback (most recent call last):
  File "/home/michael/cwltool/cwltool/executors.py", line 149, in run_jobs
    runtimeContext.make_fs_access, runtimeContext)
  File "/home/michael/cwltool/cwltool/provenance.py", line 409, in _evaluate
    process_name = urllib.parse.quote(str(job.name), safe=":/,#")
AttributeError: 'ExpressionJob' object has no attribute 'name'
Workflow error, try again with --debug for more information:
'ExpressionJob' object has no attribute 'name'
--- Running conformance test v1.0 on /home/michael/cwltool/env3/bin/cwltool ---
/home/michael/cwltool/env3/bin/cwltool 1.0.20180701175226
Test [20/132] 
Test failed: /home/michael/cwltool/env3/bin/cwltool --provenance test_20 --outdir=/tmp/tmpdplet4yj --quiet v1.0/any-type-compat.cwl v1.0/any-type-job.json
Testing Any type compatibility in outputSource
Returned non-zero
I'm sorry, I couldn't load this CWL file, try again with --debug for more information.
The error was: An identifier is missing. All PROV elements require a valid identifier.
--- Running conformance test v1.0 on /home/michael/cwltool/env3/bin/cwltool ---
/home/michael/cwltool/env3/bin/cwltool 1.0.20180701175226
Test [85/132] 
Test failed: /home/michael/cwltool/env3/bin/cwltool --provenance test_85 --outdir=/tmp/tmp0ht0pjbd --quiet v1.0/dir2.cwl v1.0/dir-job.yml
Test directory input in Docker
Returned non-zero
Got workflow error
Traceback (most recent call last):
  File "/home/michael/cwltool/cwltool/executors.py", line 154, in run_jobs
    job.run(runtimeContext)
  File "/home/michael/cwltool/cwltool/job.py", line 483, in run
    self._execute(runtime, env, runtimeContext)
  File "/home/michael/cwltool/cwltool/job.py", line 231, in _execute
    runtimeContext.reference_locations, str(self.name))
  File "/home/michael/cwltool/cwltool/provenance.py", line 493, in used_artefacts
    with fsaccess.open(location, "rb") as fhandle:
  File "/home/michael/cwltool/cwltool/stdfsaccess.py", line 49, in open
    return open(self._abs(fn), mode)
IsADirectoryError: [Errno 21] Is a directory: '/home/michael/common-workflow-language/v1.0/v1.0/testdir'
Workflow error, try again with --debug for more information:
[Errno 21] Is a directory: '/home/michael/common-workflow-language/v1.0/v1.0/testdir'

@mr-c
mr-c merged commit 2ba677a into master Jul 3, 2018
@mr-c
mr-c deleted the provenance branch July 3, 2018 03:49
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.

7 participants