Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions cpp/include/monoprop/Evolution.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,15 @@

#pragma once

#include <algorithm>
#include <bit>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <functional>
#include <limits>
#include <memory>
#include <numeric>
#include <optional>
#include <string_view>
#include <utility>
#include <vector>

#include "monoprop/MPFunctions.h"
#include "monoprop/TypeAliases.h"
#include "monoprop/Utilities.h"
#include "monoprop/detail/evolution/CosineRecomputeCallbacks.h"
#include "monoprop/detail/mpi/MPICompat.h"
#include "monoprop/detail/mpi/MPIUtils.h"
#include "monoprop/monopropExport.h"

namespace monoprop {
struct Layer;
class MPGraph;
class MPGraphView;

struct LayerCore;

/// One layer's rotation angle in factored form: the layer rotates by 2·gen_coeff·param.
struct LayerAngle {
double gen_coeff = 1.0; ///< the generator's coefficient for this layer
Expand Down Expand Up @@ -72,5 +52,3 @@ monoprop_EXPORT auto state_operator_derivative_local(VecD &state,
mpi::Comm comm,
const detail::LayerCosAccumulate &cos_acc) -> double;
} // namespace monoprop

#include "monoprop/detail/evolution/EvolutionHelpers.h"
12 changes: 2 additions & 10 deletions cpp/include/monoprop/MonomialPropagator.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include "monoprop/Validation.h"
#include "monoprop/algebra/PauliAlgebra.h"
#include "monoprop/detail/evolution/CosineRecompute.h"
#include "monoprop/detail/monomial_propagator/MonomialPropagatorCommon.h"
#include "monoprop/detail/mpi/MPICompat.h"
#include "monoprop/detail/mpi/MPIUtils.h"

Expand Down Expand Up @@ -287,12 +286,6 @@ class MonomialPropagator {
return ev_and_grad(request, comm, cos);
};

static auto expected_num_params(const VecZ &parameter_mapping) -> size_t;

template <typename Fn, typename R = std::invoke_result_t<Fn, const VecD &>>
static auto make_parameter_validated_functional(size_t expected_num_params, Fn func)
-> std::function<R(const VecD &)>;

/// Distribute op_dict across ranks and apply this rank's share; returns its new (terms, coeffs)
/// so caches can refresh.
auto apply_initial_operator_(const OperatorDict &op_dict) -> std::pair<MonomialList<NumModes>, VecD>;
Expand Down Expand Up @@ -469,6 +462,5 @@ class MonomialPropagator {

} // namespace monoprop

// These includes are here on purpose and should not be moved to the top
#include "monoprop/detail/monomial_propagator/MonomialPropagatorHelpers.h"
#include "monoprop/detail/monomial_propagator/MonomialPropagatorImpl.h"
// inline implementation
#include "monoprop/detail/monomial_propagator/MonomialPropagator.inl"
1 change: 1 addition & 0 deletions cpp/monoprop/Evolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "monoprop/MPGraph.h"
#include "monoprop/TypeAliases.h"
#include "monoprop/detail/evolution/CosineRecomputeCallbacks.h"
#include "monoprop/detail/mpi/Exchange.h"
#include "monoprop/detail/mpi/MPICompat.h"

Expand Down
1 change: 1 addition & 0 deletions cpp/monoprop/MPFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <stdexcept>

#include "monoprop/Evolution.h"
#include "monoprop/detail/evolution/CosineRecomputeCallbacks.h"

namespace monoprop {

Expand Down
3 changes: 2 additions & 1 deletion cpp/monoprop/TypeAliases.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <complex>
#include <cstddef>
#include <cstdint>
#include <format>
#include <functional>
#include <iterator>
#include <limits>
Expand All @@ -35,7 +36,6 @@
#include <vector>

#include <boost/unordered/unordered_flat_map.hpp>
#include <format>

#include "monoprop/Bitset.h"
#include "monoprop/core/Monomial.h"
Expand All @@ -47,6 +47,7 @@
}

namespace monoprop {
inline constexpr size_t kMissingIndex = std::numeric_limits<size_t>::max();

// materialize_row() returns a const ref (dense backend, zero-copy) or a fresh value (packed backend),
// so callers must bind with `const auto&` to extend the temporary's lifetime.
Expand Down Expand Up @@ -82,7 +83,7 @@

using VecZ = std::vector<size_t>;

#if defined(monoprop_WIDE_TERM_INDEX)

Check warning on line 86 in cpp/monoprop/TypeAliases.h

View workflow job for this annotation

GitHub Actions / clang-tidy analysis

preprocessor condition can be written more concisely using '#ifdef' [readability-use-concise-preprocessor-directives]
using TermIndex = std::uint64_t;
#else
using TermIndex = std::uint32_t;
Expand All @@ -100,7 +101,7 @@
using A::A;
default_init_allocator() = default;
template <typename U>
default_init_allocator(const default_init_allocator<U, typename a_traits::template rebind_alloc<U>> &o) noexcept

Check warning on line 104 in cpp/monoprop/TypeAliases.h

View workflow job for this annotation

GitHub Actions / clang-tidy analysis

single-argument constructors must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor]
: A(static_cast<const typename a_traits::template rebind_alloc<U> &>(o)) {}

template <typename U>
Expand Down
4 changes: 4 additions & 0 deletions cpp/monoprop/Validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ auto validate_only_rotate_len_k_(std::optional<size_t> only_rotate_len_k, size_t
}
}

