> ## 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.

# Journalisation

> Journalisez des métriques, des hyperparamètres, des tableaux et des données personnalisées dans W&B.

Journalisez des métriques, des hyperparamètres, des tableaux et des données personnalisées dans W\&B.

<h2 id="log-a-csv-file-to-as-a-table">
  Journaliser un fichier CSV sous forme de tableau
</h2>

```python theme={"system"}
"""
Log a CSV file to W&B as a table.

Replace:
- values enclosed in angle brackets with your own
- <name>.csv in pd.read_csv() with the name of your CSV file
"""

import wandb
import pandas as pd

# Lire le fichier CSV sous forme d’objet DataFrame (pandas)
dataframe = pd.read_csv("<name>.csv")

# Convertir le DataFrame en tableau W&B (W&B Table)
table = wandb.Table(dataframe=dataframe)

# Démarrer un run W&B pour journaliser les données
with wandb.init(project="<project>") as run:

    # Journaliser le tableau pour le visualiser dans l’interface W&B
    run.log({"<table_name>": table})
```

<h2 id="log-a-custom-summary-metric">
  Journaliser une métrique de synthèse personnalisée
</h2>

```python theme={"system"}
"""
Log a custom summary metric to W&B.
"""
import wandb
import random 

with wandb.init(project="<project>") as run:
    # Journaliser une métrique de synthèse personnalisée ayant pour valeur un entier aléatoire compris entre 1 et 10
    run.summary["<metric_name>"] = random.randint(1, 10)
```

<h2 id="log-a-custom-summary-metric-2">
  Journaliser une métrique de synthèse personnalisée
</h2>

```python theme={"system"}
"""
Log a custom summary metric to W&B.

Replace:
- values enclosed in angle brackets with your own
- <summary_function_a> and <summary_function_b> in run.define_metric() with
    one of "max", "min", "last", "mean", "best", or "none".
"""
import wandb
import random

with wandb.init() as run:
    # Valeurs de synthèse de metric_name_a selon summary_function_a et summary_function_b
    run.define_metric(name="<metric_name_a>", summary="<summary_function_a>")
    run.define_metric(name="<metric_name_a>", summary="<summary_function_b>")

    for i in range(10):
        log_dict = {
            "metric_name_a": random.uniform(0, 1 / (i + 1)),
        }
        run.log(log_dict)
```

<h2 id="download-and-log-an-existing-artifact-from-a-registry-collection">
  Télécharger et journaliser un artifact existant depuis une collection de registre
</h2>

```python theme={"system"}
"""
Download and log an existing artifact from a registry collection.
Replace the placeholders with actual registry, collection names, entity,
project, and version.
"""
import wandb

# Construire le nom complet de l’artifact avec sa version
registry_name = "<registry_name>"  # Indiquer le nom du registre
collection_name = "<collection_name>" # Indiquer le nom de la collection
version = 0 # Indiquer la version de l’artifact à utiliser
artifact_name_registry = f"wandb-registry-{registry_name}/{collection_name}:v{version}"

# Initialiser un run W&B dans l’autre équipe et l’autre projet
with wandb.init(entity="<entity>", project="<project>") as run:
    # Utiliser l’artifact de modèle issu du registre
    registry_model = run.use_artifact(artifact_or_name=artifact_name_registry)

    # Télécharger le modèle dans un répertoire local
    local_model_path = registry_model.download()
```

<h2 id="log-a-histogram-plot">
  Journaliser un histogramme
</h2>

```python theme={"system"}
"""
Log a histogram plot to W&B. 

Replace:
- values enclosed in angle brackets with your own
- [[1, 2], [2, 3]] in wandb.Table(data=) with your own 2D row-oriented array of values to plot

Pass a 2D row-oriented array of values to data (wandb.Table(data=)), with
column names specified in the `columns` parameter.
"""
import wandb

# Démarrer un nouveau run
with wandb.init(entity="<entity>", project="<project>") as run:
        
    # Créer un tableau contenant les colonnes à tracer
    table = wandb.Table(data=[[1, 2], [2, 3]] , columns=["<a_column>", "<b_column>"])

    # Utiliser le tableau pour alimenter différents graphiques personnalisés
    histogram = wandb.plot.histogram(table, value='<b_column>', title='Histogram')

    # Journaliser des tableaux personnalisés, qui apparaîtront sous forme de graphiques personnalisables dans l’interface utilisateur
    run.log({'histogram_1': histogram})
```

