Skip to content

Commit

Permalink
Merge pull request #144 from lcpp-org/143-python-bindings-optional
Browse files Browse the repository at this point in the history
Made pyo3 optional.
  • Loading branch information
drobnyjt authored Aug 3, 2021
2 parents a61666f + fbdc452 commit 445d65c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
23 changes: 15 additions & 8 deletions .github/workflows/rustbca_compile_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
- name: Install rust
run: |
curl --proto '=https' --tlsv1.2 -sSf -y https://sh.rustup.rs | sh
sudo apt-get install rustc
- name: Install pip for Python-3
run: |
sudo apt-get install python3-pip
Expand All @@ -35,17 +36,23 @@ jobs:
- name: Install HDF5 Libraries
run: |
sudo apt install libhdf5-dev
- name: test Python Bindings
run: |
sudo python3 -m pip install setuptools_rust testresources
sudo python3 setup.py install
python3 -c "from libRustBCA.pybca import *; print(simple_bca_py)"
- name: Test RustBCA
run: |
cargo test --features cpr_rootfinder_netlib,hdf5_input,distributions,parry3d
sudo cargo test --features cpr_rootfinder_netlib,hdf5_input,distributions,parry3d
- name: Run Examples
run: |
cargo run --release 0D examples/boron_nitride_0D.toml
./target/release/RustBCA 0D examples/titanium_dioxide_0D.toml
./target/release/RustBCA 1D examples/layered_geometry_1D.toml
sudo cargo run --release 0D examples/boron_nitride_0D.toml
sudo ./target/release/RustBCA 0D examples/titanium_dioxide_0D.toml
sudo ./target/release/RustBCA 1D examples/layered_geometry_1D.toml
cat 2000.0eV_0.0001deg_He_TiO2_Al_Sisummary.output
./target/release/RustBCA examples/boron_nitride.toml
./target/release/RustBCA examples/layered_geometry.toml
sudo ./target/release/RustBCA examples/boron_nitride.toml
sudo ./target/release/RustBCA examples/layered_geometry.toml
cat 2000.0eV_0.0001deg_He_TiO2_Al_Sisummary.output
./target/release/RustBCA SPHERE examples/boron_nitride_sphere.toml
cargo run --release --features parry3d TRIMESH examples/tungsten_twist_trimesh.toml
sudo ./target/release/RustBCA SPHERE examples/boron_nitride_sphere.toml
sudo cargo run --release --features parry3d TRIMESH examples/tungsten_twist_trimesh.toml
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ parry3d-f64 = {version = "0.2.0", optional = true}
[dependencies.pyo3]
version = "0.13.2"
features = ["extension-module"]
optional = true

[dev-dependencies]
float-cmp = "0.8.0"
Expand All @@ -50,4 +51,5 @@ cpr_rootfinder_intel_mkl = ["rcpr", "intel-mkl-src"]
distributions = ["ndarray"]
no_list_output = []
parry3d = ["parry3d-f64"]
accelerated_ions = []
accelerated_ions = []
python = ["pyo3"]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name="RustBCA",
rust_extensions=[RustExtension("libRustBCA.pybca", binding=Binding.PyO3)],
rust_extensions=[RustExtension("libRustBCA.pybca", binding=Binding.PyO3, features=["python"])],
# rust extensions are not zip safe, just like C-extensions.
zip_safe=False,
)
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ use std::f64::consts::FRAC_2_SQRT_PI;
use std::f64::consts::PI;
use std::f64::consts::SQRT_2;

#[cfg(feature = "python")]
use pyo3::prelude::*;
#[cfg(feature = "python")]
use pyo3::wrap_pyfunction;

//Load internal modules
Expand Down Expand Up @@ -70,6 +72,7 @@ pub use crate::sphere::{Sphere, SphereInput, InputSphere};
#[cfg(feature = "parry3d")]
pub use crate::parry::{ParryBall, ParryBallInput, InputParryBall, ParryTriMesh, ParryTriMeshInput, InputParryTriMesh};

#[cfg(feature = "python")]
#[pymodule]
pub fn pybca(py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(simple_bca_py, m)?)?;
Expand Down Expand Up @@ -467,11 +470,13 @@ pub extern "C" fn simple_bca_c(x: f64, y: f64, z: f64, ux: f64, uy: f64, uz: f64
}
}

#[cfg(feature = "python")]
#[pyfunction]
pub fn simple_bca_py(x: f64, y: f64, z: f64, ux: f64, uy: f64, uz: f64, E1: f64, Z1: f64, m1: f64, Ec1: f64, Es1: f64, Z2: f64, m2: f64, Ec2: f64, Es2: f64, n2: f64, Eb2: f64) -> Vec<[f64; 9]> {
simple_bca(x, y, z, ux, uy, uz, E1, Z1, m1, Ec1, Es1, Z2, m2, Ec2, Es2, n2, Eb2)
}

#[cfg(feature = "python")]
#[pyfunction]
pub fn simple_bca_list_py(energies: Vec<f64>, usx: Vec<f64>, usy: Vec<f64>, usz: Vec<f64>, Z1: f64, m1: f64, Ec1: f64, Es1: f64, Z2: f64, m2: f64, Ec2: f64, Es2: f64, n2: f64, Eb2: f64) -> Vec<[f64; 9]> {

Expand Down

0 comments on commit 445d65c

Please sign in to comment.