Skip to content

Move python bindings #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
[workspace]
members = [
"pineappl",
"pineappl_capi",
"pineappl_py",
"pineappl_cli",
]
members = ["pineappl", "pineappl_capi", "pineappl_cli"]

[profile.release]
lto = true
145 changes: 145 additions & 0 deletions pineappl/.gitignore
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions pineappl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions pineappl/src/bin.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<f64>,
Expand Down Expand Up @@ -148,6 +152,7 @@ impl PartialEq<BinInfo<'_>> for BinInfo<'_> {
}
}

#[cfg_attr(feature = "python", pymethods)]
impl BinRemapper {
/// Create a new `BinRemapper` object with the specified number of bins and dimensions and
/// limits.
Expand All @@ -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<f64>,
limits: Vec<(f64, f64)>,
Expand Down
3 changes: 3 additions & 0 deletions pineappl/src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SubgridEnum>,
Expand All @@ -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<LumiEntry>,
Expand Down
19 changes: 19 additions & 0 deletions pineappl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<bin::BinRemapper>()?;
//m.add_class::<grid::Grid>()?;
//m.add_class::<grid::Order>()?;
//m.add_class::<lagrange_subgrid::LagrangeSubgridV2>()?;
//m.add_class::<lumi::LumiEntry>()?;
//m.add_class::<subgrid::ExtraSubgridParams>()?;
//m.add_class::<subgrid::SubgridParams>()?;

Ok(())
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 0 additions & 23 deletions pineappl_py/Cargo.toml

This file was deleted.

3 changes: 0 additions & 3 deletions pineappl_py/src/bin.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
22 changes: 0 additions & 22 deletions pineappl_py/src/lib.rs

This file was deleted.