Skip to content
Open
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
14 changes: 6 additions & 8 deletions benches/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@
#![allow(dead_code)]

use ndarray::Array2;
use pharmsol::metadata::{self, ModelMetadata};
use pharmsol::prelude::*;
use pharmsol::simulator::equation::analytical::{
use pharmsol::simulator::backends::analytical::{
one_compartment_with_absorption, two_compartments,
};
use pharmsol::{
equation::{self, Route},
Analytical, ResidualErrorModel, ResidualErrorModels, ODE, SDE,
};
use pharmsol::{backends::Route, Analytical, ResidualErrorModel, ResidualErrorModels, ODE, SDE};

/// `ModelMetadata` for handwritten factories so route/output labels resolve like the macro/DSL paths.
fn model_metadata(workload: Workload, kind: SolverKind) -> equation::ModelMetadata {
fn model_metadata(workload: Workload, kind: SolverKind) -> ModelMetadata {
let name = match (workload, kind) {
(Workload::Short, SolverKind::Ode) => "bench_one_cpt_po_ode",
(Workload::Short, SolverKind::Analytical) => "bench_one_cpt_po_analytical",
Expand All @@ -37,7 +35,7 @@ fn model_metadata(workload: Workload, kind: SolverKind) -> equation::ModelMetada
SolverKind::Sde => &["ka", "ke", "v", "sigma_ke"],
_ => &["ka", "ke", "v"],
};
equation::metadata::new(name)
metadata::new(name)
.parameters(params.iter().copied())
.states(["depot", "central"])
.outputs(["plasma"])
Expand All @@ -52,7 +50,7 @@ fn model_metadata(workload: Workload, kind: SolverKind) -> equation::ModelMetada
SolverKind::Sde => &["ke", "kcp", "kpc", "v", "sigma_ke"],
_ => &["ke", "kcp", "kpc", "v"],
};
equation::metadata::new(name)
metadata::new(name)
.parameters(params.iter().copied())
.states(["central", "peripheral"])
.outputs(["plasma"])
Expand Down
14 changes: 7 additions & 7 deletions benches/dsl_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use pharmsol::dsl::{
NativeAotCompileOptions, NativeOdeModel, NativeSdeModel, RuntimeCompilationTarget,
};
use pharmsol::prelude::*;
use pharmsol::{Cache, Parameters};
use pharmsol::Parameters;

mod common;
use common::{
Expand Down Expand Up @@ -245,7 +245,7 @@ fn predictions_group(c: &mut Criterion) {
let model = match cache {
CacheState::Hot => compile_ode(workload, backend, &aot),
CacheState::Cold => {
compile_ode(workload, backend, &aot).disable_cache()
compile_ode(workload, backend, &aot).without_cache()
}
};
let theta = ode_parameters(&model, workload);
Expand All @@ -266,7 +266,7 @@ fn predictions_group(c: &mut Criterion) {
let model = match cache {
CacheState::Hot => compile_analytical(workload, backend, &aot),
CacheState::Cold => {
compile_analytical(workload, backend, &aot).disable_cache()
compile_analytical(workload, backend, &aot).without_cache()
}
};
let theta = analytical_parameters(&model, workload);
Expand All @@ -287,7 +287,7 @@ fn predictions_group(c: &mut Criterion) {
let model = match cache {
CacheState::Hot => compile_sde(workload, backend, &aot),
CacheState::Cold => {
compile_sde(workload, backend, &aot).disable_cache()
compile_sde(workload, backend, &aot).without_cache()
}
};
let theta = sde_parameters(&model, workload);
Expand Down Expand Up @@ -339,7 +339,7 @@ fn log_likelihood_group(c: &mut Criterion) {
let model = match cache {
CacheState::Hot => compile_ode(workload, backend, &aot),
CacheState::Cold => {
compile_ode(workload, backend, &aot).disable_cache()
compile_ode(workload, backend, &aot).without_cache()
}
};
let theta = ode_parameters(&model, workload);
Expand All @@ -361,7 +361,7 @@ fn log_likelihood_group(c: &mut Criterion) {
let model = match cache {
CacheState::Hot => compile_analytical(workload, backend, &aot),
CacheState::Cold => {
compile_analytical(workload, backend, &aot).disable_cache()
compile_analytical(workload, backend, &aot).without_cache()
}
};
let theta = analytical_parameters(&model, workload);
Expand All @@ -383,7 +383,7 @@ fn log_likelihood_group(c: &mut Criterion) {
let model = match cache {
CacheState::Hot => compile_sde(workload, backend, &aot),
CacheState::Cold => {
compile_sde(workload, backend, &aot).disable_cache()
compile_sde(workload, backend, &aot).without_cache()
}
};
let theta = sde_parameters(&model, workload);
Expand Down
26 changes: 13 additions & 13 deletions benches/native_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::time::Duration;

use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, SamplingMode};
use pharmsol::prelude::*;
use pharmsol::{Analytical, Cache, Parameters, ODE, SDE};
use pharmsol::{Analytical, Parameters, ODE, SDE};

mod common;
use common::{
Expand Down Expand Up @@ -113,7 +113,7 @@ fn predictions_group(c: &mut Criterion) {
});
}
(SolverKind::Ode, Authoring::Handwritten, CacheState::Cold) => {
let model = handwritten_ode(workload).disable_cache();
let model = handwritten_ode(workload).without_cache();
let theta = ode_parameters(&model, workload);
b.iter(|| {
black_box(
Expand Down Expand Up @@ -141,7 +141,7 @@ fn predictions_group(c: &mut Criterion) {
});
}
(SolverKind::Ode, Authoring::Macro, CacheState::Cold) => {
let model = macro_ode(workload).disable_cache();
let model = macro_ode(workload).without_cache();
let theta = ode_parameters(&model, workload);
b.iter(|| {
black_box(
Expand Down Expand Up @@ -169,7 +169,7 @@ fn predictions_group(c: &mut Criterion) {
});
}
(SolverKind::Analytical, Authoring::Handwritten, CacheState::Cold) => {
let model = handwritten_analytical(workload).disable_cache();
let model = handwritten_analytical(workload).without_cache();
let theta = analytical_parameters(&model, workload);
b.iter(|| {
black_box(
Expand Down Expand Up @@ -197,7 +197,7 @@ fn predictions_group(c: &mut Criterion) {
});
}
(SolverKind::Analytical, Authoring::Macro, CacheState::Cold) => {
let model = macro_analytical(workload).disable_cache();
let model = macro_analytical(workload).without_cache();
let theta = analytical_parameters(&model, workload);
b.iter(|| {
black_box(
Expand Down Expand Up @@ -225,7 +225,7 @@ fn predictions_group(c: &mut Criterion) {
});
}
(SolverKind::Sde, Authoring::Handwritten, CacheState::Cold) => {
let model = handwritten_sde(workload).disable_cache();
let model = handwritten_sde(workload).without_cache();
let theta = sde_parameters(&model, workload);
b.iter(|| {
black_box(
Expand Down Expand Up @@ -253,7 +253,7 @@ fn predictions_group(c: &mut Criterion) {
});
}
(SolverKind::Sde, Authoring::Macro, CacheState::Cold) => {
let model = macro_sde(workload).disable_cache();
let model = macro_sde(workload).without_cache();
let theta = sde_parameters(&model, workload);
b.iter(|| {
black_box(
Expand Down Expand Up @@ -304,7 +304,7 @@ fn log_likelihood_group(c: &mut Criterion) {
});
}
(SolverKind::Ode, Authoring::Handwritten, CacheState::Cold) => {
let model = handwritten_ode(workload).disable_cache();
let model = handwritten_ode(workload).without_cache();
let theta = ode_parameters(&model, workload);
b.iter(|| {
black_box(
Expand Down Expand Up @@ -334,7 +334,7 @@ fn log_likelihood_group(c: &mut Criterion) {
});
}
(SolverKind::Ode, Authoring::Macro, CacheState::Cold) => {
let model = macro_ode(workload).disable_cache();
let model = macro_ode(workload).without_cache();
let theta = ode_parameters(&model, workload);
b.iter(|| {
black_box(
Expand Down Expand Up @@ -364,7 +364,7 @@ fn log_likelihood_group(c: &mut Criterion) {
});
}
(SolverKind::Analytical, Authoring::Handwritten, CacheState::Cold) => {
let model = handwritten_analytical(workload).disable_cache();
let model = handwritten_analytical(workload).without_cache();
let theta = analytical_parameters(&model, workload);
b.iter(|| {
black_box(
Expand Down Expand Up @@ -394,7 +394,7 @@ fn log_likelihood_group(c: &mut Criterion) {
});
}
(SolverKind::Analytical, Authoring::Macro, CacheState::Cold) => {
let model = macro_analytical(workload).disable_cache();
let model = macro_analytical(workload).without_cache();
let theta = analytical_parameters(&model, workload);
b.iter(|| {
black_box(
Expand Down Expand Up @@ -424,7 +424,7 @@ fn log_likelihood_group(c: &mut Criterion) {
});
}
(SolverKind::Sde, Authoring::Handwritten, CacheState::Cold) => {
let model = handwritten_sde(workload).disable_cache();
let model = handwritten_sde(workload).without_cache();
let theta = sde_parameters(&model, workload);
b.iter(|| {
black_box(
Expand Down Expand Up @@ -454,7 +454,7 @@ fn log_likelihood_group(c: &mut Criterion) {
});
}
(SolverKind::Sde, Authoring::Macro, CacheState::Cold) => {
let model = macro_sde(workload).disable_cache();
let model = macro_sde(workload).without_cache();
let theta = sde_parameters(&model, workload);
b.iter(|| {
black_box(
Expand Down
4 changes: 2 additions & 2 deletions examples/compare_solvers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use pharmsol::{prelude::*, Parameters};
// between runs; the declaration-first `ode!` surface and the generated
// metadata stay the same.

fn two_cpt(solver: OdeSolver) -> equation::ODE {
fn two_cpt(solver: OdeSolver) -> backends::ODE {
ode! {
name: "two_cpt",
params: [ke, kcp, kpc, v],
Expand Down Expand Up @@ -74,7 +74,7 @@ fn main() {
)
.expect("valid named parameters");

let results: Vec<(&str, equation::ODE)> = vec![
let results: Vec<(&str, backends::ODE)> = vec![
("Bdf", bdf),
("Sdirk(TrBdf2)", trbdf2),
("Sdirk(Esdirk34)", esdirk34),
Expand Down
10 changes: 5 additions & 5 deletions examples/macro_vs_handwritten_one_cpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use pharmsol::{prelude::*, Parameters};

fn macro_model() -> equation::ODE {
fn macro_model() -> backends::ODE {
ode! {
name: "one_cpt_macro_parity",
params: [ke, v],
Expand All @@ -24,8 +24,8 @@ fn macro_model() -> equation::ODE {
}
}

fn handwritten_model() -> equation::ODE {
equation::ODE::new(
fn handwritten_model() -> backends::ODE {
backends::ODE::new(
|x, p, _t, dx, _bolus, rateiv, _cov| {
fetch_params!(p, ke, _v);
dx[0] = rateiv[0] - ke * x[0];
Expand All @@ -42,12 +42,12 @@ fn handwritten_model() -> equation::ODE {
.with_ndrugs(1)
.with_nout(1)
.with_metadata(
equation::metadata::new("one_cpt_macro_parity")
pharmsol::metadata::new("one_cpt_macro_parity")
.parameters(["ke", "v"])
.states(["central"])
.outputs(["cp"])
.route(
equation::Route::infusion("iv")
backends::Route::infusion("iv")
.to_state("central")
.inject_input_to_destination(),
),
Expand Down
12 changes: 6 additions & 6 deletions examples/macro_vs_handwritten_two_cpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use pharmsol::{prelude::*, Parameters};

fn macro_model() -> equation::ODE {
fn macro_model() -> backends::ODE {
ode! {
name: "two_cpt_shared_input_parity",
params: [ke, kcp, kpc, v],
Expand All @@ -27,8 +27,8 @@ fn macro_model() -> equation::ODE {
}
}

fn handwritten_model() -> equation::ODE {
equation::ODE::new(
fn handwritten_model() -> backends::ODE {
backends::ODE::new(
|x, p, _t, dx, bolus, rateiv, _cov| {
fetch_params!(p, ke, kcp, kpc, _v);
dx[0] = -ke * x[0] - kcp * x[0] + kpc * x[1] + rateiv[0] + bolus[0];
Expand All @@ -46,15 +46,15 @@ fn handwritten_model() -> equation::ODE {
.with_ndrugs(1)
.with_nout(1)
.with_metadata(
equation::metadata::new("two_cpt_shared_input_parity")
pharmsol::metadata::new("two_cpt_shared_input_parity")
.parameters(["ke", "kcp", "kpc", "v"])
.states(["central", "peripheral"])
.outputs(["cp"])
.routes([
equation::Route::bolus("load")
backends::Route::bolus("load")
.to_state("central")
.inject_input_to_destination(),
equation::Route::infusion("iv")
backends::Route::infusion("iv")
.to_state("central")
.inject_input_to_destination(),
]),
Expand Down
Loading