| 25 | namespace cudaq { |
| 26 | |
| 27 | void bindOperatorsModule(nanobind::module_ &mod) { |
| 28 | // Binding the functions in `cudaq::operators` as `_pycudaq` submodule |
| 29 | // so it's accessible directly in the cudaq namespace. |
| 30 | auto operators_submodule = mod.def_submodule("operators"); |
| 31 | operators_submodule.def( |
| 32 | "empty", &matrix_op::empty, |
| 33 | "Returns sum operator with no terms. Note that a sum with no terms " |
| 34 | "multiplied by anything still is a sum with no terms."); |
| 35 | operators_submodule.def( |
| 36 | "identity", []() { return matrix_op::identity(); }, |
| 37 | "Returns product operator with constant value 1."); |
| 38 | operators_submodule.def( |
| 39 | "identity", |
| 40 | [](std::size_t target) { return matrix_op::identity(target); }, |
| 41 | nanobind::arg("target"), |
| 42 | "Returns an identity operator on the given target index."); |
| 43 | operators_submodule.def( |
| 44 | "identities", |
| 45 | [](std::size_t first, std::size_t last) { |
| 46 | return matrix_op_term(first, last); |
| 47 | }, |
| 48 | nanobind::arg("first"), nanobind::arg("last"), |
| 49 | "Creates a product operator that applies an identity operation to all " |
| 50 | "degrees of " |
| 51 | "freedom in the open range [first, last)."); |
| 52 | operators_submodule.def( |
| 53 | "number", &matrix_op::number<matrix_handler>, nanobind::arg("target"), |
| 54 | "Returns a number operator on the given target index."); |
| 55 | operators_submodule.def( |
| 56 | "parity", &matrix_op::parity<matrix_handler>, nanobind::arg("target"), |
| 57 | "Returns a parity operator on the given target index."); |
| 58 | operators_submodule.def( |
| 59 | "position", &matrix_op::position<matrix_handler>, nanobind::arg("target"), |
| 60 | "Returns a position operator on the given target index."); |
| 61 | operators_submodule.def( |
| 62 | "momentum", &matrix_op::momentum<matrix_handler>, nanobind::arg("target"), |
| 63 | "Returns a momentum operator on the given target index."); |
| 64 | operators_submodule.def( |
| 65 | "squeeze", &matrix_op::squeeze<matrix_handler>, nanobind::arg("target"), |
| 66 | "Returns a squeezing operator on the given target index."); |
| 67 | operators_submodule.def( |
| 68 | "displace", &matrix_op::displace<matrix_handler>, nanobind::arg("target"), |
| 69 | "Returns a displacement operator on the given target index."); |
| 70 | operators_submodule.def( |
| 71 | "canonicalized", |
| 72 | [](const matrix_op_term &orig) { |
| 73 | return matrix_op_term::canonicalize(orig); |
| 74 | }, |
| 75 | "Removes all identity operators from the operator."); |
| 76 | operators_submodule.def( |
| 77 | "canonicalized", |
| 78 | [](const matrix_op_term &orig, const std::set<std::size_t> °rees) { |
| 79 | return matrix_op_term::canonicalize(orig, degrees); |
| 80 | }, |
| 81 | "Expands the operator to act on all given degrees, applying identities " |
| 82 | "as needed. " |
| 83 | "The canonicalization will throw a runtime exception if the operator " |
| 84 | "acts on any degrees " |
no test coverage detected