Skip to content
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

Update to PyO3 v0.23 #262

Merged
merged 3 commits into from
Dec 8, 2024
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: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.11
- name: Install pandoc
run: sudo apt-get install -y pandoc
- name: Install python dependencies
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.11
- name: Build Wheels
uses: PyO3/maturin-action@v1
with:
Expand All @@ -25,12 +25,12 @@ jobs:
path: dist

macos-x86_64:
runs-on: macos-12
runs-on: macos-14
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.11
architecture: x64
- name: Build wheels - x86_64
uses: PyO3/maturin-action@v1
Expand All @@ -48,7 +48,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.11
architecture: arm64
- name: Build wheels - aarch64
uses: PyO3/maturin-action@v1
Expand All @@ -69,7 +69,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.11
architecture: ${{ matrix.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
Expand All @@ -94,7 +94,7 @@ jobs:
merge-multiple: true
- uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.11
- name: Publish to PyPi
env:
TWINE_USERNAME: __token__
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.11
- name: Build Wheels
uses: PyO3/maturin-action@v1
with:
Expand All @@ -24,12 +24,12 @@ jobs:
name: wheel-linux-x86_64
path: dist
macos-x86_64:
runs-on: macos-12
runs-on: macos-14
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.11
architecture: x64
- name: Build wheels - x86_64
uses: PyO3/maturin-action@v1
Expand All @@ -47,7 +47,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.11
architecture: arm64
- name: Build wheels - aarch64
uses: PyO3/maturin-action@v1
Expand All @@ -65,7 +65,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.11
architecture: x64
- name: Build wheels
uses: PyO3/maturin-action@v1
Expand Down
12 changes: 6 additions & 6 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,8 +50,8 @@ itertools = "0.13"
typenum = "1.16"

[dependencies.pyo3]
version = "0.22"
features = ["extension-module", "abi3", "abi3-py37"]
version = "0.23"
features = ["extension-module", "abi3", "abi3-py39"]
optional = true

[dev-dependencies]
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
Loading
Loading