Skip to content

Commit

Permalink
frees memory after running prediction algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
dermen committed Oct 4, 2021
1 parent 75b0650 commit 56dfcc6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
11 changes: 9 additions & 2 deletions simtbx/command_line/hopper_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
.type = bool
.help = if True, save the data modelers after running refinement. The file includes model values, errors, and useful information
.help = for examining the modeling results, can be loaded using modeler = np.load(fname, allow_pickle=True)[()]
refspec = None
.type = str
.help = path to a reference .lam file to use as the spectra for each shot
"""
import os
from libtbx.phil import parse
Expand All @@ -69,10 +72,11 @@ def __init__(self, *args, **kwargs):
logging.basicConfig(level=logging.DEBUG)

if self.params.save_modelers:
self.modeler_dir = os.path.join(self.params.output.output_dir, "modelers")
if COMM.rank == 0:
self.modeler_dir = os.path.join(self.params.output.output_dir, "modelers")
if not os.path.exists(self.modeler_dir):
os.makedirs(self.modeler_dir)
COMM.barrier()

@property
def device_id(self):
Expand Down Expand Up @@ -133,7 +137,10 @@ def refine(self, exps, ref):
assert len(exps)==1
# TODO MPI select GPU device

exp, ref, data_modeler, x = refine(exps[0], ref, self.params.diffBragg, gpu_device=self.device_id, return_modeler=True)
exp, ref, data_modeler, x = refine(exps[0], ref,
self.params.diffBragg,
spec=self.params.refspec,
gpu_device=self.device_id, return_modeler=True)
orig_exp_name = os.path.abspath(self.params.output.refined_experiments_filename)
refls_name = os.path.abspath(self.params.output.indexed_filename)
self.params.diffBragg.outdir = self.params.output.output_dir
Expand Down
6 changes: 4 additions & 2 deletions simtbx/diffBragg/hopper_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class DataModeler:
2- lists whose length is the number of shoeboxes being modeled
for example if one is modeling 3 shoeboxes whose dimensions are 10x10, then
the objects below like self.all_data will have length 300, and other objects like self.selection_flags will have length 2
the objects below like self.all_data will have length 300, and other objects like self.selection_flags
will have length 3
"""

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

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

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

Expand Down
6 changes: 6 additions & 0 deletions simtbx/modeling/forward_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ def diffBragg_forward(CRYSTAL, DETECTOR, BEAM, Famp, energies, fluxes,
S.D.printout_pixel_fastslow = f,s
S.D.show_params()
S.D.add_diffBragg_spots(printout_pix)

# free up memory
S.D.free_all()
S.D.free_Fhkl2()
if S.D.gpu_free is not None:
S.D.gpu_free()
return data


Expand Down

0 comments on commit 56dfcc6

Please sign in to comment.