Version: dev

jacobian_pattern

Stable function · Sparsity and structure

Tier: stable · Kind: function · Topic: Sparsity and structure

JuliaPythonRust
jacobian_patternjacobian_patternnot exported

Julia

jacobian_pattern(input; wrt, model_name, build_kwargs, source_layout)
jacobian_pattern(input; wrt = :states) -> (pattern, rownames, colnames, entries)

The structural (global, point-independent) sparsity pattern of the Jacobian as a SparseMatrixCSC{Bool}. input is an EsmFile + model name pair (pass a Tuple), an EsmFile with a single model, or a FlattenedSystem.

source_layout skips this function’s own rebuild of the source model — see prepare_jacobian for the keyword and its contract.

Source

Example (pattern)

pat = jacobian_pattern(file)
# 4 cells x 6 variable pairs, one stored entry each, even where a value is 0.
@assert nnz(pat.pattern) == 24
@assert pat.pattern[1, 1]                    # A[1] depends on A[1]
@assert !pat.pattern[1, 2]                   # but not on A[2]
@assert pat.rownames[1] == "A[1]"

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

Python

jacobian_pattern(obj, model_name: str | None = None, wrt: str = 'states')

The structural sparsity pattern as sorted (rowname, colname) pairs plus the entries — dependency-light (no scipy).

Source

Example (pattern)

pairs, _ = earthsci_astdiff.jacobian_pattern(file)
# 4 cells x 6 variable pairs, one stored entry each, even where a value is 0.
assert len(pairs) == 24
assert ("A[1]", "B[1]") in pairs
assert ("A[1]", "A[2]") not in pairs

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

Rust

Rust does not export this function.