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

# Run

export const GitHubLink = ({url}) => <a href={url} target="_blank" rel="noopener noreferrer" className="github-source-link">
    <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
      <path d="M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z" />
    </svg>
    GitHub source
  </a>;

<GitHubLink url="https://github.com/wandb/wandb/blob/main/wandb/apis/public/runs.py" />

## <kbd>class</kbd> `Run`

Entity および Project に関連付けられた単一の Run です。

### <kbd>method</kbd> `Run.__init__`

```python theme={null}
__init__(
    client: 'RetryingClient',
    entity: 'str',
    project: 'str',
    run_id: 'str',
    attrs: 'Mapping | None' = None,
    include_sweeps: 'bool' = True,
    lazy: 'bool' = True,
    api: 'public.Api | None' = None
)
```

**引数:**

* `client`: W\&B API クライアント。
* `entity`: Run に関連付けられた Entity。
* `project`: Run に関連付けられた Project。
* `run_id`: Run の一意識別子。
* `attrs`: Run の属性。
* `include_sweeps`: Run に Sweeps を含めるかどうか。

**Attributes:**

* `tags` (\[str]): Run に関連付けられたタグのリスト
* `url` (str): この Run の URL
* `id` (str): Run の一意識別子（デフォルトは8文字）
* `name` (str): Run の名前
* `state` (str): 状態。running, finished, crashed, killed, preempting, preempted のいずれか
* `config` (dict): Run に関連付けられたハイパーパラメーターの辞書
* `created_at` (str): Run が開始されたときの ISO タイムスタンプ
* `system_metrics` (dict): Run に対して記録された最新のシステムメトリクス
* `summary` (dict): 現在のサマリーを保持する、変更可能な辞書形式のプロパティ。update を呼び出すと変更が保存されます。
* `project` (str): Run に関連付けられた Project
* `entity` (str): Run に関連付けられた Entity の名前
* `project_internal_id` (int): Project の内部 ID
* `user` (str): Run を作成した User の名前
* `path` (str): 一意識別子 \[entity]/\[project]/\[run\_id]
* `notes` (str): Run に関するノート
* `read_only` (boolean): Run が編集可能かどうか
* `history_keys` (str): `wandb.Run.log({"key": "value"})` でログ記録された履歴メトリクスキー
* `metadata` (str): wandb-metadata.json からの Run に関するメタデータ

Run オブジェクトを初期化します。

Run は常に、wandb.Api のインスタンスである api から api.runs() を呼び出すことによって初期化されます。

***

### <kbd>property</kbd> Run.config

Run の config を取得します。レイジーモード（lazy mode）の場合は、自動的に全データをロードします。

**戻り値:**

* `dict[str, Any]`: config プロパティの値。

***

### <kbd>property</kbd> Run.entity

Run に関連付けられた Entity。

**戻り値:**

* `str`: entity プロパティの値。

***

### <kbd>property</kbd> Run.id

Run の一意識別子。

**戻り値:**

* `str`: id プロパティの値。

***

### <kbd>property</kbd> Run.lastHistoryStep

Run の履歴に記録された最後のステップを返します。

**戻り値:**

* `int`: lastHistoryStep プロパティの値。

***

### <kbd>property</kbd> Run.metadata

wandb-metadata.json から取得した Run に関するメタデータ。

メタデータには、Run の説明、タグ、開始時間、メモリ使用量などが含まれます。

**戻り値:**

* `dict[str, Any] | None`: metadata プロパティの値。

***

### <kbd>property</kbd> Run.name

Run の名前。

**戻り値:**

* `str | None`: name プロパティの値。

***

### <kbd>property</kbd> Run.path

Run のパス。パスは entity、project、run\_id を含むリストです。

**戻り値:**

* `list[str]`: path プロパティの値。

***

### <kbd>property</kbd> Run.rawconfig

内部キーを含む生の Run config を取得します。レイジーモードの場合は、自動的に全データをロードします。

**戻り値:**

* `dict[str, Any]`: rawconfig プロパティの値。

***

### <kbd>property</kbd> Run.state

Run の状態。Finished, Failed, Crashed, Running のいずれかになります。

**戻り値:**

* `str`: state プロパティの値。

