Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds unit tests #41

Merged
merged 29 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b055f93
created few unit tests for bp_utils
Jul 30, 2021
faef39b
Merge branch 'vicariousinc:master' into unit_tests
NishanthJKumar Jul 30, 2021
7b25f33
Merge branch 'vicariousinc:master' into unit_tests
NishanthJKumar Aug 2, 2021
f12001e
includes first E2E test for pgmax
Aug 2, 2021
e17f697
adds new tests
Aug 2, 2021
0835ef8
Merge branch 'master' of github.com:vicariousinc/PGMax into vicarious…
Aug 13, 2021
407ccee
Merge branch 'vicariousinc-master' into unit_tests
Aug 13, 2021
2c7ab3c
updates sanity check and E2E test, but test currently fails
Aug 13, 2021
99501b4
adds coverage dependency to poetry
NishanthJKumar Aug 18, 2021
e0460e7
Merge branch 'unit_tests' into master
NishanthJKumar Aug 18, 2021
acaf801
Merge pull request #7 from NishanthJKumar/master
NishanthJKumar Aug 18, 2021
a6a32ff
small update to test_pgmax
NishanthJKumar Aug 18, 2021
f1811aa
adds codecov to CI
NishanthJKumar Aug 19, 2021
bf78603
test codecov upload with github secret
NishanthJKumar Aug 19, 2021
944297d
updates ci and poetry deps
NishanthJKumar Aug 19, 2021
e2afc5f
fixes command error in ci
NishanthJKumar Aug 19, 2021
46188df
fixes codecov yaml to be parseable
NishanthJKumar Aug 19, 2021
c5aa087
Merge branch 'master' of github.com:vicariousinc/PGMax into vicarious…
NishanthJKumar Aug 19, 2021
889479c
Merge branch 'vicariousinc-master' into unit_tests
NishanthJKumar Aug 19, 2021
cbac54a
updates ci to only run build on PR's again!
NishanthJKumar Aug 19, 2021
db8f120
testing codecov from personal fork
NishanthJKumar Aug 20, 2021
8472fd4
updates tests
NishanthJKumar Aug 21, 2021
43ccf99
adds simple e2e test inspired by the heretic model
NishanthJKumar Aug 22, 2021
2ab9fbe
includes tests reaching 95% coverage of pgmax
NishanthJKumar Aug 22, 2021
d75050e
adds more tests to get to 97% overall coverage
NishanthJKumar Aug 24, 2021
ed293af
updates tests to 100% coverage
NishanthJKumar Aug 24, 2021
401f629
addresses first major round of comments on #41
NishanthJKumar Aug 25, 2021
e894d9d
Update tests/fg/test_groups.py
NishanthJKumar Aug 25, 2021
52fdfa0
addresses second round of comments on #41
NishanthJKumar Aug 25, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pgmax/bp/bp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def segment_max_opt(

Args:
data: Array of shape (a_len,) where a_len is an arbitrary integer.
segments_lengths: Array of shape (num_segments,), where num_segments <= a_len.
segments_lengths.sum() should yield a_len.
segments_lengths: Array of shape (num_segments,), where 0 < num_segments <= a_len.
segments_lengths.sum() should yield a_len, and all elements must be > 0.
max_segment_length: The maximum value in segments_lengths.

Returns:
Expand Down
3 changes: 1 addition & 2 deletions pgmax/fg/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,7 @@ def message_passing_step(msgs, _):
return msgs_after_bp

def decode_map_states(self, msgs: jnp.ndarray) -> Dict[nodes.Variable, int]:
"""Function to computes the output of MAP inference on input messages.

"""Function to compute the output of MAP inference on input messages.
The final states are computed based on evidence obtained from the self.get_evidence
method as well as the internal wiring.

Expand Down
133 changes: 99 additions & 34 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Sphinx = "^3.0.0"
pre-commit = "^2.13.0"
jupytext = "^1.11.3"
sphinx-rtd-theme = "^0.5.2"
coverage = "^5.5"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
filterwarnings =
ignore::DeprecationWarning
NishanthJKumar marked this conversation as resolved.
Show resolved Hide resolved
File renamed without changes.
32 changes: 32 additions & 0 deletions tests/bp/test_bputils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import jax
import jax.numpy as jnp
import numpy as np

import pgmax.bp.bp_utils as bp_utils


def test_with_zero():
assert jnp.allclose(
bp_utils.segment_max_opt(jnp.zeros(1, dtype=int), jnp.ones(1, dtype=int), 1),
jnp.zeros(1),
)


def test_with_ones():
assert jnp.allclose(
bp_utils.segment_max_opt(
jnp.ones(10, dtype=int), jnp.ones(1, dtype=int) * 10, 10
),
jnp.ones(1),
)


def test_common_case():
assert jnp.allclose(
bp_utils.segment_max_opt(
jax.device_put(np.array([1.7, 2.3, 4.3, 3.8, 9.2, 111.3])),
jax.device_put(np.array([2, 3, 1])),
3,
),
jax.device_put(np.array([2.3, 9.2, 111.3])),
)
14 changes: 14 additions & 0 deletions tests/fg/test_nodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import dataclasses

import pytest

import pgmax.fg.nodes as nodes


def test_variable_frozen():
v = nodes.Variable(3)
with pytest.raises(dataclasses.FrozenInstanceError):
v.num_states = 4


# TODO: Write more tests for this file
5 changes: 1 addition & 4 deletions tests/test_pgmax.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
from numpy.random import default_rng
from scipy.ndimage import gaussian_filter

from pgmax.fg import graph, groups


def test_e2e_sanity_check():
# Helper function to easily generate a list of valid configurations for a given suppression diameter
def create_valid_suppression_config_arr(suppression_diameter):
Expand Down Expand Up @@ -348,4 +345,4 @@ def create_valid_suppression_config_arr(suppression_diameter):
final_msgs = fg.run_bp(1000, 0.5)

# Test that the output messages are close to the true messages
assert jnp.allclose(final_msgs, true_final_msgs_output, atol=1e-06)
assert jnp.allclose(final_msgs, true_final_msgs_output, atol=1e-06)