-
Notifications
You must be signed in to change notification settings - Fork 31
add argument for TBSystem to change eig_solver #325
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
abc0267
4a50501
4500b5e
0fc7d08
ccf43d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -240,7 +240,9 @@ def get_efermi(self, kmesh: List[int], | |||||||||||||||||||||||
| device=self.calculator.device) | ||||||||||||||||||||||||
| data = self._atomic_data.copy() | ||||||||||||||||||||||||
| data[AtomicDataDict.KPOINT_KEY] = torch.nested.as_nested_tensor([k_tensor]) | ||||||||||||||||||||||||
| data, eigs = self.calculator.get_eigenvalues(data) | ||||||||||||||||||||||||
| data, eigs = self.calculator.get_eigenvalues(data, | ||||||||||||||||||||||||
| nk=kwargs.get("nk", None), | ||||||||||||||||||||||||
| eig_solver=kwargs.get("eig_solver", None)) | ||||||||||||||||||||||||
|
Comment on lines
+243
to
+245
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid unconditional keyword injection into protocol calculators. At Line 243, Proposed compatibility-safe patch- data, eigs = self.calculator.get_eigenvalues(data,
- nk=kwargs.get("nk", None),
- eig_solver=kwargs.get("eig_solver", None))
+ eigen_kwargs = {}
+ nk = kwargs.get("nk", None)
+ eig_solver = kwargs.get("eig_solver", kwargs.get("solver", None))
+ if nk is not None:
+ eigen_kwargs["nk"] = nk
+ if eig_solver is not None:
+ eigen_kwargs["eig_solver"] = eig_solver
+ data, eigs = self.calculator.get_eigenvalues(data, **eigen_kwargs)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| calculated_efermi = self.estimate_efermi_e( | ||||||||||||||||||||||||
| eigenvalues=eigs.detach().numpy(), | ||||||||||||||||||||||||
|
|
@@ -294,7 +296,10 @@ def estimate_efermi_e(self, eigenvalues, | |||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| def get_bands(self, kpath_config: Optional[dict] = None, reuse: Optional[bool]=True, **kwargs): | ||||||||||||||||||||||||
| def get_bands(self, | ||||||||||||||||||||||||
| kpath_config: Optional[dict] = None, | ||||||||||||||||||||||||
| reuse: Optional[bool]=True, | ||||||||||||||||||||||||
| **kwargs): | ||||||||||||||||||||||||
| # 计算能带,返回 bands | ||||||||||||||||||||||||
| # bands 应该是一个类,也有属性。bands.kpoints, bands.eigenvalues, bands.klabels, bands.kticks, 也有函数 bands.plot() | ||||||||||||||||||||||||
| if self.has_bands and reuse: | ||||||||||||||||||||||||
|
|
@@ -303,7 +308,8 @@ def get_bands(self, kpath_config: Optional[dict] = None, reuse: Optional[bool]=T | |||||||||||||||||||||||
| assert kpath_config is not None, "kpath_config must be provided if bands not calculated." | ||||||||||||||||||||||||
| self._bands = BandAccessor(self) | ||||||||||||||||||||||||
| self._bands.set_kpath(**kpath_config) | ||||||||||||||||||||||||
| self._bands.compute() | ||||||||||||||||||||||||
| self._bands.compute(nk=kwargs.get("nk", None), | ||||||||||||||||||||||||
| eig_solver=kwargs.get("eig_solver", None)) | ||||||||||||||||||||||||
| self.has_bands = True | ||||||||||||||||||||||||
| return self._bands | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only forward solver kwargs when they were explicitly requested.
TBSystemstill allows duck-typed calculators, so always callingget_eigenvalues(..., nk=None, eig_solver=None)is a compatibility regression for calculators that still implement the oldget_eigenvalues(data)signature. Build the kwargs dict conditionally before the call.🔧 Safer forwarding
🤖 Prompt for AI Agents