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