Exemplo n.º 1
0
def test_equality_constraint(model):
    """Test equality constraint."""
    model.reactions.ACALD.bounds = (-1.5, -1.5)
    s = sample(model, 10)
    assert np.allclose(s.ACALD, -1.5, atol=1e-6, rtol=0)
    s = sample(model, 10, method="achr")
    assert np.allclose(s.ACALD, -1.5, atol=1e-6, rtol=0)
Exemplo n.º 2
0
def test_inequality_constraint(model):
    """Test inequality constraint."""
    co = model.problem.Constraint(
        model.reactions.ACALD.flux_expression, lb=-0.5)
    model.add_cons_vars(co)
    s = sample(model, 10)
    assert all(s.ACALD > -0.5 - 1e-6)
    s = sample(model, 10, method="achr")
    assert all(s.ACALD > -0.5 - 1e-6)
Exemplo n.º 3
0
def test_single_point_space(model):
    """Test the reduction of the sampling space to one point."""
    pfba_sol = pfba(model)
    pfba_const = model.problem.Constraint(
        sum(model.variables), ub=pfba_sol.objective_value)
    model.add_cons_vars(pfba_const)
    model.reactions.Biomass_Ecoli_core.lower_bound = \
        pfba_sol.fluxes.Biomass_Ecoli_core
    with pytest.raises(ValueError):
        s = sample(model, 1)
Exemplo n.º 4
0
def test_inhomogeneous_sanity(model):
    """Test whether inhomogeneous sampling gives approximately the same
    standard deviation as a homogeneous version."""
    model.reactions.ACALD.bounds = (-1.5, -1.5)
    s_inhom = sample(model, 64)

    model.reactions.ACALD.bounds = (-1.5 - 1e-3, -1.5 + 1e-3)
    s_hom = sample(model, 64)

    relative_diff = (s_inhom.std() + 1e-12) / (s_hom.std() + 1e-12)
    assert 0.5 < relative_diff.abs().mean() < 2

    model.reactions.ACALD.bounds = (-1.5, -1.5)
    s_inhom = sample(model, 64, method="achr")

    model.reactions.ACALD.bounds = (-1.5 - 1e-3, -1.5 + 1e-3)
    s_hom = sample(model, 64, method="achr")

    relative_diff = (s_inhom.std() + 1e-12) / (s_hom.std() + 1e-12)
    assert 0.5 < relative_diff.abs().mean() < 2
Exemplo n.º 5
0
def test_fixed_seed(model):
    """Test result of fixed seed for sampling."""
    s1 = sample(model, 1, seed=42)
    s2 = sample(model, 1, seed=42)
    assert np.isclose(s1.TPI[0], s2.TPI[0])
Exemplo n.º 6
0
def test_wrong_method(model):
    """Test method intake sanity."""
    with pytest.raises(ValueError):
        sample(model, 1, method="schwupdiwupp")
Exemplo n.º 7
0
def test_multi_optgp(model):
    """Test OptGP sampling (multi sample)."""
    s = sample(model, 10, processes=2)
    assert s.shape == (10, len(model.reactions))
Exemplo n.º 8
0
def test_single_optgp(model):
    """Test OptGP sampling (one sample)."""
    s = sample(model, 10, processes=1)
    assert s.shape == (10, len(model.reactions))
Exemplo n.º 9
0
def test_single_achr(model):
    """Test ACHR sampling (one sample)."""
    s = sample(model, 10, method="achr")
    assert s.shape == (10, len(model.reactions))
Exemplo n.º 10
0
def test_fixed_seed(model):
    """Test result of fixed seed for sampling."""
    s = sample(model, 1, seed=42)
    assert np.allclose(s.TPI[0], 9.12037487)