Skip to content

Commit c8c2cbc

Browse files
committed
Add progress bar
1 parent f4d5342 commit c8c2cbc

File tree

9 files changed

+28
-35
lines changed

9 files changed

+28
-35
lines changed

Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ hdf5-sys = { version = "0.7", optional = true }
3636
approx = "0.4"
3737
criterion = "0.3"
3838
nalgebra = "0.26"
39+
serial_test = "0.5"
3940
velvet-test-utils = { path = "crates/velvet-test-utils" }
4041

4142
[features]
@@ -55,7 +56,10 @@ rayon = [
5556
]
5657

5758
[package.metadata.docs.rs]
58-
features = ["hdf5-sys/static", "hdf5-sys/zlib"]
59+
features = [
60+
"hdf5-sys/static",
61+
"hdf5-sys/zlib"
62+
]
5963

6064
[[bench]]
6165
name = "argon-benchmarks"

crates/velvet-core/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ repository = "https://github.com/seatonullberg/velvet"
88
edition = "2018"
99

1010
[dependencies]
11+
indicatif = "0.15"
1112
nalgebra = "0.26"
1213
rand = "0.7"
1314
rand_distr = "0.3"

crates/velvet-core/src/simulation.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! High level abstraction for an atomistic simulation.
22
3+
use indicatif::{ProgressBar, ProgressStyle, ProgressDrawTarget};
4+
35
use crate::config::Configuration;
46
use crate::potentials::Potentials;
57
use crate::propagators::Propagator;
@@ -40,6 +42,11 @@ impl Simulation {
4042
// setup propagation
4143
self.propagator.setup(&mut self.system, &self.potentials);
4244

45+
// setup progress bar
46+
let pb = ProgressBar::new(steps as u64);
47+
pb.set_style(ProgressStyle::default_bar()
48+
.template("[{eta_precise}] {bar:40.cyan/blue} {pos:>7} /{len:>7} steps"));
49+
4350
// start iteration loop
4451
for i in 0..steps {
4552
// do one propagation step
@@ -72,8 +79,10 @@ impl Simulation {
7279
}
7380
}
7481
}
75-
}
82+
}
83+
pb.inc(1);
7684
}
85+
pb.finish();
7786
}
7887

7988
/// Consume the simulation and return its [`System`] and [`Potentials`].

examples/argon.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,7 @@ fn main() {
2626
// Run MD with no thermostat to simulate the NVE ensemble.
2727
let md = MolecularDynamics::new(velocity_verlet, NullThermostat);
2828

29-
// Create an output group which writes scalar properties to stderr (the default destination).
30-
let stderr_group = RawOutputGroupBuilder::new()
31-
.interval(100)
32-
.output(PotentialEnergy)
33-
.output(KineticEnergy)
34-
.output(TotalEnergy)
35-
.output(Temperature)
36-
.build();
37-
38-
// Write the same outputs to a file for post-processing.
29+
// Create an output group which writes scalar properties to a file for post-processing.
3930
let file_group = RawOutputGroupBuilder::new()
4031
.destination(std::fs::File::create("argon.txt").unwrap())
4132
.interval(100)
@@ -47,7 +38,6 @@ fn main() {
4738

4839
// Build the configuration.
4940
let config = ConfigurationBuilder::new()
50-
.raw_output_group(stderr_group)
5141
.raw_output_group(file_group)
5242
.build();
5343

examples/binary-gas.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,7 @@ fn main() {
3636
// Run MD with a Nose-Hoover thermostat to simulate the NVT ensemble.
3737
let md = MolecularDynamics::new(velocity_verlet, nose_hoover);
3838

39-
// Create an output group which writes scalar properties to stderr (the default destination).
40-
let stderr_group = RawOutputGroupBuilder::new()
41-
.interval(100)
42-
.output(PotentialEnergy)
43-
.output(KineticEnergy)
44-
.output(TotalEnergy)
45-
.output(Temperature)
46-
.build();
47-
48-
// Write the same outputs to a file for post-processing.
39+
// Create an output group which writes scalar properties to a file for post-processing.
4940
let file_group = RawOutputGroupBuilder::new()
5041
.destination(std::fs::File::create("binary-gas.txt").unwrap())
5142
.interval(100)
@@ -57,7 +48,6 @@ fn main() {
5748

5849
// Build the configuration.
5950
let config = ConfigurationBuilder::new()
60-
.raw_output_group(stderr_group)
6151
.raw_output_group(file_group)
6252
.build();
6353

examples/magnesium-oxide.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,7 @@ fn main() {
3939
// Run MD with a Nose-Hoover thermostat to simulate the NVT ensemble.
4040
let md = MolecularDynamics::new(velocity_verlet, nose_hoover);
4141

42-
// Create an output group which writes scalar properties to stderr (the default destination).
43-
let stderr_group = RawOutputGroupBuilder::new()
44-
.interval(100)
45-
.output(PotentialEnergy)
46-
.output(KineticEnergy)
47-
.output(TotalEnergy)
48-
.output(Temperature)
49-
.build();
50-
51-
// Write the same outputs to a file for post-processing.
42+
// Create an output group which writes scalar properties to a file for post-processing.
5243
let file_group = RawOutputGroupBuilder::new()
5344
.destination(std::fs::File::create("magnesium-oxide.txt").unwrap())
5445
.interval(100)
@@ -60,7 +51,6 @@ fn main() {
6051

6152
// Build the configuration.
6253
let config = ConfigurationBuilder::new()
63-
.raw_output_group(stderr_group)
6454
.raw_output_group(file_group)
6555
.build();
6656

tests/argon.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use approx::*;
2+
use serial_test::serial;
23

34
use velvet::prelude::*;
45
use velvet_test_utils as test_utils;
56

67
static ITERATIONS: usize = 10_000;
78

89
#[test]
10+
#[serial]
911
fn nve() {
1012
let system = test_utils::argon_system();
1113
let potentials = test_utils::argon_potentials();
@@ -37,6 +39,7 @@ fn nve() {
3739
}
3840

3941
#[test]
42+
#[serial]
4043
fn nvt() {
4144
let system = test_utils::argon_system();
4245
let potentials = test_utils::argon_potentials();

tests/binary-gas.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use approx::*;
2+
use serial_test::serial;
23

34
use velvet::prelude::*;
45
use velvet_test_utils as test_utils;
56

67
static ITERATIONS: usize = 10_000;
78

89
#[test]
10+
#[serial]
911
fn nve() {
1012
let system = test_utils::binary_gas_system();
1113
let potentials = test_utils::binary_gas_potentials();
@@ -37,6 +39,7 @@ fn nve() {
3739
}
3840

3941
#[test]
42+
#[serial]
4043
fn nvt() {
4144
let system = test_utils::binary_gas_system();
4245
let potentials = test_utils::binary_gas_potentials();

tests/xenon.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use approx::*;
2+
use serial_test::serial;
23

34
use velvet::prelude::*;
45
use velvet_test_utils as test_utils;
56

67
static ITERATIONS: usize = 10_000;
78

89
#[test]
10+
#[serial]
911
fn nve() {
1012
let system = test_utils::xenon_system();
1113
let potentials = test_utils::xenon_potentials();
@@ -37,6 +39,7 @@ fn nve() {
3739
}
3840

3941
#[test]
42+
#[serial]
4043
fn nvt() {
4144
let system = test_utils::xenon_system();
4245
let potentials = test_utils::xenon_potentials();

0 commit comments

Comments
 (0)