Skip to content
This repository has been archived by the owner on Sep 14, 2022. It is now read-only.

Move creation of python module to build_wheel crate #29

Merged
merged 1 commit into from
Mar 11, 2022
Merged
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
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ quantity = "0.5"
feos-core = { git = "https://github.com/feos-org/feos-core" }
feos-dft = { git = "https://github.com/feos-org/feos-dft", branch = "v0.2.0" }
num-dual = "0.5"
num = "0.4"
num-traits = "0.2"
ndarray = { version = "0.15", features=["approx"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
indexmap = "1.8"
lazy_static = "1.4"
thiserror = "1.0"
numpy = { version = "0.16", optional = true }
pyo3 = { version = "0.16", optional = true }

Expand Down
4 changes: 4 additions & 0 deletions build_wheel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ edition = "2018"
crate-type = ["cdylib"]

[dependencies]
quantity = "0.5"
feos-core = { git = "https://github.com/feos-org/feos-core" }
feos-dft = { git = "https://github.com/feos-org/feos-dft", branch = "v0.2.0" }
feos-pcsaft = { path = "..", features = ["python"] }
pyo3 = { version = "0.16", features = ["extension-module", "abi3", "abi3-py37"] }
numpy = "0.16"
13 changes: 7 additions & 6 deletions src/python/dft.rs → build_wheel/src/dft.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use super::parameters::*;
use crate::dft::PcSaftFunctional;
use feos_core::utils::{
DataSet, EquilibriumLiquidDensity, Estimator, LiquidDensity, VaporPressure,
};
use feos_core::*;
use feos_dft::adsorption::*;
use feos_dft::fundamental_measure_theory::FMTVersion;
use feos_dft::interface::*;
use feos_dft::python::*;
use feos_dft::solvation::*;
use feos_dft::*;
use feos_pcsaft::python::*;
use feos_pcsaft::PcSaftFunctional;
use numpy::*;
use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;
Expand Down Expand Up @@ -54,10 +55,10 @@ impl PyPcSaftFunctional {
/// PcSaftFunctional
#[staticmethod]
#[pyo3(text_signature = "(parameters, fmt_version)")]
fn new_full(parameters: PyPcSaftParameters, fmt_version: PyFMTVersion) -> Self {
fn new_full(parameters: PyPcSaftParameters, fmt_version: FMTVersion) -> Self {
Self(Rc::new(PcSaftFunctional::new_full(
parameters.0,
fmt_version.0,
fmt_version,
)))
}
}
Expand Down Expand Up @@ -88,7 +89,7 @@ pub fn dft(py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_class::<PyPhaseDiagramHetero>()?;
m.add_class::<PyPhaseEquilibrium>()?;
m.add_class::<PyPlanarInterface>()?;
m.add_class::<PyGeometry>()?;
m.add_class::<Geometry>()?;
m.add_class::<PyPore1D>()?;
m.add_class::<PyPore3D>()?;
m.add_class::<PyPairCorrelation>()?;
Expand All @@ -98,7 +99,7 @@ pub fn dft(py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_class::<PySurfaceTensionDiagram>()?;
m.add_class::<PyDFTSolver>()?;
m.add_class::<PySolvationProfile>()?;
m.add_class::<PyFMTVersion>()?;
m.add_class::<FMTVersion>()?;

let utils = PyModule::new(py, "utils")?;
utils.add_class::<PyDataSet>()?;
Expand Down
15 changes: 2 additions & 13 deletions src/python/eos.rs → build_wheel/src/eos.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use super::parameters::PyPcSaftParameters;
use crate::eos::polar::DQVariants;
use crate::eos::{PcSaft, PcSaftOptions};
use feos_core::utils::{
DataSet, EquilibriumLiquidDensity, Estimator, LiquidDensity, VaporPressure,
};
use feos_core::*;
use feos_pcsaft::python::PyPcSaftParameters;
use feos_pcsaft::{PcSaft, PcSaftOptions};
use numpy::convert::ToPyArray;
use numpy::{PyArray1, PyArray2};
use pyo3::exceptions::PyValueError;
Expand All @@ -14,16 +13,6 @@ use quantity::si::*;
use std::collections::HashMap;
use std::rc::Rc;

impl From<&str> for DQVariants {
fn from(str: &str) -> Self {
match str {
"dq35" => Self::DQ35,
"dq44" => Self::DQ44,
_ => panic!("dq_variant must be either \"dq35\" or \"dq44\""),
}
}
}

/// Initialize PC-SAFT equation of state.
///
/// Parameters
Expand Down
50 changes: 47 additions & 3 deletions build_wheel/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,51 @@
use feos_pcsaft::python::feos_pcsaft;
use feos_core::python::joback::PyJobackRecord;
use feos_core::python::parameter::*;
use feos_core::{Contributions, Verbosity};
use feos_pcsaft::python::*;
use pyo3::prelude::*;
use pyo3::wrap_pymodule;
use quantity::python::__PYO3_PYMODULE_DEF_QUANTITY;

mod dft;
mod eos;
use dft::__PYO3_PYMODULE_DEF_DFT;
use eos::__PYO3_PYMODULE_DEF_EOS;

#[pymodule]
pub fn build_wheel(py: Python<'_>, m: &PyModule) -> PyResult<()> {
feos_pcsaft(py, m)
pub fn feos_pcsaft(py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_class::<PyIdentifier>()?;
m.add_class::<Verbosity>()?;
m.add_class::<Contributions>()?;
m.add_class::<PyChemicalRecord>()?;
m.add_class::<PyJobackRecord>()?;

m.add_class::<PyPcSaftRecord>()?;
m.add_class::<PyPureRecord>()?;
m.add_class::<PySegmentRecord>()?;
m.add_class::<PyBinaryRecord>()?;
m.add_class::<PyBinarySegmentRecord>()?;
m.add_class::<PyPcSaftParameters>()?;

m.add_wrapped(wrap_pymodule!(eos))?;
m.add_wrapped(wrap_pymodule!(dft))?;
m.add_wrapped(wrap_pymodule!(quantity))?;

py.run(
"\
import sys
sys.modules['feos_pcsaft.eos'] = eos
sys.modules['feos_pcsaft.eos.utils'] = eos.utils
sys.modules['feos_pcsaft.dft'] = dft
sys.modules['feos_pcsaft.dft.utils'] = dft.utils
quantity.SINumber.__module__ = 'feos_pcsaft.si'
quantity.SIArray1.__module__ = 'feos_pcsaft.si'
quantity.SIArray2.__module__ = 'feos_pcsaft.si'
quantity.SIArray3.__module__ = 'feos_pcsaft.si'
quantity.SIArray4.__module__ = 'feos_pcsaft.si'
sys.modules['feos_pcsaft.si'] = quantity
",
None,
Some(m.dict()),
)?;
Ok(())
}
11 changes: 11 additions & 0 deletions src/python/parameters.rs → src/python.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::eos::polar::DQVariants;
use crate::parameters::{PcSaftParameters, PcSaftRecord};
use feos_core::joback::JobackRecord;
use feos_core::parameter::{
Expand All @@ -11,6 +12,16 @@ use pyo3::prelude::*;
use std::convert::TryFrom;
use std::rc::Rc;

impl From<&str> for DQVariants {
fn from(str: &str) -> Self {
match str {
"dq35" => Self::DQ35,
"dq44" => Self::DQ44,
_ => panic!("dq_variant must be either \"dq35\" or \"dq44\""),
}
}
}

/// Create a set of PC-Saft parameters from records.
#[pyclass(name = "PcSaftRecord", unsendable)]
#[pyo3(
Expand Down
52 changes: 0 additions & 52 deletions src/python/mod.rs

This file was deleted.