jacobian_pattern
Stable function · Sparsity and structure
Tier: stable · Kind: function · Topic: Sparsity and structure
| Julia | Python | Rust |
|---|---|---|
jacobian_pattern | jacobian_pattern | not 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.
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]"
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).
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
Rust
Rust does not export this function.