diff --git a/Cargo.toml b/Cargo.toml index 0d6dbe6f..e446f6df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,5 @@ [workspace] -members = [ - "pineappl", - "pineappl_capi", - "pineappl_py", - "pineappl_cli", -] +members = ["pineappl", "pineappl_capi", "pineappl_cli"] [profile.release] lto = true diff --git a/pineappl/.gitignore b/pineappl/.gitignore new file mode 100644 index 00000000..bfbb67c1 --- /dev/null +++ b/pineappl/.gitignore @@ -0,0 +1,145 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/python +# Edit at https://www.toptal.com/developers/gitignore?templates=python + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +pytestdebug.log + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ +doc/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +pythonenv* + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# profiling data +.prof + +# End of https://www.toptal.com/developers/gitignore/api/python diff --git a/pineappl/Cargo.toml b/pineappl/Cargo.toml index 35ce0d64..75508792 100644 --- a/pineappl/Cargo.toml +++ b/pineappl/Cargo.toml @@ -20,10 +20,18 @@ float-cmp = "0.8" itertools = "0.9" lz-fear = "0.1" ndarray = { features = ["serde"], version = "0.13.1" } +pyo3 = { features = ["extension-module"], optional = true, version = "0.13.1" } rustc-hash = "1.1.0" serde = { features = ["derive"], version = "1.0" } thiserror = "1.0" +[lib] +name = "pineappl" +crate-type = ["cdylib", "lib"] + +[features] +python = ["pyo3"] + [dev-dependencies] lhapdf = "0.1.8" rand = { default-features = false, version = "0.7" } diff --git a/pineappl_py/dev.requirements.txt b/pineappl/dev.py.requirements.txt similarity index 100% rename from pineappl_py/dev.requirements.txt rename to pineappl/dev.py.requirements.txt diff --git a/pineappl_py/examples/import-yadism-yaml.py b/pineappl/examples/import-yadism-yaml.py similarity index 100% rename from pineappl_py/examples/import-yadism-yaml.py rename to pineappl/examples/import-yadism-yaml.py diff --git a/pineappl_py/examples/requirements.txt b/pineappl/examples/py.requirements.txt similarity index 100% rename from pineappl_py/examples/requirements.txt rename to pineappl/examples/py.requirements.txt diff --git a/pineappl_py/pineappl/__init__.py b/pineappl/pineappl/__init__.py similarity index 100% rename from pineappl_py/pineappl/__init__.py rename to pineappl/pineappl/__init__.py diff --git a/pineappl_py/pineappl/bin.py b/pineappl/pineappl/bin.py similarity index 100% rename from pineappl_py/pineappl/bin.py rename to pineappl/pineappl/bin.py diff --git a/pineappl_py/pineappl/grid.py b/pineappl/pineappl/grid.py similarity index 100% rename from pineappl_py/pineappl/grid.py rename to pineappl/pineappl/grid.py diff --git a/pineappl_py/pineappl/lagrange_subgrid.py b/pineappl/pineappl/lagrange_subgrid.py similarity index 100% rename from pineappl_py/pineappl/lagrange_subgrid.py rename to pineappl/pineappl/lagrange_subgrid.py diff --git a/pineappl_py/pineappl/lumi.py b/pineappl/pineappl/lumi.py similarity index 100% rename from pineappl_py/pineappl/lumi.py rename to pineappl/pineappl/lumi.py diff --git a/pineappl_py/pineappl/subgrid.py b/pineappl/pineappl/subgrid.py similarity index 100% rename from pineappl_py/pineappl/subgrid.py rename to pineappl/pineappl/subgrid.py diff --git a/pineappl_py/pineappl/utils.py b/pineappl/pineappl/utils.py similarity index 100% rename from pineappl_py/pineappl/utils.py rename to pineappl/pineappl/utils.py diff --git a/pineappl/src/bin.rs b/pineappl/src/bin.rs index e4bb8111..e80eda42 100644 --- a/pineappl/src/bin.rs +++ b/pineappl/src/bin.rs @@ -1,5 +1,8 @@ //! Module that contains helpers for binning observables +#[cfg(feature = "python")] +use pyo3::prelude::*; + use super::convert::{f64_from_usize, usize_from_f64}; use float_cmp::approx_eq; use serde::{Deserialize, Serialize}; @@ -47,6 +50,7 @@ pub enum BinRemapperNewError { } /// Structure for remapping bin limits. +#[cfg_attr(feature = "python", pyclass)] #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BinRemapper { normalizations: Vec, @@ -148,6 +152,7 @@ impl PartialEq> for BinInfo<'_> { } } +#[cfg_attr(feature = "python", pymethods)] impl BinRemapper { /// Create a new `BinRemapper` object with the specified number of bins and dimensions and /// limits. @@ -156,6 +161,7 @@ impl BinRemapper { /// /// Returns an error if the length of `limits` is not a multiple of the length of /// `normalizations`. + #[cfg_attr(feature = "python", new)] pub fn new( normalizations: Vec, limits: Vec<(f64, f64)>, diff --git a/pineappl/src/grid.rs b/pineappl/src/grid.rs index c85f77f2..ae676e85 100644 --- a/pineappl/src/grid.rs +++ b/pineappl/src/grid.rs @@ -175,6 +175,7 @@ pub enum GridSetBinRemapperError { /// Main data structure of `PineAPPL`. This structure contains a `Subgrid` for each `LumiEntry`, /// bin, and coupling order it was created with. +#[cfg_attr(feature = "python", pyclass)] #[derive(Deserialize, Serialize)] pub struct Grid { subgrids: Array3, @@ -185,8 +186,10 @@ pub struct Grid { more_members: MoreMembers, } +#[cfg_attr(feature = "python", pymethods)] impl Grid { /// Constructor. + #[cfg_attr(feature = "python", new)] #[must_use] pub fn new( lumi: Vec, diff --git a/pineappl/src/lib.rs b/pineappl/src/lib.rs index 745f2525..f816e6f0 100644 --- a/pineappl/src/lib.rs +++ b/pineappl/src/lib.rs @@ -13,3 +13,22 @@ pub mod lumi; pub mod ntuple_subgrid; pub mod sparse_array3; pub mod subgrid; + +/// A Python module implemented in Rust. +/// NOTE: this name has to match the one in Cargo.toml 'lib.name' +#[cfg(feature = "python")] +use pyo3::prelude::*; + +#[cfg(feature = "python")] +#[pymodule] +fn pineappl(_py: Python, m: &PyModule) -> PyResult<()> { + m.add_class::()?; + //m.add_class::()?; + //m.add_class::()?; + //m.add_class::()?; + //m.add_class::()?; + //m.add_class::()?; + //m.add_class::()?; + + Ok(()) +} diff --git a/pineappl_py/tests/test_bin.py b/pineappl/tests/python/test_bin.py similarity index 100% rename from pineappl_py/tests/test_bin.py rename to pineappl/tests/python/test_bin.py diff --git a/pineappl_py/tests/test_grid.py b/pineappl/tests/python/test_grid.py similarity index 100% rename from pineappl_py/tests/test_grid.py rename to pineappl/tests/python/test_grid.py diff --git a/pineappl_py/tests/test_lagrange_subgrid.py b/pineappl/tests/python/test_lagrange_subgrid.py similarity index 100% rename from pineappl_py/tests/test_lagrange_subgrid.py rename to pineappl/tests/python/test_lagrange_subgrid.py diff --git a/pineappl_py/tests/test_lumi.py b/pineappl/tests/python/test_lumi.py similarity index 100% rename from pineappl_py/tests/test_lumi.py rename to pineappl/tests/python/test_lumi.py diff --git a/pineappl_py/tests/test_sugrid.py b/pineappl/tests/python/test_sugrid.py similarity index 100% rename from pineappl_py/tests/test_sugrid.py rename to pineappl/tests/python/test_sugrid.py diff --git a/pineappl_py/Cargo.toml b/pineappl_py/Cargo.toml deleted file mode 100644 index be69aa34..00000000 --- a/pineappl_py/Cargo.toml +++ /dev/null @@ -1,23 +0,0 @@ -[package] -name = "pineappl_py" -version = "0.3.0" -authors = ["Christopher Schwan ", "Alessandro Candido "] -edition = "2018" -license = "GPL-3.0-or-later" -repository = "https://github.com/N3PDF/pineappl" -readme = "README.md" -keywords = ["high-energy-physics", "physics"] -categories = ["science"] -description = "Python bindings to PineAPPL" - -[lib] -name = "pineappl" -crate-type = ["cdylib"] - -[dependencies] -pineappl = { path = "../pineappl", version = "0.3.0" } -itertools = "0.9" - -[dependencies.pyo3] -version = "0.12.4" -features = ["extension-module"] diff --git a/pineappl_py/src/bin.rs b/pineappl_py/src/bin.rs index 9a29e8f9..83189b6b 100644 --- a/pineappl_py/src/bin.rs +++ b/pineappl_py/src/bin.rs @@ -1,11 +1,8 @@ use pineappl::bin::BinRemapper; -use pyo3::prelude::*; //use pyo3::types::{PyList, PyTuple}; //use pyo3::{exceptions::PyRuntimeError, Python}; -#[pyclass] -#[derive(Clone)] #[repr(transparent)] pub struct PyBinRemapper { pub bin_remapper: BinRemapper, diff --git a/pineappl_py/src/lib.rs b/pineappl_py/src/lib.rs deleted file mode 100644 index eba581ce..00000000 --- a/pineappl_py/src/lib.rs +++ /dev/null @@ -1,22 +0,0 @@ -use pyo3::prelude::*; - -pub mod bin; -pub mod grid; -pub mod lagrange_subgrid; -pub mod lumi; -pub mod subgrid; - -/// A Python module implemented in Rust. -/// NOTE: this name has to match the one in Cargo.toml 'lib.name' -#[pymodule] -fn pineappl(_py: Python, m: &PyModule) -> PyResult<()> { - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - - Ok(()) -}