Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreMarchand20 committed Oct 15, 2024
1 parent 4707f97 commit 18517a3
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 188 deletions.
53 changes: 25 additions & 28 deletions cmake_modules/FindMPI4PY.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,32 @@

# https://compacc.fnal.gov/projects/repositories/entry/synergia2/CMake/FindMPI4PY.cmake?rev=c147eafb60728606af4fe7b1b161a660df142e9a

if(NOT MPI4PY_INCLUDE_DIR)
if (NOT PYTHON_EXECUTABLE)
set(PYTHON_EXECUTABLE "python3")
endif(NOT PYTHON_EXECUTABLE)
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" "-c" "import mpi4py; print(mpi4py.get_include())"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE MPI4PY_INCLUDE_DIR
RESULT_VARIABLE MPI4PY_COMMAND_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(MPI4PY_COMMAND_RESULT)
message("jfa: mpi4py not found")
if(NOT PYTHON_EXECUTABLE)
set(PYTHON_EXECUTABLE "python3")
endif(NOT PYTHON_EXECUTABLE)
execute_process(COMMAND "which" "${PYTHON_EXECUTABLE}")
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" "-c" "import mpi4py; print(mpi4py.get_include())"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE MPI4PY_INCLUDE_DIR
RESULT_VARIABLE MPI4PY_COMMAND_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(MPI4PY_COMMAND_RESULT)
message("jfa: mpi4py not found")
set(MPI4PY_FOUND FALSE)
else(MPI4PY_COMMAND_RESULT)
if(MPI4PY_INCLUDE_DIR MATCHES "Traceback")
message("jfa: mpi4py matches traceback")
## Did not successfully include MPI4PY
set(MPI4PY_FOUND FALSE)
else(MPI4PY_COMMAND_RESULT)
if(MPI4PY_INCLUDE_DIR MATCHES "Traceback")
message("jfa: mpi4py matches traceback")
## Did not successfully include MPI4PY
set(MPI4PY_FOUND FALSE)
else(MPI4PY_INCLUDE_DIR MATCHES "Traceback")
## successful
set(MPI4PY_FOUND TRUE)
set(MPI4PY_INCLUDE_DIR
${MPI4PY_INCLUDE_DIR}
CACHE STRING "mpi4py include path")
endif(MPI4PY_INCLUDE_DIR MATCHES "Traceback")
endif(MPI4PY_COMMAND_RESULT)
else(NOT MPI4PY_INCLUDE_DIR)
set(MPI4PY_FOUND TRUE)
endif(NOT MPI4PY_INCLUDE_DIR)
else(MPI4PY_INCLUDE_DIR MATCHES "Traceback")
## successful
set(MPI4PY_FOUND TRUE)
set(MPI4PY_INCLUDE_DIR
${MPI4PY_INCLUDE_DIR}
CACHE STRING "mpi4py include path")
endif(MPI4PY_INCLUDE_DIR MATCHES "Traceback")
endif(MPI4PY_COMMAND_RESULT)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MPI4PY DEFAULT_MSG MPI4PY_INCLUDE_DIR)
13 changes: 2 additions & 11 deletions example/use_custom_dense_block_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,8 @@
)

# Build HMatrix
hmatrix_builder = Htool.HMatrixBuilder(
target_cluster,
target_cluster,
epsilon,
eta,
"N",
"N",
-1,
mpi4py.MPI.COMM_WORLD.rank,
mpi4py.MPI.COMM_WORLD.rank,
)
# low_rank_generator = CustomSVD(generator)
hmatrix_builder = Htool.HMatrixBuilder(epsilon, eta, "N", "N")

hmatrix_builder.set_dense_blocks_generator(custom_dense_blocks_generator)

Expand Down
14 changes: 2 additions & 12 deletions example/use_custom_low_rank_approximation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,8 @@
low_rank_generator = CustomSVD(generator)