***

### <kbd>property</kbd> Run.storage\_id

Run の一意のストレージ識別子。

**戻り値:**

* `str`: storage\_id プロパティの値。

***

### <kbd>property</kbd> Run.summary

Run のサマリーメトリクスを取得します。レイジーモードの場合は、自動的に全データをロードします。

**戻り値:**

* `HTTPSummary`: summary プロパティの値。

***

### <kbd>property</kbd> Run.summary\_metrics

Run のサマリーメトリクスを取得します。レイジーモードの場合は、自動的に全データをロードします。

**戻り値:**

* `dict[str, Any]`: summary\_metrics プロパティの値。

***

### <kbd>property</kbd> Run.sweep\_name

Sweep 名を取得します。sweepName は軽量なフラグメントに含まれているため、常に利用可能です。

**戻り値:**

* `str | None`: sweep\_name プロパティの値。

***

### <kbd>property</kbd> Run.system\_metrics

Run のシステムメトリクスを取得します。レイジーモードの場合は、自動的に全データをロードします。

**戻り値:**

* `dict[str, Any]`: system\_metrics プロパティの値。

***

### <kbd>property</kbd> Run.url

Run の URL。

Run の URL は、entity、project、run\_id から生成されます。SaaS ユーザーの場合、`https://wandb.ai/entity/project/run_id` という形式になります。

**戻り値:**

* `str`: url プロパティの値。

***

### <kbd>property</kbd> Run.username

この API は非推奨です。代わりに `entity` を使用してください。

**戻り値:**

* `str`: username プロパティの値。

***

### <kbd>method</kbd> `Run.beta_scan_history`

```python theme={null}
beta_scan_history(
    keys: 'list[str] | None' = None,
    page_size: 'int' = 1000,
    min_step: 'int' = 0,
    max_step: 'int | None' = None,
    use_cache: 'bool' = True
) → public.BetaHistoryScan
```

Run のすべての履歴レコードのイテラブルなコレクションを返します。

この関数はまだ開発中であり、期待通りに動作しない可能性があります。wandb-core を使用して、ローカルにエクスポートされた Run の parquet 履歴から履歴を読み取ります。

**引数:**

* `keys`: Run の履歴から読み取るメトリクスのリスト。キーが指定されない場合、すべてのメトリクスが返されます。
* `page_size`: 一度に読み取る履歴レコードの数。
* `min_step`: 履歴の読み取りを開始する最小ステップ（含む）。
* `max_step`: 履歴を読み取る最大ステップ（含まない）。
* `use_cache`: True に設定すると、WANDB\_CACHE\_DIR に Run の履歴があるか確認します。キャッシュに履歴が見つからない場合は、サーバーからダウンロードされます。False に設定すると、履歴は毎回ダウンロードされます。

**戻り値:**
履歴レコードを取得するために反復処理可能な BetaHistoryScan オブジェクト。

***

### <kbd>classmethod</kbd> `Run.create`

```python theme={null}
create(
    api: 'public.Api',
    run_id: 'str | None' = None,
    project: 'str | None' = None,
    entity: 'str | None' = None,
    state: "Literal['running', 'pending']" = 'running'
) → Self
```

指定された Project に対して Run を作成します。

***

### <kbd>method</kbd> `Run.delete`

```python theme={null}
delete(delete_artifacts: 'bool' = False) → None
```

wandb バックエンドから指定された Run を削除します。

**引数:**

* `delete_artifacts` (bool, オプション): Run に関連付けられた Artifacts も削除するかどうか。

***

### <kbd>method</kbd> `Run.file`

```python theme={null}
file(name: 'str') → public.File
```

Artifact 内の指定された名前を持つファイルのパスを返します。

**引数:**

* `name` (str): 要求されたファイルの名前。

**戻り値:**
name 引数に一致する `File`。

***

### <kbd>method</kbd> `Run.files`

```python theme={null}
files(
    names: 'list[str] | None' = None,
    pattern: 'str | None' = None,
    per_page: 'int' = 50
) → public.Files
```

指定された条件に一致する Run 内のすべてのファイルに対して `Files` オブジェクトを返します。

