Skip to content
6 changes: 6 additions & 0 deletions bluehawk/snippets/artifact.snippet.create_artifact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import wandb

run = wandb.init(project="artifacts-example", job_type="add-dataset")
artifact = wandb.Artifact(name="example_artifact", type="dataset")
artifact.add_file(local_path="./dataset.h5", name="training_dataset")
artifact.save()
3 changes: 3 additions & 0 deletions bluehawk/snippets/artifact.snippet.download_artifact-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
artifact = run.use_artifact(
"training_dataset:latest"
) # returns a run object using the "my_data" artifact
3 changes: 3 additions & 0 deletions bluehawk/snippets/artifact.snippet.download_artifact-2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
datadir = (
artifact.download()
) # downloads the full `my_data` artifact to the default directory.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

report = wr.Report(project="report_standard")
report.save()

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
report = wr.Report(project="report-editing")

report.blocks = [wr.CodeBlock(code=["Hello, World!"], language="python")]

report.save()
10 changes: 10 additions & 0 deletions bluehawk/snippets/edit-a-report.snippet.add-code-blocks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
report = wr.Report(project = "<project>")

report.blocks = [
wr.CodeBlock(
code=["this:", "- is", "- a", "cool:", "- yaml", "- file"], language="yaml"
),
wr.CodeBlock(code=["Hello, World!"], language="python")
]

report.save()
9 changes: 9 additions & 0 deletions bluehawk/snippets/edit-a-report.snippet.add-html.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
report = wr.Report(project = "<project>")

report.blocks = [
wr.H1(text="How Programmatic Reports work"),
wr.H2(text="Heading 2"),
wr.UnorderedList(items=["Bullet 1", "Bullet 2"]),
]

report.save()
6 changes: 6 additions & 0 deletions bluehawk/snippets/edit-a-report.snippet.add-markdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
report = wr.Report(project = "<project>")

report.blocks = [
wr.MarkdownBlock(text="Markdown cell with *italics* and **bold** and $e=mc^2$")
]
report.save()
17 changes: 17 additions & 0 deletions bluehawk/snippets/edit-a-report.snippet.add-plots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
report = wr.Report(
project = "<project>",
title="<title>",
description="A descriptive description.",
)

blocks = [
wr.PanelGrid(
panels=[
wr.LinePlot(x="time", y="velocity"),
wr.ScatterPlot(x="time", y="acceleration"),
]
)
]

report.blocks = blocks
report.save()
14 changes: 14 additions & 0 deletions bluehawk/snippets/edit-a-report.snippet.add-runset-no-panels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
report = wr.Report(
project = "<project>",
title="An amazing title",
description="A descriptive description.",
)

blocks = wr.PanelGrid(
runsets=[
wr.RunSet(project="<project>", entity="<entity>")
]
)

report.blocks = [blocks]
report.save()
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
report = wr.Report(
project = "<project>",
title="An amazing title",
description="A descriptive description.",
)

blocks = wr.PanelGrid(
runsets=[
wr.RunSet(project="<project>", entity="<entity>")
],
panels=[
wr.LinePlot(
title="line title",
x="x",
y=["y"],
range_x=[0, 100],
range_y=[0, 100],
log_x=True,
log_y=True,
title_x="x axis title",
title_y="y axis title",
ignore_outliers=True,
groupby="hyperparam1",
groupby_aggfunc="mean",
groupby_rangefunc="minmax",
smoothing_factor=0.5,
smoothing_type="gaussian",
smoothing_show_original=True,
max_runs_to_show=10,
plot_type="stacked-area",
font_size="large",
legend_position="west",
),
wr.ScatterPlot(
title="scatter title",
x="y",
y="y",
# z='x',
range_x=[0, 0.0005],
range_y=[0, 0.0005],
# range_z=[0,1],
log_x=False,
log_y=False,
# log_z=True,
running_ymin=True,
running_ymean=True,
running_ymax=True,
font_size="small",
regression=True,
),
],

)

