首页 新闻 会员 周边 捐助

如何在C++中打开其他程序

0
悬赏园豆:5 [待解决问题]

我现在需要通过指令在C++执行过程中打开Python的程序可以怎么办?(也需要再Python中打开cpp文件)求大佬帮帮,最好附源码示例。

深秋晨风的主页 深秋晨风 | 初学一级 | 园豆:51
提问于:2024-11-09 22:29
< >
分享
所有回答(2)
0

试下调cmd

我才不是老家伙 | 园豆:276 (菜鸟二级) | 2024-11-11 14:22
0

正好有些素材:
cpp:
NB_MODULE(_madrona_simple_example_cpp, m) {
madrona::py::setupMadronaSubmodule(m);

nb::class_<Manager> (m, "SimpleGridworldSimulator")
    .def("__init__", [](Manager *self,
                        nb::ndarray<bool, nb::shape<nb::any, nb::any>,
                            nb::c_contig, nb::device::cpu> walls,
                        nb::ndarray<float, nb::shape<nb::any, nb::any>,
                            nb::c_contig, nb::device::cpu> rewards,
                        nb::ndarray<int32_t, nb::shape<nb::any, 2>,
                            nb::c_contig, nb::device::cpu> end_cells,
                        int64_t start_x,
                        int64_t start_y,
                        int64_t max_episode_length,
                        madrona::py::PyExecMode exec_mode,
                        int64_t num_worlds,
                        int64_t gpu_id) {
        int64_t grid_y = (int64_t)walls.shape(0);
        int64_t grid_x = (int64_t)walls.shape(1);

        if ((int64_t)rewards.shape(0) != grid_y ||
            (int64_t)rewards.shape(1) != grid_x) {
            throw std::runtime_error("walls and rewards shapes don't match");
        }

        Cell *cells =
            setupCellData(walls, rewards, end_cells, grid_x, grid_y);

        new (self) Manager(Manager::Config {
            .maxEpisodeLength = (uint32_t)max_episode_length,
            .execMode = exec_mode,
            .numWorlds = (uint32_t)num_worlds,
            .gpuID = (int)gpu_id,
        }, GridState {
            .cells = cells,
            .startX = (int32_t)start_x,
            .startY = (int32_t)start_y,
            .width = (int32_t)grid_x,
            .height = (int32_t)grid_y,
        });

        delete[] cells;
    }, nb::arg("walls"),
       nb::arg("rewards"),
       nb::arg("end_cells"),
       nb::arg("start_x"),
       nb::arg("start_y"),
       nb::arg("max_episode_length"),
       nb::arg("exec_mode"),
       nb::arg("num_worlds"),
       nb::arg("gpu_id") = -1)
    .def("step", &Manager::step)
    .def("reset_tensor", &Manager::resetTensor)
    .def("action_tensor", &Manager::actionTensor)
    .def("observation_tensor", &Manager::observationTensor)
    .def("reward_tensor", &Manager::rewardTensor)
    .def("done_tensor", &Manager::doneTensor)
    .def("results_tensor", &Manager::resultsTensor)
    .def("results2_tensor", &Manager::results2Tensor)
    .def("madronaEvents_tensor", &Manager::madronaEventsTensor)
    .def("madronaEventsResult_tensor", &Manager::madronaEventsResultTensor)
    .def("simulation_time_tensor", &Manager::simulationTimeTensor)
    .def("processParams_tensor",&Manager::processParamsTensor)
;

}

pyrhon:
grid_world = GridWorld(num_worlds, start_cell, end_cell, rewards, walls, enable_gpu_sim, gpu_id)
grid_world.step()

猝不及防 | 园豆:2878 (老鸟四级) | 2024-11-12 15:31
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册