Skip to content

Commit

Permalink
cleaning up the API a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Siel committed Jul 28, 2024
1 parent 2641f0c commit 564c65c
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 24 deletions.
5 changes: 2 additions & 3 deletions benches/compare.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use pmcore::prelude::{
data::read_pmetrics, models::one_compartment_with_absorption, simulator::Equation, *,
};
use std::path::Path;

// type V = nalgebra::DVector<f64>;
// type V = nalgebra::SVector<f64, 3>;
Expand Down Expand Up @@ -51,7 +50,7 @@ fn main() -> std::io::Result<()> {
// });
// }
pub fn analytical_ns(bencher: Bencher, len: usize) {
let data = read_pmetrics(Path::new(PATH)).unwrap();
let data = read_pmetrics(PATH).unwrap();
let subjects = data.get_subjects();
let first_subject = subjects.first().unwrap();

Expand Down Expand Up @@ -79,7 +78,7 @@ pub fn analytical_ns(bencher: Bencher, len: usize) {
}

pub fn diffsol_ns(bencher: Bencher, len: usize) {
let data = read_pmetrics(Path::new(PATH)).unwrap();
let data = read_pmetrics(PATH).unwrap();
let subjects = data.get_subjects();
let first_subject = subjects.first().unwrap();

Expand Down
7 changes: 2 additions & 5 deletions examples/bimodal_ke/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use std::path::Path;

use data::read_pmetrics;
use pmcore::prelude::{models::one_compartment, simulator::Equation, *};

fn main() {
Expand Down Expand Up @@ -39,7 +36,7 @@ fn main() {
_ => panic!("Method not found"),
};

let settings = read_settings("examples/bimodal_ke/config.toml".to_string()).unwrap();
let data = read_pmetrics(Path::new("examples/bimodal_ke/bimodal_ke.csv")).unwrap();
let settings = settings::read("examples/bimodal_ke/config.toml").unwrap();
let data = data::read_pmetrics("examples/bimodal_ke/bimodal_ke.csv").unwrap();
let _result = fit(eq, data, settings);
}
5 changes: 2 additions & 3 deletions examples/meta/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#![allow(unused_imports)]
use std::path::Path;

use data::read_pmetrics;
use pmcore::prelude::{models::one_compartment, simulator::Equation, *};

fn main() {
Expand Down Expand Up @@ -33,7 +32,7 @@ fn main() {
},
(2, 2),
);
let settings = read_settings("examples/meta/config.toml".to_string()).unwrap();
let data = read_pmetrics(Path::new("examples/meta/meta.csv")).unwrap();
let settings = settings::read("examples/meta/config.toml").unwrap();
let data = data::read_pmetrics("examples/meta/meta.csv").unwrap();
let _result = fit(eq, data, settings);
}
7 changes: 2 additions & 5 deletions examples/theophylline/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use std::path::Path;

use data::read_pmetrics;
use pmcore::prelude::{models::one_compartment_with_absorption, simulator::Equation, *};

fn main() {
Expand Down Expand Up @@ -32,7 +29,7 @@ fn main() {
},
(2, 1),
);
let settings = read_settings("examples/theophylline/config.toml".to_string()).unwrap();
let data = read_pmetrics(Path::new("examples/theophylline/theophylline.csv")).unwrap();
let settings = settings::read("examples/theophylline/config.toml").unwrap();
let data = data::read_pmetrics("examples/theophylline/theophylline.csv").unwrap();
let _result = fit(eq, data, settings);
}
2 changes: 1 addition & 1 deletion examples/tmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn main() {
(1, 1),
);

let data = read_pmetrics(std::path::Path::new("examples/bimodal_ke/bimodal_ke.csv")).unwrap();
let data = read_pmetrics("examples/bimodal_ke/bimodal_ke.csv").unwrap();
let theta = data.estimate_theta(&eq, &array![1.5, 125.0]);
dbg!(theta);
}
3 changes: 1 addition & 2 deletions examples/toml.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use pmcore::prelude::*;
use settings::read_settings;

fn main() {
let path = "examples/bimodal_ke/config.toml".to_string();
for i in 0..10 {
let s = read_settings(path.clone()).unwrap();
let s = settings::read(path.clone()).unwrap();
let keys: Vec<&String> = s.random.parameters.keys().collect();
// let values = s.random.parameters.values();
println!("{}: {:?}", i, keys);
Expand Down
4 changes: 2 additions & 2 deletions examples/two_eq_lag/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn main() {
// (2, 1),
// );

let settings = read_settings("examples/two_eq_lag/config.toml".to_string()).unwrap();
let data = read_pmetrics(Path::new("examples/two_eq_lag/two_eq_lag.csv")).unwrap();
let settings = settings::read("examples/two_eq_lag/config.toml").unwrap();
let data = data::read_pmetrics("examples/two_eq_lag/two_eq_lag.csv").unwrap();
let _result = fit(eq, data, settings);
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub mod prelude {
pub use crate::routines::expansion::*;
pub use crate::routines::initialization::*;
pub use crate::routines::optimization;
pub use crate::routines::settings::read_settings;
pub use crate::routines::settings::*;
pub use crate::routines::*;
pub use crate::tui::ui::*;
//Alma re-exports
Expand Down
4 changes: 2 additions & 2 deletions src/routines/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ impl Output {
/// This function parses the settings from a TOML configuration file. The settings are validated, and a copy of the settings is written to file.
///
/// Entries in the TOML file may be overridden by environment variables. The environment variables must be prefixed with `PMCORE__`, and the TOML entry must be in uppercase. For example, the TUI may be disabled by setting the environment variable `PMCORE__CONFIG__TUI=false` Note that a double underscore, `__`, is used as the separator, as some settings may contain a single underscore, such as `PMCORE__CONFIG__LOG_LEVEL`.
pub fn read_settings(path: String) -> Result<Settings, anyhow::Error> {
let settings_path = path;
pub fn read(path: impl Into<String>) -> Result<Settings, anyhow::Error> {
let settings_path = path.into();

let parsed = eConfig::builder()
.add_source(config::File::with_name(&settings_path).format(config::FileFormat::Toml))
Expand Down

0 comments on commit 564c65c

Please sign in to comment.