Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lobis committed Dec 1, 2023
1 parent 947177b commit 5c709d5
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 141 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ on:
inputs:
debug_enabled:
type: boolean
description: Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)
description:
Run the build with tmate debugging enabled
(https://github.com/marketplace/actions/debugging-with-tmate)
required: false
default: false
pull_request:
Expand All @@ -26,9 +28,9 @@ jobs:
geant4-version:
- 11.1.3
python-version:
- '3.9'
- '3.10'
- '3.11'
- "3.9"
- "3.10"
- "3.11"

runs-on: ${{ matrix.platform }}
defaults:
Expand Down Expand Up @@ -79,7 +81,9 @@ jobs:
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
if:
${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled
}}
with:
limit-access-to-actor: false

Expand Down
36 changes: 29 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
repos:
ci:
autoupdate_commit_msg: "chore: update pre-commit hooks"
autofix_commit_msg: "style: pre-commit fixes"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
Expand Down Expand Up @@ -45,10 +48,29 @@ repos:
- id: cmake-format
additional_dependencies: [pyyaml]

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.11.0
- repo: https://github.com/adamchainz/blacken-docs
rev: "1.16.0"
hooks:
- id: pretty-format-toml
args: [--autofix]
- id: pretty-format-yaml
args: [--autofix, --indent, '2', --offset, '2']
- id: blacken-docs
additional_dependencies: [black==23.*]

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.1.0"
hooks:
- id: prettier
types_or: [yaml, markdown, html, css, scss, javascript, json]
args: [--prose-wrap=always]

- repo: https://github.com/codespell-project/codespell
rev: "v2.2.6"
hooks:
- id: codespell
exclude: ^Gemfile\.lock$
args: ["-Lnd", "-w"]

- repo: https://github.com/pre-commit/pygrep-hooks
rev: "v1.10.0"
hooks:
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
60 changes: 27 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,58 +1,52 @@
cmake_minimum_required(VERSION 3.25)
cmake_minimum_required(VERSION 3.15...3.27)

project(
${SKBUILD_PROJECT_NAME}
VERSION ${SKBUILD_PROJECT_VERSION}
LANGUAGES CXX)
${SKBUILD_PROJECT_NAME}
VERSION ${SKBUILD_PROJECT_VERSION}
LANGUAGES CXX)

set(PYTHON_MODULE_NAME _core)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

find_package(Geant4 REQUIRED CONFIG COMPONENTS gdml)
find_package(
Python3
COMPONENTS Interpreter Development.Module
REQUIRED)
Python
COMPONENTS Interpreter Development.Module
REQUIRED)
find_package(Geant4 REQUIRED CONFIG COMPONENTS gdml)

message(STATUS "Using Geant4 ${Geant4_VERSION} from ${Geant4_DIR}")
message(STATUS "Using Python ${Python_VERSION} from ${Python_EXECUTABLE}")

add_subdirectory(external/awkward/header-only)
add_subdirectory(external/pybind11)

file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS
"${PROJECT_SOURCE_DIR}/src/geant4/*.cpp")

set(PYTHON_MODULE_NAME _core)
file(GLOB_RECURSE PYTHON_SOURCES CONFIGURE_DEPENDS
"${PROJECT_SOURCE_DIR}/src/python/*.cpp")

pybind11_add_module(${PYTHON_MODULE_NAME} ${PYTHON_SOURCES})
target_compile_options(${PYTHON_MODULE_NAME} PRIVATE -fPIC)
pybind11_add_module(${PYTHON_MODULE_NAME} ${SOURCES} ${PYTHON_SOURCES})

target_compile_definitions(${PYTHON_MODULE_NAME}
PRIVATE VERSION_INFO=${PROJECT_VERSION})

target_include_directories(
${PYTHON_MODULE_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include
${Geant4_INCLUDE_DIRS})
target_sources(${PYTHON_MODULE_NAME} PRIVATE ${SOURCES})
${PYTHON_MODULE_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/include
${Geant4_INCLUDE_DIRS})

target_link_libraries(
${PYTHON_MODULE_NAME}
PRIVATE ${Geant4_LIBRARIES}
awkward::layout-builder
pybind11::embed
pybind11::module
${Python3_LIBRARY}
Python3::Module
pybind11::headers)
${PYTHON_MODULE_NAME} PRIVATE ${Geant4_LIBRARIES} awkward::layout-builder
pybind11::headers)

set_target_properties(
${PYTHON_MODULE_NAME}
PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON
CXX_EXTENSIONS NO)
${PYTHON_MODULE_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY
${PROJECT_BINARY_DIR}/${PROJECT_NAME})

install(
TARGETS ${PYTHON_MODULE_NAME}
LIBRARY DESTINATION ${PROJECT_NAME}
RUNTIME DESTINATION ${PROJECT_NAME}
ARCHIVE DESTINATION ${PROJECT_NAME})
TARGETS ${PYTHON_MODULE_NAME}
LIBRARY DESTINATION ${PROJECT_NAME}
RUNTIME DESTINATION ${PROJECT_NAME}
ARCHIVE DESTINATION ${PROJECT_NAME})
13 changes: 6 additions & 7 deletions examples/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@
"execution_count": null,
"id": "initial_id",
"metadata": {
"collapsed": true
"collapsed": false
},
"outputs": [],
"source": [
"from geant4 import Application\n",
"from geant4_python_application import Application, basic_gdml\n",
"\n",
"app = Application()\n",
"\n",
"app.random_seed = 0\n",
"app.setup_manager(n_threads=0)\n",
"app.setup_physics()\n",
"app.setup_detector() # can take a GDML string as argument\n",
"app.setup_detector(gdml=basic_gdml)\n",
"app.setup_action()\n",
"\n",
"app.initialize()\n",
"\n",
"# if the seed is set to 0, the seed will be randomized\n",
"print(f\"Random seed: {app.random_seed}\")\n",
"\n",
"# launch 100 events\n",
"events = app.run(100)"
"events = app.run(n_events=100)\n",
"\n",
"print(events)"
]
}
],
Expand Down
96 changes: 66 additions & 30 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,63 @@
build-backend = "scikit_build_core.build"
requires = ["scikit-build-core>=0.3.3", "pybind11"]