<h2 id="initialize-a-run-and-log-hyperparameters">
  Initialiser un run et journaliser les hyperparamètres
</h2>

```python theme={"system"}
"""Initializes a W&B run and logs hyperparameters."""
import wandb

config = {
    "learning_rate": 0.01,
    "batch_size": 32,
    "optimizer": "adam",
}

with wandb.init(project="<project>", config=config) as run:
    # Placez ici le code d’entraînement et de journalisation
    pass
```

<h2 id="log-a-line-plot">
  Journaliser un graphique en courbes
</h2>

```python theme={"system"}
"""
Log a line plot to W&B. 

Replace:
- values enclosed in angle brackets with your own
- [[1, 2], [2, 3]] in wandb.Table(data=) with your own 2D row-oriented array of values to plot

Pass a 2D row-oriented array of values to data (wandb.Table(data=)), with
column names specified in the `columns` parameter.

Column names must match the x and y parameters in the `wandb.plot.line()` plotting function.
"""
import wandb

# Démarrer un nouveau run
with wandb.init(entity="<entity>", project="<project>") as run:
        
    # Créer un tableau contenant les colonnes à représenter
    table = wandb.Table(data=[[1, 2], [2, 3]], columns=["<column_a>", "<column_b>"])

    # Utiliser le tableau pour alimenter divers graphiques personnalisés
    line_plot = wandb.plot.line(table, x='<column_a>', y='<column_b>', title='<title>')
    
    # Journaliser des tableaux personnalisés, qui apparaîtront sous forme de graphiques personnalisables dans l’interface utilisateur
    run.log({'<line_plot>': line_plot})
```

<h2 id="initialize-a-run-and-log-a-metric">
  Initialiser un run et journaliser une métrique
</h2>

```python theme={"system"}
"""Initializes a W&B run and logs a metric."""
import wandb

with wandb.init(project="<project>") as run:
    # Placez ici le code d’entraînement et de journalisation

    # Exemple de journalisation d’une métrique
    run.log({"accuracy": 0.95})
```

<h2 id="log-a-scatter-plot">
  Journaliser un nuage de points
</h2>

```python theme={"system"}
"""
Log a scatter plot to W&B. 

Replace:
- values enclosed in angle brackets with your own
- [[1, 2], [2, 3]] in wandb.Table(data=) with your own 2D row-oriented array of values to plot

Pass a 2D row-oriented array of values to data (wandb.Table(data=)), with
column names specified in the `columns` parameter.

Column names must match the x and y parameters in the `wandb.plot.scatter()` plotting function.
"""
import wandb

# Démarrer un nouveau run
with wandb.init(entity="<entity>", project="<project>") as run:
        
    # Créer un tableau contenant les colonnes à représenter
    table = wandb.Table(data=[[1, 2], [2, 3]], columns=["<a_column>", "<b_column>"])

    # Utiliser le tableau pour alimenter divers graphiques personnalisés
    scatter = wandb.plot.scatter(table, x='<a_column>', y='<b_column>', title='<title>')

    # Journaliser des tableaux personnalisés, qui apparaîtront sous forme de graphiques personnalisables dans l’interface utilisateur
    run.log({'scatter_1': scatter})
```

<h2 id="explicitly-log-a-summary-metric">
  Journaliser explicitement une métrique de synthèse
</h2>

```python theme={"system"}
"""
Explicitly log a summary metric to W&B.
"""
import wandb
import random 

with wandb.init(project="<project>") as run:
    # Journaliser une métrique de synthèse personnalisée dont la valeur est un entier aléatoire compris entre 1 et 10
    run.summary["<metric_name>"] = random.randint(1, 10)
```

<h2 id="log-a-table">
  Journaliser un tableau
</h2>

```python theme={"system"}
"""
Log a table to W&B.

Replace: 
- values enclosed in angle brackets with your own
- [[1, 2], [2, 3]] in wandb.Table(data=) with your own 2D row-oriented array of values to log
"""
import wandb

# Créer un objet tableau contenant deux colonnes et deux lignes de données
my_table = wandb.Table(
    columns=["<a_column>", "<b_column>"],
    data=[[1, 2], [2, 3]],
    log_mode="<log_mode>"
    )

# Démarrer un nouveau run
with wandb.init(entity="<entity>", project="<project>") as run:
    # Journaliser le tableau dans W&B
    run.log({"<table_name>": my_table})
```
