Methods to interact with the tasks submitted to the API.
Get the last N tasks of a user.
This function fetches info about the last N tasks (with respect to submission time) of a user to stdout, sorted by submission time with the most recent first. A status can be specified to filter to get only tasks with that status, in which case the last N tasks with that status will be listed. The number of tasks can be less than N if the aren’t enough tasks that match the specified criteria.
Similar to the inductiva.task.list() function, but instead of printing to stdout, returns a list of Task objects which can be used to perform further operations on those tasks (e.g., download outputs, kill unfinished tasks, etc.).
Example usage:
: # get the last 5 tasks that haven’t started yet and kill them
tasks = inductiva.tasks.get(5, status=”submitted”)
for task in tasks:
task.kill()
Get all tasks of a user.
This function fetches all tasks of a user, sorted by submission time with the most recent first. If status is specified, only tasks with that status will be fetched. status: The status of the tasks to get. If None, tasks with any status
will be returned.
Get the last N submitted tasks.
Get the last N submitted tasks, eventually filtered by status. By default, only the last 10 submitted tasks are returned, irrespectively of their status.
Converts an Iterable of tasks to a dictionary with all the relevant information for all the tasks.
Args: : list_of_tasks: An Iterable of tasks.
Returns: : A dictionary with all the relevant information for all the tasks. Example: { “ID”: 1, 2, 3, “Simulator”: “reef3d”, “reef3d”, “reef3d”, … }
Manage running/completed tasks on the Inductiva API.
Bases: object
Represents a running/completed task on the Inductiva API.
Example usage:
task = simulator.run(...)
task.wait()
info = task.get_info() # dictionary with info about the task
task.download_outputs(
filenames=["file1.txt", "file2.dat"] # download only these files
)
Initialize the instance from a task ID.
Close the stream to the task.
Download input files of the task.
Download output files of the task.
Get the time the computation of the task took to complete.
Get a dictionary with information about the task.
Information includes e.g., “task_id”, “status”, timestamps (“create_time”, “input_submit_time, “start_time”, “end_time”), among others.
This method issues a request to the API.
Get a public URL to download the input files of the task.
Get the machine type used in the task.
Streamlines the process of obtaining the task info, extracting the machine type from the comprehensive task info.
Get the metadata associated with the task.
Get information about the output files of the task.
Get a public URL to download the output files of the task.
Get the position of the task in the queue.
This method issues a request to the API.
Get status of the task.
This method issues a request to the API and updates the task info is_terminal. The api call to get the status now returns the status and is_terminated.
Get the path to this task’s directory in the user’s remote storage.
Get the total time the task workflow took to complete.
Get information about the task.
It contains cached information about the task from the latest call to get_info, therefore it can be outdated.
Validate if the task has failed.
This method issues a request to the API.
Validate if the task is running.
This method issues a request to the API.
Check if the task is in a terminal status.
This method issues a request to the API.
Request a task to be killed.
This method requests that the current task is remotely killed.
If wait_timeout is None (default), the kill request is sent to the
backend and the method returns. However, if wait_timeout is
a positive number, the method waits up to wait_timeout seconds
to ensure that the task transitions to the KILLED state.
wait_timeout: Optional - number of seconds to wait
Display the last modified file for a given task.
This function retrieves and prints information about the most recently modified file associated with a specified task. It validates that the task computation has started before proceeding. If the task is invalid or not started, an error message is printed to stderr.
List the files in the task’s working directory.
This method will list the files, in real time, in the task’s working directory. It will also print the files in a tree-like structure.
Removes all files associated with the task from remote storage.
Set metadata for the task.
Metadata is stored as key-value pairs, where both keys and values must be strings. Metadata can be useful for categorizing, searching, and filtering tasks.
Example usage:
task = simulator.run(…)
Add experiment information to the task
task.set_metadata({
“study”: “study_1”, “experiment”: “experiment_1”, “description”: “This is a test experiment”, “parameters”: “param1=1,param2=2”,
})
It returns cached information about the task summary.
Enter context manager for blocking sync execution.
This turns an asynchronous task into a blocking task. If an exception/ctrl+c is caught while in the context manager, the remote task is killed.
Usage:
: task = scenario.simulate(…)
with task.sync_context():
: # If an exception happens here or ctrl+c is pressed, the task
# will be killed.
task.wait()
Prints the result of tailing a list of files.
Wait for the task to complete.
This method issues requests to the API.
Wait for the task to reach a specific status or complete.
This method issues requests to the API.