Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Update to PyO3 v0.23
  • Loading branch information
prehner committed Dec 5, 2024
commit 13057cfaa01d7337a58324e0da384bc632346741
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ members = ["feos-core", "feos-dft", "feos-derive"]
crate-type = ["rlib", "cdylib"]

[dependencies]
quantity = "0.9"
num-dual = "0.10"
quantity = "0.10"
num-dual = "0.11"
feos-core = { version = "0.7", path = "feos-core" }
feos-dft = { version = "0.7", path = "feos-dft", optional = true }
feos-derive = { version = "0.5", path = "feos-derive" }
numpy = { version = "0.22", optional = true }
numpy = { version = "0.23", optional = true }
ndarray = { version = "0.16", features = ["approx"] }
petgraph = { version = "0.6", optional = true }
thiserror = "1.0"
thiserror = "2.0"
conv = "0.3"
num-traits = "0.2"
serde = "1.0"
Expand All @@ -50,7 +50,7 @@ itertools = "0.13"
typenum = "1.16"

[dependencies.pyo3]
version = "0.22"
version = "0.23"
features = ["extension-module", "abi3", "abi3-py37"]
Comment thread
prehner marked this conversation as resolved.
Outdated
optional = true

Expand Down
10 changes: 5 additions & 5 deletions feos-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ rustdoc-args = ["--html-in-header", "./docs-header.html"]
features = ["rayon"]

[dependencies]
quantity = { version = "0.9", features = ["approx", "ndarray"] }
num-dual = { version = "0.10", features = ["linalg"] }
quantity = { version = "0.10", features = ["approx", "ndarray"] }
num-dual = { version = "0.11", features = ["linalg"] }
ndarray = { version = "0.16", features = ["serde", "approx"] }
nalgebra = "0.33"
num-traits = "0.2"
thiserror = "1.0"
thiserror = "2.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
indexmap = "2.0"
conv = "0.3"
numpy = { version = "0.22", optional = true }
pyo3 = { version = "0.22", features = ["multiple-pymethods"], optional = true }
numpy = { version = "0.23", optional = true }
pyo3 = { version = "0.23", features = ["multiple-pymethods"], optional = true }
rayon = { version = "1.5", optional = true }
typenum = "1.16"
approx = "0.5"
Expand Down
4 changes: 2 additions & 2 deletions feos-core/src/python/parameter/fragmentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn fragment_molecule(
smiles: &str,
smarts: Vec<PySmartsRecord>,
) -> PyResult<(Vec<String>, Vec<[usize; 2]>)> {
let chem = py.import_bound("rdkit.Chem")?;
let chem = py.import("rdkit.Chem")?;
let mol = chem.call_method1("MolFromSmiles", (smiles,))?;
let atoms = mol.call_method0("GetNumHeavyAtoms")?.extract::<usize>()?;

Expand Down Expand Up @@ -155,7 +155,7 @@ fn fragment_molecule(
.for_each(|(_, m)| m.retain(|m| !(m.len() == 1 && large_segments.contains(&m[0]))));

let bonds = mol.call_method0("GetBonds")?;
let builtins = py.import_bound("builtins")?;
let builtins = py.import("builtins")?;
let bonds = builtins
.call_method1("list", (bonds,))?
.extract::<Vec<Bound<'_, PyAny>>>()?;
Expand Down
4 changes: 2 additions & 2 deletions feos-core/src/python/parameter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ macro_rules! impl_binary_record {
#[expect(irrefutable_let_patterns)]
fn get_model_record<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyAny>> {
Ok(if let Ok(mr) = f64::try_from(self.0.model_record.clone()) {
pyo3::types::PyFloat::new_bound(py, mr).into_any()
pyo3::types::PyFloat::new(py, mr).into_any()
} else {
Bound::new(py, $py_model_record(self.0.model_record.clone()))?.into_any()
})
Expand Down Expand Up @@ -744,7 +744,7 @@ macro_rules! impl_parameter {
self.0
.records()
.1
.map(|r| r.mapv(|r| f64::try_from(r).unwrap()).view().to_pyarray_bound(py))
.map(|r| r.mapv(|r| f64::try_from(r).unwrap()).view().to_pyarray(py))
}
}
};
Expand Down
18 changes: 9 additions & 9 deletions feos-core/src/python/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ macro_rules! impl_state {
/// -------
/// numpy.ndarray
fn ln_phi<'py>(&self, py: Python<'py>) -> Bound<'py, PyArray1<f64>> {
self.0.ln_phi().into_pyarray_bound(py)
self.0.ln_phi().into_pyarray(py)
}

/// Return logarithmic fugacity coefficient of all components treated as
Expand All @@ -568,7 +568,7 @@ macro_rules! impl_state {
/// -------
/// numpy.ndarray
fn ln_phi_pure_liquid<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyArray1<f64>>> {
Ok(self.0.ln_phi_pure_liquid()?.into_pyarray_bound(py))
Ok(self.0.ln_phi_pure_liquid()?.into_pyarray(py))
}

/// Return logarithmic symmetric activity coefficient.
Expand All @@ -577,7 +577,7 @@ macro_rules! impl_state {
/// -------
/// numpy.ndarray
fn ln_symmetric_activity_coefficient<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyArray1<f64>>> {
Ok(self.0.ln_symmetric_activity_coefficient()?.into_pyarray_bound(py))
Ok(self.0.ln_symmetric_activity_coefficient()?.into_pyarray(py))
}

/// Return Henry's law constant of every solute (x_i=0) for a given solvent (x_i>0).
Expand Down Expand Up @@ -650,7 +650,7 @@ macro_rules! impl_state {
/// -------
/// numpy.ndarray
fn thermodynamic_factor<'py>(&self, py: Python<'py>) -> Bound<'py, PyArray2<f64>> {
self.0.thermodynamic_factor().into_pyarray_bound(py)
self.0.thermodynamic_factor().into_pyarray(py)
}

/// Return molar isochoric heat capacity.
Expand Down Expand Up @@ -1021,7 +1021,7 @@ macro_rules! impl_state {
/// -------
/// numpy.ndarray[Float64]
fn massfracs<'py>(&self, py: Python<'py>) -> Bound<'py, PyArray1<f64>> {
self.0.massfracs().into_pyarray_bound(py)
self.0.massfracs().into_pyarray(py)
}

/// Return mass specific Helmholtz energy.
Expand Down Expand Up @@ -1168,7 +1168,7 @@ macro_rules! impl_state {

#[getter]
fn get_molefracs<'py>(&self, py: Python<'py>) -> Bound<'py, PyArray1<f64>> {
self.0.molefracs.to_pyarray_bound(py)
self.0.molefracs.to_pyarray(py)
}

