def test_draw_graph_nopydot(): from jobflow import Flow, JobOrder # test unconnected graph add_job1 = get_test_job() add_job2 = get_test_job() flow = Flow([add_job1, add_job2]) assert flow.draw_graph() # test unconnected graph, linear order add_job1 = get_test_job() add_job2 = get_test_job() flow = Flow([add_job1, add_job2], order=JobOrder.LINEAR) assert flow.draw_graph() # test connected graph, wrong order add_job1 = get_test_job() add_job2 = get_test_job() add_job1.function_args = (2, add_job2.output) flow = Flow([add_job1, add_job2]) assert flow.draw_graph() # test connected graph, linear order add_job1 = get_test_job() add_job2 = get_test_job() add_job1.function_args = (2, add_job2.output) flow = Flow([add_job1, add_job2], order=JobOrder.LINEAR) assert flow.draw_graph()
def connect_name(first_name, second_name): return f"{first_name} {second_name}" @job def print_inputs(inputs): print(inputs) def get_name_flow(): first_name = generate_first_name() second_name = generate_second_name() full_name = connect_name(first_name.output, second_name.output) return Flow([first_name, second_name, full_name], full_name.output, name="Get Name") name_flow_a = get_name_flow() name_flow_b = get_name_flow() print_job = print_inputs([name_flow_a.output, name_flow_b.output]) # create a new flow to contain the nested flow outer_flow = Flow([name_flow_a, name_flow_b, print_job]) # draw the flow graph outer_flow.draw_graph().show() # run the flow run_locally(outer_flow)
@job def encode_message(message): """Encode a message using base64.""" from base64 import b64encode return b64encode(message.encode()).decode() @job def decode_message(message): """Decode a message from base64.""" from base64 import b64decode return b64decode(message.encode()).decode() # Create two jobs, the first to encode a message and the second to decode it. encode = encode_message("Lo, a shadow of horror is risen") decode = decode_message(encode.output) # Create a flow containing the jobs. The order of the jobs doesn't matter and will be # determined by the connectivity of the jobs. flow = Flow([encode, decode]) # draw the flow graph flow.draw_graph().show() # run the flow, "output" contains the output of all jobs output = run_locally(flow) print(output)
"""A demonstration of how to enforce linear ordering of jobs.""" from jobflow import Flow, JobOrder, job @job def add(a, b): return a + b # No edges between the jobs as they do not depend on each other add_job_first = add(1, 2) add_job_second = add(4, 6) auto_flow = Flow([add_job_first, add_job_second], order=JobOrder.AUTO) auto_flow.draw_graph().show() # flow graph now shows an edge between the jobs due to the linear execution order add_job_first = add(1, 2) add_job_second = add(4, 6) linear_flow = Flow([add_job_first, add_job_second], order=JobOrder.LINEAR) linear_flow.draw_graph().show()