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

Xdoctest project #33

Merged
merged 6 commits into from
Jan 8, 2024
Merged

Conversation

sunzhongkai588
Copy link
Contributor

xdoctest 的结项 blog.

Copy link

netlify bot commented Dec 28, 2023

Deploy Preview for pfccblog ready!

Name Link
🔨 Latest commit 41d8943
🔍 Latest deploy log https://app.netlify.com/sites/pfccblog/deploys/659af8d2da52eb00082590c8
😎 Deploy Preview https://deploy-preview-33--pfccblog.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

src/posts/xdoctest-project.md Outdated Show resolved Hide resolved
src/posts/xdoctest-project.md Show resolved Hide resolved

## 01 - 关于任务

`Python`源代码与官方文档中的`Example`,也就是示例代码,是学习与使用 Paddle 框架非常重要的学习与参考依据。赛题要求将 xdoctest 引入到飞桨框架的工作流中,利用 xdoctest 来自动检查示例代码运行正确,且与输出结果匹配,以确保示例代码输出的一致性,进一步提高飞桨框架示例代码的质量。
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
`Python`源代码与官方文档中的`Example`,也就是示例代码,是学习与使用 Paddle 框架非常重要的学习与参考依据。赛题要求将 xdoctest 引入到飞桨框架的工作流中,利用 xdoctest 来自动检查示例代码运行正确,且与输出结果匹配,以确保示例代码输出的一致性,进一步提高飞桨框架示例代码的质量。
Python 源代码与官方文档中的 Example,也就是示例代码,是学习与使用 Paddle 框架非常重要的学习与参考依据。赛题要求将 xdoctest 引入到飞桨框架的工作流中,利用 xdoctest 来自动检查示例代码运行正确,且与输出结果匹配,以确保示例代码输出的一致性,进一步提高飞桨框架示例代码的质量。

这段稍后我改写下

背景见 PaddlePaddle/Paddle#53172 (comment)

src/posts/xdoctest-project.md Outdated Show resolved Hide resolved

### >>> print(solutions) 都有哪些现成的解决方案?

[xdoctest](https://xdoctest.readthedocs.io/en/latest/) 是一个示例代码自动执行和检查工具,可以自动执行 Python docstring 中的示例代码,并对示例代码输出进行检查。
Copy link
Collaborator

Choose a reason for hiding this comment

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

图里说了 doctest,但这里并没有提及

Copy link
Contributor

Choose a reason for hiding this comment

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

doctest 还是要提一下的,尤其要提一下 xdoctest 对比 doctest 的优势。

Copy link
Contributor

Choose a reason for hiding this comment

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

可以参考 xdoctest 文档里面的描述:

The xdoctest package is a re-write of Python’s builtin doctest module. It replaces the old regex-based parser with a new abstract-syntax-tree based parser (using Python’s ast module). The goal is to make doctests easier to write, simpler to configure, and encourage the pattern of test driven development.

src/posts/xdoctest-project.md Outdated Show resolved Hide resolved
src/posts/xdoctest-project.md Outdated Show resolved Hide resolved
src/posts/xdoctest-project.md Outdated Show resolved Hide resolved
src/posts/xdoctest-project.md Outdated Show resolved Hide resolved
src/posts/xdoctest-project.md Outdated Show resolved Hide resolved
src/posts/xdoctest-project.md Outdated Show resolved Hide resolved

### >>> print(solutions) 都有哪些现成的解决方案?

[xdoctest](https://xdoctest.readthedocs.io/en/latest/) 是一个示例代码自动执行和检查工具,可以自动执行 Python docstring 中的示例代码,并对示例代码输出进行检查。
Copy link
Contributor

Choose a reason for hiding this comment

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

doctest 还是要提一下的,尤其要提一下 xdoctest 对比 doctest 的优势。

src/posts/xdoctest-project.md Outdated Show resolved Hide resolved
- Paddle 代码和 docs 都有代码检查逻辑。
- 代码检查逻辑还不尽相同。
- Paddle 与 PyTorch 很多实现方式不一样。
- PyTorch 的检查方式并不完整。
Copy link
Contributor

Choose a reason for hiding this comment

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

pytorch/pytorch#82797
这个PR,当时调研看过吗?

Copy link
Contributor

@megemini megemini Dec 29, 2023

Choose a reason for hiding this comment

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

pytorch/pytorch#82797 这个PR,当时调研看过吗?

没有 ... ... 当时对于 pytorch 的调研主要在文档和代码本身:

  • pytorch 的 xdoctest 检查逻辑与脚本
  • pytorch 的 xdoctest 实际检查结果
  • pytorch 中示例代码对于 xdoctest 的使用,如 skip 指令等

当时确实没有想到在 pr 和 issue 上调研,如果能够更多了解当时 pytorch 对于 xdoctest 引入的前因后果,后面应该可以少走一些弯路 ~~~

回到这个 PR 本身,主要干了几件事:

  • 修改示例中错误的格式
  • 添加 skip 指令
  • 处理渲染问题

以及提到了 global state 对于测试的影响。

这里对于示例的检查还是相对宽松的,比如随机数、global 影响等,基本是 skip 或者 ignore want 处理。

我们在引入 xdoctest 的时候尽量使用固定 seed 或者开进程的方式解决掉上述问题,让检查能够进行。


### >>> print(solutions) 都有哪些现成的解决方案?

[xdoctest](https://xdoctest.readthedocs.io/en/latest/) 是一个示例代码自动执行和检查工具,可以自动执行 Python docstring 中的示例代码,并对示例代码输出进行检查。
Copy link
Contributor

Choose a reason for hiding this comment

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

可以参考 xdoctest 文档里面的描述:

The xdoctest package is a re-write of Python’s builtin doctest module. It replaces the old regex-based parser with a new abstract-syntax-tree based parser (using Python’s ast module). The goal is to make doctests easier to write, simpler to configure, and encourage the pattern of test driven development.

<div style="display: flex; justify-content: center">
<figure style="width: 60%;">
<img src="../images/xdoctest-project/xdoctest-5.jpg"/>
<figcaption>项目 milestones</figcaption>
Copy link
Contributor

Choose a reason for hiding this comment

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

image

github 渲染这个 figcaption 好像不太好~ 不知道咱们线上有木有问题?

Copy link
Collaborator

Choose a reason for hiding this comment

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

不用看 GitHub 的渲染哈,这里有 Netlify 的 preview

image

Copy link
Contributor

@jzhang533 jzhang533 left a comment

Choose a reason for hiding this comment

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

Great Story~ 🥂

@jzhang533 jzhang533 added this pull request to the merge queue Jan 8, 2024
Merged via the queue into PFCCLab:main with commit d7f4e8a Jan 8, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants