@@ -146,7 +146,6 @@ def __init__(
146146 ```
147147 """
148148 self ._uuid : str = f"{ uuid .uuid4 ()} "
149- self ._name : str | None = None
150149
151150 # monitor duration with respect to retention period
152151 self ._timer : float = 0
@@ -160,7 +159,6 @@ def __init__(
160159 self ._executor = Executor (self )
161160 self ._dispatcher : DispatcherBaseClass | None = None
162161
163- self ._id : str | None = None
164162 self ._folder : Folder | None = None
165163 self ._term_color : bool = True
166164 self ._suppress_errors : bool = False
@@ -259,7 +257,7 @@ def __exit__(
259257 ) -> None :
260258 logger .debug (
261259 "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" ,
263261 self ._status ,
264262 )
265263
@@ -364,24 +362,25 @@ def _get_internal_metrics(
364362 # Set join on fail to false as if an error is thrown
365363 # join would be called on this thread and a thread cannot
366364 # 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+ )
372371
373372 # For the first emissions metrics reading, the time interval to use
374373 # Is the time since the run started, otherwise just use the time between readings
375374 if self ._emissions_monitor :
376375 _estimated = self ._emissions_monitor .estimate_co2_emissions (
377- process_id = f"{ self ._name } " ,
376+ process_id = f"{ self ._sv_obj . name } " ,
378377 cpu_percent = _current_system_measure .cpu_percent ,
379378 measure_interval = (time .time () - self ._start_time )
380379 if system_metrics_step == 0
381380 else self ._system_metrics_interval ,
382381 gpu_percent = _current_system_measure .gpu_percent ,
383382 )
384- if _estimated :
383+ if _estimated and self . status == "running" :
385384 self ._add_metrics_to_dispatch (
386385 self ._emissions_monitor .simvue_metrics (),
387386 join_on_fail = False ,
@@ -394,7 +393,7 @@ def _create_heartbeat_callback(
394393 """Defines the callback executed at the heartbeat interval for the Run."""
395394 if (
396395 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 )
398397 ) or not self ._heartbeat_termination_trigger :
399398 raise RuntimeError ("Could not commence heartbeat, run not initialised" )
400399
@@ -459,7 +458,7 @@ def _create_dispatch_callback(
459458 executed on metrics and events objects held in a buffer.
460459 """
461460
462- if self ._user_config .run .mode == "online" and not self ._id :
461+ if self ._user_config .run .mode == "online" and not self .id :
463462 raise RuntimeError ("Expected identifier for run" )
464463
465464 if (
@@ -590,7 +589,6 @@ def _error(self, message: str, join_threads: bool = True) -> None:
590589 # Simvue support now terminated as the instance of Run has entered
591590 # the dormant state due to exception throw so set listing to be 'lost'
592591 if self ._status == "running" and self ._sv_obj :
593- self ._sv_obj .name = self ._name
594592 self ._sv_obj .status = "lost"
595593 self ._sv_obj .commit ()
596594
@@ -701,8 +699,6 @@ def init(
701699 elif not name and self ._user_config .run .mode == "offline" :
702700 name = randomname .get_name ()
703701
704- self ._name = name
705-
706702 self ._status = "running" if running else "created"
707703
708704 # Parse the time to live/retention time if specified
@@ -750,28 +746,20 @@ def init(
750746 self ._data = self ._sv_obj ._staging
751747 self ._sv_obj .commit ()
752748
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 :
759750 return False
760751
761- elif name is not True :
762- self ._name = name
763-
764752 if self ._status == "running" :
765753 self ._start ()
766754
767755 if self ._user_config .run .mode == "online" :
768756 click .secho (
769- f"[simvue] Run { self ._name } created" ,
757+ f"[simvue] Run { self ._sv_obj . name } created" ,
770758 bold = self ._term_color ,
771759 fg = "green" if self ._term_color else None ,
772760 )
773761 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 } " ,
775763 bold = self ._term_color ,
776764 fg = "green" if self ._term_color else None ,
777765 )
@@ -951,7 +939,23 @@ def executor(self) -> Executor:
951939 @property
952940 def name (self ) -> str | None :
953941 """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
955959
956960 @property
957961 def uid (self ) -> str :
@@ -961,7 +965,9 @@ def uid(self) -> str:
961965 @property
962966 def id (self ) -> str | None :
963967 """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
965971
966972 @skip_if_failed ("_aborted" , "_suppress_errors" , False )
967973 @pydantic .validate_call
@@ -981,7 +987,7 @@ def reconnect(self, run_id: str) -> bool:
981987 self ._status = "running"
982988
983989 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 )
985991 self ._name = self ._sv_obj .name
986992 self ._sv_obj .status = self ._status
987993 self ._sv_obj .system = get_system ()
@@ -1614,7 +1620,7 @@ def _tidy_run(self) -> None:
16141620 and self ._status != "created"
16151621 ):
16161622 self ._user_config .offline .cache .joinpath (
1617- "runs" , f"{ self ._id } .closed"
1623+ "runs" , f"{ self .id } .closed"
16181624 ).touch ()
16191625
16201626 if _non_zero := self .executor .exit_status :
@@ -2088,7 +2094,7 @@ def log_alert(
20882094 )
20892095 return False
20902096 _alert .read_only (False )
2091- _alert .set_status (run_id = self ._id , status = state )
2097+ _alert .set_status (run_id = self .id , status = state )
20922098 _alert .commit ()
20932099
20942100 return True
0 commit comments