Skip to content

Commit

Permalink
Merge pull request #1281 from glotzerlab/nanobind-order
Browse files Browse the repository at this point in the history
Nanobind port: Order module
  • Loading branch information
joaander authored Nov 8, 2024
2 parents 7a84136 + a0286f4 commit 2157905
Show file tree
Hide file tree
Showing 31 changed files with 809 additions and 514 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ jobs:
gsd==${{ matrix.python.oldest_gsd }}
matplotlib==${{ matrix.python.oldest_matplotlib }}
# Test only the currently ported modules
CIBW_TEST_COMMAND: "cd {package}/tests && pytest test_box_box.py test_parallel.py test_locality_*.py test_data.py test_pmft.py test_util.py test_msd_msd.py test_interface.py test_cluster.py -v --log-level=DEBUG"
CIBW_TEST_COMMAND: "cd {package}/tests && pytest test_box_box.py test_parallel.py test_locality_*.py test_data.py test_pmft.py test_util.py test_msd_msd.py test_interface.py test_order_*.py test_cluster.py -v --log-level=DEBUG"

# CIBW_TEST_COMMAND: "cd {package}/tests && pytest . -v --log-level=DEBUG"

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ jobs:
pytest tests/test_interface.py -v
pytest tests/test_msd_msd.py -v
pytest tests/test_cluster.py -v
pytest tests/test_order_*.py -v
# pytest tests/ -v
tests_complete:
Expand Down
3 changes: 2 additions & 1 deletion .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ lint.ignore = [
"RUF012", # freud does not use typing hints
"N802", # Allow names like Lx
"NPY002", # TODO: Refactor benchmarks and tests to use numpy.random.Generator
"E741",
"E743"
]

[lint.flake8-import-conventions]
Expand All @@ -34,7 +36,6 @@ aliases = {}

