Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions hyperactor_mesh/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,23 @@ where
}
}

/// A trait that bundles a set of types that together define a resource.
pub trait Resource {
/// The spec specification for this resource.
type Spec: Named + Serialize + for<'de> Deserialize<'de> + Send + Sync + std::fmt::Debug;

/// The state for this resource.
type State: Named + Serialize + for<'de> Deserialize<'de> + Send + Sync + std::fmt::Debug;
}

// A behavior defining the interface for a mesh controller.
hyperactor::behavior!(
Controller<R: Resource>,
CreateOrUpdate<R::Spec>,
GetState<R::State>,
Stop,
);

/// RankedValues compactly represents rank-indexed values of type T.
/// It stores contiguous values in a set of intervals; thus it is
/// efficient and compact when the cardinality of T-typed values is
Expand Down
21 changes: 10 additions & 11 deletions hyperactor_mesh/src/resource/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ use ndslice::Extent;
use serde::Deserialize;
use serde::Serialize;

use crate::resource::CreateOrUpdate;
use crate::resource::GetState;
use crate::resource::Resource;
use crate::resource::Status;
use crate::resource::Stop;
use crate::v1::ValueMesh;

/// Mesh specs
Expand All @@ -49,17 +47,14 @@ pub trait Mesh {
/// The mesh-specific specification for this resource.
type Spec: Named + Serialize + for<'de> Deserialize<'de> + Send + Sync + std::fmt::Debug;

/// The mesh-specific state for thsi resource.
/// The mesh-specific state for this resource.
type State: Named + Serialize + for<'de> Deserialize<'de> + Send + Sync + std::fmt::Debug;
}

// A behavior defining the interface for a mesh controller.
hyperactor::behavior!(
Controller<M: Mesh>,
CreateOrUpdate<Spec<M::Spec>>,
GetState<State<M::State>>,
Stop,
);
impl<M: Mesh> Resource for M {
type Spec = Spec<M::Spec>;
type State = State<M::State>;
}

#[cfg(test)]
mod test {
Expand All @@ -68,6 +63,10 @@ mod test {
use hyperactor::Handler;

use super::*;
use crate::resource::Controller;
use crate::resource::CreateOrUpdate;
use crate::resource::GetState;
use crate::resource::Stop;

// Consider upstreaming this into `hyperactor` -- lightweight handler definitions
// can be quite useful.
Expand Down