Decorators¶
Groundhog provides three decorators:
@hog.function()- For remote-executable functions@hog.method()- For remote-executable class methods@hog.harness()- For local orchestrator functions
@hog.function()¶
function(endpoint=None, **user_endpoint_config)
¶
Decorator to mark a function for remote execution on Globus Compute.
Decorated functions can be:
- Called locally:
func(args) - Called remotely (blocking):
func.remote(args) - Submitted asynchronously:
func.submit(args) - Called locally in an isolated environment:
func.local(args)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str | None
|
Globus Compute endpoint UUID or named endpoint from
|
None
|
**user_endpoint_config
|
Any
|
Options to pass through to the Executor as user_endpoint_config (e.g. account, partition, walltime, etc) |
{}
|
Returns:
| Type | Description |
|---|---|
Callable[[FunctionType], Function]
|
A decorator function that wraps the function as a Function instance |
Example
Source code in src/groundhog_hpc/decorators.py
@hog.method()¶
method(endpoint=None, **user_endpoint_config)
¶
Decorator to mark a class method for remote execution on Globus Compute.
Analogous to @hog.function() but for use with class methods. Provides
staticmethod-like semantics - the decorated method does not receive self or cls.
Decorated methods can be:
- Called locally:
MyClass.method(args)orobj.method(args) - Called remotely (blocking):
MyClass.method.remote(args) - Submitted asynchronously:
MyClass.method.submit(args) - Called locally in an isolated environment:
MyClass.method.local(args)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str | None
|
Globus Compute endpoint UUID |
None
|
**user_endpoint_config
|
Any
|
Options to pass through to the Executor as user_endpoint_config (e.g. account, partition, walltime, etc) |
{}
|
Returns:
| Type | Description |
|---|---|
Callable[[FunctionType], Method]
|
A decorator function that wraps the function as a Method instance |
Example
Source code in src/groundhog_hpc/decorators.py
@hog.harness()¶
harness()
¶
Decorator to mark a function as a local orchestrator harness.
Harness functions are entry points that coordinate remote function calls. They run locally and can accept parameters passed as CLI arguments.
Harness functions:
- Are invoked via the CLI:
hog run script.py [harness_name] - Can accept parameters, which map to CLI arguments
- Can call
.remote()or.submit()on@hog.function-decorated functions
Returns:
| Type | Description |
|---|---|
Callable[[FunctionType], Harness]
|
A decorator function that wraps the harness |
Example
Zero-argument harness:
Parameterized harness:
@hog.harness()
def train(dataset: str, epochs: int = 10):
result = train_model.remote(dataset, epochs)
return result
Run with: hog run script.py train -- my_data --epochs=20