Available Operations
- Run Operations - Query and manipulate W&B runs
- Artifact Operations - Work with artifacts and versions
This is the multi-page printable view of this section. Click here to print.
Operations for querying and manipulating W&B artifacts
artifactLink(artifact): string
Gets the URL/link for accessing an artifact in the W&B UI.
Returns a direct link to view the artifact in the W&B web interface, useful for generating reports or sharing artifact references.
Name | Type | Description |
---|---|---|
artifact |
Artifact |
The artifact to get the link for |
const link = artifactLink(myArtifact);
console.log(View artifact: ${link});
// Output: https://wandb.ai/entity/project/artifacts/type/name
const artifacts = project.artifacts();
const markdown = artifacts.map(a =>
- ${artifactName(a)}})
).join('\n');
artifactName(artifact): string
Gets the name of an artifact.
Returns the artifact’s unique name within its project.
Name | Type | Description |
---|---|---|
artifact |
Artifact |
The artifact to get the name from |
artifacts.forEach(artifact => {
console.log(Artifact: ${artifactName(artifact)});
});
const modelArtifacts = artifacts.filter(a =>
artifactName(a).includes("model")
);
artifactVersionAlias(version): string
Gets the alias of an artifact version.
Returns the version alias (e.g., “latest”, “best”, “production”).
Name | Type | Description |
---|---|---|
version |
ArtifactVersion |
The artifact version |
const prodVersion = versions.find(v =>
artifactVersionAlias(v) === "production"
);
artifactVersions - Get all versions
artifactVersionCreatedAt(version): Date
Gets the creation date of an artifact version.
Returns when a specific version of the artifact was created.
Name | Type | Description |
---|---|---|
version |
ArtifactVersion |
The artifact version to get creation date from |
const sorted = versions.sort((a, b) =>
artifactVersionCreatedAt(a).getTime() -
artifactVersionCreatedAt(b).getTime()
);
artifactVersions - Get all versions
artifactVersionDigest(version): string
Gets the content digest/hash of an artifact version.
Returns the SHA256 digest used to verify artifact integrity.
Name | Type | Description |
---|---|---|
version |
ArtifactVersion |
The artifact version |
const digest = artifactVersionDigest(version);
const expected = "sha256:abc123...";
if (digest !== expected) {
console.error("Artifact integrity check failed!");
}
artifactVersions - Get all versions
artifactVersionNumber(version): number
Gets the version number of an artifact version.
Returns the numeric version identifier.
Name | Type | Description |
---|---|---|
version |
ArtifactVersion |
The artifact version |
const versions = artifactVersions(artifact);
const maxVersion = Math.max(...versions.map(v =>
artifactVersionNumber(v)
));
console.log(Latest version: v${maxVersion});
artifactVersions - Get all versions
artifactVersionSize(version): number
Gets the size of an artifact version in bytes.
Returns the storage size of a specific artifact version.
Name | Type | Description |
---|---|---|
version |
ArtifactVersion |
The artifact version to get size from |
const bytes = artifactVersionSize(version);
const mb = (bytes / 1e6).toFixed(2);
console.log(Size: ${mb} MB);
const largeVersions = versions.filter(v =>
artifactVersionSize(v) > 1e9 // > 1GB
);
artifactVersions - Get all versions
artifactVersions(artifact): ArtifactVersion[]
Gets all versions of an artifact.
Returns an array of all version objects for the artifact, including version numbers, aliases, sizes, and timestamps.
Name | Type | Description |
---|---|---|
artifact |
Artifact |
The artifact to get versions from |
const versions = artifactVersions(myArtifact);
versions.forEach(v => {
console.log(v${v.version}: ${v.alias} (${v.size} bytes));
});
const versions = artifactVersions(artifact);
const latest = versions.find(v => v.alias === "latest");
if (latest) {
console.log(Latest is v${latest.version});
}
const versions = artifactVersions(artifact);
const totalSize = versions.reduce((sum, v) => sum + v.size, 0);
console.log(Total storage: ${(totalSize / 1e9).toFixed(2)} GB);
Operations for querying and manipulating W&B runs
runConfig(run): ConfigDict
Extracts the configuration dictionary (ConfigDict
) from a W&B run.
The configuration contains hyperparameters and settings used when the run was initialized. This is particularly useful for comparing configurations across experiments or filtering runs based on specific parameter values.
Name | Type | Description |
---|---|---|
run |
Run |
The W&B run object to extract configuration from |
const config = runConfig(myRun);
console.log(config.learning_rate); // 0.001
console.log(config.batch_size); // 32
// Find all runs with learning rate > 0.01
const highLRRuns = runs.filter(run => {
const config = runConfig(run);
return config.learning_rate > 0.01;
});
const config1 = runConfig(baseline);
const config2 = runConfig(experiment);
const differences = Object.keys(config1).filter(key =>
config1[key] !== config2[key]
);
runCreatedAt(run): Date
Gets the creation timestamp of a W&B run.
Returns when the run was first initialized. Useful for chronological sorting, filtering by date ranges, or analyzing experiment progression over time.
Name | Type | Description |
---|---|---|
run |
Run |
The W&B run to get creation time from |
const oneWeekAgo = new Date();
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);
const recentRuns = runs.filter(run =>
runCreatedAt(run) > oneWeekAgo
);
const sortedRuns = runs.sort((a, b) =>
runCreatedAt(a).getTime() - runCreatedAt(b).getTime()
);
const runsByDate = runs.reduce((groups, run) => {
const date = runCreatedAt(run).toDateString();
groups[date] = groups[date] || [];
groups[date].push(run);
return groups;
}, {});
runHeartbeatAt(run): Date
Gets the last heartbeat timestamp of a W&B run.
The heartbeat indicates when the run last sent data to W&B. For active runs, this is continuously updated. For finished runs, it shows the completion time.
Name | Type | Description |
---|---|---|
run |
Run |
The W&B run to get heartbeat from |
const isActive = (run: Run) => {
const lastHeartbeat = runHeartbeatAt(run);
const fiveMinutesAgo = new Date(Date.now() - 5 * 60 * 1000);
return lastHeartbeat > fiveMinutesAgo;
};
runJobType(run): string | undefined
Gets the job type of a run.
Returns the job type classification (e.g., “train”, “eval”, “sweep”) if set.
Name | Type | Description |
---|---|---|
run |
Run |
The W&B run to get job type from |
const trainingRuns = runs.filter(run =>
runJobType(run) === "train"
);
const evalRuns = runs.filter(run =>
runJobType(run) === "eval"
);
Run - Run type definition
runLoggedArtifactVersion(run, artifactVersionName): ArtifactVersion | undefined
Gets a specific artifact version logged (output) by a run.
Artifacts in W&B are versioned files or directories that track model checkpoints, datasets, or other outputs. This function retrieves a specific artifact version that was created/logged during the run’s execution.
Name | Type | Description |
---|---|---|
run |
Run |
The W&B run that logged the artifact |
artifactVersionName |
string |
Artifact identifier as “name:alias” (e.g., “model:latest”, “dataset:v2”) |
const model = runLoggedArtifactVersion(run, "model:latest");
if (model) {
console.log(Model version: v${model.version});
console.log(Model size: ${model.size} bytes);
console.log(Created: ${model.createdAt});
}
const requiredOutputs = ["model:latest", "evaluation:latest"];
const missing = requiredOutputs.filter(name =>
!runLoggedArtifactVersion(run, name)
);
if (missing.length > 0) {
console.warn(Missing outputs: ${missing.join(", ")});
}
runLoggedArtifactVersions(run): ArtifactVersion[]
Gets all artifact versions logged (output) by a run.
Returns a complete list of all artifacts created during the run’s execution, including models, datasets, checkpoints, and other outputs.
Name | Type | Description |
---|---|---|
run |
Run |
The W&B run to get logged artifacts from |
const outputs = runLoggedArtifactVersions(run);
outputs.forEach(artifact => {
console.log(Logged: ${artifact.name}:${artifact.alias});
console.log( Version: ${artifact.version});
console.log( Size: ${artifact.size} bytes);
});
const outputs = runLoggedArtifactVersions(run);
const modelCount = outputs.filter(a => a.name.includes("model")).length;
const dataCount = outputs.filter(a => a.name.includes("data")).length;
console.log(Models: ${modelCount}, Datasets: ${dataCount});
runName(run): string
Gets the name/ID of a run.
Returns the unique run name (ID) assigned by W&B or set by the user.
Name | Type | Description |
---|---|---|
run |
Run |
The W&B run to get name from |
runs.forEach(run => {
console.log(Run: ${runName(run)});
});
Run - Run type definition
runRuntime(run): number
Calculates the runtime duration of a W&B run in seconds.
Returns the total execution time from creation to last heartbeat. For active runs, this represents the current runtime.
Name | Type | Description |
---|---|---|
run |
Run |
The W&B run to calculate runtime for |
const runtime = runRuntime(myRun);
const hours = Math.floor(runtime / 3600);
const minutes = Math.floor((runtime % 3600) / 60);
console.log(Runtime: ${hours}h ${minutes}m);
const longRuns = runs.filter(run =>
runRuntime(run) > 3600 // More than 1 hour
);
runSummary(run): SummaryDict
Retrieves summary metrics (SummaryDict
) from a W&B run.
Summary metrics represent the final or best values logged during a run’s execution, such as final accuracy, best validation loss, or total training time. These are scalar values that summarize the run’s overall performance.
Name | Type | Description |
---|---|---|
run |
Run |
The W&B run to extract summary from |
const summary = runSummary(myRun);
console.log(Final accuracy: ${summary.accuracy});
console.log(Best validation loss: ${summary.best_val_loss});
console.log(Training time: ${summary.training_time_seconds});
const bestRun = runs.reduce((best, current) => {
const bestSummary = runSummary(best);
const currentSummary = runSummary(current);
return currentSummary.accuracy > bestSummary.accuracy ? current : best;
});
const goodRuns = runs.filter(run => {
const summary = runSummary(run);
return summary.accuracy > 0.95 && summary.val_loss < 0.1;
});
runUsedArtifactVersions(run): ArtifactVersion[]
Gets all artifact versions used (input) by a run.
Returns artifacts that were consumed as inputs during the run’s execution, such as training datasets, pretrained models, or configuration files.
Name | Type | Description |
---|---|---|
run |
Run |
The W&B run to get used artifacts from |
const inputs = runUsedArtifactVersions(run);
console.log("Run dependencies:");
inputs.forEach(artifact => {
console.log(- ${artifact.name}:${artifact.version});
});
const inputs = runUsedArtifactVersions(run);
const dataset = inputs.find(a => a.name === "training-data");
if (dataset && dataset.version !== 3) {
console.warn(Using outdated dataset v${dataset.version});
}
runUser(run): User
Gets the user who created the run.
Returns the W&B user object associated with the run, useful for filtering by user or analyzing team member contributions.
Name | Type | Description |
---|---|---|
run |
Run |
The W&B run to get user from |
const myRuns = runs.filter(run =>
runUser(run).username === "john_doe"
);
const runsByUser = runs.reduce((groups, run) => {
const user = runUser(run).username;
groups[user] = groups[user] || [];
groups[user].push(run);
return groups;
}, {});
User - User type definition