Run a job

This example shows how to create a job, start it, and monitor it until it completes.

Once the job is complete, you can download its outputs locally or to whatever host you're on.

from pathlib import Path
from pyro_dash_py import PyroDash
from pyro_dash_py.core import PyroJobStatusTypes
import os
import time

apikey = os.environ.get("PYRO_API_KEY")
if apikey is None:
    raise SystemError("PYRO_API_KEY missing!")

# initialize comms with the pyro-dashboard api
pyro = PyroDash(
    host="https://dev-api.dashboard.pyrologix.com",
    email="jack.campanella@pyrologix.com",
    apikey=apikey,
)

job = pyro.jobs.create("fsim")
job.set_name("small fsim test")
print(f"created job: {job.name} ({job.id})")

print("adding files")
job.add_file("/Users/jack/data/fsim_pipeline_test/small/lcp.tif")
job.add_file("/Users/jack/data/fsim_pipeline_test/small/adj.adj")
job.add_file("/Users/jack/data/fsim_pipeline_test/small/idg.tif")
job.add_file("/Users/jack/data/fsim_pipeline_test/small/fms80.fms")
job.add_file("/Users/jack/data/fsim_pipeline_test/small/fms90.fms")
job.add_file("/Users/jack/data/fsim_pipeline_test/small/fms97.fms")
job.add_file("/Users/jack/data/fsim_pipeline_test/small/fdist.fdist")
job.add_file("/Users/jack/data/fsim_pipeline_test/small/frisk.frisk")

# recommended to preview a job before you start it
# the system can automatically detect issues such as
# missing inputs, corrupt configurations, etc.
preview = job.preview()
[print("File Validation Issue: ", issue) for issue in preview.file_validation.issues]
[print("Confg Issue: ", issue) for issue in preview.validation.issues]

job.start()
status = job.get_status()
print("started job, proceeding to monitor")

# keep in mind, you don't need to monitor it like this, you could just
# start it, grab some tea, come back and if you're lucky it might be
# done running!
while status not in [PyroJobStatusTypes.FAILED, PyroJobStatusTypes.COMPLETED]:
    time.sleep(5)
    status = job.get_status()
    print("job status: ", status)


# if you're curious, check out how long it ran
# and what the cost was
duration = job.duration()
print("Job Started: ", duration.start)
print("Job Finished: ", duration.end)
print("Total Runtime: ", duration.runtime)

cost = job.cost()
print("Total cents", cost.total_cents)
print("Total billable compute time: ", cost.total_compute_time_millis)

# From here, you could download these outputs
outdir = Path("/Users/jack/data/fsim_pipeline_test/small/out")
outdir.mkdir(exist_ok=True)
for output in job.list_outputs():
    print("Output:", output.display_name)
    print("downloading:", outdir / output.display_name)
    output.download(outdir / output.display_name)