Skip to content

Commit d1c5ea4

Browse files
mariusaemeta-codesync[bot]
authored andcommitted
extension: make CodeSyncMeshClient ActorMesh version polymorphic (#1482)
Summary: Pull Request resolved: #1482 This uses shimming to accept both v0 and v1 proc meshes when constructing a codesync client. ghstack-source-id: 315276133 Reviewed By: colin2328 Differential Revision: D84284336 fbshipit-source-id: 637a4e9101da2d074f982227c1f6b967d49bcbe2
1 parent 138ad1f commit d1c5ea4

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

monarch_extension/src/code_sync.rs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ use monarch_hyperactor::context::PyInstance;
2727
use monarch_hyperactor::instance_dispatch;
2828
use monarch_hyperactor::proc_mesh::PyProcMesh;
2929
use monarch_hyperactor::runtime::signal_safe_block_on;
30+
use monarch_hyperactor::v1::proc_mesh::PyProcMesh as PyProcMeshV1;
3031
use pyo3::Bound;
32+
use pyo3::exceptions::PyException;
3133
use pyo3::exceptions::PyRuntimeError;
3234
use pyo3::exceptions::PyValueError;
3335
use pyo3::prelude::*;
@@ -264,16 +266,35 @@ impl CodeSyncMeshClient {
264266
impl CodeSyncMeshClient {
265267
#[staticmethod]
266268
#[pyo3(signature = (*, client, proc_mesh))]
267-
fn spawn_blocking(py: Python, client: PyInstance, proc_mesh: &PyProcMesh) -> PyResult<Self> {
268-
let proc_mesh = proc_mesh.try_inner()?;
269-
signal_safe_block_on(py, async move {
270-
let actor_mesh = instance_dispatch!(client, |cx| {
271-
proc_mesh
272-
.spawn(cx, "code_sync_manager", &CodeSyncManagerParams {})
273-
.await?
274-
});
275-
Ok(Self { actor_mesh })
276-
})?
269+
fn spawn_blocking(
270+
py: Python,
271+
client: PyInstance,
272+
proc_mesh: &Bound<'_, PyAny>,
273+
) -> PyResult<Self> {
274+
if let Ok(v0) = proc_mesh.downcast::<PyProcMesh>() {
275+
let proc_mesh = v0.borrow().try_inner()?;
276+
signal_safe_block_on(py, async move {
277+
let actor_mesh = instance_dispatch!(client, |cx| {
278+
proc_mesh
279+
.spawn(cx, "code_sync_manager", &CodeSyncManagerParams {})
280+
.await?
281+
});
282+
Ok(Self { actor_mesh })
283+
})?
284+
} else {
285+
let proc_mesh = proc_mesh.downcast::<PyProcMeshV1>()?.borrow().mesh_ref()?;
286+
signal_safe_block_on(py, async move {
287+
let actor_mesh = instance_dispatch!(client, |cx| {
288+
proc_mesh
289+
.spawn_service(cx, "code_sync_manager", &CodeSyncManagerParams {})
290+
.await
291+
.map_err(|err| PyException::new_err(err.to_string()))?
292+
});
293+
Ok(Self {
294+
actor_mesh: SharedCell::from(RootActorMesh::from(actor_mesh)),
295+
})
296+
})?
297+
}
277298
}
278299

279300
#[pyo3(signature = (*, local, remote, method = PyCodeSyncMethod::Rsync {}, auto_reload = false))]

python/monarch/_rust_bindings/monarch_extension/code_sync.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
from pathlib import Path
1010
from typing import Any, Dict, final
1111

12-
from monarch._rust_bindings.monarch_hyperactor.proc_mesh import ProcMesh
12+
from monarch._rust_bindings.monarch_hyperactor.proc_mesh import ProcMesh as ProcMeshV0
1313

1414
from monarch._rust_bindings.monarch_hyperactor.shape import Shape
15+
from monarch._rust_bindings.monarch_hyperactor.v1.proc_mesh import (
16+
ProcMesh as ProcMeshV1,
17+
)
1518

1619
class WorkspaceLocation:
1720
"""
@@ -84,7 +87,7 @@ class CodeSyncMeshClient:
8487
@staticmethod
8588
def spawn_blocking(
8689
client: Any,
87-
proc_mesh: ProcMesh,
90+
proc_mesh: ProcMeshV0 | ProcMeshV1,
8891
) -> CodeSyncMeshClient: ...
8992
async def sync_workspace(
9093
self,

0 commit comments

Comments
 (0)