Skip to content

Use dimension-aware default origins for model transformations - #244

Open
davrens101 wants to merge 3 commits into
Z2PackDev:trunkfrom
davrens101:fix/dimension-aware-cell-origins
Open

davrens101 wants to merge 3 commits into
Z2PackDev:trunkfrom
davrens101:fix/dimension-aware-cell-origins

Conversation

@davrens101

@davrens101 davrens101 commented Nov 4, 2026 •

Copy link
Copy Markdown

Problem

Model.change_unit_cell and Model.fold_model default their origin arguments to (0, 0, 0) regardless of model.dim. Consequently, otherwise valid 1D and 2D models fail when callers omit the origin:

  • change_unit_cell() fails while solving a dim×dim system with the three-component default.
  • fold_model(new_unit_cell=..., orbital_labels=...) fails when applying that default to lower-dimensional unit-cell vertices.

I reproduced both failures for 1D and 2D models, including a supercell/folding roundtrip. The same calls work when an explicit dimension-sized zero vector is supplied.

Change

  • Represent an omitted origin as None and resolve it to np.zeros(self.dim).
  • Use the resulting array consistently in Cartesian/reduced origin conversion and both folding geometry calculations.
  • Preserve explicit origins and existing 3D behavior.
  • Add dense/sparse 1D/2D regressions with complex hopping, checking complete model equivalence after the identity cell change and supercell/folding roundtrip. Cell-change coverage includes both Cartesian and reduced modes.
  • Document the defaults and add an unreleased changelog entry.

Executed validation

Python 3.11.18, NumPy 1.26.4, SciPy 1.17.1 on Windows; imports explicitly checked to resolve to this worktree.

  • pytest tests/test_change_unit_cell.py tests/test_folding.py tests/test_equivalent_operations.py tests/test_supercell.py -q: 260 passed.
  • Direct actual-model smoke: all four previously failing 1D/2D operations now preserve occupied-band counts, orbital positions, and band energies. Maximum eigenvalue discrepancy at the sampled generic k points: 0.0.
  • Black 22.8.0 check and configured Pylint checks pass for the three changed Python files.
  • Full suite attempted: 1181 passed, 83 failed, 16 xfailed. The failures are outside these transformation paths: 79 cases reopen an already-open NamedTemporaryFile on Windows and raise PermissionError; four CLI tests pass the removed mix_stderr argument to the installed Click's CliRunner. These tests were not modified or suppressed.
  • Configured mypy run could not complete: the project's Python 3.8 target rejects pattern-matching syntax in the installed pytest dependency. No type-check success is claimed.

This contribution was prepared with AI assistance. The runtime reproductions, physical-invariance checks, and test commands above were executed, not inferred.

GitHub CI

The original setup failure from retired cache/artifact actions is resolved. Both the generated workflow and its source template now use supported action versions.

Latest head e7e2ebe298eebc02abc0001c7057e1cffb7f39b3: all seven checks passed, including documentation, pre-commit, the Python test matrix, and version consistency.

@davrens101

Copy link
Copy Markdown
Author

CI currently stops during runner preparation, before checkout or tests: GitHub rejects the workflow's retired actions/cache@v2; the docs job also uses retired actions/upload-artifact@v2. Failed run. These checks did not exercise the patch. I have not rerun them or mixed an unrelated workflow migration into this numerical fix.

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