Version: dev

forward_run

Stable type · Building and running

Tier: stable · Kind: type · Topic: Building and running

JuliaRust
not exportedschedule::ForwardRun

Julia

Julia does not export this type.

Rust

pub struct ForwardRun<T> {
    pub outputs: Vec<(f64, Vec<T>)>,
    pub tape: Tape,
    pub checkpoints: Vec<Checkpoint<T>>,
    pub accepted: u64,
    pub rejected: u64,
    pub rhs_calls: u64,
    pub integral: f64,
}

impl<T: Scalar> ForwardRun<T> { pub fn final_state(&self) -> &[T] }

The result of a forward run or a replay.

Source · Rust docs

Example (forward)

let rc = RunConfig::from_value(&config).unwrap();
let spec = RunSpec::<f64>::new(&rc, (0.0, 2.0), None).unwrap();
let (u0, p) = (spec.u0(), spec.problem.p.clone());
let fwd = spec.forward(&u0, &p).unwrap();
let u_final = fwd.final_state()[0];
// Exact solution of u' = -k u + sin(ωt), u(0) = 1.
let (k, w) = (p[0], p[1]);
let a = |t: f64| (k * (w * t).sin() - w * (w * t).cos()) / (k * k + w * w);
let u_exact = (1.0 - a(0.0)) * (-k * 2.0).exp() + a(2.0);
assert!((u_final - u_exact).abs() < 1e-4 * u_exact.abs());

From docs/api/examples/rust/forward_and_gradient.rs