Skip to content
New issue

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

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

Already on GitHub? # to your account

【快乐开源】为 PaddleScience 的 equation 模块添加单元测试 #378

Closed
HydrogenSulfate opened this issue Jun 16, 2023 · 6 comments
Assignees

Comments

@HydrogenSulfate
Copy link
Collaborator

HydrogenSulfate commented Jun 16, 2023

This project will be mentored by @HydrogenSulfate

1. 背景

PaddleScience 套件由 13 个模块构成,每个模块的代码存放在 ppsci/ 下的文件夹中,但这些模块暂时缺少对应的单元测试,虽然目前 PaddleScience 的模块没有存在严重的 BUG,但单元测试仍然是这些模块在细节上的正确性的有力保障,避免隐蔽的 BUG。因此希望在此次快乐开源活动中给核心模块 equation(文件夹是 ppsci/equation)添加单元测试

2. 收益

保障 equation 模块的正确性

3. 添加单元测试

3.1 基本要求 (整体进度:7/7)

单元测试基于 pytest 进行编写与开发,需要对 equation 模块下的各个方程类内部代码的 if-else 分支进行全面测试,覆盖率达到 100%

ppsci/equation/pde 下的 7 个文件(laplace.py 除外,已作为 3.2 单测开发 中的示例)添加单元测试,编写代码时尽量使用 pytest 的 参数化测试特性 以减少重复代码

按 merge 的时间顺序,排名不分先后:@GreatV (1), @ccsuzzh (1), @jiamingkong (1), @enkilee (1), @jjyaoao (1), @ruoyunbai (1), @mrcangye (1)

序号 单测文件 认领人 PR号
1 base.py✅ (2023/6/20) @jiamingkong #397
2 biharmonic.py✅(2023/6/23) @jjyaoao #394
3 linear_elasticity.py✅(2023/7/10) @ruoyunbai #416
4 navier_stokes.py✅(2023/7/10) @mrcangye #414
5 normal_dot_vec.py✅(2023/6/17) @GreatV #388
6 poisson.py✅ (2023/6/19) @enkilee #400
7 viv.py✅ (2023/6/20) @ccsuzzh #401

3.2 单测开发

  1. 在 ppsci 下新建一个 test 目录
  2. 在 test 目录下新建 equation 目录
  3. 在 test/equation 目录下新建与 equation 模块下同名的文件,如新建 test_biharmonic.py(对应 equation/biharmonic.py)
  4. 在新建的 test_xxx.py 文件中用 pytest 单元测试框架编写代码,单元测试代码需满足 3.1 基本要求 的内容
  5. 执行 pytest --cov=./ppsci/equation/pde test/equation/test_xxx.py,生成带有覆盖率报告的单元测试结果,并确认被测试的源代码覆盖率为 100%
  6. 提交 PR 到 PaddleScience

3.3 开发注意事项

由于 equation 模块中使用了诸多 jacobian, hessian 封装好的高阶微分函数,因此在单元测试中,计算标准参考结果时,应该使用 paddle.grad 等价实现 jacobian 和 hessian

4. 参考样例

以为 ppsci/equation/pde/laplace.py 添加单元测试 ppsci/test/equation/test_laplace.py 为例,在PR描述中可以看到 ppsci/equation/pde/laplace.py 的 Coverage 是 100%,满足要求。 参考 PR:#370 (所有流水线包括非required都要通过)

5. 参考资料

@mrcangye
Copy link
Contributor

认领3,4

@ccsuzzh
Copy link
Contributor

ccsuzzh commented Jun 16, 2023

认领 7

@jiamingkong
Copy link
Contributor

认领1

@enkilee
Copy link
Contributor

enkilee commented Jun 17, 2023

认领6,@Liyulingyue 转让

This was referenced Jun 19, 2023
@enkilee
Copy link
Contributor

enkilee commented Jun 19, 2023

抱歉,PR 395 的cla一直没法过,重新提了 PR 400

@luotao1
Copy link
Collaborator

luotao1 commented Jul 10, 2023

为 PaddleScience 的 equation 模块添加单元测试 已全部完成,感谢参与的小伙伴们!

按 merge 的时间顺序,排名不分先后:@GreatV (1), @ccsuzzh (1), @jiamingkong (1), @enkilee (1), @jjyaoao (1), @ruoyunbai (1), @mrcangye (1)

欢迎继续参与快乐开源的其他任务

@luotao1 luotao1 closed this as completed Jul 10, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in Call for Contributions Jul 10, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
Development

No branches or pull requests

6 participants