Skip to content

Commit 975f567

Browse files
authored
Merge pull request #60 from ewanwm/feature_build_with_pip
Feature build with pip
2 parents d3f6452 + 32c03a2 commit 975f567

File tree

9 files changed

+89
-3
lines changed

9 files changed

+89
-3
lines changed

.github/workflows/pip.yaml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: "Pip"
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
10+
jobs:
11+
build:
12+
name: Build with Pip
13+
runs-on: ${{ matrix.platform }}
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
platform: [ubuntu-latest]
18+
python-version: ["3.9", "3.10", "3.11"]
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- uses: actions/setup-python@v5
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
27+
- name: Install Protoc Ubuntu
28+
run: sudo apt install protobuf-compiler
29+
30+
- name: Install Python dependencies
31+
uses: py-actions/py-dependency-install@v4
32+
with:
33+
path: "PyTorch_requirements.txt"
34+
35+
- name: Build and install
36+
run: pip install --verbose .
37+
38+
#- name: Test
39+
# run: pytest

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
nuTens is a software library which uses [tensors](https://en.wikipedia.org/wiki/Tensor_(machine_learning)) to efficiently calculate neutrino oscillation probabilities.
88

99
[![CI badge](https://github.com/ewanwm/nuTens/actions/workflows/CI-build-and-test.yml/badge.svg)](https://github.com/ewanwm/nuTens/actions/workflows/CI-build-and-test.yml)
10+
[![pip](https://github.com/ewanwm/nuTens/actions/workflows/pip.yaml/badge.svg)](https://github.com/ewanwm/nuTens/actions/workflows/pip.yaml)
1011
[![Code - Doxygen](https://img.shields.io/badge/Code-Doxygen-2ea44f)](https://ewanwm.github.io/nuTens/index.html)
1112
[![test - coverage](https://codecov.io/github/ewanwm/nuTens/graph/badge.svg?token=PJ8C8CX37O)](https://codecov.io/github/ewanwm/nuTens)
1213
[![cpp - linter](https://github.com/ewanwm/nuTens/actions/workflows/cpp-linter.yaml/badge.svg)](https://github.com/ewanwm/nuTens/actions/workflows/cpp-linter.yaml)
@@ -40,6 +41,19 @@ Once [nuTens](#nutens) has been built, you can verify your installation by runni
4041
make test
4142
```
4243

44+
## Python
45+
nuTens provides a python interface which can be installed using pip by running
46+
```
47+
pip install .
48+
```
49+
in the root directory of nuTens
50+
51+
Additionally, the nuTens python module can be installed as a shared library `.so` object by specifying the CMake option
52+
```
53+
cmake -DNT_ENABLE_PYTHON=ON <other options> <source dir>
54+
```
55+
and doing `make && make install`
56+
4357
## Benchmarking
4458
nuTens uses [Googles benchmark library](https://github.com/google/benchmark) to perform benchmarking and tracks the results uing [Bencher](https://bencher.dev). Each benchmark consists of calculating neutrino oscillations for 1024 batches of 1024 neutrino energies using the standard PMNS formalism in vacuum and in constant density matter:
4559

pyproject.toml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[build-system]
2+
requires = ["scikit-build-core", "pybind11", "torch"]
3+
build-backend = "scikit_build_core.build"
4+
5+
[project]
6+
name = "pyNuTens"
7+
version = "0.0.1"
8+
description="Library to calculate neutrino oscillation probabilities using tensors"
9+
readme = "README.md"
10+
authors = [
11+
{ name = "Ewan Miller", email = "emiller@ifae.es" },
12+
]
13+
14+
[tool.scikit-build]
15+
cmake.args = ["-DNT_ENABLE_PYTHON=ON"]

python/CMakeLists.txt

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11

22
pybind11_add_module(
33
pyNuTens MODULE
4-
pyNuTens.cpp
4+
binding.cpp
55
)
66

77
if(NT_USE_PCH)
8-
target_precompile_headers(pyNuTens REUSE_FROM nuTens-pch)
8+
target_precompile_headers( pyNuTens REUSE_FROM nuTens-pch )
99
endif()
1010
target_link_libraries( pyNuTens PUBLIC nuTens )
1111

12-
install( TARGETS pyNuTens DESTINATION pyNuTens/)
12+
# This is passing in the version as a define just as an example
13+
target_compile_definitions( pyNuTens PRIVATE VERSION_INFO=${PROJECT_VERSION} )
14+
15+
install( TARGETS pyNuTens DESTINATION pyNuTens/ )

python/pyNuTens.cpp python/binding.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@ void initDtypes(py::module & /*m*/);
2222
// NOLINTNEXTLINE
2323
PYBIND11_MODULE(pyNuTens, m)
2424
{
25+
m.doc() = "Library to calculate neutrino oscillations";
2526
initTensor(m);
2627
initPropagator(m);
2728
initDtypes(m);
29+
30+
#ifdef VERSION_INFO
31+
m.attr("__version__") = Py_STRINGIFY(VERSION_INFO);
32+
#else
33+
m.attr("__version__") = "dev";
34+
#endif
2835
}
2936

3037
void initTensor(py::module &m)

python/pyNuTens/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
from .pyNuTens import __doc__, __version__
3+
4+
__all__ = ["__doc__", "__version__", "tensor", "propagator"]

python/pyNuTens/propagator.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from .pyNuTens import propagator
2+
from .pyNuTens.propagator import *

python/pyNuTens/tensor.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from .pyNuTens import tensor
2+
from .pyNuTens.tensor import *
File renamed without changes.

0 commit comments

Comments
 (0)