report.blocks = [blocks]
report.save()
9 changes: 9 additions & 0 deletions bluehawk/snippets/edit-a-report.snippet.config-filters-0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
config = {
"learning_rate": 0.01,
"batch_size": 32,
}

with wandb.init(project="<project>", entity="<entity>", config=config) as run:
# Your training code here
pass

5 changes: 5 additions & 0 deletions bluehawk/snippets/edit-a-report.snippet.config-filters-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
runset = wr.Runset(
entity="<entity>",
project="<project>",
filters="Config('learning_rate') > 0.01"
)
5 changes: 5 additions & 0 deletions bluehawk/snippets/edit-a-report.snippet.config-filters-2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
runset = wr.Runset(
entity="<entity>",
project="<project>",
filters="Config('learning_rate') > 0.01 and Config('batch_size') == 32"
)
12 changes: 12 additions & 0 deletions bluehawk/snippets/edit-a-report.snippet.config-filters-3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
report = wr.Report(
entity="<entity>",
project="<project>",
)

report.blocks = [
wr.PanelGrid(
runsets=[runset]
)
]

report.save()
6 changes: 6 additions & 0 deletions bluehawk/snippets/edit-a-report.snippet.embed-rich-media.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
report = wr.Report(project = "<project>")

report.blocks = [
wr.Video(url="https://www.youtube.com/embed/6riDJMI-Y8U")
]
report.save()
21 changes: 21 additions & 0 deletions bluehawk/snippets/edit-a-report.snippet.group-runs-config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Create a report that groups runs by a config value
report = wr.Report(
entity=entity,
project=project,
title="Grouped Runs Example",
)

# Create a runset that groups runs by the "group" config value
runset = wr.Runset(
project=project,
entity=entity,
groupby=["config.group"]
)
# Add the runset to a panel grid in the report
report.blocks = [
wr.PanelGrid(
runsets=[runset],
)
]
# Save the report
report.save()
22 changes: 22 additions & 0 deletions bluehawk/snippets/edit-a-report.snippet.group-runs-metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Create a report that groups runs by their metadata (e.g., run name)
report = wr.Report(
entity=entity,
project=project,
title="Grouped Runs by Metadata Example",
)

# Create a runset that groups runs by their name (metadata)
runset = wr.Runset(
project=project,
entity=entity,
groupby=["Name"] # Group by run names
)

# Add the runset to a panel grid in the report
report.blocks = [
wr.PanelGrid(
runsets=[runset],
)
]
# Save the report
report.save()
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Create a report that groups runs by a summary metric
report = wr.Report(
entity=entity,
project=project,
title="Grouped Runs by Summary Metrics Example",
)

# Create a runset that groups runs by the "summary.acc" summary metric
runset = wr.Runset(
project=project,
entity=entity,
groupby=["summary.acc"] # Group by summary values
)

# Add the runset to a panel grid in the report
report.blocks = [
wr.PanelGrid(
runsets=[runset],
)
]
# Save the report
report.save()
5 changes: 5 additions & 0 deletions bluehawk/snippets/edit-a-report.snippet.metric-filters-0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
with wandb.init(project="<project>", entity="<entity>") as run:
for i in range(3):
run.name = f"run{i+1}"
# Your training code here
pass
5 changes: 5 additions & 0 deletions bluehawk/snippets/edit-a-report.snippet.metric-filters-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
runset = wr.Runset(
entity="<entity>",
project="<project>",
filters="Metric('displayName') in ['run1', 'run2', 'run3']"
)
5 changes: 5 additions & 0 deletions bluehawk/snippets/edit-a-report.snippet.metric-filters-2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
runset = wr.Runset(
entity="<entity>",
project="<project>",
filters="Metric('state') in ['finished']"
)
5 changes: 5 additions & 0 deletions bluehawk/snippets/edit-a-report.snippet.metric-filters-3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
runset = wr.Runset(
entity="<entity>",
project="<project>",
filters="Metric('state') not in ['crashed']"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
runset = wr.Runset(
entity="<entity>",
project="<project>",
filters="SummaryMetric('accuracy') > 0.9"
)

runset = wr.Runset(
entity="<entity>",
project="<project>",
filters="Metric('state') in ['finished'] and SummaryMetric('train/train_loss') < 0.5"
)
5 changes: 5 additions & 0 deletions bluehawk/snippets/edit-a-report.snippet.tag-filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
runset = wr.Runset(
entity="<entity>",
project="<project>",
filters="Tags('training') == 'training'"
)
17 changes: 17 additions & 0 deletions bluehawk/snippets/group_runs.snippet.group_runs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

import wandb
import wandb_workspaces.reports.v2 as wr

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

for group in ["control", "experiment_a", "experiment_b"]:
for i in range(3):
with wandb.init(entity=entity, project=project, group=group, config={"group": group, "run": i}, name=f"{group}_run_{i}") as run:
# Simulate some training
for step in range(100):
run.log({
"acc": 0.5 + (step / 100) * 0.3 + (i * 0.05),
"loss": 1.0 - (step / 100) * 0.5
})

1 change: 1 addition & 0 deletions bluehawk/snippets/import_wandb.snippet.import_wandb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import wandb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import wandb
import wandb_workspaces.reports.v2 as wr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import wandb_workspaces.reports.v2 as wr
17 changes: 17 additions & 0 deletions bluehawk/snippets/models_quickart.snippet.publish_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

# Artifact name specifies the specific artifact version within our team's project
artifact_name = f'{TEAM_ENTITY}/{PROJECT}/{model_artifact_name}:v0'
print("Artifact name: ", artifact_name)

REGISTRY_NAME = "Model" # Name of the registry in W&B
COLLECTION_NAME = "DemoModels" # Name of the collection in the registry

# Create a target path for our artifact in the registry
target_path = f"wandb-registry-{REGISTRY_NAME}/{COLLECTION_NAME}"
print("Target path: ", target_path)

run = wandb.init(entity=TEAM_ENTITY, project=PROJECT)
model_artifact = run.use_artifact(artifact_or_name=artifact_name, type="model")
run.link_artifact(artifact=model_artifact, target_path=target_path)
run.finish()

29 changes: 29 additions & 0 deletions bluehawk/snippets/models_quickart.snippet.query_registry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

# Initialize wandb API
api = wandb.Api()

# Find all artifact versions that contains the string `model` and
# has either the tag `text-classification` or an `latest` alias
registry_filters = {
"name": {"$regex": "model"}
}

# Use logical $or operator to filter artifact versions
version_filters = {
"$or": [
{"tag": "text-classification"},
{"alias": "latest"}
]
}

# Returns an iterable of all artifact versions that match the filters
artifacts = api.registries(filter=registry_filters).collections().versions(filter=version_filters)

# Print out the name, collection, aliases, tags, and created_at date of each artifact found
for art in artifacts:
print(f"artifact name: {art.name}")
print(f"collection artifact belongs to: { art.collection.name}")
print(f"artifact aliases: {art.aliases}")
print(f"tags attached to artifact: {art.tags}")
print(f"artifact created at: {art.created_at}\n")

12 changes: 12 additions & 0 deletions bluehawk/snippets/models_quickart.snippet.retrieve_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

REGISTRY_NAME = "Model" # Name of the registry in W&B
COLLECTION_NAME = "DemoModels" # Name of the collection in the registry
VERSION = 0 # Version of the artifact to retrieve

model_artifact_name = f"wandb-registry-{REGISTRY_NAME}/{COLLECTION_NAME}:v{VERSION}"
print(f"Model artifact name: {model_artifact_name}")

run = wandb.init(entity=TEAM_ENTITY, project=PROJECT)
registry_model = run.use_artifact(artifact_or_name=model_artifact_name)
local_model_path = registry_model.download()

Loading