Skip to content

Commit

Permalink
add atol and remove redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
lazyoracle committed Jul 3, 2021
1 parent 8cc1441 commit 6cf6c1d
Showing 1 changed file with 40 additions and 20 deletions.
60 changes: 40 additions & 20 deletions test/test_envelopes.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,26 @@ def test_pwc_shape():
np.testing.assert_allclose(
actual=envelopes["pwc_shape"](t=ts, params=params),
desired=test_data["pwc_shape"],
atol=get_atol("pwc_shape"),
)

np.testing.assert_allclose(
actual=envelopes["pwc_symmetric"](t=ts, params=params),
desired=test_data["pwc_symmetric"],
atol=get_atol("pwc_symmetric"),
)

np.testing.assert_allclose(
actual=envelopes["pwc_shape_plateau"](t=ts, params=params),
desired=test_data["pwc_shape_plateau1"],
atol=get_atol("pwc_shape_plateau1"),
)

params["width"] = Quantity(5e-9)
np.testing.assert_allclose(
actual=envelopes["pwc_shape_plateau"](t=ts, params=params),
desired=test_data["pwc_shape_plateau2"],
atol=get_atol("pwc_shape_plateau2"),
)


Expand All @@ -72,6 +76,7 @@ def test_delta_pulse():
np.testing.assert_allclose(
actual=envelopes["delta_pulse"](t=ts, params=params),
desired=test_data["delta_pulse"],
atol=get_atol("delta_pulse"),
)


Expand All @@ -87,11 +92,13 @@ def test_fourier():
np.testing.assert_allclose(
actual=envelopes["fourier_sin"](t=ts, params=params),
desired=test_data["fourier_sin"],
atol=get_atol("fourier_sin"),
)

np.testing.assert_allclose(
actual=envelopes["fourier_cos"](t=ts, params=params),
desired=test_data["fourier_cos"],
atol=get_atol("fourier_cos"),
)

params = {
Expand All @@ -105,18 +112,21 @@ def test_fourier():
np.testing.assert_allclose(
actual=envelopes["slepian_fourier"](t=ts, params=params),
desired=test_data["slepian_fourier"],
atol=get_atol("slepian_fourier"),
)

params["risefall"] = Quantity(4e-9)
np.testing.assert_allclose(
actual=envelopes["slepian_fourier"](t=ts, params=params),
desired=test_data["slepian_fourier_risefall"],
atol=get_atol("slepian_fourier_risefall"),
)

params["sin_coeffs"] = Quantity([0.3])
np.testing.assert_allclose(
actual=envelopes["slepian_fourier"](t=ts, params=params),
desired=test_data["slepian_fourier_sin"],
atol=get_atol("slepian_fourier_sin"),
)


Expand All @@ -130,16 +140,19 @@ def test_flattop():
np.testing.assert_allclose(
actual=envelopes["trapezoid"](t=ts, params=params),
desired=test_data["trapezoid"],
atol=get_atol("trapezoid"),
)

np.testing.assert_allclose(
actual=envelopes["flattop_risefall"](t=ts, params=params),
desired=test_data["flattop_risefall"],
atol=get_atol("flattop_risefall"),
)

np.testing.assert_allclose(
actual=envelopes["flattop_risefall_1ns"](t=ts, params=params),
desired=test_data["flattop_risefall_1ns"],
atol=get_atol("flattop_risefall_1ns"),
)

params = {
Expand All @@ -152,6 +165,7 @@ def test_flattop():
np.testing.assert_allclose(
actual=envelopes["flattop_variant"](t=ts, params=params),
desired=test_data["flattop_variant"],
atol=get_atol("flattop_variant"),
)

params = {
Expand All @@ -178,6 +192,7 @@ def test_flattop_cut():
np.testing.assert_allclose(
actual=envelopes["flattop_cut"](t=ts, params=params),
desired=test_data["flattop_cut"],
atol=get_atol("flattop_cut"),
)

params = {
Expand All @@ -189,6 +204,7 @@ def test_flattop_cut():
np.testing.assert_allclose(
actual=envelopes["flattop_cut_center"](t=ts, params=params),
desired=test_data["flattop_cut_center"],
atol=get_atol("flattop_cut_center"),
)


Expand All @@ -202,38 +218,49 @@ def test_gaussian():
np.testing.assert_allclose(
actual=envelopes["gaussian_sigma"](t=ts, params=params),
desired=test_data["gaussian_sigma"],
atol=get_atol("gaussian_sigma"),
)

np.testing.assert_allclose(
actual=envelopes["gaussian"](t=ts, params=params), desired=test_data["gaussian"]
actual=envelopes["gaussian"](t=ts, params=params),
desired=test_data["gaussian"],
atol=get_atol("gaussian"),
)

np.testing.assert_allclose(
actual=envelopes["gaussian_nonorm"](t=ts, params=params),
desired=test_data["gaussian_nonorm"],
atol=get_atol("gaussian_nonorm"),
)

np.testing.assert_allclose(
actual=envelopes["gaussian_der_nonorm"](t=ts, params=params),
desired=test_data["gaussian_der_nonorm"],
atol=get_atol("gaussian_der_nonorm"),
)

np.testing.assert_allclose(
actual=envelopes["gaussian_der"](t=ts, params=params),
desired=test_data["gaussian_der"],
atol=get_atol("gaussian_der"),
)

np.testing.assert_allclose(
actual=envelopes["drag_sigma"](t=ts, params=params),
desired=test_data["drag_sigma"],
atol=get_atol("drag_sigma"),
)

np.testing.assert_allclose(
actual=envelopes["drag_der"](t=ts, params=params), desired=test_data["drag_der"]
actual=envelopes["drag_der"](t=ts, params=params),
desired=test_data["drag_der"],
atol=get_atol("drag_der"),
)

np.testing.assert_allclose(
actual=envelopes["drag"](t=ts, params=params), desired=test_data["drag"]
actual=envelopes["drag"](t=ts, params=params),
desired=test_data["drag"],
atol=get_atol("drag"),
)


Expand All @@ -244,7 +271,9 @@ def test_cosine():
}

np.testing.assert_allclose(
actual=envelopes["cosine"](t=ts, params=params), desired=test_data["cosine"]
actual=envelopes["cosine"](t=ts, params=params),
desired=test_data["cosine"],
atol=get_atol("cosine"),
)

params = {
Expand All @@ -255,30 +284,21 @@ def test_cosine():
np.testing.assert_allclose(
actual=envelopes["cosine_flattop"](t=ts, params=params),
desired=test_data["cosine_flattop"],
atol=get_atol("cosine_flattop"),
)


@pytest.mark.unit
def test_nodrive():
params = {}
np.testing.assert_allclose(
actual=envelopes["no_drive"](t=ts, params=params), desired=test_data["no_drive"]
actual=envelopes["no_drive"](t=ts, params=params),
desired=test_data["no_drive"],
atol=get_atol("no_drive"),
)

np.testing.assert_allclose(
actual=envelopes["rect"](t=ts, params=params), desired=test_data["rect"]
actual=envelopes["rect"](t=ts, params=params),
desired=test_data["rect"],
atol=get_atol("rect"),
)


# test_pwc_envelope()
test_pwc_shape()
test_delta_pulse()
test_fourier()
test_flattop()
test_flattop_cut()
test_cosine()
test_gaussian()
test_nodrive()

with open("test/envelopes.pickle", "wb") as filename:
pickle.dump(test_data, filename)

0 comments on commit 6cf6c1d

Please sign in to comment.