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

Refactor of reverse transfers and fixes for FD group that contains parallel group(s). #3069

Merged
merged 77 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
e7a804b
added RangeTree
naylor-b Jun 13, 2023
c20ae91
test
naylor-b Jun 17, 2023
1655e4f
added rangecollection
naylor-b Jul 3, 2023
791dee7
refactoring
naylor-b Jul 3, 2023
c434beb
progress but still distrib and par deriv coloring issues
naylor-b Sep 8, 2023
43b093f
progress
naylor-b Sep 12, 2023
255a9a9
issues with distrib and par derivs
naylor-b Sep 13, 2023
a0f5f65
interim
naylor-b Sep 18, 2023
e3c1656
interim - 10 xfer fails
naylor-b Sep 22, 2023
e6eedfd
7 fails
naylor-b Sep 27, 2023
e9c4bad
4 rev transfer related failures
naylor-b Sep 30, 2023
ae51517
2 failures, both related to rev derivs when model has an fd group
naylor-b Oct 2, 2023
d3ea671
cleanup
naylor-b Oct 2, 2023
8564ab0
cleanup
naylor-b Oct 2, 2023
7a73752
Merge remote-tracking branch 'origin/master' into transfers2
naylor-b Oct 2, 2023
71dd83f
fixed pep issues. 2 remaining failures
naylor-b Oct 2, 2023
834ca2b
fix for approx derivs when part is nonlocal
naylor-b Oct 3, 2023
7e2bdad
adding iterator of names and dist offsets
naylor-b Oct 4, 2023
3add46f
Merge remote-tracking branch 'origin/master' into RangeTree
naylor-b Oct 4, 2023
b8e5fdd
Merge branch 'RangeTree' into transfers2
naylor-b Oct 4, 2023
873896b
added dist_conns command tool to view distributed connections
naylor-b Oct 5, 2023
8464087
fixed output for no mpi and made all ranks be relative to top group
naylor-b Oct 5, 2023
c83dd2f
sorting of check_totals
naylor-b Oct 5, 2023
af988b1
fix for ken's mpi issue
naylor-b Oct 6, 2023
75a5725
fixed rev transfer issue
naylor-b Oct 6, 2023
0d3ad22
saving some transfer memory
naylor-b Oct 9, 2023
466ae19
fix for when dist desvar connected to dist input
naylor-b Oct 11, 2023
aa5baf4
updated default xfers to have 2 separate toplevel arrays for fwd/rev …
naylor-b Oct 11, 2023
3aea2c1
cleanup
naylor-b Oct 11, 2023
9e15952
passing
naylor-b Oct 13, 2023
3f06229
cleaned up test
naylor-b Oct 13, 2023
b7cdb75
new tests
naylor-b Oct 13, 2023
39d7eea
FD group tests passing for rev transfers
naylor-b Oct 16, 2023
b55ccec
merged out
naylor-b Oct 17, 2023
120e42b
passing
naylor-b Oct 17, 2023
0744c8d
added new failing tests
naylor-b Oct 18, 2023
b0406a5
cleanup
naylor-b Oct 18, 2023
2b87b63
cleanup
naylor-b Oct 18, 2023
a9b71d0
split fwd and rev transfer routines for petsc
naylor-b Oct 18, 2023
7cb812a
cleanup
naylor-b Oct 19, 2023
196d08c
cleanup
naylor-b Oct 19, 2023
d01f9b1
cleanup
naylor-b Oct 19, 2023
c7a174f
cleanup
naylor-b Oct 19, 2023
2a3b72b
cleanup of rev xfers
naylor-b Oct 19, 2023
9e4b5d9
some renaming
naylor-b Oct 19, 2023
eeaa60d
cleanup
naylor-b Oct 19, 2023
0e44bf8
updated comment
naylor-b Oct 20, 2023
fb63db8
passing
naylor-b Oct 27, 2023
d741216
merged out
naylor-b Oct 30, 2023
89b36e9
moved some tests
naylor-b Oct 30, 2023
96bebb2
updated some tests
naylor-b Oct 31, 2023
dbeb33f
passing
naylor-b Nov 1, 2023
67724de
cleanup
naylor-b Nov 1, 2023
5f20fe7
updating transfer docs
naylor-b Nov 2, 2023
af3e151
Merge remote-tracking branch 'origin/master' into transfers3
naylor-b Nov 2, 2023
0f72aeb
one broken test
naylor-b Nov 3, 2023
f838000
split test into fwd/rev
naylor-b Nov 3, 2023
f01970c
passing all tests
naylor-b Nov 3, 2023
3721a44
added test and made cosmetic improvement to check_totals output
naylor-b Nov 6, 2023
853f343
fix for missing subjac val
naylor-b Nov 7, 2023
af8766d
fix list_pre_post command
naylor-b Nov 7, 2023
11c9f28
updated RangeMappers and added tests
naylor-b Nov 9, 2023
690f316
test fixes
naylor-b Nov 9, 2023
1e3be43
docstring fix
naylor-b Nov 9, 2023
92f0b2c
fix to seed_vars
naylor-b Nov 13, 2023
d851549
cleanup of multi seed_var case
naylor-b Nov 13, 2023
f9c87d8
fixed and added test for one of andrew's cases
naylor-b Nov 14, 2023
d087796
cleanup
naylor-b Nov 14, 2023
a549142
added test for andrew's bcast case
naylor-b Nov 14, 2023
dd15037
added serial tests for several group layouts (fan in, fan out, etc.)
naylor-b Nov 14, 2023
b2cbf76
pep8 fix
naylor-b Nov 14, 2023
c1d5def
trying a change to par_deriv_jac_setter
naylor-b Nov 17, 2023
59dab6d
cleanup
naylor-b Nov 17, 2023
10f4a6c
merged out
naylor-b Nov 27, 2023
e6b3939
fix for distrib response specified by input name
naylor-b Nov 27, 2023
af8f2ec
added some tests
naylor-b Nov 27, 2023
6e16d7c
fixed docstring and test
naylor-b Nov 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 20 additions & 22 deletions openmdao/approximation_schemes/approximation_scheme.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Base class used to define the interface for derivative approximation schemes."""
import time
from collections import defaultdict
from itertools import repeat
import numpy as np

from openmdao.core.constants import INT_DTYPE
from openmdao.vectors.vector import _full_slice
from openmdao.utils.array_utils import get_input_idx_split
import openmdao.utils.coloring as coloring_mod
from openmdao.utils.general_utils import _convert_auto_ivc_to_conn_name, LocalRangeIterable
Expand Down Expand Up @@ -134,8 +136,8 @@ def add_approximation(self, abs_key, system, kwargs):
raise NotImplementedError("add_approximation has not been implemented")

def _init_colored_approximations(self, system):
is_group = _is_group(system)
is_total = is_group and system.pathname == ''
is_total = system.pathname == ''
is_semi = _is_group(system) and not is_total
self._colored_approx_groups = []

# don't do anything if the coloring doesn't exist yet
Expand All @@ -155,17 +157,17 @@ def _init_colored_approximations(self, system):
if is_total:
ccol2vcol = np.empty(coloring._shape[1], dtype=INT_DTYPE)

ordered_wrt_iter = list(system._jac_wrt_iter())
colored_start = colored_end = 0
for abs_wrt, cstart, cend, _, cinds, _ in ordered_wrt_iter:
for abs_wrt, cstart, cend, vec, cinds, _ in system._jac_wrt_iter():
if wrt_matches is None or abs_wrt in wrt_matches:
colored_end += cend - cstart
ccol2jcol[colored_start:colored_end] = np.arange(cstart, cend, dtype=INT_DTYPE)
ccol2jcol[colored_start:colored_end] = range(cstart, cend)
if is_total and abs_wrt in out_slices:
slc = out_slices[abs_wrt]
rng = np.arange(slc.start, slc.stop)
if cinds is not None:
rng = rng[cinds]
if cinds is None or cinds is _full_slice:
rng = range(slc.start, slc.stop)
else:
rng = np.arange(slc.start, slc.stop)[cinds]
ccol2vcol[colored_start:colored_end] = rng
colored_start = colored_end

Expand Down Expand Up @@ -198,7 +200,6 @@ def _init_colored_approximations(self, system):
inputs = system._inputs

from openmdao.core.implicitcomponent import ImplicitComponent
is_semi = is_group and not is_total
use_full_cols = is_semi or isinstance(system, ImplicitComponent)

for cols, nzrows in coloring.color_nonzero_iter('fwd'):
Expand Down Expand Up @@ -259,7 +260,7 @@ def _init_approximations(self, system):

if wrt in approx_wrt_idx:
if vec is None:
vec_idx = None
vec_idx = repeat(None, approx_wrt_idx[wrt].shaped_array().size)
else:
# local index into var
vec_idx = approx_wrt_idx[wrt].shaped_array(copy=True)
Expand All @@ -271,15 +272,9 @@ def _init_approximations(self, system):
in_idx = [list(in_idx)]
vec_idx = [vec_idx]
else:
if vec is None: # remote wrt
if wrt in abs2meta['input']:
vec_idx = range(abs2meta['input'][wrt]['global_size'])
else:
vec_idx = range(abs2meta['output'][wrt]['global_size'])
else:
vec_idx = LocalRangeIterable(system, wrt)
if directional:
vec_idx = [v for v in vec_idx if v is not None]
vec_idx = LocalRangeIterable(system, wrt)
if directional and vec is not None:
vec_idx = [v for v in vec_idx if v is not None]

# Directional derivatives for quick deriv checking.
# Place the indices in a list so that they are all stepped at the same time.
Expand Down Expand Up @@ -445,14 +440,16 @@ def _vec_ind_iter(self, vec_ind_list):
entry = [[None, None]]
ent0 = entry[0]
for vec, vec_idxs in vec_ind_list:
if vec_idxs is None:
continue
for vinds in vec_idxs:
ent0[0] = vec
ent0[1] = vinds
yield entry, vinds

def _uncolored_column_iter(self, system, approx_groups):
"""
Perform approximations and yields (column_index, column) for each jac column.
Perform approximations and yield (column_index, column) for each jac column.

