core.task_generator
Attributes
Classes
Class for auto-generating jobmon tasks from a python function. |
|
Directive for generating documentation for a single task generator. |
|
Directive for generating documentation for all the task generators in a module. |
Functions
|
Create a task name from the kwargs. |
|
|
|
|
Return whether the |
|
|
Return the type of collection. |
|
Return the parameters for a generic type. |
Return whether the type is a properly annotated built-in collection type. |
|
Return a list of tuples mapping collection items and their types. |
|
|
Return whether the |
|
Return the type inside an optional. |
|
Remove the |
|
|
|
Make a CLI argument string from an argument name and value. |
|
Decorator for generating jobmon tasks from a python function. |
|
Get the tasks of a TaskGenerator in a workflow that have the given node arguments. |
|
Makes a docutils node with the documentation for a task generator. |
|
Format the description of the task generator into proper rST. |
|
Format the options of the task generator into proper rST. |
|
The function that registers the extension with sphinx. |
Module Contents
- core.task_generator.create_task_name(kwargs_for_name: dict, prefix: str = '', name_func: Callable | None = None) str[source]
Create a task name from the kwargs.
- core.task_generator._is_unannotated_built_in_collection_type(obj_type: Any) bool[source]
Return whether the
obj_typeis an unannotated, built-in collection type.Ex.
listwould returnTrue,tuplewould returnTrue,list[str]would returnFalse.
- core.task_generator._get_collection_type(obj_type: Any) Type | None[source]
Return the type of collection.
To check, we extract the
__origin__component of theobj_type– this would be the type of collection (list, tuple, set).Ex.
list[int]would returnlist,tuple[str]would returntuple,floatwould returnNone(because it is not a collection).
- core.task_generator._get_generic_type_parameters(obj_type: Any) Any[source]
Return the parameters for a generic type.
The results are a tuple of types. For example, a
list[int]returns(int,), atuple[int, str], returns(int, str), and aUnion[str, None]returns(str, NoneType).
- core.task_generator._is_annotated_built_in_collection_type(obj_type: Any) bool[source]
Return whether the type is a properly annotated built-in collection type.
- core.task_generator._zip_collection_items_and_types(obj: Collection[str], collection_items_type: tuple) Any[source]
Return a list of tuples mapping collection items and their types.
Ex.
objis[1, 2, 3]andcollection_items_typeis(int,)would return[(1, int), (2, int), (3, int)].
- core.task_generator.is_optional_type(obj_type: Any) bool[source]
Return whether the
obj_typeis an Optional type.Ex.
Optional[str]would returnTrue,NoneTypewould returnTrue,str | Nonewould returnTrue,strwould returnFalse.
- core.task_generator.get_optional_type_parameter(obj_type: Type) Type[source]
Return the type inside an optional.
- core.task_generator._clean_arg_name(arg_name: str) str[source]
Remove the
--from the arg name and convert dashes to underscores.
- core.task_generator._get_short_description(task_function_docstring: docstring_parser.Docstring) str[source]
- core.task_generator.make_cli_argument_string(arg_value: str | List) str[source]
Make a CLI argument string from an argument name and value.
For string, return itself. For list, say [“a”, “b”, “c”], return string ‘[a,b,c]’
- class core.task_generator.TaskGenerator(task_function: Callable, serializers: Dict, tool_name: str, naming_args: List[str] | None = None, max_attempts: int | None = None, module_source_path: str | None = None, name_func: Callable | None = None, default_cluster_name: str = '', default_compute_resources: Dict[str, Any] | None = None, default_resource_scales: Dict[str, float] | None = None, yaml_file: str | None = None)[source]
Class for auto-generating jobmon tasks from a python function.
Arguments on the task_function are inspected to generate the task template, and type annotations are used for serializing and deserializing arguments to strings passed on the command line.
The TaskGenerator has built in serializers for:
str, int, bool, float
list, tuple, set of other serializable types
- Optional types (and types that are equivalent to Optional types) of other
serializable types
Users can also supply serializers for custom types by providing a dictionary of type to a tuple of serialization and deserialization functions. Serializers must always turn objects into a single string. Lists of strings are represented on the command line as
arg_name='[value1,value2]'.Note
While lists, tuples and sets (and their
Optionalcounterparts) can currently serialize empty collections, we can’t currently serialize custom types as empty lists.- _validate_task_function() None[source]
Check that a task can be generated from the task_function.
Currently checks: - All parameters have type annotations - All parameters have serializers
- _is_valid_annotation(annotation: Type) bool[source]
Returns True if the annotation is valid, False otherwise.
- _is_valid_type(obj: Any, expected_type: Type) bool[source]
Check that the obj type matches the expected type.
- serialize(obj: Any, expected_type: Type) str[source]
Serialize
obj, validating that it is actually of typeexpected_type.
- serialize_array(obj: Any, expected_type: Type) List[source]
Serialize obj into a list of serialized string.
- _cluster_resource_check(cluster_name: str, compute_resources: Dict | None) str[source]
Make sure a cluster name is available to use, and compute_resource is a dict.
- create_task(cluster_name: str = '', compute_resources: Dict | None = None, resource_scales: Dict[str, Any] | None = None, upstream_tasks: List[jobmon.client.task.Task] = [], task_attributes: List[str] | Dict[str, Any] = {}, **kwargs: Any) jobmon.client.task.Task[source]
Create a task for the task_function with the given kwargs.
- create_tasks(cluster_name: str = '', compute_resources: Dict | None = None, resource_scales: Dict[str, Any] | None = None, upstream_tasks: List[jobmon.client.task.Task] | None = None, **kwargs: Any) List[jobmon.client.task.Task][source]
Create a task array for the task_function with the given kwargs.
- core.task_generator.task_generator(serializers: Dict, tool_name: str, naming_args: List[str] | None = None, max_attempts: int | None = None, module_source_path: str | None = None, name_func: Callable | None = None, default_cluster_name: str = '', default_compute_resources: Dict[str, Any] | None = None, default_resource_scales: Dict[str, float] | None = None, yaml_file: str | None = None) Callable[source]
Decorator for generating jobmon tasks from a python function.
- core.task_generator.get_tasks_by_node_args(workflow: jobmon.client.workflow.Workflow, task_generator: TaskGenerator, node_args_dict: dict[str, Any], error_on_empty: bool = True) list[jobmon.client.task.Task][source]
Get the tasks of a TaskGenerator in a workflow that have the given node arguments.
This method does some value serialization and formatting before handing the node argument string over to
workflow.get_tasks_by_node_args.
- class core.task_generator.TaskGeneratorDocumenter(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]
Bases:
docutils.parsers.rst.DirectiveDirective for generating documentation for a single task generator.
- class core.task_generator.TaskGeneratorModuleDocumenter(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]
Bases:
docutils.parsers.rst.DirectiveDirective for generating documentation for all the task generators in a module.
- run() list[docutils.nodes.Node][source]
The function sphinx/docutils use to generate documentation for the directive.
- _load_module_task_generators(module_name: str, module_path: str | None = None) tuple[types.ModuleType, list[TaskGenerator]][source]
Load all the task generators in a given module.
- _generate_module_section(module_name: str, module: types.ModuleType, task_generators: Iterable[TaskGenerator]) docutils.nodes.Node[source]
Makes the docutils node for the module section.
Includes the docstring for the module, and a list of task generator names. Doesn’t include any task generator detailed documentation.
- core.task_generator._generate_nodes(task_generator: TaskGenerator, state: Any) docutils.nodes.Node[source]
Makes a docutils node with the documentation for a task generator.
Includes the docstring description for the task generator and all the arguments.
- core.task_generator._format_description(task_generator: TaskGenerator, parsed_docstring: docstring_parser.Docstring) list[str][source]
Format the description of the task generator into proper rST.
- core.task_generator._format_options(task_generator: TaskGenerator, parsed_docstring: docstring_parser.Docstring) list[str][source]
Format the options of the task generator into proper rST.