Skip to content

Commit 2c0f057

Browse files
authored
Merge pull request #431 from hiddenSymmetries/cbs/fix_spec_failure
clear spec cache to avoid sporadic mismatch
2 parents 8d6e86a + 7bc1e4c commit 2c0f057

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/simsopt/mhd/spec.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ def __init__(self,
141141
filename = f"{filename}.sp"
142142
logger.info(f"Initializing a SPEC object from file: {filename}")
143143

144+
# If spec has run before, clear the f90wrap array caches.
145+
# See https://github.com/hiddenSymmetries/simsopt/pull/431
146+
# This addresses the issue https://github.com/hiddenSymmetries/simsopt/issues/357
147+
if spec.allglobal._arrays:
148+
self._clear_f90wrap_array_caches()
149+
144150
if tolerance <= 0:
145151
raise ValueError(
146152
'tolerance should be greater than zero'
@@ -716,6 +722,18 @@ def set_dofs(self, x):
716722
if p is not None:
717723
p.phiedge = x[0]
718724

725+
def _clear_f90wrap_array_caches(self):
726+
"""
727+
Clear the f90wrap array caches. This is necessary when a new file is
728+
read after SPEC has run before.
729+
730+
See https://github.com/hiddenSymmetries/simsopt/pull/431
731+
732+
This function is for addressing the issue https://github.com/hiddenSymmetries/simsopt/issues/357
733+
"""
734+
spec.allglobal._arrays = {}
735+
spec.inputlist._arrays = {}
736+
719737
def init(self, filename: str):
720738
"""
721739
Initialize SPEC fortran state from an input file.

0 commit comments

Comments
 (0)