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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "extern/rayx"]
path = extern/rayx
url = https://github.com/hz-b/rayx
[submodule "extern/nanobind"]
path = extern/nanobind
url = https://github.com/wjakob/nanobind
13 changes: 5 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
cmake_minimum_required(VERSION 3.25.2)

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Install prefix" FORCE)
endif()
# if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
# set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Install prefix" FORCE)
# endif()

project(rayx-python)
add_subdirectory(extern)
add_subdirectory(src)
add_subdirectory(src rayx)

# Install Python package
install(DIRECTORY python/rayx DESTINATION .)
# install(DIRECTORY python/rayx DESTINATION .)

# Create and install rayxdata package (needed by C++ code)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/rayxdata/__init__.py" "")
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/rayxdata" DESTINATION .)
4 changes: 2 additions & 2 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set(RAYX_STATIC_LIB ON)
set(RAYX_BUILD_RAYX_CLI NO)
set(RAYX_BUILD_RAYX_UI NO)
set(RAYX_CUSTOM_DATA_DIR "rayxdata/share" CACHE STRING "Set this val")
# set(RAYX_CUSTOM_DATA_DIR "rayxdata/share" CACHE STRING "Set this val")

add_subdirectory(rayx)
add_subdirectory(pybind11)
add_subdirectory(nanobind)
1 change: 1 addition & 0 deletions extern/nanobind
Submodule nanobind added at 4bfeca
1 change: 0 additions & 1 deletion extern/pybind11
Submodule pybind11 deleted from 58c382
2 changes: 1 addition & 1 deletion extern/rayx
Submodule rayx updated 142 files
37 changes: 0 additions & 37 deletions python/rayx/__init__.py

This file was deleted.

76 changes: 0 additions & 76 deletions setup_dev.sh

This file was deleted.

46 changes: 39 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,47 @@ set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CUDA_STANDARD 20)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
set(PYBIND11_FINDPYTHON ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)

# Changed from 'rayx' to '_core' to make it a private module
pybind11_add_module(_core main.cpp)
target_link_libraries(_core PRIVATE rayx-core)
target_include_directories(_core PRIVATE
if (CMAKE_VERSION VERSION_LESS 3.18)
set(DEV_MODULE Development)
else()
set(DEV_MODULE Development.Module)
endif()

find_package(Python 3.9 COMPONENTS Interpreter ${DEV_MODULE} REQUIRED)

# Changed from 'rayx' to 'core' to make it a private module
nanobind_add_module(core main.cpp)
nanobind_add_stub(
core_stub
MODULE core
OUTPUT core.pyi
PYTHON_PATH $<TARGET_FILE_DIR:core>
DEPENDS core
)
target_link_libraries(core PRIVATE rayx-core)
target_include_directories(core PRIVATE
$<TARGET_PROPERTY:rayx-core,INTERFACE_INCLUDE_DIRECTORIES>
${CUDA_TOOLKIT_INCLUDE}/cccl)
${CUDA_TOOLKIT_INCLUDE})

add_custom_command(
TARGET core
COMMAND ${CMAKE_COMMAND} -E copy_directory
#"${CMAKE_CURRENT_SOURCE_DIR}/extern/rayx/Data"
"${RAYX_SOURCE_DIR}/Data"
"${CMAKE_CURRENT_BINARY_DIR}/share/RAYX/Data"
)

file(GLOB_RECURSE PY_SRC *.py)
# file(COPY PY_SRC ".")

add_custom_command(
TARGET core
COMMAND ${CMAKE_COMMAND} -E copy
${PY_SRC}
"${CMAKE_CURRENT_BINARY_DIR}"
)

# Install to rayx/ subdirectory
install(TARGETS _core LIBRARY DESTINATION rayx)
install(TARGETS core LIBRARY DESTINATION rayx)
27 changes: 27 additions & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
RAY-X Python bindings
"""
import sys
from pathlib import Path

# Import the C++ extension module
from . import core

# Re-export everything from C++ module
from .core import *

def get_info():
"""Get information about the RAYX installation"""
info = {
"version": __version__,
"python_wrapper": True,
"cpp_module": str(core.__file__),
"module_path": str(Path(__file__).parent),
}
return info

# From other files
from .data import rays_to_df

__version__ = "0.4.3"
__all__ = ['get_info', 'rays_to_df']
15 changes: 3 additions & 12 deletions python/rayx/data.py → src/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,18 @@
import pandas as pd

# Import the C++ extension module
try:
from . import _core
except ImportError:
# During development, try to find the built module
import os
build_dir = Path(__file__).parent.parent.parent / "build" / "install" / "rayx"
if build_dir.exists():
sys.path.insert(0, str(build_dir.parent))
from rayx import _core
else:
raise ImportError("Cannot find compiled _core module. Did you build the project?")

def rays_to_df(rays, columns: list | None = None) -> pd.DataFrame:
if columns is None:
columns = [
"path_id",
"path_event_id",
"position_x", "position_y", "position_z",
"direction_x", "direction_y", "direction_z",
"electric_field_x", "electric_field_y", "electric_field_z",
"optical_path_length",
"energy", "order",
"last_element_id", "source_id",
"object_id", "source_id",
"event_type",
]

Expand Down
Loading