@@ -146,7 +146,6 @@ def __init__(
146
146
```
147
147
"""
148
148
self ._uuid : str = f"{ uuid .uuid4 ()} "
149
- self ._name : str | None = None
150
149
151
150
# monitor duration with respect to retention period
152
151
self ._timer : float = 0
@@ -160,7 +159,6 @@ def __init__(
160
159
self ._executor = Executor (self )
161
160
self ._dispatcher : DispatcherBaseClass | None = None
162
161
163
- self ._id : str | None = None
164
162
self ._folder : Folder | None = None
165
163
self ._term_color : bool = True
166
164
self ._suppress_errors : bool = False
@@ -259,7 +257,7 @@ def __exit__(
259
257
) -> None :
260
258
logger .debug (
261
259
"Automatically closing run '%s' in status %s" ,
262
- self ._id if self ._user_config .run .mode == "online" else "unregistered" ,
260
+ self .id if self ._user_config .run .mode == "online" else "unregistered" ,
263
261
self ._status ,
264
262
)
265
263
@@ -364,24 +362,25 @@ def _get_internal_metrics(
364
362
# Set join on fail to false as if an error is thrown
365
363
# join would be called on this thread and a thread cannot
366
364
# join itself!
367
- self ._add_metrics_to_dispatch (
368
- _current_system_measure .to_dict (),
369
- join_on_fail = False ,
370
- step = system_metrics_step ,
371
- )
365
+ if self .status == "running" :
366
+ self ._add_metrics_to_dispatch (
367
+ _current_system_measure .to_dict (),
368
+ join_on_fail = False ,
369
+ step = system_metrics_step ,
370
+ )
372
371
373
372
# For the first emissions metrics reading, the time interval to use
374
373
# Is the time since the run started, otherwise just use the time between readings
375
374
if self ._emissions_monitor :
376
375
_estimated = self ._emissions_monitor .estimate_co2_emissions (
377
- process_id = f"{ self ._name } " ,
376
+ process_id = f"{ self ._sv_obj . name } " ,
378
377
cpu_percent = _current_system_measure .cpu_percent ,
379
378
measure_interval = (time .time () - self ._start_time )
380
379
if system_metrics_step == 0
381
380
else self ._system_metrics_interval ,
382
381
gpu_percent = _current_system_measure .gpu_percent ,
383
382
)
384
- if _estimated :
383
+ if _estimated and self . status == "running" :
385
384
self ._add_metrics_to_dispatch (
386
385
self ._emissions_monitor .simvue_metrics (),
387
386
join_on_fail = False ,
@@ -394,7 +393,7 @@ def _create_heartbeat_callback(
394
393
"""Defines the callback executed at the heartbeat interval for the Run."""
395
394
if (
396
395
self ._user_config .run .mode == "online"
397
- and (not self ._user_config .server .url or not self ._id )
396
+ and (not self ._user_config .server .url or not self .id )
398
397
) or not self ._heartbeat_termination_trigger :
399
398
raise RuntimeError ("Could not commence heartbeat, run not initialised" )
400
399
@@ -459,7 +458,7 @@ def _create_dispatch_callback(
459
458
executed on metrics and events objects held in a buffer.
460
459
"""
461
460
462
- if self ._user_config .run .mode == "online" and not self ._id :
461
+ if self ._user_config .run .mode == "online" and not self .id :
463
462
raise RuntimeError ("Expected identifier for run" )
464
463
465
464
if (
@@ -590,7 +589,6 @@ def _error(self, message: str, join_threads: bool = True) -> None:
590
589
# Simvue support now terminated as the instance of Run has entered
591
590
# the dormant state due to exception throw so set listing to be 'lost'
592
591
if self ._status == "running" and self ._sv_obj :
593
- self ._sv_obj .name = self ._name
594
592
self ._sv_obj .status = "lost"
595
593
self ._sv_obj .commit ()
596
594
@@ -701,8 +699,6 @@ def init(
701
699
elif not name and self ._user_config .run .mode == "offline" :
702
700
name = randomname .get_name ()
703
701
704
- self ._name = name
705
-
706
702
self ._status = "running" if running else "created"
707
703
708
704
# Parse the time to live/retention time if specified
@@ -750,28 +746,20 @@ def init(
750
746
self ._data = self ._sv_obj ._staging
751
747
self ._sv_obj .commit ()
752
748
753
- if self ._user_config .run .mode == "online" :
754
- name = self ._sv_obj .name
755
-
756
- self ._id = self ._sv_obj .id
757
-
758
- if not name :
749
+ if not self .name :
759
750
return False
760
751
761
- elif name is not True :
762
- self ._name = name
763
-
764
752
if self ._status == "running" :
765
753
self ._start ()
766
754
767
755
if self ._user_config .run .mode == "online" :
768
756
click .secho (
769
- f"[simvue] Run { self ._name } created" ,
757
+ f"[simvue] Run { self ._sv_obj . name } created" ,
770
758
bold = self ._term_color ,
771
759
fg = "green" if self ._term_color else None ,
772
760
)
773
761
click .secho (
774
- f"[simvue] Monitor in the UI at { self ._user_config .server .url .rsplit ('/api' , 1 )[0 ]} /dashboard/runs/run/{ self ._id } " ,
762
+ f"[simvue] Monitor in the UI at { self ._user_config .server .url .rsplit ('/api' , 1 )[0 ]} /dashboard/runs/run/{ self .id } " ,
775
763
bold = self ._term_color ,
776
764
fg = "green" if self ._term_color else None ,
777
765
)
@@ -951,7 +939,23 @@ def executor(self) -> Executor:
951
939
@property
952
940
def name (self ) -> str | None :
953
941
"""Return the name of the run"""
954
- return self ._name
942
+ if not self ._sv_obj :
943
+ raise RuntimeError ("Run has not been initialised" )
944
+ return self ._sv_obj .name
945
+
946
+ @property
947
+ def status (
948
+ self ,
949
+ ) -> (
950
+ typing .Literal [
951
+ "created" , "running" , "completed" , "failed" , "terminated" , "lost"
952
+ ]
953
+ | None
954
+ ):
955
+ """Return the status of the run"""
956
+ if not self ._sv_obj :
957
+ raise RuntimeError ("Run has not been initialised" )
958
+ return self ._sv_obj .status
955
959
956
960
@property
957
961
def uid (self ) -> str :
@@ -961,7 +965,9 @@ def uid(self) -> str:
961
965
@property
962
966
def id (self ) -> str | None :
963
967
"""Return the unique id of the run"""
964
- return self ._id
968
+ if not self ._sv_obj :
969
+ raise RuntimeError ("Run has not been initialised" )
970
+ return self ._sv_obj .id
965
971
966
972
@skip_if_failed ("_aborted" , "_suppress_errors" , False )
967
973
@pydantic .validate_call
@@ -981,7 +987,7 @@ def reconnect(self, run_id: str) -> bool:
981
987
self ._status = "running"
982
988
983
989
self ._id = run_id
984
- self ._sv_obj = RunObject (identifier = self . _id , _read_only = False )
990
+ self ._sv_obj = RunObject (identifier = run_id , _read_only = False )
985
991
self ._name = self ._sv_obj .name
986
992
self ._sv_obj .status = self ._status
987
993
self ._sv_obj .system = get_system ()
@@ -1614,7 +1620,7 @@ def _tidy_run(self) -> None:
1614
1620
and self ._status != "created"
1615
1621
):
1616
1622
self ._user_config .offline .cache .joinpath (
1617
- "runs" , f"{ self ._id } .closed"
1623
+ "runs" , f"{ self .id } .closed"
1618
1624
).touch ()
1619
1625
1620
1626
if _non_zero := self .executor .exit_status :
@@ -2088,7 +2094,7 @@ def log_alert(
2088
2094
)
2089
2095
return False
2090
2096
_alert .read_only (False )
2091
- _alert .set_status (run_id = self ._id , status = state )
2097
+ _alert .set_status (run_id = self .id , status = state )
2092
2098
_alert .commit ()
2093
2099
2094
2100
return True
0 commit comments