Esempio n. 1
0
 def test_path_3thr_backward(self):
     tc = ThresholdsAtlas([1, 2, 3], 2.5)
     p1 = tc.path(0.7)
     assert len(p1) == 3
     assert p1[0].tuple == (2.5, 2.0, 5)
     assert p1[1].tuple == (2.0, 1.0, 4)
     assert p1[2].tuple == (1.0, 0.7, 3)
Esempio n. 2
0
 def test_nf(self):
     nf4 = ThresholdsAtlas.ffns(4)
     for q2 in [1.0, 1e1, 1e2, 1e3, 1e4]:
         assert nf4.nf(q2) == 4
     ta = ThresholdsAtlas([1, 2, 3], 0.5)
     assert ta.nf(0.9) == 3
     assert ta.nf(1.1) == 4
Esempio n. 3
0
 def test_path_3thr_weird(self):
     tc = ThresholdsAtlas([1, 2, 3], 0.5)
     # the whole distance underground
     p6 = tc.path(3.5, nf_to=3)
     assert len(p6) == 1
     assert p6[0].tuple == (0.5, 3.5, 3)
     q2_from = 3.5
     q2_to = 0.7
     #                   0
     #      1 <-----------
     #      ---> 2
     #   3 < -----
     #      |    |    |
     p7 = tc.path(q2_to=q2_to, nf_to=5, q2_from=q2_from, nf_from=3)
     assert len(p7) == 3
     assert p7[0].nf == 3
     assert p7[1].nf == 4
     assert p7[2].nf == 5
     assert p7[0].q2_from == q2_from
     assert p7[2].q2_to == q2_to
     #                   0
     #      1 <-----------
     #      ---> 2 -> 3
     #   4 < ---------
     #      |    |    |
     p8 = tc.path(q2_to=q2_to, nf_to=6, q2_from=q2_from, nf_from=3)
     assert len(p8) == 4
     assert p8[0].nf == 3
     assert p8[1].nf == 4
     assert p8[2].nf == 5
     assert p8[3].nf == 6
     assert p8[0].q2_from == q2_from
     assert p8[3].q2_to == q2_to
Esempio n. 4
0
    def test_init(self):
        # 3 thr
        tc3 = ThresholdsAtlas([1, 2, 3])
        assert tc3.area_walls == [0, 1, 2, 3, np.inf]
        # 2 thr
        tc2 = ThresholdsAtlas([0, 2, 3])
        assert tc2.area_walls == [0, 0, 2, 3, np.inf]

        # errors
        with pytest.raises(ValueError):
            ThresholdsAtlas([1.0, 0.0])
Esempio n. 5
0
    def test_path_3thr(self):
        tc = ThresholdsAtlas([1, 2, 3], 0.5)
        p1 = tc.path(0.7)
        assert len(p1) == 1
        assert p1[0].q2_from == 0.5
        assert p1[0].q2_to == 0.7
        assert p1[0].nf == 3

        p2 = tc.path(1.5, q2_from=2.5)
        assert len(p2) == 2
        assert p2[0].nf == 5
        assert p2[1].nf == 4
Esempio n. 6
0
 def test_path_3thr_on_threshold(self):
     tc = ThresholdsAtlas([1, 2, 3], 0.5)
     # on the right of mc
     p3 = tc.path(1.0, nf_to=4)
     assert len(p3) == 2
     assert p3[0].nf == 3
     assert p3[1].tuple == (1.0, 1.0, 4)
     # on the left of mc
     p4 = tc.path(1.0, nf_to=3)
     assert len(p4) == 1
     assert p4[0].nf == 3
     # on the left of mt, across mb
     p5 = tc.path(1.5, q2_from=3.0, nf_from=5)
     assert len(p5) == 2
     assert p5[0].nf == 5
     assert p5[1].nf == 4
Esempio n. 7
0
 def test_labels(self):
     # setup objs
     theory_card = {
         "alphas": 0.35,
         "PTO": 0,
         "ModEv": "TRN",
         "fact_to_ren_scale_ratio": 1.0,
         "Qref": np.sqrt(2),
         "nfref": None,
         "Q0": np.sqrt(2),
         "NfFF": 3,
         "IC": 1,
         "IB": 0,
         "mc": 1.0,
         "mb": 4.75,
         "mt": 173.0,
         "kcThr": np.inf,
         "kbThr": np.inf,
         "ktThr": np.inf,
         "MaxNfPdf": 6,
         "MaxNfAs": 6,
     }
     for skip_singlet in [True, False]:
         for skip_ns in [True, False]:
             operators_card = {
                 "Q2grid": [1, 10],
                 "interpolation_xgrid": [0.1, 1.0],
                 "interpolation_polynomial_degree": 1,
                 "interpolation_is_log": True,
                 "debug_skip_singlet": skip_singlet,
                 "debug_skip_non_singlet": skip_ns,
                 "ev_op_max_order": 1,
                 "ev_op_iterations": 1,
                 "backward_inversion": "exact",
             }
             g = OperatorGrid.from_dict(
                 theory_card,
                 operators_card,
                 ThresholdsAtlas.from_dict(theory_card),
                 StrongCoupling.from_dict(theory_card),
                 InterpolatorDispatcher.from_dict(operators_card),
             )
             o = OperatorMatrixElement(g.config, g.managers, 10)
             labels = o.labels()
             test_labels = ["NS_qq", "NS_Hq"]
             for l in test_labels:
                 if skip_ns:
                     assert l not in labels
                 else:
                     assert l in labels
             test_labels = ["S_qq", "S_Hq", "S_gg", "S_Hg", "S_gH"]
             for l in test_labels:
                 if skip_singlet:
                     assert l not in labels
                 else:
                     assert l in labels
Esempio n. 8
0
    def test_build_area_walls(self):
        for k in range(3, 6 + 1):
            walls = ThresholdsAtlas.build_area_walls([1, 2, 3], [1, 2, 3], k)
            assert len(walls) == k - 3

        with pytest.raises(ValueError):
            ThresholdsAtlas.build_area_walls([1, 2], [1, 2, 3], 4)
        with pytest.raises(ValueError):
            ThresholdsAtlas.build_area_walls([1, 2, 3], [1, 2], 4)
        with pytest.raises(ValueError):
            ThresholdsAtlas.build_area_walls([1, 2], [1, 2], 4)
Esempio n. 9
0
 def _get_operator_grid(self, use_FFNS=True):
     theory_card, operators_card = self._get_setup(use_FFNS)
     # create objects
     basis_function_dispatcher = interpolation.InterpolatorDispatcher.from_dict(
         operators_card)
     threshold_holder = ThresholdsAtlas.from_dict(theory_card)
     a_s = StrongCoupling.from_dict(theory_card)
     return OperatorGrid.from_dict(
         theory_card,
         operators_card,
         threshold_holder,
         a_s,
         basis_function_dispatcher,
     )
Esempio n. 10
0
 def test_from_dict(self):
     tc = ThresholdsAtlas.from_dict(
         {
             "mc": 1.0,
             "mb": 4.0,
             "mt": 100.0,
             "kcThr": 1,
             "kbThr": 2.0,
             "ktThr": np.inf,
             "Q0": 1.0,
             "MaxNfPdf": 6,
         }
     )
     assert tc.area_walls[1:-1] == [1.0, 64.0, np.inf]
     assert tc.q2_ref == 1.0
Esempio n. 11
0
 def test_sanity(self):
     """Sanity checks for the input"""
     # errors
     with pytest.raises(ValueError):
         theory_card, operators_card = self._get_setup(True)
         basis_function_dispatcher = interpolation.InterpolatorDispatcher.from_dict(
             operators_card)
         threshold_holder = ThresholdsAtlas.from_dict(theory_card)
         a_s = StrongCoupling.from_dict(theory_card)
         theory_card.update({"ModEv": "wrong"})
         OperatorGrid.from_dict(
             theory_card,
             operators_card,
             threshold_holder,
             a_s,
             basis_function_dispatcher,
         )
Esempio n. 12
0
    def test_compute(self, monkeypatch):
        # setup objs
        theory_card = {
            "alphas": 0.35,
            "PTO": 0,
            "ModEv": "TRN",
            "fact_to_ren_scale_ratio": 1.0,
            "Qref": np.sqrt(2),
            "nfref": None,
            "Q0": np.sqrt(2),
            "FNS": "FFNS",
            "NfFF": 3,
            "IC": 0,
            "IB": 0,
            "mc": 1.0,
            "mb": 4.75,
            "mt": 173.0,
            "kcThr": np.inf,
            "kbThr": np.inf,
            "ktThr": np.inf,
            "MaxNfPdf": 6,
            "MaxNfAs": 6,
        }
        operators_card = {
            "Q2grid": [1, 10],
            "interpolation_xgrid": [0.1, 1.0],
            "interpolation_polynomial_degree": 1,
            "interpolation_is_log": True,
            "debug_skip_singlet": True,
            "debug_skip_non_singlet": False,
            "ev_op_max_order": 1,
            "ev_op_iterations": 1,
            "backward_inversion": "exact",
        }
        g = OperatorGrid.from_dict(
            theory_card,
            operators_card,
            ThresholdsAtlas.from_dict(theory_card),
            StrongCoupling.from_dict(theory_card),
            InterpolatorDispatcher.from_dict(operators_card),
        )
        o = Operator(g.config, g.managers, 3, 2, 10)
        # fake quad
        monkeypatch.setattr(scipy.integrate, "quad",
                            lambda *args, **kwargs: np.random.rand(2))
        # LO
        o.compute()
        assert "NS_m" in o.op_members
        np.testing.assert_allclose(o.op_members["NS_m"].value,
                                   o.op_members["NS_p"].value)
        np.testing.assert_allclose(o.op_members["NS_v"].value,
                                   o.op_members["NS_p"].value)
        # NLO
        o.config["order"] = 1
        o.compute()
        assert not np.allclose(o.op_members["NS_p"].value,
                               o.op_members["NS_m"].value)
        np.testing.assert_allclose(o.op_members["NS_v"].value,
                                   o.op_members["NS_m"].value)

        # unity operators
        for n in range(0, 2 + 1):
            o1 = Operator(g.config, g.managers, 3, 2, 2)
            o1.config["order"] = n
            o1.compute()
            for k in br.non_singlet_labels:
                assert k in o1.op_members
                np.testing.assert_allclose(o1.op_members[k].value,
                                           np.eye(2),
                                           err_msg=k)
Esempio n. 13
0
 def test_ffns(self):
     tc3 = ThresholdsAtlas.ffns(3)
     assert tc3.area_walls == [0] + [np.inf] * 4
     tc4 = ThresholdsAtlas.ffns(4)
     assert tc4.area_walls == [0] * 2 + [np.inf] * 3
     assert len(tc4.path(q2_to=2.0, q2_from=3.0)) == 1
Esempio n. 14
0
    def test_repr(self):
        walls = [1.23, 9.87, 14.54]
        stc3 = str(ThresholdsAtlas(walls))

        for w in walls:
            assert "%.2e" % w in stc3