| 21 | namespace cudaq { |
| 22 | |
| 23 | void bindResources(nanobind::module_ &mod) { |
| 24 | using namespace cudaq; |
| 25 | |
| 26 | nanobind::class_<Resources>( |
| 27 | mod, "Resources", |
| 28 | R"#(A data-type containing the results of a call to :func:`estimate_resources`. |
| 29 | This includes all gate counts.)#") |
| 30 | .def(nanobind::init<>()) |
| 31 | .def( |
| 32 | "dump", [](Resources &self) { self.dump(); }, |
| 33 | "Print a string of the raw resource counts data to the " |
| 34 | "terminal.\n") |
| 35 | .def( |
| 36 | "count_controls", |
| 37 | [](Resources &self, const std::string &gate, size_t nControls) { |
| 38 | return self.count_controls(gate, nControls); |
| 39 | }, |
| 40 | "Get the number of occurrences of a given gate with the given number " |
| 41 | "of controls") |
| 42 | .def( |
| 43 | "count", |
| 44 | [](Resources &self, const std::string &gate) { |
| 45 | return self.count(gate); |
| 46 | }, |
| 47 | "Get the number of occurrences of a given gate with any number of " |
| 48 | "controls") |
| 49 | .def( |
| 50 | "count", [](Resources &self) { return self.count(); }, |
| 51 | "Get the total number of occurrences of all gates") |
| 52 | .def( |
| 53 | "__str__", |
| 54 | [](Resources &self) { |
| 55 | std::stringstream ss; |
| 56 | self.dump(ss); |
| 57 | return ss.str(); |
| 58 | }, |
| 59 | "Return a string of the raw resource counts that are stored in " |
| 60 | "`self`.\n") |
| 61 | .def( |
| 62 | "to_dict", [](Resources &self) { return self.gateCounts(); }, |
| 63 | "Return a dictionary of the raw resource counts that are stored in " |
| 64 | "`self`.\n") |
| 65 | .def_prop_ro("num_qubits", &Resources::getNumQubits, |
| 66 | "The total number of qubits allocated in the kernel.\n") |
| 67 | .def_prop_ro("num_used_qubits", &Resources::getNumUsedQubits, |
| 68 | "The number of qubits touched by at least one quantum " |
| 69 | "operation.\n") |
| 70 | .def_prop_ro("depth", &Resources::getCircuitDepth, |
| 71 | "The circuit depth (longest gate chain on any qubit).\n") |
| 72 | .def_prop_ro( |
| 73 | "gate_count_by_arity", |
| 74 | [](Resources &self) { return self.getGateCountsByArity(); }, |
| 75 | "Gate counts by qubit arity, as a dict mapping arity to count.\n") |
| 76 | .def("gate_count_for_arity", &Resources::getGateCountByArity, |
| 77 | nanobind::arg("arity"), |
| 78 | "Get gate count for a specific qubit arity (total qubits " |
| 79 | "including controls and targets). Returns 0 if no gates of " |
| 80 | "that arity exist.") |
no test coverage detected