我现在需要通过指令在C++执行过程中打开Python的程序可以怎么办?(也需要再Python中打开cpp文件)求大佬帮帮,最好附源码示例。
试下调cmd
正好有些素材:
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()