pub struct Runner { /* private fields */ }Expand description
Configurable FEFF pipeline runner.
Implementations§
Source§impl Runner
impl Runner
Sourcepub fn new() -> Self
pub fn new() -> Self
Construct a runner using process defaults.
Examples found in repository?
examples/spectrum.rs (line 8)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 let mut args = std::env::args().skip(1);
6 let input = args.next().ok_or("provide input and output paths")?;
7 let output = args.next().ok_or("provide an output directory")?;
8 let report = Runner::new().run_files(FileRunRequest::new(input, &output))?;
9 let spectrum = io::xmu_dat::read_xmu_dat(std::path::Path::new(&output).join("xmu.dat"))?;
10 println!(
11 "{} completed stages; {} spectrum points",
12 report.stages.len(),
13 spectrum.photon_energy_ev.len()
14 );
15 if let Some(point) = spectrum.point(0) {
16 println!(
17 "First point: {} eV, μ={}",
18 point.photon_energy.value(),
19 point.mu
20 );
21 }
22 Ok(())
23}More examples
examples/benchmark.rs (line 12)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 let args: Vec<_> = std::env::args().skip(1).collect();
6 if args.len() != 4 {
7 return Err("expected INPUT OUTPUT MODE THREADS".into());
8 }
9 let input = PathBuf::from(&args[0]);
10 let output = PathBuf::from(&args[1]);
11 let threads: usize = args[3].parse()?;
12 let mut runner = Runner::new();
13 if let Some(n) = NonZeroUsize::new(threads) {
14 runner = runner.with_threads(n);
15 }
16 let start = Instant::now();
17 let (stages, bytes) = if args[2] == "memory" || args[2] == "typed" {
18 if args[2] == "typed" {
19 runner = runner.with_artifacts(ArtifactSelection::None);
20 }
21 let result = runner.run_in_memory(MemoryRunRequest::new(std::fs::read(input)?))?;
22 (
23 result.report.stages.len(),
24 result
25 .artifacts
26 .iter()
27 .map(|file| file.bytes.len() as u64)
28 .sum::<u64>(),
29 )
30 } else {
31 let policy = if args[2] == "recompute" {
32 ExistingOutputPolicy::Recompute
33 } else {
34 ExistingOutputPolicy::ReuseValidated
35 };
36 let report = runner
37 .run_files(FileRunRequest::new(input, &output).with_existing_output_policy(policy))?;
38 let bytes = report
39 .artifacts
40 .iter()
41 .map(|path| std::fs::metadata(output.join(path)).map(|m| m.len()))
42 .collect::<Result<Vec<_>, _>>()?
43 .into_iter()
44 .sum::<u64>();
45 (report.stages.len(), bytes)
46 };
47 println!(
48 "{{\"seconds\":{},\"stages\":{},\"artifact_bytes\":{}}}",
49 start.elapsed().as_secs_f64(),
50 stages,
51 bytes
52 );
53 Ok(())
54}Sourcepub fn with_threads(self, threads: NonZeroUsize) -> Self
pub fn with_threads(self, threads: NonZeroUsize) -> Self
Bound the calculation’s owned worker pool. ReFEFF faer calculations are serialized. WebAssembly runs on one thread regardless of this bound.
Examples found in repository?
examples/benchmark.rs (line 14)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 let args: Vec<_> = std::env::args().skip(1).collect();
6 if args.len() != 4 {
7 return Err("expected INPUT OUTPUT MODE THREADS".into());
8 }
9 let input = PathBuf::from(&args[0]);
10 let output = PathBuf::from(&args[1]);
11 let threads: usize = args[3].parse()?;
12 let mut runner = Runner::new();
13 if let Some(n) = NonZeroUsize::new(threads) {
14 runner = runner.with_threads(n);
15 }
16 let start = Instant::now();
17 let (stages, bytes) = if args[2] == "memory" || args[2] == "typed" {
18 if args[2] == "typed" {
19 runner = runner.with_artifacts(ArtifactSelection::None);
20 }
21 let result = runner.run_in_memory(MemoryRunRequest::new(std::fs::read(input)?))?;
22 (
23 result.report.stages.len(),
24 result
25 .artifacts
26 .iter()
27 .map(|file| file.bytes.len() as u64)
28 .sum::<u64>(),
29 )
30 } else {
31 let policy = if args[2] == "recompute" {
32 ExistingOutputPolicy::Recompute
33 } else {
34 ExistingOutputPolicy::ReuseValidated
35 };
36 let report = runner
37 .run_files(FileRunRequest::new(input, &output).with_existing_output_policy(policy))?;
38 let bytes = report
39 .artifacts
40 .iter()
41 .map(|path| std::fs::metadata(output.join(path)).map(|m| m.len()))
42 .collect::<Result<Vec<_>, _>>()?
43 .into_iter()
44 .sum::<u64>();
45 (report.stages.len(), bytes)
46 };
47 println!(
48 "{{\"seconds\":{},\"stages\":{},\"artifact_bytes\":{}}}",
49 start.elapsed().as_secs_f64(),
50 stages,
51 bytes
52 );
53 Ok(())
54}Sourcepub fn with_cancellation(self, cancellation: CancellationToken) -> Self
pub fn with_cancellation(self, cancellation: CancellationToken) -> Self
Use a caller-owned cooperative cancellation handle.
Sourcepub fn with_deadline(self, deadline: Instant) -> Self
pub fn with_deadline(self, deadline: Instant) -> Self
Stop cooperatively once a monotonic deadline expires.
Sourcepub fn with_artifacts(self, selection: ArtifactSelection) -> Self
pub fn with_artifacts(self, selection: ArtifactSelection) -> Self
Select returned memory artifacts before reading their payloads.
Examples found in repository?
examples/benchmark.rs (line 19)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 let args: Vec<_> = std::env::args().skip(1).collect();
6 if args.len() != 4 {
7 return Err("expected INPUT OUTPUT MODE THREADS".into());
8 }
9 let input = PathBuf::from(&args[0]);
10 let output = PathBuf::from(&args[1]);
11 let threads: usize = args[3].parse()?;
12 let mut runner = Runner::new();
13 if let Some(n) = NonZeroUsize::new(threads) {
14 runner = runner.with_threads(n);
15 }
16 let start = Instant::now();
17 let (stages, bytes) = if args[2] == "memory" || args[2] == "typed" {
18 if args[2] == "typed" {
19 runner = runner.with_artifacts(ArtifactSelection::None);
20 }
21 let result = runner.run_in_memory(MemoryRunRequest::new(std::fs::read(input)?))?;
22 (
23 result.report.stages.len(),
24 result
25 .artifacts
26 .iter()
27 .map(|file| file.bytes.len() as u64)
28 .sum::<u64>(),
29 )
30 } else {
31 let policy = if args[2] == "recompute" {
32 ExistingOutputPolicy::Recompute
33 } else {
34 ExistingOutputPolicy::ReuseValidated
35 };
36 let report = runner
37 .run_files(FileRunRequest::new(input, &output).with_existing_output_policy(policy))?;
38 let bytes = report
39 .artifacts
40 .iter()
41 .map(|path| std::fs::metadata(output.join(path)).map(|m| m.len()))
42 .collect::<Result<Vec<_>, _>>()?
43 .into_iter()
44 .sum::<u64>();
45 (report.stages.len(), bytes)
46 };
47 println!(
48 "{{\"seconds\":{},\"stages\":{},\"artifact_bytes\":{}}}",
49 start.elapsed().as_secs_f64(),
50 stages,
51 bytes
52 );
53 Ok(())
54}Sourcepub fn with_progress_sink(self, sink: Arc<dyn ProgressSink>) -> Self
pub fn with_progress_sink(self, sink: Arc<dyn ProgressSink>) -> Self
Install a progress callback.
Sourcepub fn run_files(&self, request: FileRunRequest) -> Result<RunReport>
pub fn run_files(&self, request: FileRunRequest) -> Result<RunReport>
Execute the FEFF-compatible file pipeline.
Examples found in repository?
examples/spectrum.rs (line 8)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 let mut args = std::env::args().skip(1);
6 let input = args.next().ok_or("provide input and output paths")?;
7 let output = args.next().ok_or("provide an output directory")?;
8 let report = Runner::new().run_files(FileRunRequest::new(input, &output))?;
9 let spectrum = io::xmu_dat::read_xmu_dat(std::path::Path::new(&output).join("xmu.dat"))?;
10 println!(
11 "{} completed stages; {} spectrum points",
12 report.stages.len(),
13 spectrum.photon_energy_ev.len()
14 );
15 if let Some(point) = spectrum.point(0) {
16 println!(
17 "First point: {} eV, μ={}",
18 point.photon_energy.value(),
19 point.mu
20 );
21 }
22 Ok(())
23}More examples
examples/benchmark.rs (line 37)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 let args: Vec<_> = std::env::args().skip(1).collect();
6 if args.len() != 4 {
7 return Err("expected INPUT OUTPUT MODE THREADS".into());
8 }
9 let input = PathBuf::from(&args[0]);
10 let output = PathBuf::from(&args[1]);
11 let threads: usize = args[3].parse()?;
12 let mut runner = Runner::new();
13 if let Some(n) = NonZeroUsize::new(threads) {
14 runner = runner.with_threads(n);
15 }
16 let start = Instant::now();
17 let (stages, bytes) = if args[2] == "memory" || args[2] == "typed" {
18 if args[2] == "typed" {
19 runner = runner.with_artifacts(ArtifactSelection::None);
20 }
21 let result = runner.run_in_memory(MemoryRunRequest::new(std::fs::read(input)?))?;
22 (
23 result.report.stages.len(),
24 result
25 .artifacts
26 .iter()
27 .map(|file| file.bytes.len() as u64)
28 .sum::<u64>(),
29 )
30 } else {
31 let policy = if args[2] == "recompute" {
32 ExistingOutputPolicy::Recompute
33 } else {
34 ExistingOutputPolicy::ReuseValidated
35 };
36 let report = runner
37 .run_files(FileRunRequest::new(input, &output).with_existing_output_policy(policy))?;
38 let bytes = report
39 .artifacts
40 .iter()
41 .map(|path| std::fs::metadata(output.join(path)).map(|m| m.len()))
42 .collect::<Result<Vec<_>, _>>()?
43 .into_iter()
44 .sum::<u64>();
45 (report.stages.len(), bytes)
46 };
47 println!(
48 "{{\"seconds\":{},\"stages\":{},\"artifact_bytes\":{}}}",
49 start.elapsed().as_secs_f64(),
50 stages,
51 bytes
52 );
53 Ok(())
54}Sourcepub fn run_in_memory(
&self,
request: MemoryRunRequest,
) -> Result<MemoryRunResult>
pub fn run_in_memory( &self, request: MemoryRunRequest, ) -> Result<MemoryRunResult>
Execute the same FEFF-compatible scheduler against an owned in-memory workspace.
A private temporary directory is used only as the compatibility transport for legacy FEFF file formats. Callers neither manage that directory nor receive ephemeral paths in the result.
Examples found in repository?
examples/benchmark.rs (line 21)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 let args: Vec<_> = std::env::args().skip(1).collect();
6 if args.len() != 4 {
7 return Err("expected INPUT OUTPUT MODE THREADS".into());
8 }
9 let input = PathBuf::from(&args[0]);
10 let output = PathBuf::from(&args[1]);
11 let threads: usize = args[3].parse()?;
12 let mut runner = Runner::new();
13 if let Some(n) = NonZeroUsize::new(threads) {
14 runner = runner.with_threads(n);
15 }
16 let start = Instant::now();
17 let (stages, bytes) = if args[2] == "memory" || args[2] == "typed" {
18 if args[2] == "typed" {
19 runner = runner.with_artifacts(ArtifactSelection::None);
20 }
21 let result = runner.run_in_memory(MemoryRunRequest::new(std::fs::read(input)?))?;
22 (
23 result.report.stages.len(),
24 result
25 .artifacts
26 .iter()
27 .map(|file| file.bytes.len() as u64)
28 .sum::<u64>(),
29 )
30 } else {
31 let policy = if args[2] == "recompute" {
32 ExistingOutputPolicy::Recompute
33 } else {
34 ExistingOutputPolicy::ReuseValidated
35 };
36 let report = runner
37 .run_files(FileRunRequest::new(input, &output).with_existing_output_policy(policy))?;
38 let bytes = report
39 .artifacts
40 .iter()
41 .map(|path| std::fs::metadata(output.join(path)).map(|m| m.len()))
42 .collect::<Result<Vec<_>, _>>()?
43 .into_iter()
44 .sum::<u64>();
45 (report.stages.len(), bytes)
46 };
47 println!(
48 "{{\"seconds\":{},\"stages\":{},\"artifact_bytes\":{}}}",
49 start.elapsed().as_secs_f64(),
50 stages,
51 bytes
52 );
53 Ok(())
54}Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Runner
impl !UnwindSafe for Runner
impl Freeze for Runner
impl Send for Runner
impl Sync for Runner
impl Unpin for Runner
impl UnsafeUnpin for Runner
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T, U> Imply<T> for U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more