How to use the flavio.default_parameters function in flavio

To help you get started, we’ve selected a few flavio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flav-io / flavio / flavio / statistics / test_fits.py View on Github external
def test_fastfit_covariance_sm(self):
        # This test is to assure that calling make_measurement does not
        # actually call the fit_wc_function
        # dummy observables
        o1 = Observable( 'test_obs 1' )
        # dummy predictions
        def f1(wc_obj, par_dict):
            return par_dict['m_b']
        Prediction( 'test_obs 1', f1 )
        d1 = NormalDistribution(5, 0.2)
        m1 = Measurement( 'measurement 1 of test_obs 1' )
        m1.add_constraint(['test_obs 1'], d1)
        def fit_wc_fct_tmp(X):
            pass
        fit = FastFit('fastfit_test_1', flavio.default_parameters, ['m_b'],  [], ['test_obs 1'],
                      fit_wc_function=fit_wc_fct_tmp)
        fit.fit_wc_function = fit_wc_fct_error
        fit.fit_wc_names = tuple(inspect.signature(fit.fit_wc_function).parameters.keys())
        fit.make_measurement() # single thread calculation
        FastFit.del_instance('fastfit_test_1')
        fit = FastFit('fastfit_test_1', flavio.default_parameters, ['m_b'],  [], ['test_obs 1'],
                      fit_wc_function=fit_wc_fct_tmp)
        fit.fit_wc_function = fit_wc_fct_error
        fit.fit_wc_names = tuple(inspect.signature(fit.fit_wc_function).parameters.keys())
        fit.make_measurement(threads=2) # multi thread calculation
        FastFit.del_instance('fastfit_test_1')
        Observable.del_instance('test_obs 1')
        Measurement.del_instance('measurement 1 of test_obs 1')
github flav-io / flavio / flavio / statistics / test_fits.py View on Github external
def f1(wc_obj, par_dict):
            return par_dict['m_b']
        def f2(wc_obj, par_dict):
            return 2.5
        Prediction( 'test_obs 1', f1 )
        Prediction( 'test_obs 2', f2 )
        d1 = NormalDistribution(5, 0.2)
        cov2 = [[0.1**2, 0.5*0.1*0.3], [0.5*0.1*0.3, 0.3**2]]
        d2 = MultivariateNormalDistribution([6,2], cov2)
        m1 = Measurement( 'measurement 1 of test_obs 1' )
        m2 = Measurement( 'measurement 2 of test_obs 1 and test_obs 2' )
        m1.add_constraint(['test_obs 1'], d1)
        m2.add_constraint(['test_obs 1', 'test_obs 2'], d2)
        fit2 = FastFit('fastfit_test_2', flavio.default_parameters, ['m_b'],  [], ['test_obs 1', 'test_obs 2'])
        # fit with only a single observable and measurement
        fit1 = FastFit('fastfit_test_1', flavio.default_parameters, ['m_b'],  [], ['test_obs 2',])
        # fit with 2 observables but 1 measurement
        fit3 = FastFit('fastfit_test_3', flavio.default_parameters, ['m_b'],  [], ['test_obs 1', 'test_obs 2'],
                       include_measurements=['measurement 2 of test_obs 1 and test_obs 2'])
        for fit in (fit2, fit3):
            fit.make_measurement()
            centr_cov_exp_before = fit._exp_central_covariance
            filename = os.path.join(tempfile.gettempdir(), 'tmp.p')
            fit.save_exp_central_covariance(filename)
            fit.load_exp_central_covariance(filename)
            centr_cov_exp_after = fit._exp_central_covariance
            npt.assert_array_equal(centr_cov_exp_before[0], centr_cov_exp_after[0])
            npt.assert_array_equal(centr_cov_exp_before[1], centr_cov_exp_after[1])
            os.remove(filename)
            cov_before = fit._sm_covariance
            filename = os.path.join(tempfile.gettempdir(), 'tmp-no-p')
            fit.save_sm_covariance(filename)
