Skip to content

Commit

Permalink
[bug/helpers_type] Fixing typo in fast-pauli helpers calcutate --> ca…
Browse files Browse the repository at this point in the history
…lculate
  • Loading branch information
jamesETsmith committed Nov 7, 2024
1 parent f9e94d0 commit ee6ea53
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 23 deletions.
15 changes: 12 additions & 3 deletions docs/cpp_api.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
C++ API
=======

.. toctree::
:maxdepth: 2

Pauli
-----
Expand All @@ -27,4 +25,15 @@ SummedPauliOp
-------------
.. doxygenstruct:: fast_pauli::SummedPauliOp
:project: fast_pauli
:members:
:members:

Helpers
-------
.. doxygenfunction:: fast_pauli::get_nontrivial_paulis
:project: fast_pauli
.. doxygenfunction:: fast_pauli::calculate_pauli_strings
:project: fast_pauli
.. doxygenfunction:: fast_pauli::calculate_pauli_strings_max_weight
:project: fast_pauli
.. doxygenfunction:: fast_pauli::get_sparse_repr
:project: fast_pauli
14 changes: 10 additions & 4 deletions docs/python_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ Python API
==========


.. automodule:: fast_pauli


Pauli
-----

Expand Down Expand Up @@ -33,4 +30,13 @@ SummedPauliOp

.. autoclass:: fast_pauli.SummedPauliOp
:members:
:special-members:
:special-members:


Helpers
-------

.. autofunction:: fast_pauli.helpers.calculate_pauli_strings
.. autofunction:: fast_pauli.helpers.calculate_pauli_strings_max_weight
.. autofunction:: fast_pauli.helpers.pauli_string_sparse_repr
.. autofunction:: fast_pauli.helpers.get_nontrivial_paulis
18 changes: 9 additions & 9 deletions fast_pauli/cpp/include/__pauli_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace fast_pauli
/**
* @brief Get the nontrivial sets of pauli matrices given a weight.
*
* @param weight
* @param weight The Pauli weight to get the nontrivial paulis for.
* @return std::vector<std::string>
*/
std::vector<std::string> get_nontrivial_paulis(size_t const weight)
Expand Down Expand Up @@ -62,8 +62,8 @@ std::vector<std::string> get_nontrivial_paulis(size_t const weight)
/**
* @brief Get all the combinations of k indices for a given array of size n.
*
* @param n
* @param k
* @param n The size of the array to get the combinations of.
* @param k The number of indices to choose.
* @return std::vector<std::vector<size_t>>
*/
std::vector<std::vector<size_t>> idx_combinations(size_t const n, size_t const k)
Expand Down Expand Up @@ -92,11 +92,11 @@ std::vector<std::vector<size_t>> idx_combinations(size_t const n, size_t const k
* @brief Calculate all possible PauliStrings for a given number of qubits and
* weight and return them in lexicographical order.
*
* @param n_qubits
* @param weight
* @param n_qubits The number of qubits.
* @param weight The Pauli weight.
* @return std::vector<PauliString>
*/
std::vector<PauliString> calcutate_pauli_strings(size_t const n_qubits, size_t const weight)
std::vector<PauliString> calculate_pauli_strings(size_t const n_qubits, size_t const weight)
{
// base case
if (weight == 0)
Expand Down Expand Up @@ -137,16 +137,16 @@ std::vector<PauliString> calcutate_pauli_strings(size_t const n_qubits, size_t c
* @brief Calculate all possible PauliStrings for a given number of qubits and
* all weights less than or equal to a given weight.
*
* @param n_qubits
* @param weight
* @param n_qubits The number of qubits.
* @param weight The Pauli weight.
* @return std::vector<PauliString>
*/
std::vector<PauliString> calculate_pauli_strings_max_weight(size_t n_qubits, size_t weight)
{
std::vector<PauliString> result;
for (size_t i = 0; i <= weight; ++i)
{
auto ps = calcutate_pauli_strings(n_qubits, i);
auto ps = calculate_pauli_strings(n_qubits, i);
result.insert(result.end(), ps.begin(), ps.end());
}
return result;
Expand Down
63 changes: 59 additions & 4 deletions fast_pauli/cpp/src/fast_pauli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1135,9 +1135,64 @@ SummedPauliOp
// Helpers
//
auto helpers_m = m.def_submodule("helpers");
helpers_m.def("get_nontrivial_paulis", &fp::get_nontrivial_paulis, "weight"_a);
helpers_m.def("calcutate_pauli_strings", &fp::calcutate_pauli_strings, "n_qubits"_a, "weight"_a);
helpers_m.def("get_nontrivial_paulis", &fp::get_nontrivial_paulis, "weight"_a,
R"%(Get all nontrivial Pauli strings up to a given weight.
Parameters
----------
weight : int
Maximum weight of Pauli strings to return
Returns
-------
List[str]
List of PauliStrings as strings
)%");

helpers_m.def("calculate_pauli_strings", &fp::calculate_pauli_strings, "n_qubits"_a, "weight"_a,
R"%(Calculate all Pauli strings for a given weight.
Parameters
----------
n_qubits : int
Number of qubits
weight : int
Weight of Pauli strings to return
Returns
-------
List[PauliString]
List of PauliStrings
)%");

helpers_m.def("calculate_pauli_strings_max_weight", &fp::calculate_pauli_strings_max_weight, "n_qubits"_a,
"weight"_a);
helpers_m.def("pauli_string_sparse_repr", &fp::get_sparse_repr<float_type>, "paulis"_a);
"weight"_a,
R"%(Calculate all Pauli strings up to and including a given weight.
Parameters
----------
n_qubits : int
Number of qubits
weight : int
Maximum weight of Pauli strings to return
Returns
-------
List[PauliString]
List of PauliStrings
)%");

helpers_m.def("pauli_string_sparse_repr", &fp::get_sparse_repr<float_type>, "paulis"_a,
R"%(Get a sparse representation of a list of Pauli strings.
Parameters
----------
paulis : List[PauliString]
List of PauliStrings
Returns
-------
List[Tuple[int, int]]
List of tuples representing the Pauli string in a sparse format
)%");
}
6 changes: 3 additions & 3 deletions fast_pauli/cpp/tests/test_pauli_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ TEST_CASE("idx combinations")
TEST_CASE("calculate pauli strings")
{
{
auto res = calcutate_pauli_strings(4, 0);
auto res = calculate_pauli_strings(4, 0);
CHECK(res.size() == 1);
CHECK(res[0] == PauliString("IIII"));
}

{
auto res = calcutate_pauli_strings(2, 1);
auto res = calculate_pauli_strings(2, 1);
CHECK(res.size() == 6);
CHECK(res[0] == PauliString("XI"));
CHECK(res[1] == PauliString("IX"));
Expand All @@ -127,7 +127,7 @@ TEST_CASE("calculate pauli strings")
}

{
auto res = calcutate_pauli_strings(4, 2);
auto res = calculate_pauli_strings(4, 2);
CHECK(res.size() == 54);
CHECK(res[0] == PauliString("XXII"));
CHECK(res[1] == PauliString("XIXI"));
Expand Down

0 comments on commit ee6ea53

Please sign in to comment.