一致させる正確なファイル名のリスト、または照合するパターンを指定できます。両方が指定された場合、パターンは無視されます。

**引数:**

* `names` (list): 要求されたファイルの名前。空の場合はすべてのファイルを返します。
* `pattern` (str, オプション): W\&B からファイルを返す際に一致させるパターン。このパターンは MySQL の LIKE 構文を使用するため、.json で終わるすべてのファイルに一致させるには "%.json" となります。names と pattern の両方が指定された場合、ValueError が発生します。
* `per_page` (int): 1ページあたりの結果数。

**戻り値:**
`File` オブジェクトを反復処理するイテレータである `Files` オブジェクト。

***

### <kbd>method</kbd> `Run.history`

```python theme={null}
history(
    samples: 'int' = 500,
    keys: 'list[str] | None' = None,
    x_axis: 'str' = '_step',
    pandas: 'bool' = True,
    stream: "Literal['default', 'system']" = 'default'
) → list[dict[str, Any]] | pd.DataFrame
```

Run のサンプリングされた履歴メトリクスを返します。

履歴レコードがサンプリングされても問題ない場合は、この方法がよりシンプルで高速です。

**引数:**

* `samples `: (int, オプション) 返すサンプルの数
* `pandas `: (bool, オプション) pandas dataframe を返すかどうか
* `keys `: (list, オプション) 特定のキーのメトリクスのみを返す
* `x_axis `: (str, オプション) xAxis として使用するメトリクス。デフォルトは \_step
* `stream `: (str, オプション) メトリクスには "default"、マシンメトリクスには "system" を指定

**戻り値:**

* `pandas.DataFrame`: pandas=True の場合、履歴メトリクスの `pandas.DataFrame` を返します。
* `list of dicts`: pandas=False の場合、履歴メトリクスの辞書のリストを返します。

***

### <kbd>method</kbd> `Run.load`

```python theme={null}
load(force: 'bool' = False) → dict[str, Any]
```

レイジーモードに基づいた適切なフラグメントを使用して Run データをロードします。

***

### <kbd>method</kbd> `Run.load_full_data`

```python theme={null}
load_full_data(force: 'bool' = False) → dict[str, Any]
```

config, systemMetrics, summaryMetrics などの重いフィールドを含む、すべての Run データをロードします。

このメソッドは、最初に lazy=True を使用して Run をリストしたが、特定の Run の全データにアクセスする必要がある場合に便利です。

**引数:**

* `force`: データが既にロードされている場合でも強制的に再ロードします

**戻り値:**
ロードされた Run 属性

***

### <kbd>method</kbd> `Run.log_artifact`

```python theme={null}
log_artifact(
    artifact: 'wandb.Artifact',
    aliases: 'Collection[str] | None' = None,
    tags: 'Collection[str] | None' = None
) → wandb.Artifact
```

Artifact を Run の出力として宣言します。

**引数:**

* `artifact` (`Artifact`): `wandb.Api().artifact(name)` から返された Artifact。
* `aliases` (list, オプション): この Artifact に適用するエイリアス。
* `tags`: (list, オプション) この Artifact に適用するタグ（ある場合）。

**戻り値:**
`Artifact` オブジェクト。

***

### <kbd>method</kbd> `Run.logged_artifacts`

```python theme={null}
logged_artifacts(per_page: 'int' = 100) → public.RunArtifacts
```

この Run によってログ記録されたすべての Artifacts を取得します。

Run 中にログ記録されたすべての出力 Artifacts を取得します。反復処理したり、単一のリストに収集したりできるページ分割された結果を返します。

**引数:**

* `per_page`: 1回の API リクエストで取得する Artifact の数。

**戻り値:**
この Run 中に出力としてログ記録されたすべての Artifact オブジェクトのイテラブルなコレクション。

**例:**

```python theme={null}
import wandb
import tempfile

with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".txt") as tmp:
   tmp.write("This is a test artifact")
   tmp_path = tmp.name
run = wandb.init(project="artifact-example")
artifact = wandb.Artifact("test_artifact", type="dataset")
artifact.add_file(tmp_path)
run.log_artifact(artifact)
run.finish()

api = wandb.Api()

finished_run = api.run(f"{run.entity}/{run.project}/{run.id}")

for logged_artifact in finished_run.logged_artifacts():
   print(logged_artifact.name)
```

