Skip to content

Commit

Permalink
I think we can *finally* make a distributable python module that beha…
Browse files Browse the repository at this point in the history
…ves nicely
  • Loading branch information
ewanwm committed Sep 25, 2024
1 parent 2cdc2ba commit 29ee5cb
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 22 deletions.
30 changes: 26 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
[build-system]
requires = ["scikit-build-core>=0.3.3", "pybind11", "torch"]
build-backend = "scikit_build_core.build"

[project]
name = "nuTens"
version = "0.0.2"
version = "0.0.3"
description="Library to calculate neutrino oscillation probabilities using tensors"
readme = "README.md"
authors = [
{ name = "Ewan Miller", email = "[email protected]" },
]
requires-python = ">=3.9"
license = {file="LICENSE"}
keywords = ["neutrino", "oscillations", "physics", "particle", "tensor", "experiment", "autograd", "differentiable programming"]
classifiers = [
"Development Status :: 2 - Pre-Alpha",
"Environment :: GPU",
"Programming Language :: C++",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Scientific/Engineering :: Physics",
"Intended Audience :: Science/Research"
]
dependencies = [
"torch"
]

[project.urls]
Repository = "https://github.com/ewanwm/nuTens"
Issues = "https://github.com/ewanwm/nuTens/issues"
Documentation = "https://ewanwm.github.io/nuTens/"

[build-system]
requires = ["scikit-build-core>=0.3.3", "pybind11", "torch"]
build-backend = "scikit_build_core.build"

[tool.cibuildwheel]
build-frontend = "build[uv]"
Expand Down
10 changes: 5 additions & 5 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

pybind11_add_module(
pyNuTens MODULE
_pyNuTens MODULE
binding.cpp
)

if(NT_USE_PCH)
target_precompile_headers( pyNuTens REUSE_FROM nuTens-pch )
target_precompile_headers( _pyNuTens REUSE_FROM nuTens-pch )
endif()
target_link_libraries( pyNuTens PUBLIC nuTens )
target_link_libraries( _pyNuTens PUBLIC nuTens )

# This is passing in the version as a define just as an example
target_compile_definitions( pyNuTens PRIVATE VERSION_INFO=${PROJECT_VERSION} )
target_compile_definitions( _pyNuTens PRIVATE VERSION_INFO=${PROJECT_VERSION} )

install( TARGETS pyNuTens DESTINATION pyNuTens/ )
install( TARGETS _pyNuTens DESTINATION nuTens/ )
5 changes: 5 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Python Interface

nuTens provides a python interface that can be installed manually or via [pyPi](https://pypi.org/). [binding.cpp](binding.cpp) defines the python bindings of many of the nuTens c++ objects, which are then compiled into a python module using [pybind11](https://github.com/pybind/pybind11) (see [CMakeLists.txt](CMakeLists.txt)).

The [nuTens](nuTens) folder defines the python module and any pure python extension code for nuTens should go in there.
4 changes: 2 additions & 2 deletions python/binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ void initTensor(py::module & /*m*/);
void initPropagator(py::module & /*m*/);
void initDtypes(py::module & /*m*/);

// initialise the top level module "pyNuTens"
// initialise the top level module "_pyNuTens"
// NOLINTNEXTLINE
PYBIND11_MODULE(pyNuTens, m)
PYBIND11_MODULE(_pyNuTens, m)
{
m.doc() = "Library to calculate neutrino oscillations";
initTensor(m);
Expand Down
3 changes: 3 additions & 0 deletions python/nuTens/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from ._pyNuTens import __doc__, __version__, tensor, propagator, dtype

__all__ = ["__doc__", "__version__", "tensor", "propagator", "dtype"]
2 changes: 2 additions & 0 deletions python/nuTens/dtype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from ._pyNuTens import dtype
from ._pyNuTens.dtype import *
2 changes: 2 additions & 0 deletions python/nuTens/propagator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from ._pyNuTens import propagator
from ._pyNuTens.propagator import *
2 changes: 2 additions & 0 deletions python/nuTens/tensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from ._pyNuTens import tensor
from ._pyNuTens.tensor import *
4 changes: 0 additions & 4 deletions python/pyNuTens/__init__.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/pyNuTens/propagator.py

This file was deleted.

2 changes: 0 additions & 2 deletions python/pyNuTens/tensor.py

This file was deleted.

6 changes: 3 additions & 3 deletions tests/pyNuTens-test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import torch
import pyNuTens as nt
from pyNuTens import tensor
from pyNuTens.tensor import Tensor
import nuTens as nt
from nuTens import tensor
from nuTens.tensor import Tensor
import matplotlib.pyplot as plt
import typing

Expand Down

0 comments on commit 29ee5cb

Please sign in to comment.