Skip to content

Commit

Permalink
Refactor project structure (#80)
Browse files Browse the repository at this point in the history
* Project structure

Routines is now under /src, and not /src/algorithms. Cleaned up mod-files and lib.rs

* Update README.md

* Simplify prelude
  • Loading branch information
mhovd authored Feb 18, 2025
1 parent 62309ab commit abab41c
Show file tree
Hide file tree
Showing 31 changed files with 85 additions and 103 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# PMcore
![Build](https://github.com/LAPKB/PMcore/actions/workflows/rust.yml/badge.svg)
[![Build](https://github.com/LAPKB/PMcore/actions/workflows/rust.yml/badge.svg)](https://github.com/LAPKB/PMcore/actions/workflows/rust.yml)
[![Documentation](https://github.com/LAPKB/PMcore/actions/workflows/docs.yml/badge.svg)](https://lapkb.github.io/PMcore/pmcore/)
![Security Audit](https://github.com/LAPKB/PMcore/actions/workflows/security_audit.yml/badge.svg)
[![Security Audit](https://github.com/LAPKB/PMcore/actions/workflows/security_audit.yml/badge.svg)](https://github.com/LAPKB/PMcore/actions/workflows/security_audit.yml)
[![crates.io](https://img.shields.io/crates/v/pmcore.svg)](https://crates.io/crates/pmcore)


Expand Down
1 change: 0 additions & 1 deletion examples/bimodal_ke/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use logger::setup_log;
use pmcore::prelude::*;
fn main() {
let eq = equation::ODE::new(
Expand Down
5 changes: 4 additions & 1 deletion examples/debug.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use algorithms::{npag::NPAG, Algorithm};
use ipm::burke;
use logger::setup_log;
use pmcore::prelude::*;
use pmcore::{
prelude::*,
routines::{evaluation::ipm, logger, settings},
};
fn main() {
let ode = equation::ODE::new(
|x, p, _t, dx, rateiv, _cov| {
Expand Down
5 changes: 4 additions & 1 deletion examples/drusano/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use argmin::{
solver::neldermead::NelderMead,
};
use logger::setup_log;
use pmcore::prelude::*;
use pmcore::{
prelude::*,
routines::{logger, settings},
};
use std::process::exit;
#[allow(unused_variables)]
fn main() {
Expand Down
1 change: 0 additions & 1 deletion examples/meta/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![allow(unused_variables)]
#![allow(unused_imports)]

use logger::setup_log;
use pmcore::prelude::*;

fn main() {
Expand Down
5 changes: 4 additions & 1 deletion examples/theophylline/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use pmcore::prelude::{models::one_compartment_with_absorption, *};
use pmcore::{
prelude::{models::one_compartment_with_absorption, *},
routines::settings,
};

fn main() {
// let eq = Equation::new_ode(
Expand Down
2 changes: 1 addition & 1 deletion examples/toml.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pmcore::prelude::*;
use pmcore::routines::settings;

fn main() {
let path = "examples/bimodal_ke/config.toml".to_string();
Expand Down
6 changes: 1 addition & 5 deletions examples/two_eq_lag/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_imports)]
use std::path::Path;

use data::read_pmetrics;
use logger::setup_log;
use ndarray::Array2;
use pmcore::prelude::{models::one_compartment_with_absorption, simulator::Equation, *};
use pmcore::prelude::*;

fn main() {
let eq = equation::ODE::new(
Expand Down
2 changes: 0 additions & 2 deletions meta_rust.csv

This file was deleted.

8 changes: 3 additions & 5 deletions src/algorithms/mod.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
use std::fs;
use std::path::Path;

use crate::prelude::{self, settings::Settings};

use crate::routines::output::NPResult;
use crate::routines::settings::Settings;
use anyhow::{bail, Result};
use anyhow::{Context, Error};
use ndarray::Array2;
use npag::*;
use npod::NPOD;
use output::NPResult;
use pharmsol::prelude::{data::Data, simulator::Equation};
use postprob::POSTPROB;
use prelude::*;

// use self::{data::Subject, simulator::Equation};

pub mod npag;
pub mod npod;
pub mod postprob;
pub mod routines;

pub trait Algorithm<E: Equation> {
fn new(config: Settings, equation: E, data: Data) -> Result<Box<Self>, Error>
Expand Down
19 changes: 11 additions & 8 deletions src/algorithms/npag.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::prelude::{
algorithms::Algorithm,
ipm::burke,
output::{CycleLog, NPCycle, NPResult},
qr,
settings::Settings,
};
use crate::prelude::algorithms::Algorithm;

pub use crate::routines::evaluation::ipm::burke;
pub use crate::routines::evaluation::qr;
use crate::routines::settings::Settings;

use crate::routines::output::{CycleLog, NPCycle, NPResult};

use anyhow::Error;
use anyhow::Result;
use pharmsol::{
Expand All @@ -15,10 +16,12 @@ use pharmsol::{
Subject,
};

use crate::routines::initialization;

use ndarray::{Array, Array1, Array2, ArrayBase, Axis, Dim, OwnedRepr};
use ndarray_stats::{DeviationExt, QuantileExt};

use super::{adaptative_grid::adaptative_grid, initialization};
use crate::routines::expansion::adaptative_grid::adaptative_grid;

const THETA_E: f64 = 1e-4; // Convergence criteria
const THETA_G: f64 = 1e-4; // Objective function convergence criteria
Expand Down
10 changes: 5 additions & 5 deletions src/algorithms/npod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::prelude::{
algorithms::Algorithm,
ipm::burke,
output::{CycleLog, NPCycle, NPResult},
qr,
settings::Settings,
routines::evaluation::ipm::burke,
routines::evaluation::qr,
routines::output::{CycleLog, NPCycle, NPResult},
routines::settings::Settings,
};
use anyhow::Error;
use anyhow::Result;
Expand All @@ -21,7 +21,7 @@ use ndarray::{
};
use ndarray_stats::{DeviationExt, QuantileExt};

use super::{condensation::prune::prune, initialization, optimization::d_optimizer::SppOptimizer};
use crate::routines::{condensation::prune, initialization, optimization::SppOptimizer};

const THETA_F: f64 = 1e-2;
const THETA_D: f64 = 1e-4;
Expand Down
8 changes: 6 additions & 2 deletions src/algorithms/postprob.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::prelude::{algorithms::Algorithm, ipm::burke, output::NPResult, settings::Settings};
use crate::prelude::algorithms::Algorithm;
use anyhow::{Error, Result};
use pharmsol::prelude::{
data::{Data, ErrorModel, ErrorType},
Expand All @@ -7,7 +7,11 @@ use pharmsol::prelude::{

use ndarray::{Array1, Array2};

use super::{initialization, output::CycleLog};
use crate::routines::evaluation::ipm::burke;
use crate::routines::initialization;
use crate::routines::output::CycleLog;
use crate::routines::output::NPResult;
use crate::routines::settings::Settings;

/// Posterior probability algorithm
/// Reweights the prior probabilities to the observed data and error model
Expand Down
27 changes: 0 additions & 27 deletions src/algorithms/routines/mod.rs

This file was deleted.

22 changes: 0 additions & 22 deletions src/algorithms/routines/optimization/optim.rs

This file was deleted.

18 changes: 8 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@
/// Provides the various algorithms used within the framework
// pub mod algorithms;
pub mod algorithms;
/// Logger functionality for the framework using [tracing]
pub mod logger;

/// Routines
pub mod routines;

// Re-export commonly used items
pub use anyhow::Result;
Expand All @@ -63,14 +64,11 @@ pub mod prelude {
pub use super::Result;
pub use crate::algorithms;
pub use crate::algorithms::dispatch_algorithm;
pub use crate::algorithms::routines::condensation;
pub use crate::algorithms::routines::expansion::*;
pub use crate::algorithms::routines::initialization::*;
pub use crate::algorithms::routines::optimization;
pub use crate::logger;
pub use crate::prelude::evaluation::*;
// pub use crate::algorithms::routines::settings::*;
pub use crate::algorithms::routines::*;
pub use crate::routines;
pub use crate::routines::logger;
pub use crate::routines::logger::setup_log;
pub use crate::routines::settings;

//Alma re-exports
pub mod simulator {
pub use pharmsol::prelude::simulator::*;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions src/routines/evaluation/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod ipm;
pub mod qr;
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ndarray::{Array, Array2};

use crate::algorithms::routines::condensation::prune::prune;
use crate::routines::condensation::prune;

/// Implements the adaptive grid algorithm for support point expansion.
///
Expand Down
1 change: 1 addition & 0 deletions src/routines/expansion/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod adaptative_grid;
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use anyhow::{bail, Context, Result};
use ndarray::{Array1, Array2};
use pharmsol::prelude::EstimateTheta;

use crate::prelude::settings::Settings;
use crate::routines::settings::Settings;

pub mod latin;
pub mod sobol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ pub fn generate(
}

#[cfg(test)]
use crate::prelude::*;

#[test]
fn basic_sobol() {
assert_eq!(
initialization::sobol::generate(5, &vec![(0., 1.), (0., 1.), (0., 1.)], 347).unwrap(),
crate::routines::initialization::sobol::generate(
5,
&vec![(0., 1.), (0., 1.), (0., 1.)],
347
)
.unwrap(),
ndarray::array![
[0.10731887817382813, 0.14647412300109863, 0.5851038694381714],
[0.9840304851531982, 0.7633365392684937, 0.19097506999969482],
Expand All @@ -64,7 +67,12 @@ fn basic_sobol() {
#[test]
fn scaled_sobol() {
assert_eq!(
initialization::sobol::generate(5, &vec![(0., 1.), (0., 2.), (-1., 1.)], 347).unwrap(),
crate::routines::initialization::sobol::generate(
5,
&vec![(0., 1.), (0., 2.), (-1., 1.)],
347
)
.unwrap(),
ndarray::array![
[
0.10731887817382813,
Expand Down
4 changes: 2 additions & 2 deletions src/logger.rs → src/routines/logger.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::time::Instant;

use crate::algorithms::routines::settings::Settings;
use crate::prelude::output::OutputFile;
use crate::routines::output::OutputFile;
use crate::routines::settings::Settings;
use anyhow::Result;
use tracing_subscriber::fmt::time::FormatTime;
use tracing_subscriber::fmt::{self};
Expand Down
16 changes: 16 additions & 0 deletions src/routines/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Routines for condensation
pub mod condensation;
// Routines for evaluation
pub mod evaluation;
// Routines for expansion
pub mod expansion;
// Routines for initialization
pub mod initialization;
// Routines for logging
pub mod logger;
// Routines for optimization
pub mod optimization;
// Routines for output
pub mod output;
// Routines for settings
pub mod settings;
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use pharmsol::prelude::data::*;
use pharmsol::prelude::simulator::Equation;
use serde::Serialize;
// use pharmsol::Cache;
use settings::Settings;
use crate::routines::settings::Settings;
use std::fs::{create_dir_all, File, OpenOptions};
use std::path::{Path, PathBuf};
/// Defines the result objects from an NPAG run
Expand Down
File renamed without changes.

0 comments on commit abab41c

Please sign in to comment.