> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreweave.com/llms.txt
> Use this file to discover all available pages before exploring further.

# W&B run を関数の Call のトレースにリンクする

> 実験管理のために Weave トレースを W&B run に関連付ける

W\&B Weave を使用すると、コード内の関数の Call をトレースし、その Call が実行された [W\&B run](/ja/products/wandb/runs) に直接リンクできます。
`@weave.op()` で関数をトレースし、`wandb.init()` のコンテキスト内でその関数を呼び出すと、Weave はトレースを W\&B run に自動的に関連付けます。
**Traces** 表には、関連付けられた run へのリンクが表示されます。

<h2 id="view-a-wb-run-in-the-traces-table">
  Traces の表で W\&B run を表示する
</h2>

<Tabs>
  <Tab title="Python">
    次の Python コードは、`wandb.init()` コンテキスト内でトレースされた Op を実行したときに、Weave がそれらを W\&B
    run に関連付ける仕組みを示しています。これらのトレースは
    Weights & Biases の UI に表示され、対応する run に関連付けられます。

    W\&B run を Weave のトレースとして表示するには、次の手順に従います。

    1. ターミナルで依存関係をインストールします。

    ```bash lines theme={"system"}
    pip install wandb weave
    ```

    2. Forge にログインします。

    ```bash lines theme={"system"}
    wandb login
    ```

    3. 次のスクリプト内の `your-team-name/your-project-name` を、ご自身の W\&B entity と project に置き換えます。

    ```python lines theme={"system"}
    import wandb
    import weave

    def example_wandb(projname):
        # projname を entity と project に分割する
        entity, project = projname.split("/", 1)

        # トレース用に Weave コンテキストを初期化する
        weave.init(projname)

        # トレース可能な Op を定義する
        @weave.op()
        def say(message: str) -> str:
            return f"I said: {message}"

        # 1 つ目の W&B run
        with wandb.init(
            entity=entity,
            project=project,
            notes="Experiment 1",
            tags=["baseline", "paper1"],
        ) as run:
            say("Hello, world!")
            say("How are you!")
            run.log({"messages": 2})

        # 2 つ目の W&B run
        with wandb.init(
            entity=entity,
            project=project,
            notes="Experiment 2",
            tags=["baseline", "paper1"],
        ) as run:
            say("Hello, world from experiment 2!")
            say("How are you!")
            run.log({"messages": 2})

    if __name__ == "__main__":
        # 実際の W&B ユーザー名/project に置き換えてください
        example_wandb("your-team-name/your-project-name")
    ```

    4. スクリプトを実行します。

    ```bash lines theme={"system"}
    python weave_trace_with_wandb.py
    ```

    5. [W\&B アプリ](https://forge.coreweave.com/wandb) にアクセスし、ご自身の project を選択します。
    6. **Weave プロジェクトのサイドバー** で **Traces** をクリックします。**Traces** の表に、関連付けられた run へのリンクが表示されます。

    これで、**Traces** の表から任意のトレースを開いて、リンクされた W\&B run を調べ、関連する実験のコンテキストを確認できます。
  </Tab>

  <Tab title="TypeScript">
    ```text theme={"system"}
    This feature is not available for the TypeScript SDK yet.
    ```
  </Tab>
</Tabs>


## Related topics

- [コードから評価データをログする](/ja/products/wandb/weave/guides/evaluation/evaluation_logger.md)
