From 4e93655e9a266e10efecb6210a2333cbce9b826c Mon Sep 17 00:00:00 2001 From: Josue De Santiago Date: Mon, 30 Oct 2023 15:30:21 -0600 Subject: [PATCH] 45 parallelize point est hist and naive stack (#64) * First working parallel version for Naive_Stack * Simplifying the logic in the iterator * Added Output_BPZ_lite.hdf5 with the new format for pq files --- src/rail/core/data.py | 12 ++++ src/rail/core/stage.py | 21 +++--- src/rail/estimation/algos/naive_stack.py | 62 ++++++++++++++---- .../testdata/output_BPZ_lite.hdf5 | Bin 0 -> 37192 bytes tests/core/test_core.py | 2 +- tests/estimation/test_classifier.py | 2 +- tests/estimation/test_summarizers.py | 2 +- 7 files changed, 79 insertions(+), 22 deletions(-) create mode 100644 src/rail/examples_data/testdata/output_BPZ_lite.hdf5 diff --git a/src/rail/core/data.py b/src/rail/core/data.py index 74dd10df..1e336b58 100644 --- a/src/rail/core/data.py +++ b/src/rail/core/data.py @@ -35,6 +35,7 @@ def __init__(self, tag, data=None, path=None, creator=None): self.fileObj = None self.groups = None self.partial = False + self.lenght = None def open(self, **kwargs): """Open and return the associated file @@ -309,6 +310,17 @@ def _validate_data(cls, data): if not isinstance(data, qp.Ensemble): raise TypeError(f"Expected `data` to be a `qp.Ensemble`, but {type(data)} was provided. Perhaps you meant to use `TableHandle`?") + # @classmethod + def _size(cls, path, **kwargs): + if path == 'None': + return cls.data.npdf + return tables_io.io.getInputDataLengthHdf5(path, groupname='data') + + @classmethod + def _iterator(cls, path, **kwargs): + """Iterate over the data""" + kwargs.pop('groupname','None') + return qp.iterator(path, **kwargs) def default_model_read(modelfile): """Default function to read model files, simply used pickle.load""" diff --git a/src/rail/core/stage.py b/src/rail/core/stage.py index c2a1ca1c..c8ca0ea0 100644 --- a/src/rail/core/stage.py +++ b/src/rail/core/stage.py @@ -326,10 +326,17 @@ def input_iterator(self, tag, **kwargs): These will be passed to the Handle's iterator method """ handle = self.get_handle(tag, allow_missing=True) - if self.config.hdf5_groupname and handle.path: - self._input_length = handle.size(groupname=self.config.hdf5_groupname) + + try: + self.config.hdf5_groupname + except: + self.config.hdf5_groupname = None + self._input_length = handle.size(groupname=self.config.hdf5_groupname) + + if handle.path and handle.path!='None': total_chunks_needed = ceil(self._input_length/self.config.chunk_size) - if total_chunks_needed=start) & (bootstrap_draws~roB^(2aqGCW0l%OC2ii!xE zEJy|cL2?!(XC&t|=q}E>bN+Sio%^p@GiUDI&017dcXfT=^LBN2?W)?l?rN-4pEPm$ zMB2}do14Z?6ZjP!|2IlD4Lio3@$~p{0}^2&;T;nCureYnw4Z-8+ElV%kd*(&d^@(U zUr!s$IbQyFNKT`bb1-7u<2#t)zm)(^-g1lA+eQY1_!^^7EGXO5U0{24bq$OsRf zJ$&NySbDsEDvxLUFNS|se>K<`1so^!@*mY-Wm0iv|BH5++5WW@_+$NDOz`fI`ZG>@ z&hY4gvj@){`P=lRBj+!iFgp8dm)WI*r!S1f#_RJxs!uxGG}p1v*nWTh_T6EWJbu2^ zT}GO^#|X!t{`E8eb3TDtjP&9;jF41kniRPY#>@NTeZk26fB!!Vjf0^%0c9bIvam3A zjPs9&Y&7m)`Gv=JaE{?~kTfeR>#r=_bZ08;^`0!#&%3NRJ;uPE@(w<`sH zwJQb28eWXH7xl}`pSLfqN&9lVr8e%>qw&aJD*S)-V6+HX7|rJ2Kldyo4ejyv_IUc| zC!L@B1f}u2K1w_^rBU)Z<C1IMHid7PIjPGh`~jRDh`fQvs#||LqFkrbWdD zzsbMBfrM^h+D*44!r(>HZ=8Q_F7PA!1AZRWZblF}9y)Q=InRQL2q*a>WxL~S_s&BU z$saRzaMd|4#FF#k6@P6=Am=BJ<(BP^$7fPb@-Oq-kwVH#{pp@X1=2{l=|8QlGR9X@ zekMZ_WD+}Bzp`r}i`dKlS$v!=a){lWpYC`TAeY$B8>4BuC5b%ZNB+^D+c7Y*O+>*@ z>l^$~Nc<}Ni6`5GBH~~1FZ|UgCVrOul&9$yz7c=FrTyH}QA+$S`&HZ&lo9{G|8j3H z$_Ym~u~SZX%85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