Parameters
----------
Expand All @@ -477,9 +474,10 @@ def _uncolored_column_iter(self, system, approx_groups):
solution array corresponding to the jacobian column at the given column index
"""
total = system.pathname == ''
ordered_of_iter = list(system._jac_of_iter())
if total:
tot_result = np.zeros(ordered_of_iter[-1][2])
for _, _, end, _, _ in system._jac_of_iter():
pass
tot_result = np.zeros(end)

total_or_semi = total or _is_group(system)

Expand Down
13 changes: 1 addition & 12 deletions openmdao/core/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -1006,17 +1006,6 @@ def _update_dist_src_indices(self, abs_in2out, all_abs2meta, all_abs2idx, all_si
if dist_in:
offset = np.sum(sizes_in[:iproc, i])
end = offset + sizes_in[iproc, i]
else:
if src.startswith('_auto_ivc.'):
nzs = np.nonzero(vout_sizes)[0]
if nzs.size == 1:
# special case where we have a 'distributed' auto_ivc output
# that has a nonzero value in only one proc, so we can treat
# it like a non-distributed output. This happens in cases
# where an auto_ivc output connects to a variable that is
# remote on at least one proc.
offset = 0
end = vout_sizes[nzs[0]]

# total sizes differ and output is distributed, so can't determine mapping
if offset is None:
Expand Down Expand Up @@ -1776,7 +1765,7 @@ def _get_dist_nz_dresids(self):
"""
nzresids = []
dresids = self._dresiduals.asarray()
for of, start, end, _full_slice, dist_sizes in self._jac_of_iter():
for of, start, end, _, dist_sizes in self._jac_of_iter():
if dist_sizes is not None:
if np.any(dresids[start:end]):
nzresids.append(of)
Expand Down