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

Function bindSpinOperator

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

Source from the content-addressed store, hash-verified

126}
127
128void bindSpinOperator(nanobind::module_ &mod) {
129
130 auto spin_op_class = nanobind::class_<spin_op>(mod, "SpinOperator");
131 auto spin_op_term_class =
132 nanobind::class_<spin_op_term>(mod, "SpinOperatorTerm");
133
134 spin_op_class
135 .def(
136 "__iter__",
137 [](spin_op &self) {
138 nanobind::list items;
139 for (auto it = self.begin(); it != self.end(); ++it)
140 items.append(nanobind::cast(*it));
141 return items.attr("__iter__")();
142 },
143 "Loop through each term of the operator.")
144
145 // properties
146
147 .def_prop_ro("parameters", &spin_op::get_parameter_descriptions,
148 "Returns a dictionary that maps each parameter "
149 "name to its description.")
150 .def_prop_ro("degrees", &spin_op::degrees,
151 "Returns a vector that lists all degrees of "
152 "freedom that the operator targets. "
153 "The order of degrees is from smallest to largest "
154 "and reflects the ordering of "
155 "the matrix returned by `to_matrix`. "
156 "Specifically, the indices of a statevector "
157 "with two qubits are {00, 01, 10, 11}. An "
158 "ordering of degrees {0, 1} then indicates "
159 "that a state where the qubit with index 0 equals "
160 "1 with probability 1 is given by "
161 "the vector {0., 1., 0., 0.}.")
162 .def_prop_ro("min_degree", &spin_op::min_degree,
163 "Returns the smallest index of the degrees of "
164 "freedom that the operator targets.")
165 .def_prop_ro("max_degree", &spin_op::max_degree,
166 "Returns the smallest index of the degrees of "
167 "freedom that the operator targets.")
168 .def_prop_ro("term_count", &spin_op::num_terms,
169 "Returns the number of terms in the operator.")
170 // only exists for spin operators
171 .def_prop_ro("qubit_count", &spin_op::num_qubits<spin_handler>,
172 "Return the number of qubits this operator acts on.")
173
174 // constructors
175
176 .def(nanobind::init<>(),
177 "Creates a default instantiated sum. A default instantiated "
178 "sum has no value; it will take a value the first time an "
179 "arithmetic operation "
180 "is applied to it. In that sense, it acts as both the additive and "
181 "multiplicative "
182 "identity. To construct a `0` value in the mathematical sense "
183 "(neutral element "
184 "for addition), use `empty()` instead.")
185 .def(nanobind::init<std::size_t>(), nanobind::arg("size"),

Callers 1

bindSpinWrapperFunction · 0.85

Calls 15

cmat_to_numpyFunction · 0.85
kwargs_to_param_mapFunction · 0.85
scalar_operatorClass · 0.85
identityFunction · 0.85
evaluate_coefficientMethod · 0.80
get_raw_dataMethod · 0.80
for_each_termMethod · 0.80
for_each_pauliMethod · 0.80
get_pauli_wordMethod · 0.80
distribute_termsMethod · 0.80

Tested by

no test coverage detected