@@ -51,6 +51,7 @@ class DockerConfig(BaseModel):
51
51
52
52
build_timeout : float | None = None
53
53
safe_build : bool = False
54
+ set_cpus : str | list [str ] | None = None
54
55
generator : RunParameters = RunParameters ()
55
56
solver : RunParameters = RunParameters ()
56
57
advanced_run_params : "AdvancedRunArgs | None" = None
@@ -199,6 +200,7 @@ async def run(
199
200
timeout : float | None = None ,
200
201
memory : int | None = None ,
201
202
cpus : int = 1 ,
203
+ set_cpus : str | None = None ,
202
204
ui : ProgramUiProxy | None = None ,
203
205
) -> float :
204
206
"""Runs a docker image.
@@ -209,6 +211,8 @@ async def run(
209
211
timeout: Timeout in seconds.
210
212
memory: Memory limit in MB.
211
213
cpus: Number of physical cpus the container can use.
214
+ set_cpus: Which cpus to execute the container on. Either a comma separated list or a hyphen-separated range.
215
+ A value of `None` means the container can use any core (but still only `cpus` many of them).
212
216
ui: Interface to update the ui with new data about the executing program.
213
217
214
218
Raises:
@@ -222,8 +226,8 @@ async def run(
222
226
"""
223
227
name = f"algobattle_{ uuid1 ().hex [:8 ]} "
224
228
if memory is not None :
225
- memory = int ( memory * 1000000 )
226
- cpus = int ( cpus * 1000000000 )
229
+ memory = memory * 1_000_000
230
+ cpus = cpus * 1_000_000_000
227
231
228
232
mounts = []
229
233
if input_dir is not None :
@@ -243,6 +247,7 @@ async def run(
243
247
nano_cpus = cpus ,
244
248
detach = True ,
245
249
mounts = mounts ,
250
+ cpuset_cpus = set_cpus ,
246
251
** self .run_kwargs ,
247
252
),
248
253
)
@@ -410,6 +415,7 @@ async def _run(
410
415
cpus : int = ...,
411
416
battle_input : Encodable | None = None ,
412
417
battle_output : type [Encodable ] | None = None ,
418
+ set_cpus : str | None = None ,
413
419
ui : ProgramUiProxy | None = None ,
414
420
) -> GeneratorResult | SolverResult :
415
421
"""Execute the program, processing input and output data."""
@@ -450,7 +456,9 @@ async def _run(
450
456
)
451
457
452
458
try :
453
- runtime = await self .image .run (input , output , timeout = timeout , memory = space , cpus = cpus , ui = ui )
459
+ runtime = await self .image .run (
460
+ input , output , timeout = timeout , memory = space , cpus = cpus , ui = ui , set_cpus = set_cpus
461
+ )
454
462
except ExecutionError as e :
455
463
return result_class (
456
464
ProgramRunInfo (
@@ -566,6 +574,7 @@ async def run(
566
574
cpus : int = ...,
567
575
battle_input : Encodable | None = None ,
568
576
battle_output : type [Encodable ] | None = None ,
577
+ set_cpus : str | None = None ,
569
578
ui : ProgramUiProxy | None = None ,
570
579
) -> GeneratorResult :
571
580
"""Executes the generator and parses its output into a problem instance.
@@ -577,6 +586,8 @@ async def run(
577
586
cpus: Number of physical cpus the generator can use.
578
587
battle_input: Additional data that will be given to the generator.
579
588
battle_output: Class that will be used to parse additional data the generator outputs.
589
+ set_cpus: Which cpus to execute the container on. Either a comma separated list or a hyphen-separated range.
590
+ A value of `None` means the container can use any core (but still only `cpus` many of them).
580
591
ui: Interface the program execution uses to update the ui.
581
592
582
593
Returns:
@@ -592,6 +603,7 @@ async def run(
592
603
cpus = cpus ,
593
604
battle_input = battle_input ,
594
605
battle_output = battle_output ,
606
+ set_cpus = set_cpus ,
595
607
ui = ui ,
596
608
),
597
609
)
@@ -632,6 +644,7 @@ async def run(
632
644
cpus : int = ...,
633
645
battle_input : Encodable | None = None ,
634
646
battle_output : type [Encodable ] | None = None ,
647
+ set_cpus : str | None = None ,
635
648
ui : ProgramUiProxy | None = None ,
636
649
) -> SolverResult :
637
650
"""Executes the solver on the given problem instance and parses its output into a problem solution.
@@ -643,6 +656,8 @@ async def run(
643
656
cpus: Number of physical cpus the solver can use.
644
657
battle_input: Additional data that will be given to the solver.
645
658
battle_output: Class that will be used to parse additional data the solver outputs.
659
+ set_cpus: Which cpus to execute the container on. Either a comma separated list or a hyphen-separated range.
660
+ A value of `None` means the container can use any core (but still only `cpus` many of them).
646
661
ui: Interface the program execution uses to update the ui.
647
662
648
663
Returns:
@@ -658,6 +673,7 @@ async def run(
658
673
cpus = cpus ,
659
674
battle_input = battle_input ,
660
675
battle_output = battle_output ,
676
+ set_cpus = set_cpus ,
661
677
ui = ui ,
662
678
),
663
679
)
@@ -710,7 +726,6 @@ class _UlimitArgs(TypedDict):
710
726
cpu_rt_period : int | None = None
711
727
cpu_rt_runtime : int | None = None
712
728
cpu_shares : int | None = None
713
- cpuset_cpus : str | None = None
714
729
cpuset_mems : str | None = None
715
730
device_cgroup_rules : list [str ] | None = None
716
731
device_read_bps : list [_DeviceRate ] | None = None
0 commit comments