Skip to content

retrieve previously logged experiment metadata#11

Merged
justusschock merged 2 commits intomainfrom
retrieve_previous_experiment_metadata
Jan 23, 2026
Merged

retrieve previously logged experiment metadata#11
justusschock merged 2 commits intomainfrom
retrieve_previous_experiment_metadata

Conversation

@justusschock
Copy link
Member

Allows scripts like

"""
Script 1: Log files, configs, and metadata using litlogger
"""

import json
import os

import litlogger

# Create some sample files to log
CONFIG_FILE = "/tmp/experiment_config.json"
DATA_FILE = "/tmp/sample_data.txt"

# Create a config file
config = {
    "model": "ResNet50",
    "learning_rate": 0.001,
    "batch_size": 32,
    "epochs": 100,
    "optimizer": "Adam",
}

with open(CONFIG_FILE, "w") as f:
    json.dump(config, f, indent=2)

# Create a sample data file
with open(DATA_FILE, "w") as f:
    f.write("Sample training data\n")
    f.write("epoch,loss,accuracy\n")
    f.write("1,0.5,0.7\n")
    f.write("2,0.3,0.85\n")
    f.write("3,0.1,0.95\n")

# Initialize experiment with metadata
litlogger.init(
    name="my-demo-experiment",
    metadata={
        "project": "image-classification",
        "dataset": "CIFAR10",
        "model": "ResNet50",
        "learning_rate": "0.001",
        "batch_size": "32",
    },
    verbose=True,
)

# Log some metrics
for epoch in range(10):
    loss = 1.0 / (epoch + 1)
    accuracy = 1 - loss
    litlogger.log_metrics({"train/loss": loss, "train/accuracy": accuracy}, step=epoch)

# Log files
print("\nLogging config file...")
litlogger.log_file(CONFIG_FILE, verbose=True)

print("\nLogging data file...")
litlogger.log_file(DATA_FILE, verbose=True)

# Finalize the experiment
litlogger.finalize()

print("\nExperiment logged successfully!")

and

"""
Script 2: Fetch logged files, configs, and metadata using litlogger

This script retrieves data that was logged in the first script.
"""

import json
import os

import litlogger

# Initialize with the SAME experiment name to access logged data
# You can also pass the exact version if you want a specific run
litlogger.init(
    name="my-demo-experiment",
    verbose=True,
)

# Fetch metadata from the experiment
print("\n--- Fetching Metadata ---")
metadata = litlogger.get_metadata()
print(f"Experiment metadata: {json.dumps(metadata, indent=2)}")

# You can also access metadata via the experiment object
print(f"\nMetadata via experiment.metadata: {litlogger.experiment.metadata}")

# Define where to download files locally
RETRIEVED_CONFIG = "/tmp/retrieved_config.json"
RETRIEVED_DATA = "/tmp/retrieved_data.txt"

# Fetch the config file
print("\n--- Fetching Config File ---")
config_path = litlogger.get_file(
    path=RETRIEVED_CONFIG,
    remote_path="experiment_config.json",  # Basename of the original file
    verbose=True,
)

if os.path.exists(config_path):
    with open(config_path, "r") as f:
        config = json.load(f)
    print(f"Retrieved config: {json.dumps(config, indent=2)}")
else:
    print(f"Config file not found at {config_path}")

# Fetch the data file
print("\n--- Fetching Data File ---")
data_path = litlogger.get_file(
    path=RETRIEVED_DATA,
    remote_path="sample_data.txt",  # Basename of the original file
    verbose=True,
)

if os.path.exists(data_path):
    with open(data_path, "r") as f:
        data = f.read()
    print(f"Retrieved data:\n{data}")
else:
    print(f"Data file not found at {data_path}")

# Finalize
litlogger.finalize()

to work for retrieving logged metadata.

@justusschock justusschock force-pushed the retrieve_previous_experiment_metadata branch from b7bb3bd to 58c95c8 Compare January 23, 2026 10:43
@KaelanDt
Copy link
Collaborator

Do you have a sense of how things will be displayed UI-wise? seems like files can all be shown in the same view, but what about metadata? would it be a separate metadata.json file? I recall wandb has something similar.

@justusschock
Copy link
Member Author

@KaelanDt they're in the table view already.

@justusschock justusschock merged commit 7e4e8c2 into main Jan 23, 2026
63 checks passed
@justusschock justusschock deleted the retrieve_previous_experiment_metadata branch January 23, 2026 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants