Skip to content

Commit

Permalink
Improvements to algorithm and attractor visualisation.
Browse files Browse the repository at this point in the history
  • Loading branch information
daemontus committed Dec 11, 2020
1 parent 90e175c commit a6eaa95
Show file tree
Hide file tree
Showing 10 changed files with 755 additions and 243 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ debug = true

[dependencies]
biodivine-lib-std = { git = "https://github.com/sybila/biodivine-lib-std.git" }
biodivine-lib-param-bn = { git = "https://github.com/sybila/biodivine-lib-param-bn.git", rev = "62db744ff0b217522081db4f9edacceee698daae" }
biodivine-lib-param-bn = { git = "https://github.com/sybila/biodivine-lib-param-bn.git", rev = "f9dd65e584f81debe9e17ea2c6a439070fdaf6a9" }
biodivine-lib-bdd = "0.1.0"
rocket = "0.4.6"
rayon = "1.5.0"
Expand Down
87 changes: 65 additions & 22 deletions src/bin/benchmark_validator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use biodivine_lib_param_bn::{BooleanNetwork, FnUpdate};
use std::convert::TryFrom;
use biodivine_lib_param_bn::symbolic_async_graph::SymbolicAsyncGraph;
use biodivine_lib_param_bn::{BooleanNetwork, FnUpdate};
use std::collections::HashSet;
use std::convert::TryFrom;

fn main() {
//let args: Vec<String> = std::env::args().collect();
Expand All @@ -24,54 +24,84 @@ fn main() {
let sbml_model_path = bench_dir.path().join("model.sbml");
let sbml_model = if !sbml_model_path.exists() {
errors += 1;
eprintln!("ERROR: Missing model.sbml in {}.", bench_dir.path().display());
continue
eprintln!(
"ERROR: Missing model.sbml in {}.",
bench_dir.path().display()
);
continue;
} else {
// Check that the sbml model is readable:
let model_string = std::fs::read_to_string(sbml_model_path).unwrap();
let model = BooleanNetwork::from_sbml(&model_string);
match model {
Err(err) => {
errors += 1;
eprintln!("ERROR: Invalid SBML model in {}.", bench_dir.path().display());
eprintln!(
"ERROR: Invalid SBML model in {}.",
bench_dir.path().display()
);
eprintln!("\t\t{}", err);
continue
continue;
}
Ok((model, _)) => model
Ok((model, _)) => model,
}
};
let aeon_model_path = bench_dir.path().join("model.aeon");
if !aeon_model_path.exists() {
errors += 1;
eprintln!("ERROR: Missing model.aeon in {}.", bench_dir.path().display());
eprintln!(
"ERROR: Missing model.aeon in {}.",
bench_dir.path().display()
);
} else {
// Check that the aeon model is valid:
let model_string = std::fs::read_to_string(aeon_model_path.clone()).unwrap();
let model = BooleanNetwork::try_from(model_string.as_str());
match model {
Ok(mut model) => {
// Check that basic properties match SBML model. But note that variables can be re-ordered...
let mut models_match = model.graph().num_vars() == sbml_model.graph().num_vars();
let mut models_match =
model.graph().num_vars() == sbml_model.graph().num_vars();
if model.graph().num_vars() != sbml_model.graph().num_vars() {
eprintln!("{} != {}", model.graph().num_vars(), sbml_model.graph().num_vars());
eprintln!(
"{} != {}",
model.graph().num_vars(),
sbml_model.graph().num_vars()
);
}
for v in model.graph().variable_ids() {
let regulators_in_model: HashSet<String> = model.graph().regulators(v).into_iter()
let regulators_in_model: HashSet<String> = model
.graph()
.regulators(v)
.into_iter()
.map(|r| model.graph().get_variable(r).get_name().clone())
.collect();
let regulators_in_sbml_model: HashSet<String> = sbml_model.graph().regulators(
sbml_model.graph().find_variable(model.graph().get_variable(v).get_name()).unwrap()
).into_iter()
let regulators_in_sbml_model: HashSet<String> = sbml_model
.graph()
.regulators(
sbml_model
.graph()
.find_variable(model.graph().get_variable(v).get_name())
.unwrap(),
)
.into_iter()
.map(|r| sbml_model.graph().get_variable(r).get_name().clone())
.collect();
if regulators_in_model != regulators_in_sbml_model {
eprintln!("{:?} != {:?}", regulators_in_model, regulators_in_sbml_model);
eprintln!(
"{:?} != {:?}",
regulators_in_model, regulators_in_sbml_model
);
}
models_match = models_match && regulators_in_model == regulators_in_sbml_model;
models_match =
models_match && regulators_in_model == regulators_in_sbml_model;
}
if !models_match {
errors += 1;
eprintln!("ERROR: SBML and AEON model are different in {}.", bench_dir.path().display());
eprintln!(
"ERROR: SBML and AEON model are different in {}.",
bench_dir.path().display()
);
}
// Check that all update functions are set (for non-parametrized model anyway).
let mut model_ok = true;
Expand All @@ -84,7 +114,10 @@ fn main() {
}
if !model_ok {
errors += 1;
eprintln!("ERROR: Model in {} contains unconstrained variables.", bench_dir.path().display());
eprintln!(
"ERROR: Model in {} contains unconstrained variables.",
bench_dir.path().display()
);
if auto_fix {
std::fs::write(aeon_model_path, model.to_string()).unwrap();
} else {
Expand All @@ -97,25 +130,35 @@ fn main() {
Ok(graph) => {
if graph.unit_colors().cardinality() != 1.0 {
errors += 1;
eprintln!("ERROR: Default model has {} colors in {}.", graph.unit_colors().cardinality(), bench_dir.path().display());
eprintln!(
"ERROR: Default model has {} colors in {}.",
graph.unit_colors().cardinality(),
bench_dir.path().display()
);
}
}
Err(err) => {
errors += 1;
eprintln!("ERROR: Cannot build graph from model in {}.", bench_dir.path().display());
eprintln!(
"ERROR: Cannot build graph from model in {}.",
bench_dir.path().display()
);
eprintln!("{}", err);
}
}
}
}
Err(err) => {
errors += 1;
eprintln!("ERROR: Invalid AEON model in {}.", bench_dir.path().display());
eprintln!(
"ERROR: Invalid AEON model in {}.",
bench_dir.path().display()
);
eprintln!("\t\t{}", err);
}
}
}
println!("OK: {}", bench_dir.path().display());
}
println!("TOTAL ERRORS: {}", errors);
}
}
21 changes: 11 additions & 10 deletions src/bin/experiment.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use biodivine_aeon_server::scc::algo_symbolic_components::components;
use biodivine_aeon_server::scc::algo_symbolic_components::{components, components_2};
use biodivine_aeon_server::scc::{Classifier, ProgressTracker};
use biodivine_lib_param_bn::symbolic_async_graph::SymbolicAsyncGraph;
use biodivine_lib_param_bn::BooleanNetwork;
Expand Down Expand Up @@ -32,18 +32,19 @@ fn main() {
"Admissible parametrisations: {}",
graph.unit_colors().cardinality()
);
println!(
"State space: {}",
graph.unit_vertices().cardinality()
);
println!("State space: {}", graph.unit_vertices().cardinality());

let classifier = Classifier::new(&graph);
let progress = ProgressTracker::new(&graph);
components(&graph, &progress, &AtomicBool::new(false), |component| {
println!("Found attractor...");
println!("Remaining: {}", progress.get_percent_string());
classifier.add_component(component, &graph);
});
components_2(
&graph,
/*&progress, &AtomicBool::new(false), */
|component| {
println!("Found attractor...");
println!("Remaining: {}", progress.get_percent_string());
classifier.add_component(component, &graph);
},
);

classifier.print();

Expand Down
Loading

0 comments on commit a6eaa95

Please sign in to comment.