Skip to content

Commit

Permalink
Add clone methods for fp structs
Browse files Browse the repository at this point in the history
  • Loading branch information
stand-by committed Dec 10, 2024
1 parent 078beed commit 8c00327
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")

# Set up OpenMP
find_package(OpenMP REQUIRED)
Expand Down
47 changes: 43 additions & 4 deletions fast_pauli/cpp/src/fast_pauli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ Returns
-------
np.ndarray
2D numpy array of complex numbers
)%")
.def(
"clone", [](fp::Pauli const &self) { return fp::Pauli(self); },
R"%(Returns a copy of the Pauli object.
Returns
-------
Pauli
A copy of the Pauli object
)%")
.def(
"__str__", [](fp::Pauli const &self) { return fmt::format("{}", self); },
Expand Down Expand Up @@ -314,7 +323,16 @@ Returns
-------
np.ndarray
2D numpy array of complex numbers
)%");
)%")
.def(
"clone", [](fp::PauliString const &self) { return fp::PauliString(self); },
R"%(Returns a copy of the PauliString object.
Returns
-------
PauliString
A copy of the PauliString object
)%");

//
//
Expand Down Expand Up @@ -735,7 +753,6 @@ dedupe : bool
.def_prop_ro("n_qubits", &fp::PauliOp<float_type>::n_qubits, "int: The number of qubits in PauliOp")
.def_prop_ro("n_pauli_strings", &fp::PauliOp<float_type>::n_pauli_strings,
"int: The number of PauliString terms in PauliOp")
// TODO these may dangerous, keep an eye on them if users start modifying internals
.def_prop_ro(
"coeffs", [](fp::PauliOp<float_type> const &self) { return self.coeffs; },
"List[complex]: Ordered list of coefficients corresponding to Pauli strings")
Expand Down Expand Up @@ -889,7 +906,18 @@ Returns
-------
np.ndarray
2D numpy array of complex numbers with a shape of :math:`2^n \times 2^n, n` - number of qubits
)%");
)%")
.def(
"clone", [](fp::PauliOp<float_type> const &self) { return fp::PauliOp<float_type>(self); },
R"%(Returns a copy of the PauliOp object.
Returns
-------
PauliOp
A copy of the PauliOp object
)%")

;

//
//
Expand Down Expand Up @@ -1120,7 +1148,18 @@ Returns
np.ndarray
3D numpy array of complex numbers with a shape of (n_operators, 2^n_qubits, 2^n_qubits)
)%")
//
.def(
"clone",
[](fp::SummedPauliOp<float_type> const &self) {
return fp::SummedPauliOp<float_type>(self.pauli_strings, self.coeffs_raw);
},
R"%(Returns a copy of the SummedPauliOp object.
Returns
-------
SummedPauliOp
A copy of the SummedPauliOp object
)%")
.def("square", &fp::SummedPauliOp<float_type>::square, R"%(Square the SummedPauliOp.
Returns
Expand Down

0 comments on commit 8c00327

Please sign in to comment.