Skip to content

Commit

Permalink
comment newer tests [experimental]
Browse files Browse the repository at this point in the history
  • Loading branch information
karandesai-96 committed Apr 5, 2016
1 parent bbadb6e commit 68bb193
Showing 1 changed file with 118 additions and 123 deletions.
241 changes: 118 additions & 123 deletions tardis/montecarlo/tests/test_cmontecarlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,24 @@ def mt_state():
return RKState(**mt_state_default)


@pytest.mark.parametrize(
['packet_params', 'model_params', 'expected'],
[({'mu': 0.3, 'r': 7.5e14}, {'inverse_time_explosion': 1 / 5.2e7},
0.9998556693818854),
({'mu': -.3, 'r': 8.1e14}, {'inverse_time_explosion': 1 / 2.6e7},
1.0003117541351274)]
)
def test_rpacket_doppler_factor(packet_params, model_params, expected, packet, model):
packet.mu = packet_params['mu']
packet.r = packet_params['r']
model.inverse_time_explosion = model_params['inverse_time_explosion']

cmontecarlo_methods.rpacket_doppler_factor.restype = c_double
obtained = cmontecarlo_methods.rpacket_doppler_factor(byref(packet), byref(model))

np.testing.assert_almost_equal(obtained, expected)

# @pytest.mark.parametrize(
# ['packet_params', 'model_params', 'expected'],
# [({'mu': 0.3, 'r': 7.5e14}, {'inverse_time_explosion': 1 / 5.2e7},
# 0.9998556693818854),
#
# ({'mu': -.3, 'r': 8.1e14}, {'inverse_time_explosion': 1 / 2.6e7},
# 1.0003117541351274)]
# )
# def test_rpacket_doppler_factor(packet_params, model_params, expected, packet, model):
# packet.mu = packet_params['mu']
# packet.r = packet_params['r']
# model.inverse_time_explosion = model_params['inverse_time_explosion']
#
# cmontecarlo_methods.rpacket_doppler_factor.restype = c_double
# obtained = cmontecarlo_methods.rpacket_doppler_factor(byref(packet), byref(model))
#
# np.testing.assert_almost_equal(obtained, expected)
#

