Skip to content

Commit

Permalink
Remove _set_up method now that io save stuff was...
Browse files Browse the repository at this point in the history
    determined to be cause of the bug. The transform matrices
    attribute is being assigned and is persistent. The error the
    previous commits were trying to isolate was just an issue with
    loosing the matrices attribute while saving to output.
    By calling .matrics property attribute everywhere we do not need
    a _set_up method.
  • Loading branch information
unalmis committed Jul 19, 2023
1 parent 15f816a commit d78e4a5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
2 changes: 2 additions & 0 deletions desc/basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def __init__(self):

def _set_up(self):
"""Do things after loading or changing resolution."""
# Also recreates any attributes not in _io_attrs on load from input file.
# See IOAble class docstring for more info.
self._enforce_symmetry()
self._sort_modes()
self._create_idx()
Expand Down
13 changes: 4 additions & 9 deletions desc/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def build(self):

if self.method == "direct1":
for d in self.derivatives:
self._matrices["direct1"][d[0]][d[1]][d[2]] = self.basis.evaluate(
self.matrices["direct1"][d[0]][d[1]][d[2]] = self.basis.evaluate(
self.grid.nodes, d, unique=True
)

Expand Down Expand Up @@ -406,7 +406,7 @@ def build_pinv(self):
rcond = None if self.rcond == "auto" else self.rcond
if self.method == "direct1":
A = self.basis.evaluate(self.grid.nodes, np.array([0, 0, 0]))
self._matrices["pinv"] = (
self.matrices["pinv"] = (
scipy.linalg.pinv(A, rcond=rcond) if A.size else np.zeros_like(A.T)
)
elif self.method == "direct2":
Expand Down Expand Up @@ -726,19 +726,14 @@ def change_derivatives(self, derivs, build=True):
self._sort_derivatives()

if len(derivs_to_add):
# if we actually added derivatives and didn't build them, then it's not built
# if we actually added derivatives and didn't build them, then it's not
# built
self._built = False
if build:
# we don't update self._built here because it is still built from before,
# but it still might have unbuilt matrices from new derivatives
self.build()

def _set_up(self):
"""Recreate attributes that were not saved to output files."""
# fixme: Make api for reloading attributes that are not saved better.
# See equilibrium_io.py for the logic that calls this function.
self._matrices = self.matrices

@property
def matrices(self):
"""dict: transform matrices such that x=A*c."""
Expand Down

0 comments on commit d78e4a5

Please sign in to comment.