Using Julia in a task type

Julia can be used in a task type if Core.Host.Julia is installed.

For example Example.Julia.PlotXY uses Julia to create a simple plot:

The main script.py contains the boilerplate XamFlow input and output handling, and uses runutil.run() to execute a Julia script:

import xfworkerutil
import runutil
import os

worker = xfworkerutil.XFWorkerJob()

inputs = worker.job['inputs']

# Download input files
table_path = worker.download_input_file(inputs['table'])

plot_path = worker.create_related_path(table_path, '_plot.png')

# Run Julia script
runutil.run("Julia", [os.environ['JULIA_EXE'], "plot.jl", str(table_path), str(plot_path)])

# Upload output files
worker.upload_output_file(plot_path)

# Save outputs
outputs = {
    "plot": worker.create_output_bitmap(plot_path.name),
}
worker.finish(outputs)

The plot.jl script contains the Julia code:

using CSV
using DataFrames
using Plots

# Use GR Plots
gr();

# Open CSV-file
df = DataFrame(CSV.File(ARGS[1]))

# Column nr x-axis
xname = names(df)[1]
x = df[!, xname]
# Column nr y-axis
yname = names(df)[2]
y = df[!, yname]

# Regression line
scatter!(x, y, label="$xname / $yname")
bhat = [x ones(length(x))]\y
Plots.abline!(bhat..., label="Regression")

# Save plot
savefig(ARGS[2])