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

[Community Sprint] Improving Code Coverage 🚀 #6528

Open
53 of 58 tasks
rusty1s opened this issue Jan 27, 2023 · 0 comments
Open
53 of 58 tasks

[Community Sprint] Improving Code Coverage 🚀 #6528

rusty1s opened this issue Jan 27, 2023 · 0 comments

Comments

@rusty1s
Copy link
Member

rusty1s commented Jan 27, 2023

🚀 The feature, motivation and pitch

We are kicking off our third community sprint!

This community sprint resolves around improving test coverage across the PyG code base.
Currently, our tests cover 85.68% of all code in PyG. The goal of the community sprint is to bump this number into the high 90s (and to get yourself more familiar with the various parts of the code base). Each individual contribution is designed to only take around 30 minutes to two hours to complete.

The sprint begins Friday Janurary 27th and will last 2 weeks. If you are interested in helping out, please also join our PyG slack channel #code-coverage-sprint for more information.

You can assign yourself to the test you are planning to work on here (code-coverage tab).

🚀 Improving Code Coverage

Example

Take a look at the current code coverage report of PyG. For example, we can see that we never test the copy() function of the InMemoryDataset class, see here:

Screenshot 2023-01-26 at 15 51 43

As such, we create a test_in_memory_dataset_copy() function in test/data/test_dataset.py to add a corresponding test:

def test_in_memory_dataset_copy():
    data_list = [Data(x=torch.randn(5, 16)) for _ in range(4)]
    dataset = MyTestDataset(data_list)

    copied_dataset = dataset.copy()

    # Test that we actually do a copy:
    assert id(copied_dataset) != id(dataset)

    # Test that the copied dataset holds the same objects:
    assert len(copied_dataset) == len(dataset) == 4
    
    # Tests that the data is identical:
    for copied_data, data in zip(copied_dataset, dataset):
        assert torch.equal(copied_data.x, data.x)

Furthermore, we see in the code coverage report that copy() utilizes different code paths, depending on whether the dataset should be filtered before copying. As such, we test this functionality as well:

def test_in_memory_dataset_copy():
    ...
    
    copied_dataset = dataset.copy([1, 2])
    assert len(copied_dataset) == 2
    assert torch.equal(copied_dataset[0].x, data_list[1].x)
    assert torch.equal(copied_dataset[1].x, data_list[2].x)

We can check that everything works by running pytest test/data/test_dataset.py -k test_in_memory_dataset_copy:

test/data/test_dataset.py .

========================== 1 passed, 9 deselected in 0.07s =========================

Guide to contributing

See here for a basic example to follow.

  1. Ensure you have read our contributing guidelines.
  2. Claim the test you want to improve here (code coverage tab).
  3. Implement the test changes as in [Code Coverage] InMemoryDataset #6523. For this, look closely at the parts of a model and function you want to cover. Think about test cases that would increase the coverage. If you stumble upon a bug in untested code paths, try to fix the bug on your own, create a GitHub issue or discuss it with us in our PyG slack channel #code-coverage-sprint.
  4. Open a PR to the PyG repository and name it: "[Code Coverage] {model_name/function_name}". Afterwards, add your PR number to the "Improved code coverage" line in CHANGELOG.md.

Tips for making your PR

  • If you are unfamiliar with how the current test pipeline works, you can read more about it here. We use pytest to run all tests.
  • The corresponding tests of PyG models and functions can be found in the test/ directory. For example, tests for torch_geometric/utils/isolated.py can be found in test/utils/test_isolated.py. You can run individual test files via pytest test/utils/test_isolated.py. You can run individual test functions via pytest test/utils/test_isolated.py -k test_contains_isolated_nodes.
  • You can use @pytest.mark.parametrize('arg_name', [1, 2, 3]) to test different configurations inside your test. See here for an example.
  • There exists special test decorators for testing in torch_geometric/testing/decorators.py, e.g., to only run with specific packages installed via the @withPackage('networkx') decorator.
  • For code paths that are nearly impossible to test, consider adding a # pragma: no cover comment, e.g., @overload routines

Tests to update

This list may be incomplete. If you still find a function with missing code coverage, please let us know or add them on your own.

@wsad1 wsad1 pinned this issue Jan 27, 2023
rusty1s added a commit that referenced this issue Feb 8, 2023
Improve coverage for `tests_inits.py` (#6528)

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Matthias Fey <matthias.fey@tu-dortmund.de>
rusty1s added a commit that referenced this issue Feb 23, 2023
Part of #6528, improves typing and code coverage for "[SchNet: A
Continuous-filter Convolutional Neural Network for Modeling Quantum
Interactions](https://arxiv.org/abs/1706.08566)"

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: rusty1s <matthias.fey@tu-dortmund.de>
rusty1s added a commit that referenced this issue Feb 24, 2023
Part of #6528, improves typing and code coverage for DimeNet.

---------

Co-authored-by: rusty1s <matthias.fey@tu-dortmund.de>
rusty1s pushed a commit that referenced this issue Apr 18, 2023
@akihironitta akihironitta self-assigned this Jul 24, 2023
rusty1s added a commit that referenced this issue Jul 31, 2023
… homogeneous graphs (#7807)

Fixes `edge_label_time.size() == (2*batch_size,)` to have
`(batch_size,)`.
Adds a test case for #7791.
Part of #7796 and #6528.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: rusty1s <matthias.fey@tu-dortmund.de>
rusty1s added a commit that referenced this issue Aug 1, 2023
Part of #6528.

IMO, exceptions are also part of the public API so we should measure the
test coverage over them, but feel free to close this PR if you think
otherwise ;)

---------

Co-authored-by: rusty1s <matthias.fey@tu-dortmund.de>
rusty1s added a commit that referenced this issue Aug 10, 2023
Part of #6528.

---------

Co-authored-by: rusty1s <matthias.fey@tu-dortmund.de>
rusty1s added a commit that referenced this issue Sep 4, 2023
…mer_conv.py` (#7968)

Part of #6528.

---------

Co-authored-by: rusty1s <matthias.fey@tu-dortmund.de>
rusty1s added a commit that referenced this issue Sep 24, 2023
…conv.py` (#8047)

- Part of #6528
- Fix `AttributeError: 'function' object has no attribute 'pop'` when
calling `remove_edge_index`

Not sure if I am misunderstanding, please take a look:)

---------

Co-authored-by: rusty1s <matthias.fey@tu-dortmund.de>
JakubPietrakIntel pushed a commit that referenced this issue Sep 27, 2023
…mer_conv.py` (#7968)

Part of #6528.

---------

Co-authored-by: rusty1s <matthias.fey@tu-dortmund.de>
JakubPietrakIntel pushed a commit that referenced this issue Sep 27, 2023
…conv.py` (#8047)

- Part of #6528
- Fix `AttributeError: 'function' object has no attribute 'pop'` when
calling `remove_edge_index`

Not sure if I am misunderstanding, please take a look:)

---------

Co-authored-by: rusty1s <matthias.fey@tu-dortmund.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants