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

Setup sybil #1574

Merged
merged 23 commits into from
Jun 16, 2023
Merged

Setup sybil #1574

merged 23 commits into from
Jun 16, 2023

Conversation

joaander
Copy link
Member

@joaander joaander commented Jun 13, 2023

Description

Add Sybil documentation example tests to methods.py and thermostats.py.

Motivation and context

Users wish to copy and paste example code from the documentation. Sybil tests those snippets to ensure that they work now and in the future.

These tests currently run both in serial and MPI. That may be helpful. However future examples we write might only work in MPI and/or only in serial (or only on the GPU or only on the CPU). pytest.skip works within these blocks, however Sybil generates each code block as a separate test. Users will see the pytest.skip logic in tests that need to be skipped in some configurations. If we were to add pytest.skip in a hidden code block, it would only skip that block and not the next. The skip: next if syntax may be a solution to this, I just found it and have not yet tried it: https://sybil.readthedocs.io/en/latest/rest.html#skipping-examples

In my testing, Sybil only parses .. code-block:: sphinx directives and not literals Example::. This format makes the raw docstring more verbose (for users of help()), but the HTML output is as expected:

.. rubric:: Example:

.. code-block:: python

    example code

Note that the package-level example code the users sees in module-md-methods.html comes from md/methods/__init__.py, but the example code that Sybil runs in the namespace of all the MD methods is in md/methods/methods.py. This is because __init__.py imports from methods.py to create a different canonical namespace for the methods while Sybil runs all examples in the context of a document (a single .py file).

This pull request adds documentation for previously undocumented methods in hoomd.util. Should these be documented, or should they remain hidden?

  • dict_map
  • dict_fold
  • dict_flatten
  • dict_filter
  • GPUNotAvailableError

How has this been tested?

  • I have tested this locally and ensured that all code blocks are indeed being tested.
  • I have examined the generated html docs and ensured that the formatting is consistent and readable.

Change log

Added:

* Tested example code snippets in select modules.
* ``hoomd.util.make_example_simulation`` - create an example Simulation object.

Checklist:

Will be used to minimize boilerplate code in examples.
Apparently, hoomd.util was not documented. Make the docs for
make_example_simulation appear in the output. This also documents
previously undocumented methods in hoomd.util.
Classes from methods.py are imported into __init__.py. Sybil executes
all code in a single .py file in the same namespace. This commit duplicates
the setup code in __init__.py and methods.py. The code shown in __init__.py
is shown to the user in the rendered HTML output. The code in methods.py
is needed to prepare the namespace for the examples to run.
Process only methods.py for now.
@joaander
Copy link
Member Author

@b-butler @DomFijan Take a look at the changes and rendered Sphinx docs and let me know what you think.

Copy link
Contributor

@DomFijan DomFijan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went through the documentation. This is looks really good and I think it will be very useful, especially for newish users.

I have some suggestions, they might be too much in some cases and if you feel like it is too much feel free to discard proposed changes.

hoomd/md/methods/methods.py Outdated Show resolved Hide resolved
hoomd/md/methods/methods.py Outdated Show resolved Hide resolved
hoomd/md/methods/methods.py Show resolved Hide resolved
hoomd/md/methods/methods.py Show resolved Hide resolved
hoomd/md/methods/methods.py Show resolved Hide resolved
hoomd/md/methods/methods.py Outdated Show resolved Hide resolved
hoomd/md/methods/thermostats.py Outdated Show resolved Hide resolved
hoomd/md/methods/thermostats.py Outdated Show resolved Hide resolved
hoomd/md/methods/thermostats.py Outdated Show resolved Hide resolved
hoomd/md/methods/thermostats.py Outdated Show resolved Hide resolved
2023.06 includes sybil.
Test the skip parser with GPU only and MPI rank requirements.
@joaander joaander added the validate Execute long running validation tests on pull requests label Jun 14, 2023
@joaander
Copy link
Member Author

Updated with device.py examples ensuring that the skip next syntax allows us to write GPU and MPI specific examples that are tested when possible and skipped when not. This is as far as I'm taking this specific pull request. Future pull requests will add examples in batches to other parts of the code.

@joaander joaander marked this pull request as ready for review June 14, 2023 19:06
@joaander joaander requested review from a team and melodyyzh and removed request for a team June 14, 2023 19:06
@joaander joaander requested review from DomFijan and removed request for a team and melodyyzh June 14, 2023 19:06
Copy link
Member

@b-butler b-butler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great start and definitely going to aid users. I left some small comment to address.

hoomd/device.py Outdated Show resolved Hide resolved
hoomd/md/methods/__init__.py Outdated Show resolved Hide resolved
hoomd/md/methods/__init__.py Outdated Show resolved Hide resolved
hoomd/md/methods/methods.py Outdated Show resolved Hide resolved
hoomd/md/methods/methods.py Outdated Show resolved Hide resolved
hoomd/md/methods/thermostats.py Outdated Show resolved Hide resolved
hoomd/md/methods/thermostats.py Outdated Show resolved Hide resolved
@joaander joaander requested a review from b-butler June 16, 2023 13:20
Copy link
Member

@b-butler b-butler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@joaander joaander merged commit 5d06cd6 into trunk-minor Jun 16, 2023
@joaander joaander deleted the setup-sybil branch June 16, 2023 18:55
@joaander joaander mentioned this pull request Jul 14, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
validate Execute long running validation tests on pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants