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

clear spec cache to avoid sporadic mismatch #431

Merged
merged 3 commits into from
Jul 3, 2024
Merged
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
18 changes: 18 additions & 0 deletions src/simsopt/mhd/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ def __init__(self,
filename = f"{filename}.sp"
logger.info(f"Initializing a SPEC object from file: {filename}")

# If spec has run before, clear the f90wrap array caches.
# See https://github.com/hiddenSymmetries/simsopt/pull/431
# This addresses the issue https://github.com/hiddenSymmetries/simsopt/issues/357
if spec.allglobal._arrays:
self._clear_f90wrap_array_caches()

if tolerance <= 0:
raise ValueError(
'tolerance should be greater than zero'
Expand Down Expand Up @@ -716,6 +722,18 @@ def set_dofs(self, x):
if p is not None:
p.phiedge = x[0]

def _clear_f90wrap_array_caches(self):
"""
Clear the f90wrap array caches. This is necessary when a new file is
read after SPEC has run before.

See https://github.com/hiddenSymmetries/simsopt/pull/431

This function is for addressing the issue https://github.com/hiddenSymmetries/simsopt/issues/357
"""
spec.allglobal._arrays = {}
spec.inputlist._arrays = {}

def init(self, filename: str):
"""
Initialize SPEC fortran state from an input file.
Expand Down
Loading