Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issues with scipy sparse storage in scipy 1.11 #943

Merged
merged 2 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions dymos/transcriptions/common/control_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ def _configure_controls(self):

size = np.prod(shape)
self.sizes[name] = size
sp_eye = sp.eye(size, format='csr')

# The partial of interpolated value wrt the control input values is linear
# and can be computed as the kronecker product of the interpolation matrix (L)
# and eye(size).
J_val = sp.kron(self.L, sp.eye(size), format='csr')
J_val = sp.kron(self.L, sp_eye, format='csr')
rs, cs, data = sp.find(J_val)
self.declare_partials(of=self._output_val_names[name],
wrt=self._input_names[name],
Expand All @@ -138,14 +139,14 @@ def _configure_controls(self):
# The partials of the rates and second derivatives are nonlinear but the sparsity
# pattern is obtained from the kronecker product of the 1st and 2nd differentiation
# matrices (D and D2) and eye(size).
self.rate_jacs[name] = sp.kron(sp.csr_matrix(self.D), sp.eye(size), format='csr')
self.rate_jacs[name] = sp.kron(self.D, sp_eye, format='csr')
rs, cs = self.rate_jacs[name].nonzero()

self.declare_partials(of=self._output_rate_names[name],
wrt=self._input_names[name],
rows=rs, cols=cs)

self.rate2_jacs[name] = sp.kron(sp.csr_matrix(self.D2), sp.eye(size), format='csr')
self.rate2_jacs[name] = sp.kron(self.D2, sp_eye, format='csr')
rs, cs = self.rate2_jacs[name].nonzero()

self.declare_partials(of=self._output_rate2_names[name],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,10 @@ def configure_io(self):

for key in self.jacs:
# Each jacobian matrix has a form that is defined by the Kronecker product
# of the interpolation matrix and np.eye(size). Make sure to specify csc format
# here to avoid spurious zeros.
# of the interpolation matrix eye(size).
self.jacs[key][name] = sp.kron(sp.csr_matrix(self.matrices[key]),
sp.eye(size),
format='csc')
sp.eye(size, format='csr'),
format='csr')

self.sizes[name] = size

Expand All @@ -157,15 +156,15 @@ def configure_io(self):
self.declare_partials(of=self.xc_str[name], wrt=self.xd_str[name],
rows=Ai_rows, cols=Ai_cols, val=data)

Bi_rows, Bi_cols, _ = sp.find(self.jacs['Bi'][name])
Bi_rows, Bi_cols = self.jacs['Bi'][name].nonzero()
self.declare_partials(of=self.xc_str[name], wrt=self.fd_str[name],
rows=Bi_rows, cols=Bi_cols)

Bd_rows, Bd_cols, data = sp.find(self.jacs['Bd'][name])
self.declare_partials(of=self.xdotc_str[name], wrt=self.fd_str[name],
rows=Bd_rows, cols=Bd_cols, val=data)

Ad_rows, Ad_cols, _ = sp.find(self.jacs['Ad'][name])
Ad_rows, Ad_cols = self.jacs['Ad'][name].nonzero()
self.declare_partials(of=self.xdotc_str[name], wrt=self.xd_str[name],
rows=Ad_rows, cols=Ad_cols)

Expand Down Expand Up @@ -242,7 +241,8 @@ def _compute_partials_radau(self, inputs, partials):

dstau_dt_x_size = np.repeat(dstau_dt, size)[:, np.newaxis]

partials[xdotc_name, xd_name] = self.jacs['Ad'][name].multiply(dstau_dt_x_size).data
dxdotc_dxd = self.jacs['Ad'][name].multiply(dstau_dt_x_size)
partials[xdotc_name, xd_name] = dxdotc_dxd.data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok to still use data here? Will it work the same way in old and new scipy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to work fine, ultimately the issue was a change in formats to the matrices involved that I've resolved


def _compute_partials_gauss_lobatto(self, inputs, partials):
ndn = self.options['grid_data'].subset_num_nodes['state_disc']
Expand Down