Skip to content

Commit 45d823c

Browse files
benjipelletierfacebook-github-bot
authored andcommitted
Add attachable simulator to PaftManager tests with sqlite db assertions (#898)
Summary: This diff: * exposes paft_manager.py's main so we can attach the simulator to it * Allows test_paft_manager.py to write log assertions using sqlite db * Add `is_simulator_active()` so we can decide whether to real/sim sleep in the actor Reviewed By: thomasywang Differential Revision: D80271648
1 parent 5bfacfe commit 45d823c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

monarch_extension/src/simulation_tools.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ pub fn py_sim_sleep<'py>(py: Python<'py>, seconds: f64) -> PyResult<Bound<'py, P
3131
})
3232
}
3333

34+
#[pyfunction]
35+
#[pyo3(name = "is_simulator_active")]
36+
pub fn is_simulator_active() -> PyResult<bool> {
37+
// Use the existing simnet_handle() function to check if SimNet is active
38+
Ok(hyperactor::simnet::simnet_handle().is_ok())
39+
}
40+
3441
pub(crate) fn register_python_bindings(simulation_tools_mod: &Bound<'_, PyModule>) -> PyResult<()> {
3542
{
3643
let f = wrap_pyfunction!(py_sim_sleep, simulation_tools_mod)?;
@@ -48,5 +55,13 @@ pub(crate) fn register_python_bindings(simulation_tools_mod: &Bound<'_, PyModule
4855
)?;
4956
simulation_tools_mod.add_function(f)?;
5057
}
58+
{
59+
let f = wrap_pyfunction!(is_simulator_active, simulation_tools_mod)?;
60+
f.setattr(
61+
"__module__",
62+
"monarch._rust_bindings.monarch_extension.simulation_tools",
63+
)?;
64+
simulation_tools_mod.add_function(f)?;
65+
}
5166
Ok(())
5267
}

python/monarch/_rust_bindings/monarch_extension/simulation_tools.pyi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,12 @@ async def start_event_loop() -> None:
1515
Starts the simulator event loop
1616
"""
1717
...
18+
19+
def is_simulator_active() -> bool:
20+
"""
21+
Check if the simulation network is currently active.
22+
23+
Returns True if SimNet has been started (typically after calling
24+
start_event_loop()), False otherwise.
25+
"""
26+
...

0 commit comments

Comments
 (0)