Skip to content

Commit

Permalink
[feature/CI_setup] Cleaning up problems from other compilers
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesETsmith committed Jun 6, 2024
1 parent fce60ba commit 2575f07
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@ __pycache__
logs
scratch
notes
.cache
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ include(cmake/CPM.cmake)

# Dependencies
cpmaddpackage("gh:doctest/[email protected]")
# cpmaddpackage("gh:p-ranav/[email protected]")
cpmaddpackage("gh:pybind/[email protected]")
cpmaddpackage("gh:fmtlib/fmt#10.2.1")
cpmaddpackage("gh:kokkos/mdspan#b885a2c60ad42f9e1aaa0d317a38105b950cbed0")
Expand Down Expand Up @@ -62,9 +61,8 @@ target_compile_options(
-Werror
# -stdlib=libc++
${FAST_PAULI_EXTRA_CXX_COMPILE_FLAGS})
target_link_options(fast_pauli INTERFACE ${FAST_PAULI_EXTRA_CXX_LD_FLAGS}
-fuse-ld=mold)
# target_compile_definitions(fast_pauli INTERFACE)
# target_link_options(fast_pauli INTERFACE ${FAST_PAULI_EXTRA_CXX_LD_FLAGS}
# -fuse-ld=mold) target_compile_definitions(fast_pauli INTERFACE)

# Testing
include(CTest)
Expand Down
1 change: 1 addition & 0 deletions include/__factory.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef __FAST_PAULI_FACTORY_HPP
#define __FAST_PAULI_FACTORY_HPP

#include <algorithm>
#include <array>
#include <complex>
#include <experimental/mdspan>
Expand Down
3 changes: 0 additions & 3 deletions include/__pauli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ struct Pauli {
} // namespace fast_pauli

// Adding specialization to the fmt library so we can easily print Pauli
namespace fmt {
template <> struct fmt::formatter<fast_pauli::Pauli> {
constexpr auto parse(format_parse_context &ctx) { return ctx.begin(); }

Expand Down Expand Up @@ -199,6 +198,4 @@ template <> struct fmt::formatter<std::complex<double>> {
}
};

} // namespace fmt