github flav-io / flavio / flavio / physics / bdecays / test_bxll.py View on Github external
def test_bxll(self):
        # check whether QED corrections have the right behaviour
        wc_obj = flavio.WilsonCoefficients()
        par = flavio.default_parameters.get_central_all()
        br_1_noqedpc =  _bxll_dbrdq2(1, wc_obj, par, 's', 'mu', include_qed=False, include_pc=False)
        br_1_qed =  _bxll_dbrdq2(1, wc_obj, par, 's', 'mu', include_qed=True, include_pc=False)
        br_6_noqedpc =  _bxll_dbrdq2(6, wc_obj, par, 's', 'mu', include_qed=False, include_pc=False)
        br_6_qed =  _bxll_dbrdq2(6, wc_obj, par, 's', 'mu', include_qed=True, include_pc=False)
        br_15_noqedpc =  _bxll_dbrdq2(15, wc_obj, par, 's', 'mu', include_qed=False, include_pc=False)
        br_15_qed =  _bxll_dbrdq2(15, wc_obj, par, 's', 'mu', include_qed=True, include_pc=False)
        br_21_noqedpc =  _bxll_dbrdq2(21, wc_obj, par, 's', 'mu', include_qed=False, include_pc=False)
        br_21_qed =  _bxll_dbrdq2(21, wc_obj, par, 's', 'mu', include_qed=True, include_pc=False)
        self.assertAlmostEqual((br_1_qed+br_6_qed)/(br_1_noqedpc+br_6_noqedpc),
                                1.02, delta=0.01) # should lead to a 2% enhancement
        self.assertAlmostEqual((br_15_qed+br_21_qed)/(br_15_noqedpc+br_21_noqedpc),
                                0.92, delta=0.03) # should lead to a 8% suppression


        # compare SM predictions to arXiv:1503.04849
        # to convert to the parameters used there
github flav-io / flavio / flavio / physics / edms / test_paraedm.py View on Github external
import unittest
import flavio
from wilson import wcxf
from math import sqrt


par = flavio.default_parameters.get_central_all()


class TestParamagneticEDM(unittest.TestCase):
    def test_sm(self):
        self.assertEqual(flavio.sm_prediction('d_Tl'), 0)
        self.assertEqual(flavio.sm_prediction('omega_YbF'), 0)
        self.assertEqual(flavio.sm_prediction('omega_HfF'), 0)
        self.assertEqual(flavio.sm_prediction('omega_ThO'), 0)
github flav-io / flavio / flavio / physics / bdecays / bvll / test_lfv.py View on Github external
def test_lfv(self):
        obs_1 = flavio.classes.Observable["BR(B0->K*emu)"]
        obs_2 = flavio.classes.Observable["BR(B0->K*mue)"]
        self.assertEqual(obs_1.prediction_central(flavio.default_parameters, wc_sm), 0)
        # BR(B->K*emu) should be 4 times larger as Wilson coeff is 2x the mue one
        self.assertAlmostEqual(
            obs_1.prediction_central(flavio.default_parameters, wc_np)
            /obs_2.prediction_central(flavio.default_parameters, wc_np),
            4.,  places=10)
        # test for errors
        flavio.sm_prediction("BR(B+->K*mue)")
        flavio.sm_prediction("BR(B0->rhotaue)")
        flavio.sm_prediction("BR(B+->rhotaumu)")
        flavio.sm_prediction("BR(Bs->phimutau)")
github flav-io / flavio / flavio / physics / bdecays / test_bc_lifetime.py View on Github external
import unittest
import flavio


par = flavio.default_parameters.get_central_all()