***

### <kbd>method</kbd> `Run.save`

```python theme={null}
save() → None
```

Run オブジェクトへの変更を W\&B バックエンドに保存します。

***

### <kbd>method</kbd> `Run.scan_history`

```python theme={null}
scan_history(
    keys: 'list[str] | None' = None,
    page_size: 'int' = 1000,
    min_step: 'int | None' = None,
    max_step: 'int | None' = None
) → Iterator[dict[str, Any]]
```

Run のすべての履歴レコードのイテラブルなコレクションを返します。

**引数:**

* `keys` (\[str], オプション): これらのキーのみを取得し、すべてのキーが定義されている行のみを取得します。
* `page_size` (int, オプション): API から取得するページのサイズ。
* `min_step` (int, オプション): 一度にスキャンする最小ページ数。
* `max_step` (int, オプション): 一度にスキャンする最大ページ数。

**戻り値:**
履歴レコード（dict）を反復処理するイテラブルなコレクション。

**例:**
サンプル Run のすべての loss 値をエクスポートする

```python theme={null}
run = api.run("entity/project-name/run-id")
history = run.scan_history(keys=["Loss"])
losses = [row["Loss"] for row in history]
```

***

### <kbd>method</kbd> `Run.to_html`

```python theme={null}
to_html(height: 'int' = 420, hidden: 'bool' = False) → str
```

この Run を表示する iframe を含む HTML を生成します。

***

### <kbd>method</kbd> `Run.update`

```python theme={null}
update() → None
```

Run オブジェクトへの変更を wandb バックエンドに保存します。

***

### <kbd>method</kbd> `Run.upload_file`

```python theme={null}
upload_file(path: 'str', root: 'str' = '.') → public.File
```

ローカルファイルを W\&B にアップロードし、この Run に関連付けます。

**引数:**

* `path` (str): アップロードするファイルへのパス。絶対パスまたは相対パスを指定できます。
* `root` (str): ファイルを保存する際の基準となるルートパス。例えば、ファイルを Run 内で "my\_dir/file.txt" として保存したく、現在 "my\_dir" にいる場合は、root を "../" に設定します。デフォルトはカレントディレクトリ (".") です。

**戻り値:**
アップロードされたファイルを表す `File` オブジェクト。

***

### <kbd>method</kbd> `Run.use_artifact`

```python theme={null}
use_artifact(
    artifact: 'wandb.Artifact',
    use_as: 'str | None' = None
) → wandb.Artifact
```

Artifact を Run の入力として宣言します。

**引数:**

* `artifact` (`Artifact`): `wandb.Api().artifact(name)` から返された Artifact
* `use_as` (string, オプション): スクリプト内で Artifact がどのように使用されるかを識別する文字列。ベータ版の wandb launch 機能の Artifact 入れ替え機能を使用する際に、Run で使用される Artifact を簡単に区別するために使用されます。

**戻り値:**
`Artifact` オブジェクト。

***

### <kbd>method</kbd> `Run.used_artifacts`

```python theme={null}
used_artifacts(per_page: 'int' = 100) → public.RunArtifacts
```

この Run で明示的に使用された Artifacts を取得します。

Run 中に明示的に使用が宣言された入力 Artifacts（通常は `run.use_artifact()` 経由）のみを取得します。反復処理したり、単一のリストに収集したりできるページ分割された結果を返します。

**引数:**

* `per_page`: 1回の API リクエストで取得する Artifact の数。

**戻り値:**
この Run で入力として明示的に使用された Artifact オブジェクトのイテラブルなコレクション。

**例:**

```python theme={null}
import wandb

run = wandb.init(project="artifact-example")
run.use_artifact("test_artifact:latest")
run.finish()

api = wandb.Api()
finished_run = api.run(f"{run.entity}/{run.project}/{run.id}")
for used_artifact in finished_run.used_artifacts():
   print(used_artifact.name)
test_artifact
```

***

### <kbd>method</kbd> `Run.wait_until_finished`

```python theme={null}
wait_until_finished() → None
```

Run が終了するまでその状態を確認します。
