Task Execution & Management

Tasks run asynchronously by default, allowing you to submit simulations and continue working without blocking your code. This design enables efficient batch processing, parallel execution across multiple resources, and resilient handling of long-running computations.

Core Concepts

Asynchronous Execution

When you submit a task by doing simulator.run(), it immediately returns a Task object while the simulation runs in the background. This allows you to:

  • Submit multiple simulations in parallel
  • Continue local work while computations run remotely
  • Handle task completion at your own pace
  • Maintain fault tolerance for long-running jobs

Task Lifecycle

Each task progresses through several main states:

StatusDescriptionNext States
pending-inputTask is waiting for input filesin-queue
in-queueTask is queued in machine waiting for it to become availablesubmitted
submittedTask is queued and waiting for resourcesstarted, failed
startedTask is actively running on compute resourcessuccess, failed
successTask finished successfully-
failedTask encountered an error-
killedTask was manually terminated-

For complete Task Lifecycle documentation, see our Task Lifecycle guide

Execution Control

Blocking Execution with wait()

Convert asynchronous tasks into blocking operations by using the wait method. This method will block the call, forcing your script to wait until the task reaches a terminal status to continue its execution.

This is particularly useful when you want to wait for the completion of a task before proceeding with some other operation (e.g., downloading the output files):

# Submit task (non-blocking)
task = simulator.run(input_dir="config/", on=machine_group)

# Block the call until the simulation completes
task.wait()  # <- The remote simulation WILL NOT DIE if the local session is
             #    interrupted while waiting for the wait() call to return

# Now safe to download results
task.download_outputs()

Note: The wait() method is resilient to local interruptions. Your remote simulation will continue running even if your Python script is terminated.

Parallel Execution Workflow

Leverage asynchronous execution to run multiple simulations simultaneously:

import inductiva

# Initialize resources
machine_group = inductiva.resources.MachineGroup("c2-standard-4")
machine_group.start()
simulator = inductiva.simulators.SplishSplash()

# Submit batch of tasks
tasks = []
configs = ["wind_10ms", "wind_15ms", "wind_20ms", "wind_25ms"]

for config in configs:
    task = simulator.run(
        input_dir=f"scenarios/{config}",
        on=machine_group
    )
    tasks.append(task)
    print(f"✓ Submitted {config}: {task.id}")

print(f"Submitted {len(tasks)} tasks in parallel")

# Process results as they complete
for i, task in enumerate(tasks):
    print(f"⏳ Waiting for task {i+1}/{len(tasks)}...")
    task.wait()
    
    if task.status == "success":
        print(f"✅ {configs[i]} completed successfully")
        task.download_outputs(f"results/{configs[i]}")
    else:
        print(f"❌ {configs[i]} failed: {task.status}")

machine_group.terminate()

Task Management

The Python Client provides several methods for managing tasks.

MethodDescriptionExample
inductiva.tasks.get_all()Fetch all tasksinductiva.tasks.get_all(project="fluid-dynamics")
inductiva.tasks.get_tasks()Retrieve N most recent tasks with optional filteringinductiva.tasks.get_tasks(last_n=5, status="started")
task.wait()Block until task reaches terminal statetask.wait()
task.kill()Terminate a running or queued tasktask.kill()
task.get_info()Fetch detailed task informationtask.get_info()
task.get_position_in_queue()Check queue position for pending taskstask.get_position_in_queue()
task.download_outputs()Download simulation resultstask.download_outputs("./results")

Inductiva also provides CLI methods for managing your tasks.

CommandDescriptionExample
inductiva tasks listList all tasks with status and detailsinductiva tasks list -n 4
inductiva tasks infoGet detailed information about a taskinductiva tasks info <task-id>
inductiva tasks downloadDownload task outputs to a local machineinductiva tasks download <task-id>
inductiva tasks killTerminate a running or queued taskinductiva tasks kill <task-id>
inductiva tasks list-filesShow current files of a running taskinductiva tasks list-files --id <task-id>
inductiva tasks tailDisplay last lines of task outputinductiva tasks tail --id <task-id> -L 50
inductiva tasks topShow system processes on the task machineinductiva tasks top <task-id>
inductiva tasks last-modified-fileShow the most recently modified fileinductiva tasks last-modified-file <task-id>
inductiva logsStream task logs in real-timeinductiva logs <task-id>