Skip to content

Commit 13d7be6

Browse files
techniciantedfacebook-github-bot
authored andcommitted
Refactor AllocConstraints::none() to default()
Reviewed By: pablorfb-meta Differential Revision: D75297949 fbshipit-source-id: 55ea59b07801b7d5a42ebffd09f80bdb3589dd9a
1 parent e2f78ea commit 13d7be6

File tree

8 files changed

+23
-30
lines changed

8 files changed

+23
-30
lines changed

hyperactor_extension/src/alloc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl PyAllocConstraints {
9191
#[new]
9292
#[pyo3(signature = (match_labels=None))]
9393
fn new(match_labels: Option<HashMap<String, String>>) -> PyResult<Self> {
94-
let mut constraints = AllocConstraints::none();
94+
let mut constraints = AllocConstraints::default();
9595
if let Some(match_lables) = match_labels {
9696
constraints.match_labels = match_lables;
9797
}

hyperactor_mesh/src/actor_mesh.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ mod tests {
363363
let alloc = $allocator
364364
.allocate(AllocSpec {
365365
shape: shape! { replica = 4 },
366-
constraints: AllocConstraints::none(),
366+
constraints: Default::default(),
367367
})
368368
.await
369369
.unwrap();
@@ -384,7 +384,7 @@ mod tests {
384384
let alloc = $allocator
385385
.allocate(AllocSpec {
386386
shape: shape! { replica = 2, host = 2, gpu = 8 },
387-
constraints: AllocConstraints::none(),
387+
constraints: Default::default(),
388388
})
389389
.await
390390
.unwrap();
@@ -423,7 +423,7 @@ mod tests {
423423
// required for this test in the process case
424424
// reasonable (< 60s).
425425
shape: shape! { replica = 2, host = 2, gpu = 8 },
426-
constraints: AllocConstraints::none(),
426+
constraints: Default::default(),
427427
})
428428
.await
429429
.unwrap();
@@ -454,7 +454,7 @@ mod tests {
454454
let alloc = $allocator
455455
.allocate(AllocSpec {
456456
shape: shape! { replica = 1 },
457-
constraints: AllocConstraints::none(),
457+
constraints: Default::default(),
458458
})
459459
.await
460460
.unwrap();

hyperactor_mesh/src/alloc/mod.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,13 @@ pub enum AllocatorError {
5353
}
5454

5555
/// Constraints on the allocation.
56-
#[derive(Debug, Clone, Serialize, Deserialize)]
56+
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
5757
pub struct AllocConstraints {
5858
/// Aribitrary name/value pairs that are interpreted by individual
5959
/// allocators to control allocation process.
6060
pub match_labels: HashMap<String, String>,
6161
}
6262

63-
impl AllocConstraints {
64-
pub fn none() -> Self {
65-
Self {
66-
match_labels: HashMap::new(),
67-
}
68-
}
69-
}
70-
7163
/// A specification (desired state) of an alloc.
7264
#[derive(Debug, Clone, Serialize, Deserialize)]
7365
pub struct AllocSpec {
@@ -313,7 +305,7 @@ pub(crate) mod testing {
313305
let mut alloc = allocator
314306
.allocate(AllocSpec {
315307
shape: shape! { replica = 4 },
316-
constraints: AllocConstraints::none(),
308+
constraints: Default::default(),
317309
})
318310
.await
319311
.unwrap();

hyperactor_mesh/src/alloc/remoteprocess.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ mod test {
10481048

10491049
let spec = AllocSpec {
10501050
shape: shape!(host = 1, gpu = 2),
1051-
constraints: AllocConstraints::none(),
1051+
constraints: Default::default(),
10521052
};
10531053
let tx = channel::dial(serve_addr.clone()).unwrap();
10541054

@@ -1182,7 +1182,7 @@ mod test {
11821182

11831183
let spec = AllocSpec {
11841184
shape: shape!(host = 1, gpu = 2),
1185-
constraints: AllocConstraints::none(),
1185+
constraints: Default::default(),
11861186
};
11871187
let tx = channel::dial(serve_addr.clone()).unwrap();
11881188

@@ -1256,7 +1256,7 @@ mod test {
12561256

12571257
let spec = AllocSpec {
12581258
shape: shape!(host = 1, gpu = 2),
1259-
constraints: AllocConstraints::none(),
1259+
constraints: Default::default(),
12601260
};
12611261
let tx = channel::dial(serve_addr.clone()).unwrap();
12621262

@@ -1365,6 +1365,7 @@ mod test {
13651365

13661366
#[timed_test::async_timed_test(timeout_secs = 15)]
13671367
async fn test_upstream_closed() {
1368+
// SAFETY: This test is single-threaded.
13681369
// TODO: Audit that the environment access only happens in single-threaded code.
13691370
unsafe { std::env::set_var("MONARCH_MESSAGE_DELIVERY_TIMEOUT_SECS", "1") };
13701371

@@ -1375,7 +1376,7 @@ mod test {
13751376

13761377
let spec = AllocSpec {
13771378
shape: shape!(host = 1, gpu = 2),
1378-
constraints: AllocConstraints::none(),
1379+
constraints: Default::default(),
13791380
};
13801381
let tx = channel::dial(serve_addr.clone()).unwrap();
13811382

@@ -1464,7 +1465,7 @@ mod test_alloc {
14641465

14651466
let spec = AllocSpec {
14661467
shape: shape!(host = 2, gpu = 2),
1467-
constraints: AllocConstraints::none(),
1468+
constraints: Default::default(),
14681469
};
14691470
let world_id = WorldId("test_world_id".to_string());
14701471
let transport = ChannelTransport::Unix;
@@ -1580,7 +1581,7 @@ mod test_alloc {
15801581

15811582
let spec = AllocSpec {
15821583
shape: shape!(host = 2, gpu = 2),
1583-
constraints: AllocConstraints::none(),
1584+
constraints: Default::default(),
15841585
};
15851586
let world_id = WorldId("test_world_id".to_string());
15861587
let transport = ChannelTransport::Unix;

hyperactor_mesh/src/proc_mesh/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ mod tests {
394394
let alloc = LocalAllocator
395395
.allocate(AllocSpec {
396396
shape: shape! { replica = 4 },
397-
constraints: AllocConstraints::none(),
397+
constraints: Default::default(),
398398
})
399399
.await
400400
.unwrap();

monarch_rdma/examples/parameter_server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ pub async fn run(num_workers: usize, num_steps: usize) -> Result<(), anyhow::Err
481481
alloc
482482
.allocate(AllocSpec {
483483
shape: shape! {replica=1, host=1, gpu=1},
484-
constraints: AllocConstraints::none(),
484+
constraints: Default::default(),
485485
})
486486
.await?,
487487
)
@@ -507,7 +507,7 @@ pub async fn run(num_workers: usize, num_steps: usize) -> Result<(), anyhow::Err
507507
alloc
508508
.allocate(AllocSpec {
509509
shape: shape! {replica=1, host=1, gpu=num_workers},
510-
constraints: AllocConstraints::none(),
510+
constraints: Default::default(),
511511
})
512512
.await?,
513513
)

monarch_rdma/src/rdma_buffer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ mod tests {
486486
let alloc1 = LocalAllocator
487487
.allocate(AllocSpec {
488488
shape: shape! {replica=1, host=1, gpu=1},
489-
constraints: AllocConstraints::none(),
489+
constraints: Default::default(),
490490
})
491491
.await?;
492492
let proc_mesh_1 = ProcMesh::allocate(alloc1).await?;
@@ -496,7 +496,7 @@ mod tests {
496496
let alloc2 = LocalAllocator
497497
.allocate(AllocSpec {
498498
shape: shape! {replica=1, host=1, gpu=1},
499-
constraints: AllocConstraints::none(),
499+
constraints: Default::default(),
500500
})
501501
.await?;
502502
let proc_mesh_2 = ProcMesh::allocate(alloc2).await?;
@@ -562,7 +562,7 @@ mod tests {
562562
let alloc1 = LocalAllocator
563563
.allocate(AllocSpec {
564564
shape: shape! {replica=1, host=1, gpu=1},
565-
constraints: AllocConstraints::none(),
565+
constraints: Default::default(),
566566
})
567567
.await?;
568568
let proc_mesh_1 = ProcMesh::allocate(alloc1).await?;
@@ -572,7 +572,7 @@ mod tests {
572572
let alloc2 = LocalAllocator
573573
.allocate(AllocSpec {
574574
shape: shape! {replica=1, host=1, gpu=1},
575-
constraints: AllocConstraints::none(),
575+
constraints: Default::default(),
576576
})
577577
.await?;
578578
let proc_mesh_2 = ProcMesh::allocate(alloc2).await?;

monarch_rdma/src/rdma_manager_actor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ mod tests {
585585
let alloc_1 = LocalAllocator
586586
.allocate(AllocSpec {
587587
shape: shape! { proc = 1 },
588-
constraints: AllocConstraints::none(),
588+
constraints: Default::default(),
589589
})
590590
.await
591591
.unwrap();
@@ -597,7 +597,7 @@ mod tests {
597597
let alloc_2 = LocalAllocator
598598
.allocate(AllocSpec {
599599
shape: shape! { proc = 1 },
600-
constraints: AllocConstraints::none(),
600+
constraints: Default::default(),
601601
})
602602
.await
603603
.unwrap();

0 commit comments

Comments
 (0)