Skip to content

Commit e5df38e

Browse files
authored
Merge pull request #3905 from eslickj/sens-fix
Minor efficiency change to sensitivity toolbox Pynumero calculations
2 parents fd3f317 + 17f46ba commit e5df38e

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

pyomo/contrib/sensitivity_toolbox/pynumero.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,10 @@ def get_dsdp_dfdp(model, theta):
8080
col_remap = {mv_map[id(v)]: i for i, v in enumerate(s_list + theta)}
8181
_coo_reorder_cols(J, remap=col_remap)
8282
J = J.tocsc()
83-
dB = -(
84-
J
85-
@ scipy.sparse.vstack(
86-
(scipy.sparse.coo_matrix((ns, np)), scipy.sparse.identity(np))
87-
).tocsc()
88-
)
8983
# Calculate sensitivity matrix
90-
dsdp = scipy.sparse.linalg.spsolve(J[:, range(ns)], dB)
84+
dsdp = -scipy.sparse.linalg.spsolve(
85+
J[:, :ns], J[:, ns:] @ scipy.sparse.identity(np)
86+
)
9187
# Get a map of state vars to columns
9288
s_map = {id(v): i for i, v in enumerate(s_list)}
9389
# Get the outputs we are interested in from the list of output vars

0 commit comments

Comments
 (0)