fn _repr_markdown_(&self) -> String {
Expand Down Expand Up @@ -1318,7 +1318,7 @@ macro_rules! impl_state {

#[getter]
fn get_compressibility<'py>(&self, py: Python<'py>) -> Bound<'py, PyArray1<f64>> {
StateVec::from(self).compressibility().into_pyarray_bound(py)
StateVec::from(self).compressibility().into_pyarray(py)
}

#[getter]
Expand All @@ -1333,7 +1333,7 @@ macro_rules! impl_state {

#[getter]
fn get_molefracs<'py>(&self, py: Python<'py>) -> Bound<'py, PyArray2<f64>> {
StateVec::from(self).molefracs().into_pyarray_bound(py)
StateVec::from(self).molefracs().into_pyarray(py)
}

#[getter]
Expand All @@ -1343,7 +1343,7 @@ macro_rules! impl_state {

#[getter]
fn get_massfracs<'py>(&self, py: Python<'py>) -> Option<Bound<'py, PyArray2<f64>>> {
self.0[0].eos.residual.has_molar_weight().then(|| StateVec::from(self).massfracs().into_pyarray_bound(py))
self.0[0].eos.residual.has_molar_weight().then(|| StateVec::from(self).massfracs().into_pyarray(py))
}

/// Returns selected properties of a StateVec as dictionary.
Expand Down
2 changes: 1 addition & 1 deletion feos-core/src/python/user_defined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ macro_rules! impl_residual {
let py_result = self
.0
.bind(py)
.call_method1("max_density", (moles.to_owned().into_pyarray_bound(py),))
.call_method1("max_density", (moles.to_owned().into_pyarray(py),))
.unwrap();
py_result.extract().unwrap()
})
Expand Down
8 changes: 4 additions & 4 deletions feos-core/src/state/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub struct StateBuilder<'a, E, const IG: bool> {
initial_temperature: Option<Temperature>,
}

