Skip to content

Commit fb24ab9

Browse files
benjipelletierfacebook-github-bot
authored andcommitted
Add simulator context manager and execution summary (#908)
Summary: Pull Request resolved: #908 To make the simulator a bit easier to use for monarch test workloads: * Add context manager to set up logging, tracing, sim event loop * print execution details after run including execution ID, scuba links to tracing/metrics table Reviewed By: eliothedeman Differential Revision: D80366675 fbshipit-source-id: 22c6267bc2e024b06a42215978cd1d863895a5a0
1 parent 22f6b4d commit fb24ab9

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

monarch_hyperactor/src/telemetry.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ pub fn use_sim_clock() -> PyResult<()> {
113113
Ok(())
114114
}
115115

116+
/// Get the current execution ID
117+
#[pyfunction]
118+
pub fn get_execution_id() -> PyResult<String> {
119+
Ok(hyperactor_telemetry::env::execution_id())
120+
}
121+
116122
// opentelemetry requires that the names of counters etc are static for the lifetime of the program.
117123
// Since we are binding these classes from python to rust, we have to leak these strings in order to
118124
// ensure they live forever. This is fine, as these classes aren't dynamically created.
@@ -320,6 +326,13 @@ pub fn register_python_bindings(module: &Bound<'_, PyModule>) -> PyResult<()> {
320326
)?;
321327
module.add_function(use_sim_clock_fn)?;
322328

329+
let get_execution_id_fn = wrap_pyfunction!(get_execution_id, module)?;
330+
get_execution_id_fn.setattr(
331+
"__module__",
332+
"monarch._rust_bindings.monarch_hyperactor.telemetry",
333+
)?;
334+
module.add_function(get_execution_id_fn)?;
335+
323336
module.add_class::<PySpan>()?;
324337
module.add_class::<PyCounter>()?;
325338
module.add_class::<PyHistogram>()?;

python/monarch/_rust_bindings/monarch_hyperactor/telemetry.pyi

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@ def use_sim_clock() -> None:
8787
"""
8888
...
8989

90+
def get_execution_id() -> str:
91+
"""
92+
Get the current execution ID.
93+
94+
Returns the execution ID that is set by the telemetry system. This ID is either:
95+
- Set from the HYPERACTOR_EXECUTION_ID environment variable
96+
- Set from the MAST_HPC_JOB_NAME environment variable (in MAST environments)
97+
- Generated as a random string if neither environment variable is available
98+
99+
Returns:
100+
str: The current execution ID
101+
"""
102+
...
103+
90104
class PySpan:
91105
def __init__(self, name: str) -> None:
92106
"""

0 commit comments

Comments
 (0)