Skip to content

Commit

Permalink
[python] Expose solutions to Python.
Browse files Browse the repository at this point in the history
  • Loading branch information
krivenko committed Nov 25, 2016
1 parent 4f64cc9 commit ef0cc9b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
9 changes: 7 additions & 2 deletions c++/rectangle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ struct rectangle {

std::complex<double> hilbert_transform(std::complex<double> z, bool multiply_by_e = false) const {
if(multiply_by_e)
// -\int_{c-w/2}^{c+w/2} d\epsilon' \frac{\epsilon'}{\epsilon' - \epsilon - i0}
// -h \int_{c-w/2}^{c+w/2} d\epsilon' \frac{\epsilon'}{\epsilon' - \epsilon - i0}
return -height*(width + z*std::log((center + width/2 - z)/(center - width/2 - z)));
else
// -\int_{c-w/2}^{c+w/2} d\epsilon' \frac{1}{\epsilon' - \epsilon - i0}
// -h \int_{c-w/2}^{c+w/2} d\epsilon' \frac{1}{\epsilon' - \epsilon - i0}
return -height*std::log((center + width/2 - z)/(center - width/2 - z));
}
vector<double> tail_coefficients(long order_min, long order_max, bool multiply_by_e = false) const {
Expand Down Expand Up @@ -135,6 +135,11 @@ struct rectangle {
pod_t(rectangle const& r) : center(r.center), width(r.width), height(r.height) {}
};

// Convert to tuple (center,width,height)
operator std::tuple<double,double,double>() const {
return std::make_tuple(center,width,height);
}

};

}
Expand Down
3 changes: 3 additions & 0 deletions c++/som_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ class som_core {
template<typename MeshType>
friend void triqs_gf_view_assign_delegation(gf_view<MeshType> g, som_core const& cont);

/// Accumulated solutions
std::vector<configuration> const& get_solutions() const { return results; }

/// Accumulated objective function histograms
std::vector<histogram> const& get_histograms() const { return histograms; }

Expand Down
11 changes: 11 additions & 0 deletions python/core_desc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# Add here anything to add in the C++ code at the start, e.g. namespace using
module.add_preamble("""
#include <triqs/python_tools/converters/pair.hpp>
#include <triqs/python_tools/converters/tuple.hpp>
#include <triqs/python_tools/converters/vector.hpp>
using namespace triqs::gfs;
using namespace triqs::statistics;
Expand Down Expand Up @@ -60,6 +61,16 @@
getter = cfunction("int get_run_status ()"),
doc = """Status of the run on exit """)

solutions_cp = """
auto const& solutions = self_c.get_solutions();
std::vector<std::vector<std::tuple<double,double,double>>> result;
for(auto const& sol : solutions) result.emplace_back(sol.begin(), sol.end());
"""
c.add_property(name = "solutions",
getter = cfunction(signature = "std::vector<std::vector<std::tuple<double,double,double>>>()",
calling_pattern = solutions_cp),
doc = """Accumulated solutions as lists of rectangle parameter tuples (center,width,height)""")

c.add_property(name = "histograms",
getter = cfunction("std::vector<histogram> get_histograms ()"),
doc = """Accumulated objective function histograms""")
Expand Down

0 comments on commit ef0cc9b

Please sign in to comment.