Client
The ComputeHordeClient
class provides an interface for interacting with the ComputeHorde service,
which allows users to run jobs on decentralized, scalable compute resources.
This class includes methods for creating, managing, and retrieving jobs.
- class compute_horde_sdk.v1.ComputeHordeClient
The class used to communicate with the ComputeHorde.
- __init__(hotkey, compute_horde_validator_hotkey, job_queue=None, facilitator_url='https://facilitator.computehorde.io/')
Create a new ComputeHorde client.
- Parameters:
hotkey (Keypair) – Your wallet hotkey, used for signing requests.
compute_horde_validator_hotkey (str) – The hotkey for the validator that your jobs should go to.
job_queue (str | None) – A user-defined string value that will allow for retrieving all pending jobs, for example after process restart, relevant to this process.
facilitator_url (str) – The URL to use for the ComputeHorde Facilitator API.
- async report_cheated_job(job_uuid)
Reports to validator that a miner has cheated on a job.
- Parameters:
job_uuid (str) – The UUID of the job that was cheated on.
- Return type:
str
- async create_job(job_spec, on_trusted_miner=False)
Run a job in the ComputeHorde. This method does not retry a failed job. Use
run_until_complete()
if you want failed jobs to be automatically retried.- Parameters:
job_spec (ComputeHordeJobSpec) – Job specification to run.
on_trusted_miner (bool) – If true, the job will be run on the sn12 validator’s trusted miner.
- Returns:
A
ComputeHordeJob
class instance representing the created job.- Return type:
- async run_until_complete(job_spec, on_trusted_miner=False, job_attempt_callback=None, timeout=None, max_attempts=3)
Run a job in the ComputeHorde until it is successful. It will call
create_job()
repeatedly until the job is successful.- Parameters:
job_spec (ComputeHordeJobSpec) – Job specification to run.
on_trusted_miner (bool) – If true, the job will be run on the sn12 validator’s trusted miner.
job_attempt_callback (Callable[[ComputeHordeJob], None] | Callable[[ComputeHordeJob], Awaitable[None]] | Callable[[ComputeHordeJob], Coroutine[Any, Any, None]] | None) – A callback function that will be called after every attempt of running the job. The callback will be called immediately after an attempt is made run the job, before waiting for the job to complete. The function must take one argument of type ComputeHordeJob. It can be a regular or an async function.
timeout (float | None) – Maximum number of seconds to wait for.
max_attempts (int) – Maximum number times the job will be attempted to run within
timeout
seconds. Negative or0
means unlimited attempts.
- Returns:
A
ComputeHordeJob
class instance representing the created job. If the job was rerun, it will represent the last attempt.- Return type:
- async get_job(job_uuid)
Retrieve information about a job from the ComputeHorde.
- Parameters:
job_uuid (str) – The UUID of the job to retrieve.
- Returns:
A
ComputeHordeJob
instance representing this job.- Raises:
ComputeHordeNotFoundError – If the job with this UUID does not exist.
- Return type:
- async get_jobs(page=1, page_size=10)
Retrieve information about your jobs from the ComputeHorde.
- Parameters:
page (int) – The page number.
page_size (int) – The page size.
- Returns:
A list of
ComputeHordeJob
instances representing your jobs.- Raises:
ComputeHordeNotFoundError – If the requested page does not exist.
- Return type:
list[ComputeHordeJob]
- async iter_jobs()
Retrieve information about your jobs from the ComputeHorde.
- Returns:
An async iterator of
ComputeHordeJob
instances representing your jobs.- Return type:
AsyncIterator[ComputeHordeJob]
Usage:
async for job in client.iter_jobs(): process(job)