impl<'a, E: Residual> StateBuilder<'a, E, false> {
impl<E: Residual> StateBuilder<'_, E, false> {
/// Create a new `StateBuilder` for the given equation of state.
pub fn new(eos: &Arc<E>) -> Self {
StateBuilder {
Expand Down Expand Up @@ -211,7 +211,7 @@ impl<'a, E: Residual + IdealGas, const IG: bool> StateBuilder<'a, E, IG> {
}
}

impl<'a, E: Residual> StateBuilder<'a, E, false> {
impl<E: Residual> StateBuilder<'_, E, false> {
/// Try to build the state with the given inputs.
pub fn build(self) -> EosResult<State<E>> {
State::new(
Expand All @@ -229,7 +229,7 @@ impl<'a, E: Residual> StateBuilder<'a, E, false> {
}
}

impl<'a, E: Residual + IdealGas> StateBuilder<'a, E, true> {
impl<E: Residual + IdealGas> StateBuilder<'_, E, true> {
/// Try to build the state with the given inputs.
pub fn build(self) -> EosResult<State<E>> {
State::new_full(
Expand All @@ -251,7 +251,7 @@ impl<'a, E: Residual + IdealGas> StateBuilder<'a, E, true> {
}
}

impl<'a, E, const IG: bool> Clone for StateBuilder<'a, E, IG> {
impl<E, const IG: bool> Clone for StateBuilder<'_, E, IG> {
fn clone(&self) -> Self {
Self {
eos: self.eos.clone(),
Expand Down
8 changes: 4 additions & 4 deletions feos-core/src/state/statevec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl<'a, E> Deref for StateVec<'a, E> {
}
}

impl<'a, E: Residual> StateVec<'a, E> {
impl<E: Residual> StateVec<'_, E> {
pub fn temperature(&self) -> Temperature<Array1<f64>> {
Temperature::from_shape_fn(self.0.len(), |i| self.0[i].temperature)
}
Expand Down Expand Up @@ -67,7 +67,7 @@ impl<'a, E: Residual> StateVec<'a, E> {
}
}

impl<'a, E: Residual + Molarweight> StateVec<'a, E> {
impl<E: Residual + Molarweight> StateVec<'_, E> {
pub fn mass_density(&self) -> MassDensity<Array1<f64>> {
MassDensity::from_shape_fn(self.0.len(), |i| self.0[i].mass_density())
}
Expand All @@ -79,7 +79,7 @@ impl<'a, E: Residual + Molarweight> StateVec<'a, E> {
}
}

impl<'a, E: Residual + IdealGas> StateVec<'a, E> {
impl<E: Residual + IdealGas> StateVec<'_, E> {
pub fn molar_enthalpy(&self, contributions: Contributions) -> MolarEnergy<Array1<f64>> {
MolarEnergy::from_shape_fn(self.0.len(), |i| self.0[i].molar_enthalpy(contributions))
}
Expand All @@ -89,7 +89,7 @@ impl<'a, E: Residual + IdealGas> StateVec<'a, E> {
}
}

impl<'a, E: Residual + Molarweight + IdealGas> StateVec<'a, E> {
impl<E: Residual + Molarweight + IdealGas> StateVec<'_, E> {
pub fn specific_enthalpy(&self, contributions: Contributions) -> SpecificEnergy<Array1<f64>> {
SpecificEnergy::from_shape_fn(self.0.len(), |i| self.0[i].specific_enthalpy(contributions))
}
Expand Down
8 changes: 4 additions & 4 deletions feos-dft/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ rustdoc-args = ["--html-in-header", "./docs-header.html"]
features = ["rayon"]

[dependencies]
quantity = "0.9"
num-dual = "0.10"
quantity = "0.10"
num-dual = "0.11"
feos-core = { version = "0.7", path = "../feos-core" }
ndarray = "0.16"
nalgebra = "0.33"
Expand All @@ -32,8 +32,8 @@ libm = "0.2"
gauss-quad = { version = "0.2", optional = true }
petgraph = "0.6"
typenum = "1.16"
numpy = { version = "0.22", optional = true }
pyo3 = { version = "0.22", optional = true }
numpy = { version = "0.23", optional = true }
pyo3 = { version = "0.23", optional = true }

[features]
default = []
Expand Down
2 changes: 1 addition & 1 deletion feos-dft/src/python/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ macro_rules! impl_planar_interface {
/// numpy.ndarray
///
fn interfacial_enrichment<'py>(&self, py: Python<'py>) -> Bound<'py, PyArray1<f64>> {
self.0.interfacial_enrichment().to_pyarray_bound(py)
self.0.interfacial_enrichment().to_pyarray(py)
}

/// Calculates the interfacial thickness (90-10 number density difference)
Expand Down
2 changes: 1 addition & 1 deletion feos-dft/src/python/interface/surface_tension_diagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ macro_rules! impl_surface_tension_diagram {

#[getter]
pub fn get_interfacial_enrichment<'py>(&self, py: Python<'py>) -> Vec<Bound<'py, PyArray1<f64>>> {
self.0.interfacial_enrichment().iter().map(|i| i.to_pyarray_bound(py)).collect()
self.0.interfacial_enrichment().iter().map(|i| i.to_pyarray(py)).collect()
}

#[getter]
Expand Down
8 changes: 4 additions & 4 deletions feos-dft/src/python/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ macro_rules! impl_profile {
py: Python<'py>,
) -> PyResult<(Bound<'py, $arr2<f64>>, Bound<'py, PyArray1<f64>>, f64)> {
let (res_rho, res_mu, res_norm) = self.0.profile.residual(log)?;
Ok((res_rho.view().to_pyarray_bound(py), res_mu.view().to_pyarray_bound(py), res_norm))
Ok((res_rho.view().to_pyarray(py), res_mu.view().to_pyarray(py), res_norm))
}

/// Solve the profile in-place. A non-default solver can be provided
Expand Down Expand Up @@ -74,7 +74,7 @@ macro_rules! impl_profile {

#[getter]
fn get_external_potential<'py>(&self, py: Python<'py>) -> Bound<'py, $py_arr2<f64>> {
self.0.profile.external_potential.view().to_pyarray_bound(py)
self.0.profile.external_potential.view().to_pyarray(py)
}

#[getter]
Expand All @@ -93,15 +93,15 @@ macro_rules! impl_profile {
py: Python<'py>,
) -> PyResult<Vec<Bound<'py, $arr2<f64>>>> {
let n = self.0.profile.weighted_densities()?;
Ok(n.into_iter().map(|n| n.view().to_pyarray_bound(py)).collect())
Ok(n.into_iter().map(|n| n.view().to_pyarray(py)).collect())
}

#[getter]
fn get_functional_derivative<'py>(
&self,
py: Python<'py>,
) -> PyResult<Bound<'py, $arr2<f64>>> {
Ok(self.0.profile.functional_derivative()?.view().to_pyarray_bound(py))
Ok(self.0.profile.functional_derivative()?.view().to_pyarray(py))
}

/// Calculate the entropy density of the inhomogeneous system.
Expand Down
2 changes: 1 addition & 1 deletion feos-dft/src/python/solvation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ macro_rules! impl_pair_correlation {
self.0
.pair_correlation_function
.as_ref()
.map(|g| g.view().to_pyarray_bound(py))
.map(|g| g.view().to_pyarray(py))
}

#[getter]
Expand Down
2 changes: 1 addition & 1 deletion feos-dft/src/python/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub struct PyDFTSolverLog(pub DFTSolverLog);
impl PyDFTSolverLog {
#[getter]
fn get_residual<'py>(&self, py: Python<'py>) -> Bound<'py, PyArray1<f64>> {
self.0.residual().to_pyarray_bound(py)
self.0.residual().to_pyarray(py)
}

#[getter]
Expand Down
5 changes: 1 addition & 4 deletions feos-dft/src/weight_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,7 @@ pub enum WeightFunctionShape {
DeltaVec,
}

/// Defining `type` for information about weight functions based on
/// `WeightFunctionBase<TScal, TVec>`.
// pub type WeightFunctionInfo<T> = WeightFunctionBase<WeightFunction<T>, WeightFunction<T>>;

/// Information about weight functions
pub struct WeightFunctionInfo<T> {
/// Index of the component that each individual segment belongs to.
pub(crate) component_index: Array1<usize>,
Expand Down
Loading