sparsity
Sparsity analysis helpers for symbolic Jacobian patterns.
This module contains all sparsity-related utilities used by the symbolic expression layer:
- AST helpers (
_broadcast_sparsity,_broadcast_liveness,_bool_matmul,_element_liveness) support the per-nodeExpr.sparsity()method implementations. - Discretization helpers (
transitive_closure,discrete_sparsity) lift continuous-time Jacobian sparsity to discrete-time patterns for use with CVXPY sparse parameters.
Note
The actual sparsity patterns are computed by the sparsity() method
defined on each AST node in expr/. This module only provides the
shared helpers that those per-node implementations depend on.
discrete_sparsity(A_c: np.ndarray, B_c: np.ndarray, dis_type: Union[str, Sequence[str], np.ndarray] = 'ZOH') -> Tuple[np.ndarray, np.ndarray, np.ndarray]
¶
Discrete-time sparsity from continuous-time Jacobian patterns.
The linearize-then-discretize scheme integrates the variational equations::
dΦ/dτ = A · Φ, Φ(0) = I
dB_d/dτ = A · B_d + α · B, B_d(0) = 0
dC_d/dτ = A · C_d + β · B, C_d(0) = 0
where α, β are per-control interpolation weights (ZOH: α=1, β=0;
FOH: linear blend).
Because the sparsity pattern of A and B is constant along
the trajectory, the discrete patterns follow from the transitive
closure::
A_d = transitive_closure(A_c)
B_d = bool_matmul(A_d, B_c)
C_d = per-column: all-False (ZOH) or B_d column (FOH)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A_c
|
ndarray
|
|
required |
B_c
|
ndarray
|
|
required |
dis_type
|
Union[str, Sequence[str], ndarray]
|
|
'ZOH'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
|
ndarray
|
|
Source code in openscvx/symbolic/sparsity.py
transitive_closure(A: np.ndarray) -> np.ndarray
¶
Reachability matrix of a boolean adjacency matrix.
Given A[i,j] = True meaning j directly influences i, returns
R[i,j] = True meaning j influences i through a path of any
length (including zero — the identity is included).
This is the sparsity pattern of the matrix exponential:
expm(A·dt) = I + A·dt + A²·dt²/2 + …, so R[i,j] is nonzero
iff any power of A has a nonzero (i,j) entry.
Used to lift continuous-time Jacobian sparsity to discrete-time state-transition sparsity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
ndarray
|
Boolean matrix of shape |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Boolean reachability matrix of shape |