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

# Runs

> W&B run を初期化して管理し、実験を整理して作業をトラッキングします。

実験を整理し、作業をトラッキングするために、W\&B の run を初期化して管理します。

<div id="create-an-experiment">
  ## 実験を作成する
</div>

```python theme={null}
"""
W&B でエクスペリメントを作成します。プロジェクトが存在しない場合、W&B が自動的に作成します。

このファイルはエクスペリメントの初期化のみを行います。`with` ブロック内にメトリクスや
Artifacts などをログするコードを追加できます。
"""
import wandb

# W&B の run を初期化する
with wandb.init(project="<project>") as run:
    # エクスペリメントのコードをここに記述する
    pass
```

<div id="fork-an-existing-run-from-a-specific-step">
  ## 既存のrunを特定のstepからフォークする
</div>

```python theme={null}
"""特定のstepから既存のW&B runをフォークします。"""

import wandb

# 後でフォークするrunを初期化します
with wandb.init(project="<project>", entity="<entity>") as original_run:
    # トレーニングとloggingのコードをここに記述します。
    pass

# 特定のstepからrunをフォークします。この例ではstep 200からフォークします。必要に応じてstep番号を調整してください。
with wandb.init(project="<project>",entity="<entity>", fork_from=f"{original_run.id}?_step=200") as forked_run:
    # トレーニングとloggingのコードをここに記述します。
    pass
```

<div id="initialize-a-run">
  ## run を初期化する
</div>

```python theme={null}
"""
W&B の run を初期化します。

プロジェクトが存在しない場合、W&B は自動的に作成します。このファイルは
実験の初期化のみを行います。メトリクスや Artifacts などをログするコードは
`with` ブロック内に追加できます。
"""
import wandb

# リソースを適切に管理するため、`with` 文を使用しています。
with wandb.init(project="<project>") as run:
    # トレーニングおよびログのコードをここに記述します
    pass
```

<div id="set-resume-behaviour-for-a-run-if-it-is-paused-stops-or-fails">
  ## run が一時停止、停止、または失敗した場合の再開時の動作を設定する
</div>

```python theme={null}
"""
一時停止、停止、または失敗した場合のrunの再開動作を設定します。

これは中断される可能性のある長時間実行のexperimentに役立ちます。すべての再開オプションの一覧については、
wandb.init(resume=) のリファレンスドキュメントを参照してください。
"""
import wandb

# 再開動作を指定してW&B runを初期化する
with wandb.init(project="<project>", resume="<resume_option>") as run:
    # トレーニングおよびloggingのコードをここに記述する
    pass
```

<div id="rewind-a-run-to-modify-the-history-of-a-run">
  ## run を巻き戻して履歴を変更する
</div>

```python theme={null}
"""
Rewind a run to modify the history of a run.

Specify the run ID and step to rewind to with the `resume_from` parameter in `wandb.init()`.
"""
import wandb
import math

# runを初期化してメトリクスをログする
with wandb.init(project="<project>", entity="<entity>") as run:
    # トレーニングとloggingのコードをここに記述する
    pass

run_ID = "<run_id>" # 元のrunのrun IDに置き換えてください
step = int("<step>") # 巻き戻し先のstepを指定する

# 元のrunの指定したstepから再開する新しいrunを開始する
with wandb.init(project="<project>", entity="<entity>", resume_from=f"{run_ID}?_step={step}") as run:
    # トレーニングとloggingのコードをここに記述する
    pass    
```

<div id="add-one-or-more-tags-to-a-run">
  ## run に 1 つ以上の タグ を追加する
</div>

```python theme={null}
"""
Add one or more tags to a run.
"""
import wandb

with wandb.init(entity="<entity>", project="<project>", tags=["<tag1>", "<tag2>"]) as run:
    # トレーニングとloggingのコードをここに記述します
    pass
```

<div id="add-one-or-more-runs-to-a-group">
  ## 1つ以上の run をグループに追加する
</div>

```python theme={null}
"""
1つ以上のrunをグループに追加します。

`wandb.init(group="")` でrunを初期化する際に、`group` パラメーターの引数としてグループ名を渡してください。
"""
import wandb

entity = "<entity>"
project = "<project>"

# 以下では、各グループに3つのrunを含む、合計3つのグループを作成します。 
for group in ["<GroupA>", "<GroupB>", "<GroupC>"]: # 任意のグループ名に置き換えてください
    # 各グループに3つのrunを作成するシミュレーションです。
    for i in range(3):
        with wandb.init(entity=entity, project=project, group=group, name=f"{group}_run_{i}") as run:
            # トレーニングおよびloggingのコードをここに記述します
            pass    
```

<div id="organize-runs-by-their-job-type">
  ## run をジョブタイプごとに整理する
</div>

```python theme={null}
"""
Organize runs by their job type.

Add a job type to a run by passing the `job_type` parameter to `wandb.init(job_type="")`.
"""
import wandb

entity = "<entity>"
project = "<project>"

# runを作成し、ジョブタイプごとに整理します。
for job_type in ["<JobType1>", "<JobType2>"]: # ジョブタイプ名に置き換えてください
    # 各ジョブタイプに対して2つのrunを作成するシミュレーションです。
    for i in range(2):
        with wandb.init(entity=entity, project=project, job_type=job_type, name=f"{job_type}_run_{i}") as run:
            # トレーニングおよびloggingのコードをここに記述します
            pass    
```

<div id="add-one-or-more-tags-to-an-active-run">
  ## アクティブな run に1つ以上の タグ を追加する
</div>

```python theme={null}
"""
アクティブなrunに1つ以上のタグを追加します。

runオブジェクトの`tags`プロパティはタプルです。既存のrunに新しいタグを追加するには、
既存のタグと新しいタグを含む新しいタプルで`tags`プロパティを更新してください。
"""

import wandb

with wandb.init(entity="<entity>", project="<project>", tags=["<tag1>", "<tag2>"]) as run:
    # トレーニングとloggingのコードをここに記述します

    # 既存のタグと新しいタグを含む新しいタプルを作成して、既存のタグに新しいタグを追加します。
    run.tags += ("<tag3>",)
```

<div id="add-one-or-more-tags-to-previously-saved-runs">
  ## 以前に保存した run にタグを1つ以上追加する
</div>

```python theme={null}
"""
保存済みのrunに1つ以上のタグを追加します。

runが終了した後、またはrunプロセスの外で作業している場合に、
Public APIを使用して保存済みデータのタグを更新します。

runに新しいタグを追加するには、既存のタグと新しいタグを含む
新しいリストで "tags" プロパティを更新してください。
runのパスはentity/project/run_idで構成されます。
タグを更新した後、runの `update()` methodを呼び出して変更を保存してください。
"""
import wandb

entity = "<entity>"
project = "<project>"
run_id = "<run-id>"  # 更新したいrunのIDに置き換えてください

# パスはentity/project/run_idで構成されます
with wandb.Api().run(f"{entity}/{project}/{run_id}") as run:
  run.tags.append("<tag>")
  run.update()
```
