Skip to content

[Code scan] Initialize EigLoss windowed loss when no bands fall inside the energy window #356

Description

@njzjz

This issue is part of a Codex global repository scan.

Problem:
In EigLoss.forward, loss is assigned only if mask_in contains at least one selected value. If the configured energy window excludes all selected bands but mask_out contains entries, the code evaluates loss + ... before loss exists.

Code reference:
https://github.com/deepmodeling/deeptb/blob/86c60c73996f0dd961c3138f2e88424382cb734e/dptb/nnops/loss.py#L215-L219

Impact:
Valid narrow-window configurations can fail with UnboundLocalError during training or evaluation.

Suggested fix:
Initialize loss before the mask branches, or compute in-window and out-of-window terms independently before summing the terms that are present.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions