| 2472 | } |
| 2473 | |
| 2474 | void ExposePipeline(py::module &m) { |
| 2475 | py::class_<Pipeline, PyPipeline>(m, "Pipeline") |
| 2476 | .def(py::init( |
| 2477 | [](const PipelineParams ¶ms) { |
| 2478 | return std::make_unique<PyPipeline>(params); |
| 2479 | }), |
| 2480 | "params"_a |
| 2481 | ) |
| 2482 | // initialize from serialized pipeline |
| 2483 | .def(py::init( |
| 2484 | [](const string &serialized_pipe, |
| 2485 | const PipelineParams ¶ms) { |
| 2486 | return std::make_unique<PyPipeline>(serialized_pipe, params); |
| 2487 | }), |
| 2488 | "serialized_pipe"_a, |
| 2489 | "params"_a |
| 2490 | ) |
| 2491 | .def("AddOperator", |
| 2492 | static_cast<int (Pipeline::*)(const OpSpec &, std::string_view)> |
| 2493 | (&Pipeline::AddOperator)) |
| 2494 | .def("AddOperator", |
| 2495 | static_cast<int (Pipeline::*)(const OpSpec &, std::string_view, int)> |
| 2496 | (&Pipeline::AddOperator)) |
| 2497 | .def("AddOperatorInstance", |
| 2498 | [](Pipeline *p, const OpSpec &spec, std::string_view name, |
| 2499 | std::unique_ptr<OperatorBase> op) { |
| 2500 | return p->AddOperatorInstance(spec, name, std::move(op)); |
| 2501 | }) |
| 2502 | .def("AddOperatorInstance", |
| 2503 | [](Pipeline *p, const OpSpec &spec, std::string_view name, |
| 2504 | std::unique_ptr<OperatorBase> op, int logical_id) { |
| 2505 | return p->AddOperatorInstance(spec, name, std::move(op), logical_id); |
| 2506 | }) |
| 2507 | .def("GetOperatorNode", &Pipeline::GetOperatorNode) |
| 2508 | .def("Build", |
| 2509 | [](Pipeline *p, const std::vector<OutputDesc> &outputs) { |
| 2510 | std::vector<PipelineOutputDesc> build_args; |
| 2511 | for (auto& out : outputs) { |
| 2512 | build_args.emplace_back(to_struct<PipelineOutputDesc>(out)); |
| 2513 | } |
| 2514 | p->Build(build_args); |
| 2515 | }) |
| 2516 | .def("Build", [](Pipeline *p) { p->Build(); }) |
| 2517 | .def("Shutdown", &Pipeline::Shutdown, py::call_guard<py::gil_scoped_release>()) |
| 2518 | .def("EnableCheckpointing", |
| 2519 | [](Pipeline *p, bool checkpointing) { |
| 2520 | p->EnableCheckpointing(checkpointing); |
| 2521 | }, |
| 2522 | "checkpointing"_a = true) |
| 2523 | .def("GetSerializedCheckpoint", |
| 2524 | [](Pipeline *p, const ExternalContextCheckpoint &external_ctx_cpt) -> py::bytes { |
| 2525 | return p->GetSerializedCheckpoint(external_ctx_cpt); |
| 2526 | }) |
| 2527 | .def("RestoreFromSerializedCheckpoint", |
| 2528 | [](Pipeline *p, const std::string &serialized_checkpoint) { |
| 2529 | return p->RestoreFromSerializedCheckpoint(serialized_checkpoint); |
| 2530 | }) |
| 2531 | .def("executor_statistics", |
no test coverage detected