Beispiel #1
0
def test_input_output_with_links():

    mg = ModelGetter()
    m = mg.model

    # Make a link
    m.link(m.one.spectrum.main.Powerlaw.K, m.two.spectrum.main.Powerlaw.K)

    temp_file = "__test.yml"

    m.save(temp_file, overwrite=True)

    # Now reload it again
    m_reloaded = load_model(temp_file)

    os.remove(temp_file)

    # Check that all sources have been recovered
    assert m_reloaded.sources.keys() == m.sources.keys()

    # Check that the link have been recovered
    new_value = 0.987
    m_reloaded.two.spectrum.main.Powerlaw.K.value = new_value

    assert m_reloaded.one.spectrum.main.Powerlaw.K.value == new_value
Beispiel #2
0
def test_input_output_with_external_parameters():

    mg = ModelGetter()
    m = mg.model

    # Create an external parameter
    fake_parameter = Parameter("external_parameter", 1.0, min_value=-1.0, max_value=1.0, free=True)

    # Link as equal (default)
    m.add_external_parameter(fake_parameter)

    # Save model

    temp_file = "__test.yml"

    m.save(temp_file, overwrite=True)

    # Now reload it again
    m_reloaded = load_model(temp_file)

    os.remove(temp_file)

    # Check that all sources have been recovered
    assert m_reloaded.sources.keys() == m.sources.keys()

    # Check that the external parameter have been recovered
    assert 'external_parameter' in m_reloaded
Beispiel #3
0
def test_input_output_basic():

    mg = ModelGetter()
    m = mg.model

    temp_file = "__test.yml"

    m.save(temp_file, overwrite=True)

    # Now reload it again
    m_reloaded = load_model(temp_file)

    os.remove(temp_file)

    # Check that all sources have been recovered
    assert m_reloaded.sources.keys() == m.sources.keys()