Skip to content

Commit

Permalink
Move benchmarks to separate crate (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
prehner authored Dec 28, 2024
1 parent cf852b5 commit 8ec3ab8
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 72 deletions.
27 changes: 1 addition & 26 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ features = ["all_models", "rayon"]
rustdoc-args = ["--html-in-header", "./docs-header.html"]

[workspace]
members = ["feos-core", "feos-dft", "feos-derive"]
members = ["feos-core", "feos-dft", "feos-derive", "feos-benchmarks"]

[lib]
crate-type = ["rlib", "cdylib"]
Expand Down Expand Up @@ -56,7 +56,6 @@ optional = true

[dev-dependencies]
approx = "0.5"
criterion = "0.5"

[profile.release-lto]
inherits = "release"
Expand Down Expand Up @@ -101,27 +100,3 @@ all_models = [
"saftvrqmie",
"saftvrmie",
]

[[bench]]
name = "state_properties"
harness = false

[[bench]]
name = "state_creation"
harness = false

[[bench]]
name = "dual_numbers"
harness = false

[[bench]]
name = "dual_numbers_saftvrmie"
harness = false

[[bench]]
name = "contributions"
harness = false

[[bench]]
name = "dft_pore"
harness = false
38 changes: 38 additions & 0 deletions feos-benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = "feos-benchmarks"
version = "0.1.0"
edition = "2021"

[dependencies]
feos = { path = "..", features = ["pcsaft", "saftvrmie", "gc_pcsaft", "dft"] }
quantity = "0.10"
num-dual = "0.11"
ndarray = "0.16"
typenum = "1"

[dev-dependencies]
criterion = "0.5"

[[bench]]
name = "state_properties"
harness = false

[[bench]]
name = "state_creation"
harness = false

[[bench]]
name = "dual_numbers"
harness = false

[[bench]]
name = "dual_numbers_saftvrmie"
harness = false

[[bench]]
name = "contributions"
harness = false

[[bench]]
name = "dft_pore"
harness = false
18 changes: 9 additions & 9 deletions benches/README.md → feos-benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

This directory contains different benchmarks.
For best performance, use the `release-lto` profile.
Depending on the benchmark, you might have to consider different Cargo `features` as denoted in the table below.

For example, to run the benchmarks in `dual_numbers`, which uses PC-SAFT, use

```
cargo bench --profile=release-lto --features=pcsaft --bench=dual_numbers
cargo bench --profile=release-lto --bench=dual_numbers
```

|Name|Description|Cargo features|
|--|--|--|
|`dual_numbers`|Helmholtz energy function evaluated using `StateHD` with different dual number types.|`pcsaft`|
|`state_properties`|Properties of `State`. Including state creation using the natural variables of the Helmholtz energy (no density iteration).|`pcsaft`|
|`state_creation`|Different constructors of `State` and `PhaseEquilibrium` including critical point calculations. For pure substances and mixtures.|`pcsaft`|
|`contributions`|Helmholtz energy evaluated for various binary mixtures with different Helmholtz energy contributions. |`pcsaft`|
|`dft_pore`|Calculation of density profiles in pores using different functionals and bulk conditions. For pure substances, mixtures and heterosegmented chains.|`pcsaft`, `gc_pcsaft`, `dft`|
|Name|Description|
|--|--|
|`dual_numbers`|Helmholtz energy function evaluated using `StateHD` with different dual number types using the PC-SAFT equation of state.|
|`dual_numbers_saftvrmie`|Helmholtz energy function evaluated using `StateHD` with different dual number types using the SAFT-VR-Mie equation of state.|
|`state_properties`|Properties of `State`. Including state creation using the natural variables of the Helmholtz energy (no density iteration).|
|`state_creation`|Different constructors of `State` and `PhaseEquilibrium` including critical point calculations. For pure substances and mixtures.|
|`contributions`|Helmholtz energy evaluated for various binary mixtures with different Helmholtz energy contributions. |
|`dft_pore`|Calculation of density profiles in pores using different functionals and bulk conditions. For pure substances, mixtures and heterosegmented chains.|
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
//! performance when more complex physical interactions are
//! modeled.
use criterion::{criterion_group, criterion_main, Criterion};
use feos::core::parameter::{IdentifierOption, Parameter};
use feos::core::{DensityInitialization, Derivative, Residual, State};
use feos::pcsaft::{PcSaft, PcSaftParameters};
use feos_core::parameter::{IdentifierOption, Parameter};
use quantity::*;
use feos_core::{DensityInitialization, Derivative, Residual, State};
use ndarray::arr1;
use quantity::*;
use std::sync::Arc;

/// Benchmark for the PC-SAFT equation of state
Expand All @@ -20,7 +20,7 @@ fn pcsaft(c: &mut Criterion) {
// non-polar components
let mut records = PcSaftParameters::from_json(
vec!["hexane", "heptane"],
"./parameters/pcsaft/gross2001.json",
"../parameters/pcsaft/gross2001.json",
None,
IdentifierOption::Name,
)
Expand All @@ -32,7 +32,7 @@ fn pcsaft(c: &mut Criterion) {
// dipolar components
records = PcSaftParameters::from_json(
vec!["acetone", "dimethyl ether"],
"./parameters/pcsaft/gross2006.json",
"../parameters/pcsaft/gross2006.json",
None,
IdentifierOption::Name,
)
Expand All @@ -44,7 +44,7 @@ fn pcsaft(c: &mut Criterion) {
// quadrupolar components
records = PcSaftParameters::from_json(
vec!["carbon dioxide", "acetylene"],
"./parameters/pcsaft/gross2005_literature.json",
"../parameters/pcsaft/gross2005_literature.json",
None,
IdentifierOption::Name,
)
Expand All @@ -56,7 +56,7 @@ fn pcsaft(c: &mut Criterion) {
// associating components
records = PcSaftParameters::from_json(
vec!["ethanol", "1-propanol"],
"./parameters/pcsaft/gross2002.json",
"../parameters/pcsaft/gross2002.json",
None,
IdentifierOption::Name,
)
Expand Down
16 changes: 8 additions & 8 deletions benches/dft_pore.rs → feos-benchmarks/benches/dft_pore.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! Benchmarks for the calculation of density profiles
//! in pores at different conditions.
use criterion::{criterion_group, criterion_main, Criterion};
use feos::core::parameter::{IdentifierOption, Parameter, ParameterHetero};
use feos::core::{PhaseEquilibrium, State, StateBuilder};
use feos::dft::adsorption::{ExternalPotential, Pore1D, PoreSpecification};
use feos::dft::{DFTSolver, Geometry};
use feos::gc_pcsaft::{GcPcSaftFunctional, GcPcSaftFunctionalParameters};
use feos::hard_sphere::{FMTFunctional, FMTVersion};
use feos::pcsaft::{PcSaftFunctional, PcSaftParameters};
use feos_core::parameter::{IdentifierOption, Parameter, ParameterHetero};
use feos_core::{PhaseEquilibrium, State, StateBuilder};
use feos_dft::adsorption::{ExternalPotential, Pore1D, PoreSpecification};
use feos_dft::{DFTSolver, Geometry};
use ndarray::arr1;
use quantity::{ANGSTROM, KELVIN, NAV};
use std::sync::Arc;
Expand All @@ -34,7 +34,7 @@ fn pcsaft(c: &mut Criterion) {
let mut group = c.benchmark_group("DFT_pore_pcsaft");
let parameters = PcSaftParameters::from_json(
vec!["butane"],
"./parameters/pcsaft/gross2001.json",
"../parameters/pcsaft/gross2001.json",
None,
IdentifierOption::Name,
)
Expand Down Expand Up @@ -63,7 +63,7 @@ fn pcsaft(c: &mut Criterion) {

let parameters = PcSaftParameters::from_json(
vec!["butane", "pentane"],
"./parameters/pcsaft/gross2001.json",
"../parameters/pcsaft/gross2001.json",
None,
IdentifierOption::Name,
)
Expand Down Expand Up @@ -98,8 +98,8 @@ fn gc_pcsaft(c: &mut Criterion) {

let parameters = GcPcSaftFunctionalParameters::from_json_segments(
&["butane"],
"./parameters/pcsaft/gc_substances.json",
"./parameters/pcsaft/sauer2014_hetero.json",
"../parameters/pcsaft/gc_substances.json",
"../parameters/pcsaft/sauer2014_hetero.json",
None,
IdentifierOption::Name,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
//! on the dual number type used without the overhead of the `State`
//! creation.
use criterion::{criterion_group, criterion_main, Criterion};
use feos::pcsaft::{PcSaft, PcSaftParameters};
use quantity::*;
use feos_core::{
use feos::core::{
parameter::{IdentifierOption, Parameter},
Derivative, Residual, State, StateHD,
};
use feos::pcsaft::{PcSaft, PcSaftParameters};
use ndarray::{arr1, Array, ScalarOperand};
use num_dual::DualNum;
use quantity::*;
use std::sync::Arc;
use typenum::P3;

Expand Down Expand Up @@ -63,7 +63,7 @@ fn pcsaft(c: &mut Criterion) {
// methane
let parameters = PcSaftParameters::from_json(
vec!["methane"],
"./parameters/pcsaft/gross2001.json",
"../parameters/pcsaft/gross2001.json",
None,
IdentifierOption::Name,
)
Expand All @@ -73,7 +73,7 @@ fn pcsaft(c: &mut Criterion) {
// water (4C, polar)
let parameters = PcSaftParameters::from_json(
vec!["water_4C_polar"],
"./parameters/pcsaft/rehner2020.json",
"../parameters/pcsaft/rehner2020.json",
None,
IdentifierOption::Name,
)
Expand All @@ -87,7 +87,7 @@ fn pcsaft(c: &mut Criterion) {
// methane, ethane, propane
let parameters = PcSaftParameters::from_json(
vec!["methane", "ethane", "propane"],
"./parameters/pcsaft/gross2001.json",
"../parameters/pcsaft/gross2001.json",
None,
IdentifierOption::Name,
)
Expand All @@ -104,10 +104,10 @@ fn pcsaft(c: &mut Criterion) {
fn methane_co2_pcsaft(c: &mut Criterion) {
let parameters = PcSaftParameters::from_multiple_json(
&[
(vec!["methane"], "./parameters/pcsaft/gross2001.json"),
(vec!["methane"], "../parameters/pcsaft/gross2001.json"),
(
vec!["carbon dioxide"],
"./parameters/pcsaft/gross2005_fit.json",
"../parameters/pcsaft/gross2005_fit.json",
),
],
None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
//! on the dual number type used without the overhead of the `State`
//! creation.
use criterion::{criterion_group, criterion_main, Criterion};
use feos::core::{Derivative, Residual, State, StateHD};
use feos::hard_sphere::HardSphereProperties;
use feos::saftvrmie::{test_utils::test_parameters, SaftVRMie, SaftVRMieParameters};
use feos_core::{Derivative, Residual, State, StateHD};
use ndarray::{Array, ScalarOperand};
use num_dual::DualNum;
use quantity::*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#![allow(clippy::type_complexity)]
use criterion::{criterion_group, criterion_main, Criterion};
use feos::pcsaft::{PcSaft, PcSaftParameters};
use quantity::*;
use feos_core::{
use feos::core::{
parameter::{IdentifierOption, Parameter},
Contributions, DensityInitialization, PhaseEquilibrium, Residual, State, TemperatureOrPressure,
};
use feos::pcsaft::{PcSaft, PcSaftParameters};
use ndarray::{Array, Array1};
use quantity::*;
use std::sync::Arc;

/// Evaluate NPT constructor
Expand Down Expand Up @@ -152,7 +152,7 @@ fn bench_states<E: Residual>(c: &mut Criterion, group_name: &str, eos: &Arc<E>)
fn pcsaft(c: &mut Criterion) {
let parameters = PcSaftParameters::from_json(
vec!["methane"],
"./parameters/pcsaft/gross2001.json",
"../parameters/pcsaft/gross2001.json",
None,
IdentifierOption::Name,
)
Expand All @@ -162,7 +162,7 @@ fn pcsaft(c: &mut Criterion) {

let parameters = PcSaftParameters::from_json(
vec!["methane", "ethane"],
"./parameters/pcsaft/gross2001.json",
"../parameters/pcsaft/gross2001.json",
None,
IdentifierOption::Name,
)
Expand All @@ -172,7 +172,7 @@ fn pcsaft(c: &mut Criterion) {

let parameters = PcSaftParameters::from_json(
vec!["methane", "ethane", "propane"],
"./parameters/pcsaft/gross2001.json",
"../parameters/pcsaft/gross2001.json",
None,
IdentifierOption::Name,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#![allow(clippy::type_complexity)]
use criterion::{criterion_group, criterion_main, Criterion};
use feos::core::parameter::{IdentifierOption, Parameter};
use feos::core::{Contributions, Residual, State};
use feos::pcsaft::{PcSaft, PcSaftParameters};
use quantity::*;
use feos_core::{
parameter::{IdentifierOption, Parameter},
Contributions, Residual, State,
};
use ndarray::{arr1, Array1};
use quantity::*;
use std::sync::Arc;
use typenum::P3;

Expand Down Expand Up @@ -40,7 +38,7 @@ fn property_no_contributions<E: Residual, T, F: Fn(&State<E>) -> T>(
fn properties_pcsaft(c: &mut Criterion) {
let parameters = PcSaftParameters::from_json(
vec!["methane", "ethane", "propane"],
"./parameters/pcsaft/gross2001.json",
"../parameters/pcsaft/gross2001.json",
None,
IdentifierOption::Name,
)
Expand Down Expand Up @@ -75,7 +73,7 @@ fn properties_pcsaft(c: &mut Criterion) {
fn properties_pcsaft_polar(c: &mut Criterion) {
let parameters = PcSaftParameters::from_json(
vec!["acetone", "butanal", "dimethyl ether"],
"./parameters/pcsaft/gross2006.json",
"../parameters/pcsaft/gross2006.json",
None,
IdentifierOption::Name,
)
Expand Down
1 change: 1 addition & 0 deletions feos-benchmarks/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit 8ec3ab8

Please sign in to comment.