Version: dev

sysview

Stable function · Differentiate a model

Tier: stable · Kind: function · Topic: Differentiate a model

JuliaPythonRust
sysviewsysviewsysview

Julia

sysview(file::EarthSciAST.EsmFile, model_name)
sysview(flat::EarthSciAST.FlattenedSystem)
sysview(file::EsmFile, model_name) -> SysView
sysview(flat::FlattenedSystem)     -> SysView

Source

Example (bands)

file = EarthSciAST.load_path(joinpath(FIXTURES, "bd_chem.esm"))
view = sysview(file, "Chem")
entries = jacobian_bands(view)
# One entry per (row variable, column variable) pair that occurs in the model.
@assert sort(unique([(en.u, en.v) for en in entries])) ==
        [("A", "A"), ("A", "B"), ("A", "C"), ("B", "A"), ("B", "B"), ("C", "B")]

From docs/api/examples/julia/jacobians.jl

Python

sysview(obj, model_name: str | None = None) -> SysView

View a model of an EsmFile, or a FlattenedSystem, for differentiation.

Parameters

  • obj — an EsmFile or a flattened system.
  • model_name — which model of an EsmFile; may be omitted when the file has exactly one.

Source

Example (bands)

file = earthsci_ast.load_path(FIXTURES / "bd_chem.esm")
entries = earthsci_astdiff.jacobian_bands(file)
# One entry per (row variable, column variable) pair that occurs in the model.
assert sorted({(en.u, en.v) for en in entries}) == [
    ("A", "A"), ("A", "B"), ("A", "C"), ("B", "A"), ("B", "B"), ("C", "B"),
]
view = earthsci_astdiff.sysview(file)

From docs/api/examples/python/jacobians.py

Rust

pub fn sysview<'a>(file: &'a EsmFile, model_name: Option<&str>) -> Result<SysView<'a>, BandError>

View a model of file for differentiation. model_name may be None when the file has exactly one model.

Source · Rust docs

Example (bands)

let file = load_path(fixture("bd_chem.esm"))?;
let entries = jacobian_bands(&file, None, Wrt::States)?;
// One entry per (row variable, column variable) pair that occurs in the model.
let mut pairs: Vec<(&str, &str)> =
    entries.iter().map(|en| (en.u.as_str(), en.v.as_str())).collect();
pairs.sort();
pairs.dedup();
assert_eq!(
    pairs,
    [("A", "A"), ("A", "B"), ("A", "C"), ("B", "A"), ("B", "B"), ("C", "B")]
);
let view = sysview(&file, None)?;

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