> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-sdk-testing-latest.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# LaunchAgent

<Card title="ソースコードを表示" href="https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L164-L924" icon="github" />

指定された run キューをポーリングし、wandb launch 用に run を起動する Launch エージェント クラス。

```python theme={null}
LaunchAgent(
    api: Api,
    config: Dict[str, Any]
)
```

| 引数       | 説明                               |
| :------- | :------------------------------- |
| `api`    | バックエンドへのリクエスト送信に使用する API オブジェクト。 |
| `config` | エージェントの設定 dict。                  |

| 属性                       | 説明                                 |
| :----------------------- | :--------------------------------- |
| `num_running_jobs`       | スケジューラを含まないジョブ数を返します。              |
| `num_running_schedulers` | スケジューラ数のみを返します。                    |
| `thread_ids`             | エージェントで実行中のスレッド ID を表すキーのリストを返します。 |

<div id="methods">
  ## Methods
</div>

<div id="check_sweep_state">
  ### `check_sweep_state`
</div>

[ソースを表示](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L786-L803)

```python theme={null}
check_sweep_state(
    launch_spec, api
)
```

run を起動する前に、その sweep の状態を確認します。

<div id="fail_run_queue_item">
  ### `fail_run_queue_item`
</div>

[ソースを表示](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L295-L304)

```python theme={null}
fail_run_queue_item(
    run_queue_item_id, message, phase, files=None
)
```

<div id="finish_thread_id">
  ### `finish_thread_id`
</div>

[ソースを表示](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L416-L509)

```python theme={null}
finish_thread_id(
    thread_id, exception=None
)
```

ひとまず、リストからジョブを削除します。

<div id="get_job_and_queue">
  ### `get_job_and_queue`
</div>

[ソースを表示](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L908-L915)

```python theme={null}
get_job_and_queue()
```

<div id="initialized">
  ### `initialized`
</div>

[ソースを表示](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L190-L193)

```python theme={null}
@classmethod
initialized() -> bool
```

エージェント が初期化済みかどうかを返します。

<div id="loop">
  ### `loop`
</div>

[ソースを表示](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L572-L653)

```python theme={null}
loop()
```

ジョブをポーリングして実行し続けるため、無限にループします。

| Raises              | 説明                 |
| :------------------ | :----------------- |
| `KeyboardInterrupt` | エージェントに停止要求があった場合。 |

<div id="name">
  ### `name`
</div>

[ソースを表示](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L180-L188)

```python theme={null}
@classmethod
name() -> str
```

エージェント の名を返します。

<div id="pop_from_queue">
  ### `pop_from_queue`
</div>

[ソースを表示](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L340-L363)

```python theme={null}
pop_from_queue(
    queue
)
```

runqueue から項目を取り出し、ジョブとして実行します。

| 引数      | 説明         |
| :------ | :--------- |
| `queue` | 取り出し元のキュー。 |

| 戻り値            | 説明 |
| :------------- | :- |
| キューから取り出された項目。 |    |

| 発生する例外      | 説明                      |
| :---------- | :---------------------- |
| `Exception` | キューからの取り出し時にエラーが発生した場合。 |

<div id="print_status">
  ### `print_status`
</div>

[ソースを表示](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L365-L381)

```python theme={null}
print_status() -> None
```

エージェントの現在のステータスを出力します。

<div id="run_job">
  ### `run_job`
</div>

[ソースを表示](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L511-L541)

```python theme={null}
run_job(
    job, queue, file_saver
)
```

プロジェクトを設定して、ジョブを実行します。

| 引数    | 説明       |
| :---- | :------- |
| `job` | 実行するジョブ。 |

<div id="task_run_job">
  ### `task_run_job`
</div>

[ソースを表示](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L656-L688)

```python theme={null}
task_run_job(
    launch_spec, job, default_config, api, job_tracker
)
```

<div id="update_status">
  ### `update_status`
</div>

[ソースを表示](https://www.github.com/wandb/wandb/tree/v0.20.1/wandb/sdk/launch/agent/agent.py#L383-L394)

```python theme={null}
update_status(
    status
)
```

エージェントのステータスを更新します。

| 引数       | 説明                |
| :------- | :---------------- |
| `status` | エージェントに設定するステータス。 |
