static GList * _query_counter_hash(const gchar *key_str) { GPatternSpec *pattern = g_pattern_spec_new(key_str); GList *counters = NULL; gpointer key, value; GHashTableIter iter; gboolean single_match; _update_index(); single_match = _is_single_match(key_str); g_static_mutex_lock(&stats_query_mutex); g_hash_table_iter_init(&iter, counter_index); while (g_hash_table_iter_next(&iter, &key, &value)) { if (_is_pattern_matches_key(pattern, key)) { StatsCounterItem *counter = (StatsCounterItem *) value; counters = g_list_append(counters, counter); if (single_match) break; } } g_static_mutex_unlock(&stats_query_mutex); g_pattern_spec_free(pattern); return counters; }
space_partition(state_t const& st, operator_t const& H, bool store_matrix_elements = true) : subspaces(st.size()), tmp_state(make_zero_state(st)) { auto size = tmp_state.size(); // Iteration over all initial basis states for (index_t i = 0; i < size; ++i) { tmp_state(i) = amplitude_t(1.0); state_t final_state = H(tmp_state); // Iterate over non-zero final amplitudes foreach(final_state, [&](index_t f, amplitude_t amplitude) { if (triqs::utility::is_zero(amplitude)) return; auto i_subspace = subspaces.find_set(i); auto f_subspace = subspaces.find_set(f); if (i_subspace != f_subspace) subspaces.link(i_subspace, f_subspace); if (store_matrix_elements) matrix_elements[std::make_pair(i, f)] = amplitude; }); tmp_state(i) = amplitude_t(0.); } _update_index(); }
// Algorithm by Michel Ferrero // FIXME WARNING: Redundant implementation, must be revisited later std::pair<matrix_element_map_t, matrix_element_map_t> merge_subspaces(operator_t const& Cd, operator_t const& C, bool store_matrix_elements = true) { matrix_element_map_t Cd_elements, C_elements; std::set<index_t> initial_basis_states; for (index_t i = 0; i < tmp_state.size(); ++i) initial_basis_states.insert(i); do { bool merge_occured; index_t i = *initial_basis_states.cbegin(); auto apply_and_merge = [&](operator_t const& op, matrix_element_map_t& me, bool exclude_from_ibs) { index_t final_subspace = -1; // Iteration over all initial basis states for (index_t n = 0; n < tmp_state.size(); ++n) { // Is n in initial_subspace? if (subspaces.find_set(i) != subspaces.find_set(n)) continue; if (exclude_from_ibs && initial_basis_states.count(n) != 0) initial_basis_states.erase(n); tmp_state(n) = amplitude_t(1.); state_t final_state = op(tmp_state); foreach(final_state, [&](index_t f, amplitude_t amplitude) { if (triqs::utility::is_zero(amplitude)) return; auto f_subspace = subspaces.find_set(f); if (final_subspace == -1) final_subspace = f_subspace; else { if (final_subspace != f_subspace) { subspaces.link(final_subspace, f_subspace); merge_occured = true; } } if (store_matrix_elements) me.insert(std::make_pair(std::make_pair(n, f), amplitude)); }); tmp_state(n) = amplitude_t(0.); } i = final_subspace; }; do { merge_occured = false; // Apply op1 to i subspace and merge final subspaces // All used initial states will be excluded from initial_basis_states apply_and_merge(Cd, Cd_elements, true); if (i == -1) break; // No final subspace, just 0 // Apply op2 to i subspace and merge final subspaces apply_and_merge(C, C_elements, false); if (i == -1) break; // No final subspace, just 0 } while (merge_occured); // If there were merges, repeat application once more } while (initial_basis_states.size() != 0); _update_index(); return std::make_pair(Cd_elements, C_elements); }