Skip to content

Commit

Permalink
Merge pull request #60 from ewanwm/feature_build_with_pip
Browse files Browse the repository at this point in the history
Feature build with pip
  • Loading branch information
ewanwm authored Sep 20, 2024
2 parents d3f6452 + 32c03a2 commit 975f567
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 3 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/pip.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: "Pip"

on:
workflow_dispatch:
pull_request:
push:
branches:
- main

jobs:
build:
name: Build with Pip
runs-on: ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest]
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Protoc Ubuntu
run: sudo apt install protobuf-compiler

- name: Install Python dependencies
uses: py-actions/py-dependency-install@v4
with:
path: "PyTorch_requirements.txt"

- name: Build and install
run: pip install --verbose .

#- name: Test
# run: pytest
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
nuTens is a software library which uses [tensors](https://en.wikipedia.org/wiki/Tensor_(machine_learning)) to efficiently calculate neutrino oscillation probabilities.

[![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)
[![pip](https://github.com/ewanwm/nuTens/actions/workflows/pip.yaml/badge.svg)](https://github.com/ewanwm/nuTens/actions/workflows/pip.yaml)
[![Code - Doxygen](https://img.shields.io/badge/Code-Doxygen-2ea44f)](https://ewanwm.github.io/nuTens/index.html)
[![test - coverage](https://codecov.io/github/ewanwm/nuTens/graph/badge.svg?token=PJ8C8CX37O)](https://codecov.io/github/ewanwm/nuTens)
[![cpp - linter](https://github.com/ewanwm/nuTens/actions/workflows/cpp-linter.yaml/badge.svg)](https://github.com/ewanwm/nuTens/actions/workflows/cpp-linter.yaml)
Expand Down Expand Up @@ -40,6 +41,19 @@ Once [nuTens](#nutens) has been built, you can verify your installation by runni
make test
```

## Python
nuTens provides a python interface which can be installed using pip by running
```
pip install .
```
in the root directory of nuTens

Additionally, the nuTens python module can be installed as a shared library `.so` object by specifying the CMake option
```
cmake -DNT_ENABLE_PYTHON=ON <other options> <source dir>
```
and doing `make && make install`

## Benchmarking
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:

Expand Down
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[build-system]
requires = ["scikit-build-core", "pybind11", "torch"]
build-backend = "scikit_build_core.build"

[project]
name = "pyNuTens"
version = "0.0.1"
description="Library to calculate neutrino oscillation probabilities using tensors"
readme = "README.md"
authors = [
{ name = "Ewan Miller", email = "[email protected]" },
]

[tool.scikit-build]
cmake.args = ["-DNT_ENABLE_PYTHON=ON"]
9 changes: 6 additions & 3 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@

pybind11_add_module(
pyNuTens MODULE
pyNuTens.cpp
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 )

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

install( TARGETS pyNuTens DESTINATION pyNuTens/ )
7 changes: 7 additions & 0 deletions python/pyNuTens.cpp → python/binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ void initDtypes(py::module & /*m*/);
// NOLINTNEXTLINE
PYBIND11_MODULE(pyNuTens, m)
{
m.doc() = "Library to calculate neutrino oscillations";
initTensor(m);
initPropagator(m);
initDtypes(m);

#ifdef VERSION_INFO
m.attr("__version__") = Py_STRINGIFY(VERSION_INFO);
#else
m.attr("__version__") = "dev";
#endif
}

void initTensor(py::module &m)
Expand Down
4 changes: 4 additions & 0 deletions python/pyNuTens/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

from .pyNuTens import __doc__, __version__

__all__ = ["__doc__", "__version__", "tensor", "propagator"]
2 changes: 2 additions & 0 deletions python/pyNuTens/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/pyNuTens/tensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .pyNuTens import tensor
from .pyNuTens.tensor import *
File renamed without changes.

0 comments on commit 975f567

Please sign in to comment.