class TestTauBc(unittest.TestCase):
    def test_sm(self):
        self.assertEqual(flavio.sm_prediction('tau_Bc'), par['tau_Bc_SM'])
        self.assertAlmostEqual(flavio.sm_prediction('tau_Bc'), par['tau_Bc'],
                               delta=0.1 * par['tau_Bc'])

    def test_np(self):
        wc = flavio.WilsonCoefficients()
        for l in ['e', 'mu', 'tau']:
            wc.set_initial({'CSL_bc' + l + 'nu' + l: 1}, 4.8)
            self.assertTrue(par['tau_Bc_SM'] / flavio.np_prediction('tau_Bc', wc) > 1.1)
            self.assertAlmostEqual(par['tau_Bc_SM'] / flavio.np_prediction('tau_Bc', wc),
                                   1 + flavio.np_prediction('BR(Bc->' + l + 'nu)', wc)
                                   - flavio.sm_prediction('BR(Bc->' + l + 'nu)'),
github flav-io / flavio / flavio / physics / bdecays / formfactors / lambdab_12 / test_lambda.py View on Github external
def test_lambdab_lambda_ff(self):
        ff_obj = Implementation['Lambdab->Lambda SSE2']
        par = flavio.default_parameters
        mL = par.get_central('m_Lambda')
        mLb = par.get_central('m_Lambdab')
        q2max = (mLb-mL)**2
        ff_max = ff_obj.get_central(constraints_obj=par, wc_obj=None, q2=q2max)
        ff_0 = ff_obj.get_central(constraints_obj=par, wc_obj=None, q2=0)
        # g_perp(q2_max) = g_+(q2_max)
        self.assertAlmostEqual(ff_max['fAperp'], ff_max['fA0'], delta=0.001)
        # htilde_perp(q2_max) = htilde_+(q2_max)
        self.assertAlmostEqual(ff_max['fT5perp'], ff_max['fT50'], delta=0.001)
        # f_0(0) = f+(0)
        self.assertAlmostEqual(ff_0['fVt'], ff_0['fV0'], delta=0.05) # this constraint is poorly satisfied
        # g_0(0) = g+(0)
        self.assertAlmostEqual(ff_0['fAt'], ff_0['fA0'], delta=0.1) # this constraint is poorly satisfied
github flav-io / flavio / flavio / physics / ddecays / formfactors / test_formfactors.py View on Github external
import unittest
import flavio
from flavio.classes import AuxiliaryQuantity

constraints = flavio.default_parameters
wc_obj = flavio.WilsonCoefficients()
par = constraints.get_central_all()


class TestDPFF(unittest.TestCase):
    def test_etm(self):
        # compare to ETM result at kinematic endpoints
        q2max_pi = (par['m_D0'] - par['m_pi+'])**2
        q2max_K = (par['m_D0'] - par['m_K+'])**2
        ff_pi_0 = AuxiliaryQuantity["D->pi form factor"].prediction_central(constraints, wc_obj, 0)
        ff_K_0 = AuxiliaryQuantity["D->K form factor"].prediction_central(constraints, wc_obj, 0)
        ff_pi_max = AuxiliaryQuantity["D->pi form factor"].prediction_central(constraints, wc_obj, q2max_pi)
        ff_K_max = AuxiliaryQuantity["D->K form factor"].prediction_central(constraints, wc_obj, q2max_K)
        self.assertAlmostEqual(ff_pi_0['f0'], 0.612, delta=0.001)
        self.assertAlmostEqual(ff_pi_max['f0'], 1.134, delta=0.01)
        self.assertAlmostEqual(ff_pi_0['f+'], 0.612, delta=0.001)
github flav-io / flavio / flavio / physics / bdecays / test_bxlnu.py View on Github external
def test_bxlnu_nu(self):
        wc_sm = flavio.WilsonCoefficients()
        wc_np_tau = flavio.WilsonCoefficients()
        wc_np_tau.set_initial({'CVL_bctaunutau': 1}, 4.8)
        wc_np_e = flavio.WilsonCoefficients()
        wc_np_e.set_initial({'CVL_bctaunue': 1}, 4.8)
        obs = flavio.Observable["BR(B->Xctaunu)"]
        constraints = flavio.default_parameters
        br_sm = obs.prediction_central(constraints, wc_sm)
        br_tau = obs.prediction_central(constraints, wc_np_tau)
        br_e = obs.prediction_central(constraints, wc_np_e)
        # with interference: (1 + 1)^2 = 4
        self.assertAlmostEqual(br_tau/br_sm, 4, delta=0.04)
        # without interference: 1 + 1 = 2
        self.assertAlmostEqual(br_e/br_sm, 2, delta=0.02)
github flav-io / flavio / flavio / statistics / likelihood.py View on Github external
def __init__(self, name,
                 par_obj=flavio.default_parameters,
                 fit_parameters=None,
                 nuisance_parameters='all',
                 observables=None,
                 exclude_measurements=None,
                 include_measurements=None,
                 ):
        self.par_obj = par_obj
        self.parameters_central = self.par_obj.get_central_all()
        self.fit_parameters = fit_parameters or []
        if nuisance_parameters == 'all':
            self.nuisance_parameters = self.par_obj.all_parameters
        else:
            self.nuisance_parameters = nuisance_parameters or []
        self.observables = observables
        self.exclude_measurements = exclude_measurements
        self.include_measurements = include_measurements