Skip to content

Commit 56dfcc6

Browse files
committed
frees memory after running prediction algorithm
1 parent 75b0650 commit 56dfcc6

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

simtbx/command_line/hopper_process.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
.type = bool
4646
.help = if True, save the data modelers after running refinement. The file includes model values, errors, and useful information
4747
.help = for examining the modeling results, can be loaded using modeler = np.load(fname, allow_pickle=True)[()]
48+
refspec = None
49+
.type = str
50+
.help = path to a reference .lam file to use as the spectra for each shot
4851
"""
4952
import os
5053
from libtbx.phil import parse
@@ -69,10 +72,11 @@ def __init__(self, *args, **kwargs):
6972
logging.basicConfig(level=logging.DEBUG)
7073

7174
if self.params.save_modelers:
75+
self.modeler_dir = os.path.join(self.params.output.output_dir, "modelers")
7276
if COMM.rank == 0:
73-
self.modeler_dir = os.path.join(self.params.output.output_dir, "modelers")
7477
if not os.path.exists(self.modeler_dir):
7578
os.makedirs(self.modeler_dir)
79+
COMM.barrier()
7680

7781
@property
7882
def device_id(self):
@@ -133,7 +137,10 @@ def refine(self, exps, ref):
133137
assert len(exps)==1
134138
# TODO MPI select GPU device
135139

136-
exp, ref, data_modeler, x = refine(exps[0], ref, self.params.diffBragg, gpu_device=self.device_id, return_modeler=True)
140+
exp, ref, data_modeler, x = refine(exps[0], ref,
141+
self.params.diffBragg,
142+
spec=self.params.refspec,
143+
gpu_device=self.device_id, return_modeler=True)
137144
orig_exp_name = os.path.abspath(self.params.output.refined_experiments_filename)
138145
refls_name = os.path.abspath(self.params.output.indexed_filename)
139146
self.params.diffBragg.outdir = self.params.output.output_dir

simtbx/diffBragg/hopper_utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class DataModeler:
4545
2- lists whose length is the number of shoeboxes being modeled
4646
4747
for example if one is modeling 3 shoeboxes whose dimensions are 10x10, then
48-
the objects below like self.all_data will have length 300, and other objects like self.selection_flags will have length 2
48+
the objects below like self.all_data will have length 300, and other objects like self.selection_flags
49+
will have length 3
4950
"""
5051

5152
def __init__(self, params):
@@ -76,12 +77,13 @@ def __init__(self, params):
7677
self.simple_weights = None # not used
7778
self.refls_idx = None # position of modeled spot in original refl array
7879
self.refls = None # reflection table
80+
self.sigma_rdout = None # the value of the readout noise in photon units
7981

8082
self.Hi = None # miller index (P1)
8183
self.Hi_asu = None # miller index (high symmetry)
8284

8385
# which attributes to save when pickling a data modeler
84-
self.saves = ["all_data", "all_background", "all_trusted", "best_model", "all_sigmas",
86+
self.saves = ["all_data", "all_background", "all_trusted", "best_model", "sigma_rdout",
8587
"rois", "pids", "tilt_abc", "selection_flags", "refls_idx", "pan_fast_slow",
8688
"Hi", "Hi_asu", "roi_id", "params", "all_pid", "all_fast", "all_slow"]
8789

simtbx/modeling/forward_models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ def diffBragg_forward(CRYSTAL, DETECTOR, BEAM, Famp, energies, fluxes,
260260
S.D.printout_pixel_fastslow = f,s
261261
S.D.show_params()
262262
S.D.add_diffBragg_spots(printout_pix)
263+
264+
# free up memory
265+
S.D.free_all()
266+
S.D.free_Fhkl2()
267+
if S.D.gpu_free is not None:
268+
S.D.gpu_free()
263269
return data
264270

265271

0 commit comments

Comments
 (0)