1. Hello World

examples/ex1.py

import sys

from cosmos.api import Cosmos, py_call


def say(text, out_file):
    with open(out_file, "w") as fp:
        fp.write(text)


def main():
    cosmos = Cosmos("cosmos.sqlite").initdb()

    workflow = cosmos.start("ex1", skip_confirm=True)

    t = workflow.add_task(
        func=say,
        params=dict(text="Hello World", out_file="out.txt"),
        uid="my_task",
        time_req=None,
        core_req=1,
        mem_req=1024,
    )

    print(("task.params", t.params))
    print(("task.input_map", t.input_map))
    print(("task.output_map", t.output_map))
    print(("task.core_req", t.core_req))
    print(("task.time_req", t.time_req))
    print(("task.drm", t.drm))
    print(("task.uid", t.uid))

    workflow.run(cmd_wrapper=py_call)

    sys.exit(0 if workflow.successful else 1)


if __name__ == "__main__":
    main()

Running the above file…

17:29 $ python ex1.py
Initializing sql database for Cosmos v2.0.11...
INFO: 2016-11-02 17:29:53: Deleting <Workflow[1] Example1>, delete_files=False
<Workflow[1] Example1> Deleting from SQL...
<Workflow[1] Example1> Deleted
INFO: 2016-11-02 17:29:53: Execution Command: ex1.py
task.params {'core_req': 2, 'text': 'Hello World', 'out_file': 'out.txt'}
task.input_map {}
task.output_map {'out_file': 'out.txt'}
task.core_req 2
task.drm local
task.uid my_task
INFO: 2016-11-02 17:29:53: Preparing to run <Workflow[1] Example1> using DRM `local`, cwd is `/Users/egafni/projects/Cosmos/examples/analysis_output/ex1`
INFO: 2016-11-02 17:29:53: <Stage[6] Say> Has not been attempted
INFO: 2016-11-02 17:29:53: Skipping 0 successful tasks...
INFO: 2016-11-02 17:29:53: Committing to SQL db...
INFO: 2016-11-02 17:29:53: Executing TaskGraph
INFO: 2016-11-02 17:29:54: <Stage[6] Say> Running (stage has 0/1 successful tasks)
INFO: 2016-11-02 17:29:54: <Task[13] Say(uid='my_task')> Submitted to the job manager. drm=local; drm_jobid=54670
INFO: 2016-11-02 17:29:54: <Task[13] Say(uid='my_task')> Finished successfully
INFO: 2016-11-02 17:29:54: <Stage[6] Say> Finished successfully (stage has 1/1 successful tasks)
INFO: 2016-11-02 17:29:54: <Workflow[1] Example1> Successfully Finished