[lint.per-file-ignores]
"tests/*.py" = ["PLR6301", # methods defined this way are used by pytest.
"E741", # l is an appropriate variable name for Qlm order parameters.
"PLW2901", # TODO: Enable this check and fix after tests can be executed.
"B018", # TODO: Enable this check and fix after tests can be executed.
"PT011", # TODO: Enable this check and fix after tests can be executed.
Expand Down
53 changes: 34 additions & 19 deletions freud/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,23 @@ add_library(
${VOROPP_SOURCE_DIR}/wall.cc
${VOROPP_SOURCE_DIR}/pre_container.cc
${VOROPP_SOURCE_DIR}/container_prd.cc
# order
# order/ContinuousCoordination.h
# order/ContinuousCoordination.cc
# order/Cubatic.cc
# order/Cubatic.h
# order/HexaticTranslational.cc
# order/HexaticTranslational.h
# order/Nematic.cc
# order/Nematic.h
# order/RotationalAutocorrelation.cc
# order/RotationalAutocorrelation.h
# order/SolidLiquid.cc
# order/SolidLiquid.h
# order/Steinhardt.cc
# order/Steinhardt.h
# order/Wigner3j.cc
# order/Wigner3j.h
order
order/ContinuousCoordination.h
order/ContinuousCoordination.cc
order/Cubatic.cc
order/Cubatic.h
order/HexaticTranslational.cc
order/HexaticTranslational.h
order/Nematic.cc
order/Nematic.h
order/RotationalAutocorrelation.cc
order/RotationalAutocorrelation.h
order/SolidLiquid.cc
order/SolidLiquid.h
order/Steinhardt.cc
order/Steinhardt.h
order/Wigner3j.cc
order/Wigner3j.h
# parallel
parallel/tbb_config.h
parallel/tbb_config.cc
Expand Down Expand Up @@ -173,6 +173,20 @@ target_set_install_rpath(_locality)
# order nanobind_add_module(_order order/...) target_link_libraries(_order
# PUBLIC freud TBB::tbb) target_set_install_rpath(_order)

# order
nanobind_add_module(
_order
order/module-order.cc
order/export-Nematic.cc
order/export-RotationalAutocorrelation.cc
order/export-Steinhardt.cc
order/export-SolidLiquid.cc
order/export-ContinuousCoordination.cc
order/export-Cubatic.cc
order/export-HexaticTranslational.cc)
target_link_libraries(_order PUBLIC freud)
target_set_install_rpath(_order)

# parallel
nanobind_add_module(_parallel parallel/module-parallel.cc)
target_link_libraries(_parallel PUBLIC freud TBB::tbb)
Expand Down Expand Up @@ -201,12 +215,13 @@ set(python_files
errors.py
locality.py
msd.py
order.py
parallel.py
pmft.py
interface.py
plot.py
util.py)
# density.py diffraction.py environment.py order.py)
# cluster.py density.py diffraction.py environment.py interface.py msd.py)

copy_files_to_build("${python_files}" "freud" "*.py")

Expand All @@ -218,7 +233,7 @@ if(SKBUILD)
# install(TARGETS _density DESTINATION freud) install(TARGETS _diffraction
# DESTINATION freud) install(TARGETS _environment DESTINATION freud)
install(TARGETS _locality DESTINATION freud)
# install(TARGETS _order DESTINATION freud)
install(TARGETS _order DESTINATION freud)
install(TARGETS _parallel DESTINATION freud)
install(TARGETS _pmft DESTINATION freud)
install(TARGETS _util DESTINATION freud)
Expand Down
6 changes: 3 additions & 3 deletions freud/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright (c) 2010-2024 The Regents of the University of Michigan
# This file is from the freud project, released under the BSD 3-Clause License.

# density,; diffraction,; environment,; order,
from . import box, cluster, data, interface, locality, msd, parallel, pmft
# cluster,; density,; diffraction,; environment,; interface,; msd,;
from . import box, cluster, data, interface, locality, msd, order, parallel, pmft
from .box import Box
from .locality import AABBQuery, LinkCell, NeighborList
from .parallel import NumThreads, get_num_threads, set_num_threads
Expand All @@ -24,7 +24,7 @@
"interface",
"locality",
"msd",
# "order",
"order",
"parallel",
"pmft",
"Box",
Expand Down
16 changes: 9 additions & 7 deletions freud/locality/NeighborComputeFunctional.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ std::shared_ptr<NeighborList> makeDefaultNlist(const std::shared_ptr<NeighborQue
class NeighborListPerPointIterator : public NeighborPerPointIterator
{
public:
NeighborListPerPointIterator(const NeighborList* nlist, size_t point_index)
NeighborListPerPointIterator(const std::shared_ptr<NeighborList>& nlist, size_t point_index)
: NeighborPerPointIterator(point_index), m_nlist(nlist)
{
m_current_index = m_nlist->find_first_index(point_index);
Expand Down Expand Up @@ -76,8 +76,8 @@ class NeighborListPerPointIterator : public NeighborPerPointIterator
}

private:
const NeighborList* m_nlist; //! The NeighborList being iterated over.
size_t m_current_index; //! The row of m_nlist where the iterator is currently located.
const std::shared_ptr<NeighborList> m_nlist; //! The NeighborList being iterated over.
size_t m_current_index; //! The row of m_nlist where the iterator is currently located.
size_t m_returned_point_index {
0xffffffff}; //! The index of the last returned point (i.e. the value of
//! m_nlist.getNeighbors()(m_current_index, 0)). Initialized to an arbitrary sentinel in
Expand Down Expand Up @@ -110,9 +110,10 @@ class NeighborListPerPointIterator : public NeighborPerPointIterator
* input. It should implement iteration logic over the iterator.
*/
template<typename ComputePairType>
void loopOverNeighborsIterator(const NeighborQuery* neighbor_query, const vec3<float>* query_points,
unsigned int n_query_points, QueryArgs qargs, const NeighborList* nlist,
const ComputePairType& cf, bool parallel = true)
void loopOverNeighborsIterator(const std::shared_ptr<NeighborQuery>& neighbor_query,
const vec3<float>* query_points, unsigned int n_query_points, QueryArgs qargs,
const std::shared_ptr<NeighborList>& nlist, const ComputePairType& cf,
bool parallel = true)
{
// check if nlist exists
if (nlist != nullptr)
Expand Down Expand Up @@ -235,7 +236,8 @@ void loopOverNeighbors(const std::shared_ptr<NeighborQuery>& neighbor_query, con
* input. It should implement iteration logic over the iterator.
*/
template<typename ComputePairType>
void loopOverNeighborListIterator(const NeighborList* nlist, const ComputePairType& cf, bool parallel = true)
void loopOverNeighborListIterator(const std::shared_ptr<NeighborList>& nlist, const ComputePairType& cf,
bool parallel = true)
{
util::forLoopWrapper(
0, nlist->getNumQueryPoints(),
Expand Down
Loading

0 comments on commit 2157905

Please sign in to comment.