@@ -674,6 +674,7 @@ def __init__(
674
674
test_stat = "qtilde" ,
675
675
ntoys = 2000 ,
676
676
track_progress = True ,
677
+ skip_failing_toys = False ,
677
678
):
678
679
r"""
679
680
Toy-based Calculator.
@@ -704,6 +705,7 @@ def __init__(
704
705
~pyhf.infer.calculators.ToyCalculator: The calculator for toy-based quantities.
705
706
706
707
"""
708
+ self .skip_failing_toys = skip_failing_toys
707
709
self .ntoys = ntoys
708
710
self .data = data
709
711
self .pdf = pdf
@@ -753,6 +755,9 @@ def distributions(self, poi_test, track_progress=None):
753
755
Tuple (~pyhf.infer.calculators.EmpiricalDistribution): The distributions under the hypotheses.
754
756
755
757
"""
758
+
759
+ print ('skip?' ,self .skip_failing_toys )
760
+
756
761
tensorlib , _ = get_backend ()
757
762
sample_shape = (self .ntoys ,)
758
763
@@ -791,29 +796,47 @@ def distributions(self, poi_test, track_progress=None):
791
796
792
797
signal_teststat = []
793
798
for sample in tqdm .tqdm (signal_sample , ** tqdm_options , desc = 'Signal-like' ):
794
- signal_teststat .append (
795
- teststat_func (
796
- poi_test ,
797
- sample ,
798
- self .pdf ,
799
- self .init_pars ,
800
- self .par_bounds ,
801
- self .fixed_params ,
799
+ try :
800
+ value = teststat_func (
801
+ poi_test ,
802
+ sample ,
803
+ self .pdf ,
804
+ self .init_pars ,
805
+ self .par_bounds ,
806
+ self .fixed_params ,
807
+ )
808
+ except RuntimeError :
809
+ if self .skip_failing_toys :
810
+ value = None
811
+ else :
812
+ raise
813
+
814
+ if (value is not None ) and (tensorlib .isfinite (value )):
815
+ signal_teststat .append (
816
+ value
802
817
)
803
- )
804
818
805
819
bkg_teststat = []
806
820
for sample in tqdm .tqdm (bkg_sample , ** tqdm_options , desc = 'Background-like' ):
807
- bkg_teststat .append (
808
- teststat_func (
809
- poi_test ,
810
- sample ,
811
- self .pdf ,
812
- self .init_pars ,
813
- self .par_bounds ,
814
- self .fixed_params ,
821
+ try :
822
+ value = teststat_func (
823
+ poi_test ,
824
+ sample ,
825
+ self .pdf ,
826
+ self .init_pars ,
827
+ self .par_bounds ,
828
+ self .fixed_params ,
829
+ )
830
+ except RuntimeError :
831
+ if self .skip_failing_toys :
832
+ value = None
833
+ else :
834
+ raise
835
+
836
+ if (value is not None ) and (tensorlib .isfinite (value )):
837
+ bkg_teststat .append (
838
+ value
815
839
)
816
- )
817
840
818
841
s_plus_b = EmpiricalDistribution (tensorlib .astensor (signal_teststat ))
819
842
b_only = EmpiricalDistribution (tensorlib .astensor (bkg_teststat ))
0 commit comments