[dependencies]
awkward = {extras = ["arrow"], version = "2.5.0"}

[project]
description = "Geant4 Python Application"
name = "geant4_python_application"
version = "0.0.1"
name = "geant4_python_application"
description = "Geant4 Python Application"
readme = "README.md"
requires-python = ">=3.8"

authors = [
{name = "Luis Antonio Obis Aparicio", email = "luis.antonio.obis@gmail.com"},
]
classifiers = [
"Intended Audience :: Developers",
"Intended Audience :: Information Technology",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Operating System :: MacOS",
"Operating System :: POSIX",
"Operating System :: Unix",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Information Analysis",
"Topic :: Scientific/Engineering :: Mathematics",
"Topic :: Scientific/Engineering :: Physics",
"Topic :: Software Development",
"Topic :: Utilities"
]

dependencies = [
"awkward",
"numpy",
]

[project.optional-dependencies]
dev = [
"boost_histogram",
"hist",
"pandas",
"awkward-pandas"
]
test = ["pytest"]

[tool.cibuildwheel]
build-verbosity = 1
test-command = "pytest /tests"
test-command = "pytest tests"
test-extras = ["test"]
test-skip = ["*universal2:arm64"]

[tool.pytest.ini_options]
addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"]
filterwarnings = [
"error"
"error"
]
log_cli_level = "INFO"
minversion = "6.0"
Expand All @@ -34,31 +70,31 @@ src = ["src"]

[tool.ruff.lint]
extend-select = [
"B", # flake8-bugbear
"I", # isort
"ARG", # flake8-unused-arguments
"C4", # flake8-comprehensions
"EM", # flake8-errmsg
"ICN", # flake8-import-conventions
"G", # flake8-logging-format
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # pylint
"PT", # flake8-pytest-style
"PTH", # flake8-use-pathlib
"RET", # flake8-return
"RUF", # Ruff-specific
"SIM", # flake8-simplify
"T20", # flake8-print
"UP", # pyupgrade
"YTT", # flake8-2020
"EXE", # flake8-executable
"NPY", # NumPy specific rules
"PD" # pandas-vet
"B", # flake8-bugbear
"I", # isort
"ARG", # flake8-unused-arguments
"C4", # flake8-comprehensions
"EM", # flake8-errmsg
"ICN", # flake8-import-conventions
"G", # flake8-logging-format
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # pylint
"PT", # flake8-pytest-style
"PTH", # flake8-use-pathlib
"RET", # flake8-return
"RUF", # Ruff-specific
"SIM", # flake8-simplify
"T20", # flake8-print
"UP", # pyupgrade
"YTT", # flake8-2020
"EXE", # flake8-executable
"NPY", # NumPy specific rules
"PD" # pandas-vet
]
ignore = [
"PLR09", # Too many X
"PLR2004" # Magic comparison
"PLR09", # Too many X
"PLR2004" # Magic comparison
]
isort.required-imports = ["from __future__ import annotations"]

Expand Down
19 changes: 16 additions & 3 deletions src/geant4_python_application/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
from __future__ import annotations

lib_path = ""
# sys.path.append(lib_path)
from geant4_python_application._core import (
Application,
PrimaryGeneratorAction,
StackingAction,
__doc__,
__version__,
)
from geant4_python_application.gdml import basic_gdml

from ._core import *
__all__ = [
"__doc__",
"__version__",
"Application",
"PrimaryGeneratorAction",
"StackingAction",
"basic_gdml",
]
39 changes: 39 additions & 0 deletions src/geant4_python_application/gdml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from __future__ import annotations

basic_gdml = R"""<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<gdml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://service-spi.web.cern.ch/service-spi/app/releases/GDML/schema/gdml.xsd">
<define>
<constant name="worldSize" value="1000"/>
<constant name="boxSize" value="500"/>
</define>
<solids>
<box name="WorldSolid" x="worldSize" y="worldSize" z="worldSize" lunit="mm"/>
<box name="boxSolid" x="boxSize" y="boxSize" z="boxSize" lunit="mm"/>
</solids>
<structure>
<volume name="boxVolume">
<materialref ref="G4_WATER"/>
<solidref ref="boxSolid"/>
</volume>
<volume name="World">
<materialref ref="G4_AIR"/>
<solidref ref="WorldSolid"/>
<physvol name="box">
<volumeref ref="boxVolume"/>
<position name="boxPosition" unit="mm" x="0" y="0" z="0"/>
</physvol>
</volume>
</structure>
<setup name="Default" version="1.0">
<world ref="World"/>
</setup>
</gdml>
"""
Loading

0 comments on commit 5c709d5

Please sign in to comment.