Function¶
The Function class wraps user functions decorated with @hog.function() to enable remote execution on HPC clusters. This class is NOT intended to be instantiated directly by users; the decorator is the preferred way to wrap functions.
Function Class¶
Function(func, endpoint=None, **user_endpoint_config)
¶
Wrapper that enables a Python function to be executed remotely on Globus Compute.
Decorated functions can be called in four ways:
- Direct call:
func(*args)- executes locally (regular python call) - Remote call:
func.remote(*args)- executes remotely and blocks until complete - Async submit:
func.submit(*args)- executes remotely and returns a GroundhogFuture - Local subprocess:
func.local(*args)- executes locally in a separate process
Attributes:
| Name | Type | Description |
|---|---|---|
endpoint |
str | None
|
Default Globus Compute endpoint UUID or named endpoint from
|
default_user_endpoint_config |
dict[str, Any]
|
Default endpoint configuration (e.g., worker_init, walltime) |
Initialize a Function wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
FunctionType
|
The Python function to wrap |
required |
endpoint
|
str | None
|
Globus Compute endpoint UUID or named endpoint from |
None
|
**user_endpoint_config
|
Any
|
Additional endpoint configuration to pass to Globus Compute Executor (e.g., worker_init commands, walltime) |
{}
|
Source code in src/groundhog_hpc/function.py
__call__(*args, **kwargs)
¶
Execute the function locally (not remotely).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments to pass to the function |
()
|
**kwargs
|
Any
|
Keyword arguments to pass to the function |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The result of the local function execution |
Source code in src/groundhog_hpc/function.py
remote(*args, endpoint=None, user_endpoint_config=None, executor_kwargs=None, **kwargs)
¶
Execute the function remotely and block until completion.
This is a convenience method that calls submit() and immediately waits for the result. While waiting, displays live status updates with task ID, elapsed time, and status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments to pass to the function |
()
|
endpoint
|
str | None
|
Globus Compute endpoint UUID (or named endpoint from
|
None
|
user_endpoint_config
|
dict[str, Any] | None
|
Endpoint configuration dict (merged with decorator default) |
None
|
executor_kwargs
|
dict[str, Any] | None
|
Keyword arguments forwarded to Globus Compute Executor |
None
|
**kwargs
|
Any
|
Keyword arguments to pass to the function |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The deserialized result of the remote function execution |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called during module import |
ValueError
|
If source file cannot be located |
PayloadTooLargeError
|
If serialized arguments exceed 10MB |
RemoteExecutionError
|
If remote execution fails (non-zero exit code) |
Source code in src/groundhog_hpc/function.py
submit(*args, endpoint=None, user_endpoint_config=None, executor_kwargs=None, **kwargs)
¶
Submit the function for asynchronous remote execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments to pass to the function |
()
|
endpoint
|
str | None
|
Globus Compute endpoint UUID (or named endpoint from
|
None
|
user_endpoint_config
|
dict[str, Any] | None
|
Endpoint configuration dict (merged with decorator default) |
None
|
executor_kwargs
|
dict[str, Any] | None
|
Keyword arguments forwarded to Globus Compute Executor |
None
|
**kwargs
|
Any
|
Keyword arguments to pass to the function |
{}
|
Returns:
| Type | Description |
|---|---|
GroundhogFuture
|
A GroundhogFuture that will contain the deserialized result |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called during module import |
ValueError
|
If endpoint is not specified and cannot be resolved from config |
PayloadTooLargeError
|
If serialized arguments exceed 10MB |
Source code in src/groundhog_hpc/function.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
local(*args, **kwargs)
¶
Execute the function locally in an isolated subprocess.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments to pass to the function |
()
|
**kwargs
|
Any
|
Keyword arguments to pass to the function |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The deserialized result of the local function execution |
Raises:
| Type | Description |
|---|---|
ModuleImportError
|
If called during module import |
ValueError
|
If source file cannot be located |
LocalExecutionError
|
If local execution fails (non-zero exit code) |
Source code in src/groundhog_hpc/function.py
batch_submit(args=None, kwargs=None, endpoint=None, user_endpoint_config=None)
¶
Submit the function for asynchronous remote execution as a batch.
Submits all tasks as a single Globus Compute batch request, avoiding per-task API calls that can hit rate limits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
list[tuple] | None
|
List of positional-argument tuples, one per task |
None
|
kwargs
|
list[dict] | None
|
List of keyword-argument dicts, one per task |
None
|
endpoint
|
str | None
|
Globus Compute endpoint UUID or named endpoint |
None
|
user_endpoint_config
|
dict[str, Any] | None
|
Endpoint configuration dict (merged with decorator default) |
None
|
Returns:
| Type | Description |
|---|---|
list[GroundhogFuture]
|
A list of GroundhogFutures in the same order as the input tasks |
Raises:
| Type | Description |
|---|---|
ModuleImportError
|
If called during module import |
ValueError
|
If both args and kwargs are empty |
Source code in src/groundhog_hpc/function.py
batch_local(args=None, kwargs=None, executor_kwargs=None)
¶
Execute the function locally in parallel subprocesses for each task.
Submits all tasks to a ThreadPoolExecutor immediately and returns futures without waiting for completion. Each task runs in its own subprocess with an isolated temporary directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
list[tuple] | None
|
List of positional-argument tuples, one per task |
None
|
kwargs
|
list[dict] | None
|
List of keyword-argument dicts, one per task |
None
|
executor_kwargs
|
dict[str, Any] | None
|
Keyword arguments forwarded to ThreadPoolExecutor |
None
|
Returns:
| Type | Description |
|---|---|
list[GroundhogFuture]
|
A list of GroundhogFutures in the same order as the input tasks |
Raises:
| Type | Description |
|---|---|
ModuleImportError
|
If called during module import |
ValueError
|
If both args and kwargs are empty |
Source code in src/groundhog_hpc/function.py
Method Class¶
The Method class is similar to Function but designed for class methods decorated with @hog.method().
Method(func, endpoint=None, **user_endpoint_config)
¶
Bases: Function
Minimal descriptor variant of Function for use as class methods.
Provides staticmethod-like semantics (no self/cls) with remote execution.