def test_remove_auxiliary_variable(): p1 = Parameter('test_parameter', 1.0, min_value=-5.0, max_value=5.0, delta=0.2, desc='test', free=False, unit='MeV') x = Parameter('aux_variable', 1.0) # ax + b law = Line() law.a = 1.0 law.b = 2.0 p1.add_auxiliary_variable(x, law) assert p1.value == 3.0 x.value = 4.0 assert p1.value == 6.0 p1.remove_auxiliary_variable() assert p1.has_auxiliary_variable() == False p1.value = -1.0 assert p1.value == -1.0 with pytest.warns(RuntimeWarning): p1.remove_auxiliary_variable()
def test_links_and_pickle(): import pickle p_orig = Parameter('test_parameter', 1.0, min_value=-5.0, max_value=5.0, delta=0.2, desc='test', free=False, unit=u.MeV, prior=Uniform_prior()) # Test the linkinking and pickle # Add a link x = Parameter('aux_variable', 1.0) # ax + b law = Line() law.a = 2.0 law.b = 1.0 p_orig.add_auxiliary_variable(x, law) # Now pickle and unpickle d = pickle.dumps(p_orig) p = pickle.loads(d) assert p.has_auxiliary_variable() == True assert p.value == 3.0 assert p.free == False p.auxiliary_variable[0].value = 4.0 assert p.value == 6.0 # Check that assigning to the parameter doesn't produce any effect p.value = -1.0 assert p.value == 6.0
def test_set_auxiliary_variable(): p1 = Parameter('test_parameter', 1.0, min_value=-5.0, max_value=5.0, delta=0.2, desc='test', free=False, unit='MeV') x = Parameter('aux_variable', 1.0) # ax + b law = Line() law.a = 2.0 law.b = 1.0 p1.add_auxiliary_variable(x, law) assert p1.has_auxiliary_variable() == True assert p1.value == 3.0 assert p1.free == False x.value = 4.0 assert p1.value == 6.0 # Check that assigning to the parameter doesn't produce any effect p1.value = -1.0 assert p1.value == 6.0 # Now check errors reporting with pytest.raises(AttributeError): p1.add_auxiliary_variable(1.0, law) # Now add it twice to verify that it overwrites it p1.add_auxiliary_variable(x, law) p1.add_auxiliary_variable(x, law) p1.display()