# Build HMatrix
hmatrix_builder = Htool.HMatrixBuilder(
target_cluster,
source_cluster,
epsilon,
eta,
"N",
"N",
-1,
mpi4py.MPI.COMM_WORLD.rank,
mpi4py.MPI.COMM_WORLD.rank,
)
hmatrix_builder.set_low_rank_generator(low_rank_generator)
hmatrix_builder = Htool.HMatrixBuilder(epsilon, eta, "N", "N")
# or hmatrix_builder.set_low_rank_generator(low_rank_generator)

# Build distributed operator
distributed_operator_from_hmatrix = Htool.DistributedOperatorFromHMatrix(
Expand Down
2 changes: 1 addition & 1 deletion lib/htool
Binary file removed src/Htool.cpython-311-darwin.so
Binary file not shown.
Binary file removed src/Htool.cpython-39-x86_64-linux-gnu.so
Binary file not shown.
89 changes: 0 additions & 89 deletions src/htool.egg-info/PKG-INFO

This file was deleted.

16 changes: 0 additions & 16 deletions src/htool.egg-info/SOURCES.txt

This file was deleted.

1 change: 0 additions & 1 deletion src/htool.egg-info/dependency_links.txt

This file was deleted.

1 change: 0 additions & 1 deletion src/htool.egg-info/not-zip-safe

This file was deleted.

11 changes: 0 additions & 11 deletions src/htool.egg-info/requires.txt

This file was deleted.

2 changes: 0 additions & 2 deletions src/htool.egg-info/top_level.txt

This file was deleted.

29 changes: 23 additions & 6 deletions src/htool/hmatrix/hmatrix_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,34 @@ void declare_hmatrix_builder(py::module &m, const std::string &className) {
using Class = htool::HMatrixTreeBuilder<CoefficientPrecision, CoordinatePrecision>;
py::class_<Class> py_class(m, className.c_str());

// Constructor
py_class.def(py::init<const htool::Cluster<CoordinatePrecision> &, const htool::Cluster<CoordinatePrecision> &, htool::underlying_type<CoefficientPrecision>, CoordinatePrecision, char, char, int, int, int>());
// // Constructor
// py_class.def(py::init([](underlying_type<CoefficientPrecision> epsilon, CoordinatePrecision eta, char symmetry, char UPLO) {
// return std::unique_ptr<Class>(new Class(epsilon, eta, symmetry, UPLO));
// }),
// py::arg("epsilon"),
// py::arg("eta"),
// py::arg("symmetry"),
// py::arg("UPLO"));

py_class.def(py::init([](underlying_type<CoefficientPrecision> epsilon, CoordinatePrecision eta, char symmetry, char UPLO, int reqrank, std::shared_ptr<VirtualLowRankGeneratorPython<CoefficientPrecision, CoordinatePrecision>> low_rank_strategy) {
std::cout << epsilon << "\n";
return std::unique_ptr<Class>(new Class(epsilon, eta, symmetry, UPLO, reqrank, low_rank_strategy));
}),
py::arg("epsilon"),
py::arg("eta"),
py::arg("symmetry"),
py::arg("UPLO"),
py::kw_only(),
py::arg("reqrank") = -1,
py::arg("low_rank_strategy") = nullptr);

// Build
// py_class.def("build", [](const Class &self, const VirtualGenerator<CoefficientPrecision> &generator) { return self.build(generator); });
py_class.def("build", [](const Class &self, const VirtualGenerator<CoefficientPrecision> &generator) { return self.build(InternalGeneratorWithPermutation<CoefficientPrecision>(generator, self.get_target_cluster().get_permutation().data(), self.get_source_cluster().get_permutation().data())); });
py_class.def("build", [](const Class &self, const VirtualGenerator<CoefficientPrecision> &generator, const Cluster<CoordinatePrecision> &target_cluster, const Cluster<CoordinatePrecision> &source_cluster, int target_partition_number, int partition_number_for_symmetry) { return self.build(generator, target_cluster, source_cluster, target_partition_number, partition_number_for_symmetry); }, py::arg("generator"), py::arg("target_cluster"), py::arg("source_cluster"), py::arg("target_partition_number") = -1, py::arg("partition_number_for_symmetry") = -1);

// Setters
py_class.def("set_minimal_source_depth", &Class::set_minimal_source_depth);
py_class.def("set_minimal_target_depth", &Class::set_minimal_target_depth);
py_class.def("set_low_rank_generator", [](Class &self, const std::shared_ptr<VirtualLowRankGeneratorPython<CoefficientPrecision, CoordinatePrecision>> &low_rank_generator) { self.set_low_rank_generator(low_rank_generator); });
py_class.def("set_dense_blocks_generator", [](Class &self, const std::shared_ptr<VirtualDenseBlocksGeneratorPython<CoefficientPrecision>> &dense_blocks_generator) { self.set_dense_blocks_generator(dense_blocks_generator); });
py_class.def("set_low_rank_generator", [](Class &self, std::shared_ptr<VirtualLowRankGeneratorPython<CoefficientPrecision, CoordinatePrecision>> low_rank_generator) { self.set_low_rank_generator(low_rank_generator); });
py_class.def("set_dense_blocks_generator", [](Class &self, std::shared_ptr<VirtualDenseBlocksGeneratorPython<CoefficientPrecision>> dense_blocks_generator) { self.set_dense_blocks_generator(dense_blocks_generator); });
}
#endif
9 changes: 4 additions & 5 deletions src/htool/hmatrix/interfaces/virtual_low_rank_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class VirtualLowRankGeneratorPython : public VirtualLowRankGenerator<Coefficient

VirtualLowRankGeneratorPython() {}

void copy_low_rank_approximation(const VirtualInternalGenerator<CoefficientPrecision> &A, const Cluster<CoordinatePrecision> &target_cluster, const Cluster<CoordinatePrecision> &source_cluster, underlying_type<CoefficientPrecision> epsilon, int &rank, Matrix<CoefficientPrecision> &U, Matrix<CoefficientPrecision> &V) const override {
py::array_t<int, py::array::f_style> rows(std::array<int,1>{target_cluster.get_size()}, target_cluster.get_permutation().data() + target_cluster.get_offset(), py::capsule(target_cluster.get_permutation().data()));
py::array_t<int, py::array::f_style> cols(std::array<int,1>{source_cluster.get_size()}, source_cluster.get_permutation().data() + source_cluster.get_offset(), py::capsule(source_cluster.get_permutation().data()));
void copy_low_rank_approximation(const VirtualInternalGenerator<CoefficientPrecision> &A, int M, int N, const int *const rows, const int *const cols, underlying_type<CoefficientPrecision> epsilon, int &rank, Matrix<CoefficientPrecision> &U, Matrix<CoefficientPrecision> &V) const override {
py::array_t<int> py_rows(std::array<long int, 1>{M}, rows, py::capsule(rows));
py::array_t<int> py_cols(std::array<long int, 1>{N}, cols, py::capsule(cols));

build_low_rank_approximation(rows, cols, epsilon);
build_low_rank_approximation(py_rows, py_cols, epsilon);
U.assign(m_mats_U.back().shape()[0], m_mats_U.back().shape()[1], m_mats_U.back().mutable_data(), false);
V.assign(m_mats_V.back().shape()[0], m_mats_V.back().shape()[1], m_mats_V.back().mutable_data(), false);
}
Expand All @@ -39,7 +39,6 @@ class VirtualLowRankGeneratorPython : public VirtualLowRankGenerator<Coefficient
m_mats_U.push_back(U0); // no copy here
}
void set_V(py::array_t<CoefficientPrecision, py::array::f_style> V0) { m_mats_V.push_back(V0); }

};

template <typename CoefficientPrecision, typename CoordinatePrecision>
Expand Down
5 changes: 0 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,10 @@ def custom_distributed_operator(
)
else:
hmatrix_builder = Htool.HMatrixBuilder(
target_cluster,
source_cluster,
epsilon,
eta,
symmetry,
UPLO,
-1,
mpi4py.MPI.COMM_WORLD.rank,
mpi4py.MPI.COMM_WORLD.rank,
)
if dense_blocks_generator is not None:
hmatrix_builder.set_dense_blocks_generator(dense_blocks_generator)
Expand Down

0 comments on commit 18517a3

Please sign in to comment.