Skip to content

Examples

This section provides practical examples demonstrating Groundhog's features and common usage patterns.

Getting Started Examples

These examples cover the basics of using Groundhog:

  • Hello World - The simplest possible Groundhog script showing basic remote execution
  • Dependencies - Adding and using external packages in your remote functions
  • Running Locally - Using .local() to run functions in isolated local environments (without Globus Compute)
  • Organizing with Classes - Using @hog.method() to group related functions into classes

Common Patterns

Examples showing how to handle typical workflows:

  • Parallel Execution - Using .batch_submit() or .batch_local() for concurrent execution
  • Parameterized Harnesses - Harnesses that accept CLI arguments for runtime configuration
  • Endpoint Configuration - How the configuration system merges settings from multiple sources (PEP 723, decorators, call-time overrides)
  • PyTorch from Custom Sources - Configuring uv to install packages from cluster-specific indexes, local paths, or internal mirrors
  • Importing Groundhog Functions - Calling Groundhog functions from regular Python scripts, REPLs, and notebooks (includes import safety and mark_import_safe())

Integration Examples

Examples showing how to use Groundhog with other frameworks:

  • Academy Integration - Using Groundhog functions within Academy agents for isolated compute with dependency management

Running the Examples

All examples in this section are available in the examples directory of the Groundhog repository, and should be runnable with minimal modification (e.g. configuring your own endpoint/account etc)

To run an example:

  1. Clone the repository:

    git clone https://github.com/Garden-AI/groundhog.git
    cd groundhog/examples
    

  2. Update the endpoint configuration in the example file to match your setup

  3. Run with the hog CLI:

    hog run example_name.py
    

Kick the tires

You can also import and call functions from these examples in a Python REPL or Jupyter notebook:

import groundhog_hpc as hog
from hello_world import hello_world

result = hello_world.remote("from the REPL")