deepmodeling / deepmodeling/tbplas

[Code scan] Validate HopDict diagonal data before mutating state

Open Beginner friendly
#19 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
19
Forks
6
PR merge metrics
No merged PRs in 30d

Description

This issue comes from a Codex global scan of deepmodeling/tbplas at commit 4d3652b3dba8eb930e4869a6d41074f62d703692.

Severity: Medium

`HopDict.__setitem__()` copies the matrix into `_hoppings` before checking whether `(0, 0, 0)` contains forbidden diagonal onsite terms. If `_check_diag()` raises and the caller catches the exception, the invalid matrix remains stored in the object.

Code reference:
https://github.com/deepmodeling/tbplas/blob/4d3652b3dba8eb930e4869a6d41074f62d703692/tbplas/builder/base.py#L542-L548

Suggested fix: validate the candidate matrix before assigning it to `_hoppings`, or roll back the assignment when validation fails.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in tbplas/builder/base.py around HopDict.__setitem__() at lines 542-548, then inspect _check_diag() to understand when validation raises. Ensure the candidate matrix is validated before _hoppings changes, and verify that a caught validation error leaves the previous state unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.