Skip to content

Commit

Permalink
add: memfolder field for FitConfig. Use /tmp space for joblib memmaps…
Browse files Browse the repository at this point in the history
… in edd.
  • Loading branch information
keara-soloway committed Oct 16, 2024
1 parent 7ba4c73 commit 9f1e9b2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHAP/edd/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,7 @@ def get_spectra_fits(spectra, energies, peak_locations, detector):
numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray,
numpy.ndarray]
"""
from os import getpid
# Third party modules
from nexusformat.nexus import NXdata, NXfield

Expand Down Expand Up @@ -1432,6 +1433,7 @@ def get_spectra_fits(spectra, energies, peak_locations, detector):
# 'method': 'trf',
'method': 'leastsq',
# 'method': 'least_squares',
'memfolder': f'/tmp/{getpid()}_joblib_memmap',
}

# Perform uniform fit
Expand Down
4 changes: 1 addition & 3 deletions CHAP/utils/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2084,7 +2084,7 @@ def __init__(self, nxdata, config):
self._best_values = None
self._inv_transpose = None
self._max_nfev = None
self._memfolder = None
self._memfolder = config.memfolder
self._new_parameters = None
self._num_func_eval = None
self._out_of_bounds = None
Expand Down Expand Up @@ -2319,7 +2319,6 @@ def freemem(self):
return
try:
rmtree(self._memfolder)
self._memfolder = None
except:
logger.warning('Could not clean-up automatically.')

Expand Down Expand Up @@ -2514,7 +2513,6 @@ def fit(self, config=None, **kwargs):
np.zeros(self._map_dim, dtype=np.float64)
for _ in range(num_new_parameters)]
else:
self._memfolder = 'joblib_memmap'
try:
mkdir(self._memfolder)
except FileExistsError:
Expand Down
1 change: 1 addition & 0 deletions CHAP/utils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ class FitConfig(BaseModel):
num_proc: conint(gt=0) = 1
plot: StrictBool = False
print_report: StrictBool = False
memfolder: str = 'joblib_memmap'

@field_validator('method')
@classmethod
Expand Down

0 comments on commit 9f1e9b2

Please sign in to comment.