MCPcopy
hub / github.com/ray-project/ray / test_map_operator_ray_args

Function test_map_operator_ray_args

python/ray/data/tests/test_map_operator.py:380–420  ·  view source on GitHub ↗
(shutdown_only, use_actors)

Source from the content-addressed store, hash-verified

378
379@pytest.mark.parametrize("use_actors", [False, True])
380def test_map_operator_ray_args(shutdown_only, use_actors):
381 ray.shutdown()
382 ray.init(num_cpus=0, num_gpus=1)
383 # Create with inputs.
384 input_op = InputDataBuffer(
385 DataContext.get_current(), make_ref_bundles([[i] for i in range(10)])
386 )
387 compute_strategy = ActorPoolStrategy(size=1) if use_actors else TaskPoolStrategy()
388 op = MapOperator.create(
389 _mul2_map_data_prcessor,
390 input_op=input_op,
391 data_context=DataContext.get_current(),
392 name="TestMapper",
393 compute_strategy=compute_strategy,
394 ray_remote_args={"num_cpus": 0, "num_gpus": 1},
395 )
396
397 # Feed data and block on exec.
398 op.start(ExecutionOptions())
399 if use_actors:
400 # Wait for the actor to start.
401 run_op_tasks_sync(op)
402
403 while input_op.has_next():
404 if use_actors:
405 # For actors, we need to check capacity before adding input
406 # and process tasks when the actor pool is at capacity.
407 while not op.can_add_input():
408 run_one_op_task(op)
409
410 assert op.can_add_input()
411 op.add_input(input_op.get_next(), 0)
412
413 op.all_inputs_done()
414 run_op_tasks_sync(op)
415
416 # Check we don't hang and complete with num_gpus=1.
417 outputs = _take_outputs(op)
418 expected = [[i * 2] for i in range(10)]
419 assert sorted(outputs) == expected, f"Expected {expected}, got {outputs}"
420 assert op.has_completed()
421
422
423@pytest.mark.parametrize("use_actors", [False, True])

Callers

nothing calls this directly

Calls 15

has_nextMethod · 0.95
InputDataBufferClass · 0.90
make_ref_bundlesFunction · 0.90
ActorPoolStrategyClass · 0.90
TaskPoolStrategyClass · 0.90
ExecutionOptionsClass · 0.90
run_op_tasks_syncFunction · 0.90
run_one_op_taskFunction · 0.90
_take_outputsFunction · 0.90
rangeFunction · 0.70
shutdownMethod · 0.65
initMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…