MCPcopy Create free account
hub / github.com/NVIDIA/cuda-quantum / bindSpinModule

Function bindSpinModule

python/runtime/cudaq/operators/py_spin_op.cpp:53–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53void bindSpinModule(nanobind::module_ &mod) {
54 // Binding the functions in `cudaq::spin` as `_pycudaq` submodule
55 // so it's accessible directly in the cudaq namespace.
56 auto spin_submodule = mod.def_submodule("spin");
57 spin_submodule.def(
58 "empty", &spin_op::empty,
59 "Returns sum operator with no terms. Note that a sum with no terms "
60 "multiplied by anything still is a sum with no terms.");
61 spin_submodule.def(
62 "identity", []() { return spin_op::identity(); },
63 "Returns product operator with constant value 1.");
64 // here for consistency with other operators
65 spin_submodule.def(
66 "identity", [](std::size_t target) { return spin_op::identity(target); },
67 nanobind::arg("target"),
68 "Returns an identity operator on the given target index.");
69 spin_submodule.def(
70 "identities",
71 [](std::size_t first, std::size_t last) {
72 return spin_op_term(first, last);
73 },
74 nanobind::arg("first"), nanobind::arg("last"),
75 "Creates a product operator that applies an identity operation to all "
76 "degrees of "
77 "freedom in the open range [first, last).");
78 spin_submodule.def("i", &spin_op::i<spin_handler>, nanobind::arg("target"),
79 "Returns a Pauli I spin operator on the given "
80 "target qubit index.");
81 spin_submodule.def(
82 "x", &spin_op::x<spin_handler>, nanobind::arg("target"),
83 "Returns a Pauli X spin operator on the given target qubit index.");
84 spin_submodule.def(
85 "y", &spin_op::y<spin_handler>, nanobind::arg("target"),
86 "Returns a Pauli Y spin operator on the given target qubit index.");
87 spin_submodule.def(
88 "z", &spin_op::z<spin_handler>, nanobind::arg("target"),
89 "Returns a Pauli Z spin operator on the given target qubit index.");
90 spin_submodule.def("plus", &spin_op::plus<spin_handler>,
91 nanobind::arg("target"),
92 "Return a sigma plus spin operator on the given "
93 "target qubit index.");
94 spin_submodule.def("minus", &spin_op::minus<spin_handler>,
95 nanobind::arg("target"),
96 "Return a sigma minus spin operator on the given "
97 "target qubit index.");
98 spin_submodule.def(
99 "canonicalized",
100 [](const spin_op_term &orig) { return spin_op_term::canonicalize(orig); },
101 "Removes all identity operators from the operator.");
102 spin_submodule.def(
103 "canonicalized",
104 [](const spin_op_term &orig, const std::set<std::size_t> &degrees) {
105 return spin_op_term::canonicalize(orig, degrees);
106 },
107 "Expands the operator to act on all given degrees, applying identities "
108 "as needed. "
109 "The canonicalization will throw a runtime exception if the operator "
110 "acts on any degrees "

Callers 1

bindSpinWrapperFunction · 0.85

Calls 1

identityFunction · 0.85

Tested by

no test coverage detected