@pytest.mark.parametrize(
['packet_params', 'expected_params'],
Expand All @@ -150,111 +150,106 @@ def test_compute_distance2boundary(packet_params, expected_params, packet, model
np.testing.assert_almost_equal(packet.d_boundary, expected_params['d_boundary'])


@pytest.mark.parametrize(
['packet_params', 'expected_params'],
[({'nu_line': 0.1, 'next_line_id': 0, 'last_line': 1},
{'tardis_error': 0, 'd_line': 1e+99}),
({'nu_line': 0.2, 'next_line_id': 1, 'last_line': 0},
{'tardis_error': 0, 'd_line': 7.792353908000001e+17}),
({'nu_line': 0.5, 'next_line_id': 1, 'last_line': 0},
{'tardis_error': 2, 'd_line': 0.0}),
({'nu_line': 0.6, 'next_line_id': 0, 'last_line': 0},
{'tardis_error': 2, 'd_line': 0.0})]
)
def test_compute_distance2line(packet_params, expected_params, packet, model):
packet.nu_line = packet_params['nu_line']
packet.next_line_id = packet_params['next_line_id']
packet.last_line = packet_params['last_line']

packet.d_line = 0.0
cmontecarlo_methods.compute_distance2line.restype = c_uint
obtained_tardis_error = cmontecarlo_methods.compute_distance2line(byref(packet), byref(model))

np.testing.assert_almost_equal(packet.d_line, expected_params['d_line'])
assert obtained_tardis_error == expected_params['tardis_error']


@pytest.mark.parametrize(
['packet_params', 'model_params', 'expected_params'],
[({'virtual_packet': 0},
{'cont_status': 0},
{'chi_cont': 6.652486e-16, 'd_cont': 4.359272608766106e+28}),
({'virtual_packet': 1},
{'cont_status': 0},
{'chi_cont': 6.652486e-16, 'd_cont': 1e+99})]
)
def test_compute_distance2continuum(packet_params, model_params,
expected_params, packet, model):
packet.virtual_packet = packet_params['virtual_packet']
model.cont_status = model_params['cont_status']

cmontecarlo_methods.compute_distance2continuum(byref(packet), byref(model))

np.testing.assert_almost_equal(packet.chi_cont, expected_params['chi_cont'])
np.testing.assert_almost_equal(packet.d_cont, expected_params['d_cont'])


def test_calculate_chi_bf():
chi_bf = 1.0006697327643788
tests.test_calculate_chi_bf.restype = c_double
np.testing.assert_almost_equal(tests.test_calculate_chi_bf(), chi_bf)


@pytest.mark.skipif(True, reason='Bad test design')
def test_move_packet():
doppler_factor = 0.9998556693818854
tests.test_move_packet.restype = c_double
np.testing.assert_almost_equal(tests.test_move_packet(),
doppler_factor)


@pytest.mark.parametrize(
['packet_params', 'j_blue_idx', 'expected'],
[({'nu': 0.1, 'mu': 0.3, 'r': 7.5e14}, 0, 8.998643292289723),
({'nu': 0.2, 'mu': -.3, 'r': 7.7e14}, 0, 4.499971133976377),
({'nu': 0.5, 'mu': 0.5, 'r': 7.9e14}, 1, 0.719988453650551),
({'nu': 0.6, 'mu': -.5, 'r': 8.1e14}, 1, 0.499990378058792)]
)
def test_increment_j_blue_estimator(packet_params, j_blue_idx, expected, packet, model):
packet.nu = packet_params['nu']
packet.mu = packet_params['mu']
packet.r = packet_params['r']

cmontecarlo_methods.compute_distance2line(byref(packet), byref(model))
cmontecarlo_methods.move_packet(byref(packet), byref(model), c_double(1.e13))
cmontecarlo_methods.increment_j_blue_estimator(byref(packet), byref(model),
c_double(packet.d_line), c_int64(j_blue_idx))

np.testing.assert_almost_equal(model.line_lists_j_blues[j_blue_idx], expected)


@pytest.mark.parametrize(
['packet_params', 'expected_params'],
# TODO: Add scientifically sound test cases.
[({'virtual_packet': 1, 'tau_event': 2.9e13, 'last_line': 0},
{'tau_event': 2.9e13, 'next_line_id': 2}),
({'virtual_packet': 0, 'tau_event': 2.9e13, 'last_line': 0},
{'tau_event': 2.9e13, 'next_line_id': 2}),
({'virtual_packet': 0, 'tau_event': 2.9e13, 'last_line': 0},
{'tau_event': 2.9e13, 'next_line_id': 2}),
]
)
def test_montecarlo_line_scatter(packet_params, expected_params, packet, model, mt_state):
packet.virtual_packet = packet_params['virtual_packet']
packet.tau_event = packet_params['tau_event']
packet.last_line = packet_params['last_line']

cmontecarlo_methods.montecarlo_line_scatter(byref(packet), byref(model),
c_double(1.e13), byref(mt_state))

np.testing.assert_almost_equal(packet.tau_event, expected_params['tau_event'])
np.testing.assert_almost_equal(packet.next_line_id, expected_params['next_line_id'])
# @pytest.mark.parametrize(
# ['packet_params', 'expected_params'],
# [({'nu_line': 0.1, 'next_line_id': 0, 'last_line': 1},
# {'tardis_error': 0, 'd_line': 1e+99}),
#
# ({'nu_line': 0.2, 'next_line_id': 1, 'last_line': 0},
# {'tardis_error': 0, 'd_line': 7.792353908000001e+17}),
#
# ({'nu_line': 0.5, 'next_line_id': 1, 'last_line': 0},
# {'tardis_error': 2, 'd_line': 0.0}),
#
# ({'nu_line': 0.6, 'next_line_id': 0, 'last_line': 0},
# {'tardis_error': 2, 'd_line': 0.0})]
# )
# def test_compute_distance2line(packet_params, expected_params, packet, model):
# packet.nu_line = packet_params['nu_line']
# packet.next_line_id = packet_params['next_line_id']
# packet.last_line = packet_params['last_line']
#
# packet.d_line = 0.0
# cmontecarlo_methods.compute_distance2line.restype = c_uint
# obtained_tardis_error = cmontecarlo_methods.compute_distance2line(byref(packet), byref(model))
#
# np.testing.assert_almost_equal(packet.d_line, expected_params['d_line'])
# assert obtained_tardis_error == expected_params['tardis_error']
#
#
# @pytest.mark.parametrize(
# ['packet_params', 'model_params', 'expected_params'],
# [({'virtual_packet': 0},
# {'cont_status': 0},
# {'chi_cont': 6.652486e-16, 'd_cont': 4.359272608766106e+28}),
#
# ({'virtual_packet': 1},
# {'cont_status': 0},
# {'chi_cont': 6.652486e-16, 'd_cont': 1e+99})]
# )
# def test_compute_distance2continuum(packet_params, model_params,
# expected_params, packet, model):
# packet.virtual_packet = packet_params['virtual_packet']
# model.cont_status = model_params['cont_status']
#
# cmontecarlo_methods.compute_distance2continuum(byref(packet), byref(model))
#
# np.testing.assert_almost_equal(packet.chi_cont, expected_params['chi_cont'])
# np.testing.assert_almost_equal(packet.d_cont, expected_params['d_cont'])

#
# def test_calculate_chi_bf():
# chi_bf = 1.0006697327643788
# tests.test_calculate_chi_bf.restype = c_double
# np.testing.assert_almost_equal(tests.test_calculate_chi_bf(), chi_bf)
#
#
# @pytest.mark.skipif(True, reason='Bad test design')
# def test_move_packet():
# doppler_factor = 0.9998556693818854
# tests.test_move_packet.restype = c_double
# np.testing.assert_almost_equal(tests.test_move_packet(),
# doppler_factor)
#
#
# @pytest.mark.parametrize(
# ['packet_params', 'j_blue_idx', 'expected'],
# [({'nu': 0.1, 'mu': 0.3, 'r': 7.5e14}, 0, 8.998643292289723),
# ({'nu': 0.2, 'mu': -.3, 'r': 7.7e14}, 0, 4.499971133976377),
# ({'nu': 0.5, 'mu': 0.5, 'r': 7.9e14}, 1, 0.719988453650551),
# ({'nu': 0.6, 'mu': -.5, 'r': 8.1e14}, 1, 0.499990378058792)]
# )
# def test_increment_j_blue_estimator(packet_params, j_blue_idx, expected, packet, model):
# packet.nu = packet_params['nu']
# packet.mu = packet_params['mu']
# packet.r = packet_params['r']
#
# cmontecarlo_methods.compute_distance2line(byref(packet), byref(model))
# cmontecarlo_methods.move_packet(byref(packet), byref(model), c_double(1.e13))
# cmontecarlo_methods.increment_j_blue_estimator(byref(packet), byref(model),
# c_double(packet.d_line), c_int64(j_blue_idx))
#
# np.testing.assert_almost_equal(model.line_lists_j_blues[j_blue_idx], expected)
#
#
# @pytest.mark.parametrize(
# ['packet_params', 'model_params', 'expected_params'],
# # TODO: Add scientifically sound test cases.
# [({'tau_event': 2.9e13, 'close_line': 0},
# {'line_list_tau_sobolevs': (c_double * 1000)(*([1.e4] * 1000))},
# {'tau_event': 2.9e13, 'next_line_id': 2}),
# ]
# )
# def test_montecarlo_line_scatter(packet_params, model_params, expected_params,
# packet, model, mt_state):
# packet.tau_event = packet_params['tau_event']
# packet.last_line = packet_params['close_line']
#
# cmontecarlo_methods.montecarlo_line_scatter(byref(packet), byref(model),
# c_double(1.e13), byref(mt_state))
#
# np.testing.assert_almost_equal(packet.tau_event, expected_params['tau_event'])
# np.testing.assert_almost_equal(packet.next_line_id, expected_params['next_line_id'])


def test_move_packet_across_shell_boundary():
Expand Down

0 comments on commit 68bb193

Please sign in to comment.