auto expected_num_params(const VecZ &parameter_mapping) -> size_t {
return parameter_mapping.empty() ? 0 : *std::ranges::max_element(parameter_mapping) + 1;
}

// NOLINTEND(misc-use-internal-linkage)

} // namespace monoprop
2 changes: 2 additions & 0 deletions cpp/monoprop/Validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ monoprop_EXPORT auto validate_expected_graph_layers(size_t current_layers, size_
// only_rotate_len_k is optional; when set it must satisfy 0 < k <= max_k.
monoprop_EXPORT auto validate_only_rotate_len_k_(std::optional<size_t> only_rotate_len_k, size_t max_k) -> void;

monoprop_EXPORT auto expected_num_params(const VecZ &parameter_mapping) -> size_t;

} // namespace monoprop
2 changes: 1 addition & 1 deletion cpp/monoprop/detail/evolution/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ target_sources(
FILES
"CosineRecompute.h"
"CosineRecomputeCallbacks.h"
"EvolutionHelpers.h"
"CutoffContext.h"
"LayerBuilder.h"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,8 @@
#pragma once

#include "monoprop/TypeAliases.h"
#include "monoprop/algebra/MajoranaAlgebra.h"

namespace monoprop::detail {

inline constexpr size_t kMissingIndex = std::numeric_limits<size_t>::max();

inline auto empty_coeffs() -> const VecD & {
static const VecD coeffs;
return coeffs;
}

struct CutoffContext {
bool check_atol = false;
bool check_upper_atol = false;
Expand All @@ -38,7 +29,7 @@ struct CutoffContext {
if (!use_coeff_checks) {
return 0.0;
}
// Out-of-range indices read as zero: callers scan past the end of a shorter coeff vector.

const double coeff = i < coeffs.size() ? coeffs[i] : 0.0;
return std::abs(coeff);
}
Expand All @@ -49,5 +40,4 @@ struct CutoffContext {
}
auto is_below_sin(double abs_coeff) const -> bool { return check_atol && (abs_sin_val * abs_coeff <= atol_value); }
};

} // namespace monoprop::detail
9 changes: 7 additions & 2 deletions cpp/monoprop/detail/evolution/layer_build/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include "monoprop/Validation.h"
#include "monoprop/algebra/Algebra.h"
#include "monoprop/detail/evolution/EvolutionHelpers.h"
#include "monoprop/detail/evolution/CutoffContext.h"
#include "monoprop/detail/evolution/layer_build/Common.h"
#include "monoprop/detail/evolution/layer_build/Resolve.h"
#include "monoprop/detail/evolution/layer_build/Scan.h"
Expand Down Expand Up @@ -513,6 +513,11 @@ struct LayerBuildEngine {
}
};

static inline auto empty_coeffs() -> const VecD & {
static const VecD coeffs;
return coeffs;
}

// Primary-path layer builder: one fused scan, then two resolve passes into the chosen sink. See LayerBuilder.h.
template <size_t NumModes>
auto build_layer(MPOperator<NumModes> &local_op,
Expand All @@ -537,7 +542,7 @@ auto build_layer(MPOperator<NumModes> &local_op,
// Fused contraction runs at all rank counts (R>1 via the cross-rank half-rotation exchange).
const bool use_fused = (fused_contract != nullptr);
const auto cut_st = build_majorana_evolution_cutoff_state(atol, local_coeffs, upper_atol, param);
const auto &coeffs = local_coeffs ? local_coeffs->get() : empty_coeffs();
const auto &coeffs = local_coeffs.value_or(empty_coeffs()).get();
const CutoffEvaluator<NumModes> cut_eval{cutoff_fn};

// Fused cos sweep: fold the per-gate cosine scale into the scan's own coefficient pass. No length cap only (a
Expand Down
2 changes: 1 addition & 1 deletion cpp/monoprop/detail/evolution/layer_build/Resolve.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "monoprop/TypeAliases.h"
#include "monoprop/algebra/Algebra.h"
#include "monoprop/detail/evolution/EvolutionHelpers.h"
#include "monoprop/detail/evolution/CutoffContext.h"
#include "monoprop/detail/evolution/layer_build/Common.h"
#include "monoprop/detail/operator/MPOperator.h"

Expand Down
2 changes: 1 addition & 1 deletion cpp/monoprop/detail/evolution/layer_build/Scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "monoprop/TypeAliases.h"
#include "monoprop/Validation.h"
#include "monoprop/algebra/Algebra.h"
#include "monoprop/detail/evolution/EvolutionHelpers.h"
#include "monoprop/detail/evolution/CutoffContext.h"
#include "monoprop/detail/evolution/layer_build/Common.h"
#include "monoprop/detail/graph_encoding/MPGraphEncodingTypes.h"
#include "monoprop/detail/mpi/MPIUtils.h"
Expand Down
2 changes: 2 additions & 0 deletions cpp/monoprop/detail/graph_encoding/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ target_sources(
"MPGraphEncodingStorage.h"
"MPGraphEncodingTypes.h"
)

target_sources(monoprop-objs PRIVATE MPGraphEncoding.cpp)
Loading
Loading