#endif // __PAULI_HPP
50 changes: 23 additions & 27 deletions include/__pauli_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ struct PauliString {
* @brief Default constructor, initialize weight and empty vector for paulis.
*
*/
constexpr PauliString() noexcept = default;
PauliString() noexcept = default;

/**
* @brief Constructs a PauliString from a span of pauli operators and
* calculates the weight.
*
*/
constexpr PauliString(std::span<fast_pauli::Pauli> const &paulis)
PauliString(std::span<fast_pauli::Pauli> const &paulis)
: weight(0), paulis(paulis.begin(), paulis.end()) {
for (auto const &pauli : paulis) {
weight += pauli.code > 0;
Expand All @@ -51,7 +51,7 @@ struct PauliString {
* This is often the most compact way to initialize a PauliString.
*
*/
constexpr PauliString(std::string const &str) : weight(0) {
PauliString(std::string const &str) : weight(0) {
for (auto const &c : str) {
switch (c) {
case 'I':
Expand Down Expand Up @@ -81,11 +81,11 @@ struct PauliString {
* @brief
*
*/
constexpr PauliString(char const *str) : PauliString(std::string(str)) {}
PauliString(char const *str) : PauliString(std::string(str)) {}

constexpr PauliString(PauliString const &other)
PauliString(PauliString const &other)
: weight(other.weight), paulis(other.paulis){};
constexpr PauliString &operator=(PauliString const &other) {
PauliString &operator=(PauliString const &other) {
this->weight = other.weight;
this->paulis = other.paulis;
return *this;
Expand All @@ -98,16 +98,16 @@ struct PauliString {
/**
* @brief Return the number of qubits in the PauliString.
*
* @return constexpr size_t
* @return size_t
*/
constexpr size_t n_qubits() const noexcept { return paulis.size(); }
size_t n_qubits() const noexcept { return paulis.size(); }

/**
* @brief Return the dimension (2^n_qubits) of the PauliString.
*
* @return constexpr size_t
* @return size_t
*/
constexpr size_t dims() const noexcept { return 1UL << paulis.size(); }
size_t dims() const noexcept { return 1UL << paulis.size(); }

/**
* @brief Get the sparse representation of the pauli string matrix.
Expand All @@ -126,8 +126,8 @@ struct PauliString {
* @param m The values of the matrix
*/
template <std::floating_point T>
constexpr void get_sparse_repr(std::vector<size_t> &j, std::vector<size_t> &k,
std::vector<std::complex<T>> &m) const {
void get_sparse_repr(std::vector<size_t> &j, std::vector<size_t> &k,
std::vector<std::complex<T>> &m) const {
// We reverse the view here because the tensor product is taken from right
// to left
auto ps = paulis | std::views::reverse;
Expand Down Expand Up @@ -184,11 +184,11 @@ struct PauliString {
* @tparam T The floating point base to use for all the complex numbers
* @param v The input vector to apply the PauliString to. Must be the same
* size as PauliString.dims().
* @return constexpr std::vector<std::complex<T>> The output state after
* @return std::vector<std::complex<T>> The output state after
* applying the PauliString.
*/
template <std::floating_point T>
constexpr std::vector<std::complex<T>>
std::vector<std::complex<T>>
apply(std::vector<std::complex<T>> const &v) const {
// Input check
if (v.size() != dims()) {
Expand All @@ -214,11 +214,11 @@ struct PauliString {
* @tparam T The floating point base to use for all the complex numbers
* @param v The input vector to apply the PauliString to. Must be the same
* size as PauliString.dims().
* @return constexpr std::vector<std::complex<T>> The output state after
* @return std::vector<std::complex<T>> The output state after
* applying the PauliString.
*/
template <std::floating_point T>
constexpr std::vector<std::complex<T>>
std::vector<std::complex<T>>
apply(std::mdspan<std::complex<T>, std::dextents<size_t, 1>> v) const {
// Input check
if (v.size() != dims()) {
Expand Down Expand Up @@ -251,12 +251,11 @@ struct PauliString {
* @param c Multiplication factor to apply to the PauliString
*/
template <std::floating_point T>
constexpr void
apply_batch(std::mdspan<std::complex<T>, std::dextents<size_t, 2>>
new_states_T, // extent(0) = dims, extent(1) = n_states
std::mdspan<std::complex<T>, std::dextents<size_t, 2>> const
states_T, // extent(0) = dims, extent(1) = n_states
std::complex<T> const c) const {
void apply_batch(std::mdspan<std::complex<T>, std::dextents<size_t, 2>>
new_states_T, // extent(0) = dims, extent(1) = n_states
std::mdspan<std::complex<T>, std::dextents<size_t, 2>> const
states_T, // extent(0) = dims, extent(1) = n_states
std::complex<T> const c) const {
// Input check
if (states_T.extent(0) != dims()) {
auto error_msg =
Expand Down Expand Up @@ -297,10 +296,10 @@ struct PauliString {
* @brief Get the dense representation of the object as a 2D-std::vector
*
* @tparam T The floating point base to use for all the complex numbers
* @return constexpr std::vector<std::vector<std::complex<T>>>
* @return std::vector<std::vector<std::complex<T>>>
*/
template <std::floating_point T>
constexpr std::vector<std::vector<std::complex<T>>> get_dense_repr() const {
std::vector<std::vector<std::complex<T>>> get_dense_repr() const {
//
std::vector<size_t> j, k;
std::vector<std::complex<T>> m;
Expand Down Expand Up @@ -450,7 +449,6 @@ std::vector<PauliString> calculate_pauli_strings_max_weight(size_t n_qubits,
// fmt::formatter specialization
//

namespace fmt {
//
template <> struct fmt::formatter<fast_pauli::PauliString> {
constexpr auto parse(format_parse_context &ctx) { return ctx.begin(); }
Expand All @@ -462,6 +460,4 @@ template <> struct fmt::formatter<fast_pauli::PauliString> {
}
};

} // namespace fmt

#endif // __PAULI_STRING_HPP

0 comments on commit 2575f07

Please sign in to comment.