Skip to content

Fix two runtime warnings: non-writable array and docstring escape#348

Merged
QG-phy merged 3 commits into
deepmodeling:mainfrom
QG-phy:fix-runtime-warnings-cleanup
Jun 25, 2026
Merged

Fix two runtime warnings: non-writable array and docstring escape#348
QG-phy merged 3 commits into
deepmodeling:mainfrom
QG-phy:fix-runtime-warnings-cleanup

Conversation

@QG-phy

@QG-phy QG-phy commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

Two small DeePTB-side warning fixes from the dependency-baseline review (#346).

  • dptb/data/dataset/_default_dataset.py: h5py-backed arrays are read-only (writeable=False), so torch.as_tensor emitted UserWarning: The given NumPy array is not writable when converting kpoint/eigenvalue data. Add .copy() to produce a writable array before the tensor conversion. ([:] slicing does not help — a slice of a read-only array stays read-only; only .copy() makes it writable.)
  • dptb/tests/test_feast_wrapper.py: the docstring Ax = \lambda Mx used an invalid escape sequence, raising SyntaxWarning on Python 3.12+. Switch to a raw string r"""...""".

Scope

Two files, three lines. No behavioral change.

Tests

Local not slow (Python 3.12, numpy 2.4.6, torch 2.12.1): 447 passed, 0 failed, warnings 84 → 75. The two targeted warnings are gone (grep count 0).

Remaining warnings (not in this PR — all external-library debt)

  • pythtb tb_model / get_orb deprecation → tracked: pythtb 1.x→2.x migration
  • spglib OLD_ERROR_HANDLING → tracked: spglib error-handling migration (2.8.0 flips the default)
  • ASE __array__ copy keyword → ASE adapting to numpy 2.0 protocol
  • torch.jit.script deprecated → TorchScript migration task

Merge decision

Mergeable. Independent of #346 (dependency baseline) and #347 (sfd fix); this is a standalone code cleanup.

Summary by CodeRabbit

  • Bug Fixes
    • Improved how frame-specific k-point and eigenvalue data is handled during dataset conversion, preventing unintended side effects from shared array memory.
  • Chores
    • Updated a test docstring for consistency.
    • Adjusted the unit test workflow to conditionally run the build job and simplified the workflow by removing a dependent follow-up job.

- _default_dataset.py: h5py-backed arrays are read-only, so torch.as_tensor
  emitted "NumPy array is not writable" when converting kpoint/eigenvalue
  data. Add .copy() to produce a writable array before the tensor conversion.
- test_feast_wrapper.py: the docstring "Ax = \lambda Mx" used an invalid
  escape sequence (SyntaxWarning on Python 3.12+). Switch to a raw string.

Local not-slow run: warnings drop 84 -> 75, 447 passed, 0 failed.
The remaining warnings are all external-library debt (pythtb 1.x->2.x
migration, spglib OLD_ERROR_HANDLING, ASE numpy 2.0 __array__, torch.jit)
tracked in separate migration tasks.
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@QG-phy, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 30 minutes and 21 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ab364218-8207-4781-a863-0fce378a3b83

📥 Commits

Reviewing files that changed from the base of the PR and between e0a800a and b24760b.

📒 Files selected for processing (1)
  • .github/workflows/unit_test.yml
📝 Walkthrough

Walkthrough

Dataset frame conversion now copies per-frame k-point and eigenvalue arrays before tensor creation. The unit test workflow now gates the build job by repository owner and removes a dependent job. One test docstring was changed to a raw string literal.

Changes

Dataset tensor copy and workflow cleanup

Layer / File(s) Summary
Copy tensor inputs
dptb/data/dataset/_default_dataset.py
Per-frame KPOINT_KEY and ENERGY_EIGENVALUE_KEY slices are copied before torch.as_tensor creates the frame tensors.
Condition build job
.github/workflows/unit_test.yml
The build job is guarded by github.repository_owner == 'deepmodeling', the job outputs block is removed, and the downstream job2 is deleted from the workflow.
Raw docstring literal
dptb/tests/test_feast_wrapper.py
The test_generalized_hermitian docstring uses a raw triple-quoted string literal.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers summary, scope, tests, and merge decision, but omits several required template sections. Add the missing template sections: DeePTB Impact Area, Risk And Compatibility, AI Assistance, and the full Merge Decision fields.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the two warning fixes in the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown

This advisory review plan was generated from changed file names using trusted base-branch code.
此审查计划由受信任的 base 分支代码根据变更文件名生成,仅作为维护者辅助。

DeePTB PR Review Plan / DeePTB PR 审查计划

Risk / 风险等级: Medium (中) · Changed files / 变更文件: 3

Why / 风险来源

  • Dataset backends changed. / 数据集后端 有变更。
  • GitHub Actions and CI changed. / GitHub Actions 与 CI 有变更。
  • Tests changed. / 测试 有变更。

Recommended Review / 建议审查重点

  • Run the Maintainer Review Prompt. / 运行维护者审查 prompt。
  • Run the Test Gap Review Prompt. / 运行测试缺口审查 prompt。
  • Confirm the changed behavior matches the PR scope. / 确认变更行为和 PR 范围一致。
Detailed risk areas
  • Dataset backends (Medium): dptb/data/dataset/_default_dataset.py
  • GitHub Actions and CI (Medium): .github/workflows/unit_test.yml
  • Tests (Medium): dptb/tests/test_feast_wrapper.py
Human review focus
  • Dataset backends: format compatibility, missing fields, and cutoff behavior
  • GitHub Actions and CI: trigger scope, required checks, dependency installation, and runtime noise
  • Tests: marker choice, regression coverage, skipped environments, and assertions
Local commands and hold conditions

Suggested local commands:

  • python scripts/ci/check_repository_hygiene.py
  • uv run pytest ./dptb/tests -m smoke
  • uv run pytest ./dptb/tests -m regression

Hold conditions:

  • CI failed and the failure is not explained.
  • The PR scope is unclear or mixes unrelated changes.
  • AI review found a plausible correctness issue that was not fixed or explicitly waived.

Advisory only. / 仅作为审查辅助。

QG-phy added 2 commits June 26, 2026 02:16
job2 depended on build only to echo unset/removed outputs ($OUTPUT1 was
never declared in env; $OUTPUT2/$OUTPUT3 came from build outputs that
the build steps never set — output3 was deleted back in deepmodeling#23 but job2's
reference was left). It ran ~9s per PR with no effect. Drop job2 and the
now-unread build outputs block.
The job checks out the PR, installs DeePTB, and runs ut.sh. It does no
build/compile step and produces no artifact, so "build" is a historical
misnomer. Rename to "test". No branch-protection required checks reference
the old name, and no other workflow/job reads this job by name.
@QG-phy QG-phy merged commit 9b456ab into deepmodeling:main Jun 25, 2026
5 of 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.

1 participant