@@ -860,7 +860,11 @@ def tag(self, *tag: str, to: ToObject = "task-or-run") -> None:
860860
861861 target = (task or run ) if to == "task-or-run" else run
862862 if target is None :
863- raise RuntimeError ("Tagging must be done within a run" )
863+ warn_at_user_stacklevel (
864+ "tag() was called outside of a task or run." ,
865+ category = DreadnodeUsageWarning ,
866+ )
867+ return
864868
865869 target .add_tags (tag )
866870
@@ -883,7 +887,11 @@ def push_update(self) -> None:
883887 # do more work
884888 """
885889 if (run := current_run_span .get ()) is None :
886- raise RuntimeError ("Run updates must be pushed within a run" )
890+ warn_at_user_stacklevel (
891+ "push_update() was called outside of a run." ,
892+ category = DreadnodeUsageWarning ,
893+ )
894+ return
887895
888896 run .push_update (force = True )
889897
@@ -934,7 +942,12 @@ def log_params(self, **params: JsonValue) -> None:
934942 **params: The parameters to log. Each parameter is a key-value pair.
935943 """
936944 if (run := current_run_span .get ()) is None :
937- raise RuntimeError ("Parameters must be logged within a run" )
945+ warn_at_user_stacklevel (
946+ "log_params() was called outside of a run." ,
947+ category = DreadnodeUsageWarning ,
948+ )
949+ return
950+
938951 run .log_params (** params )
939952
940953 @t .overload
@@ -1085,13 +1098,6 @@ def log_metric(
10851098 Returns:
10861099 The logged metric object.
10871100 """
1088- task = current_task_span .get ()
1089- run = current_run_span .get ()
1090-
1091- target = (task or run ) if to == "task-or-run" else run
1092- if target is None :
1093- raise RuntimeError ("log_metric() must be called within a run" )
1094-
10951101 metric = (
10961102 value
10971103 if isinstance (value , Metric )
@@ -1102,6 +1108,18 @@ def log_metric(
11021108 attributes or {},
11031109 )
11041110 )
1111+
1112+ task = current_task_span .get ()
1113+ run = current_run_span .get ()
1114+
1115+ target = (task or run ) if to == "task-or-run" else run
1116+ if target is None :
1117+ warn_at_user_stacklevel (
1118+ "log_metric() was called outside of a task or run." ,
1119+ category = DreadnodeUsageWarning ,
1120+ )
1121+ return metric
1122+
11051123 return target .log_metric (name , metric , origin = origin , mode = mode )
11061124
11071125 @t .overload
@@ -1240,7 +1258,11 @@ def log_metrics(
12401258
12411259 target = (task or run ) if to == "task-or-run" else run
12421260 if target is None :
1243- raise RuntimeError ("log_metrics() must be called within a run" )
1261+ warn_at_user_stacklevel (
1262+ "log_metrics() was called outside of a task or run." ,
1263+ category = DreadnodeUsageWarning ,
1264+ )
1265+ return []
12441266
12451267 logged_metrics : list [Metric ] = []
12461268
@@ -1312,7 +1334,11 @@ def log_artifact(
13121334 local_uri: The local path to the file to upload.
13131335 """
13141336 if (run := current_run_span .get ()) is None :
1315- raise RuntimeError ("log_artifact() must be called within a run" )
1337+ warn_at_user_stacklevel (
1338+ "log_artifact() was called outside of a run." ,
1339+ category = DreadnodeUsageWarning ,
1340+ )
1341+ return
13161342
13171343 run .log_artifact (local_uri = local_uri )
13181344
@@ -1350,7 +1376,11 @@ async def my_task(x: int) -> int:
13501376
13511377 target = (task or run ) if to == "task-or-run" else run
13521378 if target is None :
1353- raise RuntimeError ("log_inputs() must be called within a run" )
1379+ warn_at_user_stacklevel (
1380+ "log_input() was called outside of a task or run." ,
1381+ category = DreadnodeUsageWarning ,
1382+ )
1383+ return
13541384
13551385 target .log_input (name , value , label = label , attributes = attributes )
13561386
@@ -1412,9 +1442,11 @@ async def my_task(x: int) -> int:
14121442
14131443 target = (task or run ) if to == "task-or-run" else run
14141444 if target is None :
1415- raise RuntimeError (
1416- "log_output() must be called within a run or a task" ,
1445+ warn_at_user_stacklevel (
1446+ "log_output() was called outside of a task or run." ,
1447+ category = DreadnodeUsageWarning ,
14171448 )
1449+ return
14181450
14191451 target .log_output (name , value , label = label , attributes = attributes )
14201452
@@ -1461,7 +1493,11 @@ def link_objects(
14611493 attributes: Additional attributes to attach to the link.
14621494 """
14631495 if (run := current_run_span .get ()) is None :
1464- raise RuntimeError ("link() must be called within a run" )
1496+ warn_at_user_stacklevel (
1497+ "link_objects() was called outside of a run." ,
1498+ category = DreadnodeUsageWarning ,
1499+ )
1500+ return
14651501
14661502 origin_hash = run .log_object (origin )
14671503 link_hash = run .log_object (link )
0 commit comments