diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3768e9a..93b4485 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: - name: Install minimal pinned dependencies run: | python -m pip install -e . --no-deps - python -m pip install matplotlib==3.11.1 networkx==3.6.1 numpy==2.4.6 pytest==9.1.1 quimb==1.14.0 + python -m pip install matplotlib==3.11.2 networkx==3.6.1 numpy==2.4.5 pytest==9.2.0 quimb==1.14.0 - name: Run headless example run: python scripts/verify.py smoke @@ -55,7 +55,7 @@ jobs: cache: "pip" - name: Install build tool - run: python -m pip install build==1.5.0 twine==6.2.0 setuptools==83.0.0 + run: python -m pip install build==1.6.1 twine==7.0.0 setuptools==84.2.1 - name: Build package artifacts run: python scripts/verify.py package diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b1a634..bb8b892 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- **Dependency refresh:** Raised runtime minimums for Matplotlib, NetworkX (3.6.1 on Python 3.11, 3.7 on Python 3.12+), and NumPy (2.4.5 on Python 3.11, 2.5.5 on Python 3.12+); refreshed development and CI pins while retaining the TensorKrowch, TensorNetwork, Quimb, and TeNPy version requirements. +- **Package version:** Prepared `2.0.4` for the updated runtime dependency baseline. +- **PyTorch compatibility:** Removed the obsolete `setuptools<82` maintenance assumption after verifying that the current PyTorch package permits newer setuptools versions. +- **Grid layout stability:** Canonicalized grid reflections across NetworkX isomorphism versions to preserve boundary-vector orientation. +- **Typing:** Kept top-k index values explicitly typed as integers under the newer NumPy and Pyright packages. - **CI maintenance:** Updated `actions/checkout` from `v6` to `v7` in the GitHub Actions workflow. -- **Dependabot policy:** Ignore `setuptools` updates to `>=82` for the `pip` ecosystem until the pinned PyTorch dependency no longer requires `setuptools<82`. ## [2.0.3] — 2026-05-17 diff --git a/pyproject.toml b/pyproject.toml index bc3aa5e..3f872c3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "tensor-network-visualization" -version = "2.0.3" +version = "2.0.4" description = "Minimal Matplotlib visualizations for TensorKrowch, TensorNetwork, Quimb, TeNPy, and traced PyTorch/NumPy einsum tensor networks." authors = [{ name = "Alejandro Mata Ali" }] readme = "README.md" @@ -13,9 +13,11 @@ license-files = ["LICENSE"] requires-python = ">=3.11" keywords = ["tensor-network", "visualization", "pytorch", "numpy", "tensorkrowch", "tensornetwork", "quimb", "tenpy", "einsum", "quantum-inspired", "matplotlib"] dependencies = [ - "matplotlib>=3.7", - "networkx>=3.0", - "numpy>=2.0", + "matplotlib>=3.11.2", + "networkx>=3.6.1; python_version < '3.12'", + "networkx>=3.7; python_version >= '3.12'", + "numpy>=2.4.5; python_version < '3.12'", + "numpy>=2.5.5; python_version >= '3.12'", ] classifiers = [ "Development Status :: 5 - Production/Stable", @@ -40,15 +42,15 @@ Issues = "https://github.com/DOKOS-TAYOS/Tensor-Network-Visualization/issues" [project.optional-dependencies] dev = [ "bandit>=1.9.4", - "build>=1.5.0", - "pytest>=9.1.1", - "ruff>=0.15.22", - "setuptools>=83.0.0", - "pyright>=1.1.411", + "build>=1.6.1", + "pytest>=9.2.0", + "ruff>=0.17.5", + "setuptools>=84.2.1", + "pyright>=1.1.414", "pip-audit>=2.10.1", - "twine>=6.0.0", - "ipython>=8.10.0", + "twine>=7.0.0", + "ipython>=9.18.1", "tensorkrowch>=1.1", "tensornetwork>=0.4", "quimb>=1.7", diff --git a/requirements.dev.txt b/requirements.dev.txt index 27ee2eb..1907ba6 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -1,18 +1,20 @@ -e . bandit==1.9.4 -build==1.5.0 -ipython==9.15.0 ; python_version >= "3.12" -ipython==9.15.0 ; python_version < "3.12" -matplotlib==3.11.1 -networkx==3.6.1 -numpy==2.4.6 +build==1.6.1 +ipython==9.18.1 ; python_version >= "3.12" +ipython==9.18.1 ; python_version < "3.12" +matplotlib==3.11.2 +networkx==3.6.1 ; python_version < "3.12" +networkx==3.7 ; python_version >= "3.12" +numpy==2.4.5 ; python_version < "3.12" +numpy==2.5.5 ; python_version >= "3.12" pip-audit==2.10.1 physics-tenpy==1.1.0 -pyright==1.1.411 -pytest==9.1.1 +pyright==1.1.414 +pytest==9.2.0 quimb==1.14.0 -ruff==0.15.22 -setuptools==84.1.0 +ruff==0.17.5 +setuptools==84.2.1 tensorkrowch==1.1.6 tensornetwork==0.4.6 twine==7.0.0 diff --git a/src/tensor_network_viz/_core/layout_structure.py b/src/tensor_network_viz/_core/layout_structure.py index fbb2ad9..19148a2 100644 --- a/src/tensor_network_viz/_core/layout_structure.py +++ b/src/tensor_network_viz/_core/layout_structure.py @@ -673,7 +673,29 @@ def _detect_grid(nx_graph: nx.Graph) -> dict[int, tuple[int, int]] | None: mapping = nx.vf2pp_isomorphism(nx_graph, grid_graph) if mapping is None: continue - return {node_id: (grid_col, grid_row) for node_id, (grid_row, grid_col) in mapping.items()} + coordinates = { + node_id: (grid_col, grid_row) for node_id, (grid_row, grid_col) in mapping.items() + } + # Grid isomorphisms have reflection symmetries. NetworkX may choose a + # different representative across releases, so orient each axis using + # the node IDs instead of relying on the isomorphism iteration order. + for axis in (0, 1): + low = min(value[axis] for value in coordinates.values()) + high = max(value[axis] for value in coordinates.values()) + if low == high: + continue + low_id = min(node_id for node_id, value in coordinates.items() if value[axis] == low) + high_id = min(node_id for node_id, value in coordinates.items() if value[axis] == high) + if low_id > high_id: + coordinates = { + node_id: ( + (low + high - value[0], value[1]) + if axis == 0 + else (value[0], low + high - value[1]) + ) + for node_id, value in coordinates.items() + } + return coordinates return None diff --git a/src/tensor_network_viz/_tensor_elements_data.py b/src/tensor_network_viz/_tensor_elements_data.py index cae25d2..af8cbbd 100644 --- a/src/tensor_network_viz/_tensor_elements_data.py +++ b/src/tensor_network_viz/_tensor_elements_data.py @@ -646,13 +646,12 @@ def _topk_flat_indices(magnitudes: NumericArray, *, count: int) -> NumericArray: partitioned = np.argpartition(normalized, partition_index) threshold = float(normalized[int(partitioned[partition_index])]) higher = np.flatnonzero(normalized > threshold) - higher_ranked = np.asarray( - sorted( - (int(flat_index) for flat_index in higher), - key=lambda flat_index: _topk_sort_key(float(normalized[flat_index]), flat_index), - ), - dtype=np.intp, + higher_indices: list[int] = [int(flat_index) for flat_index in higher] + higher_sorted = sorted( + higher_indices, + key=lambda flat_index: _topk_sort_key(float(normalized[flat_index]), flat_index), ) + higher_ranked = np.asarray(higher_sorted, dtype=np.intp) remaining = requested_count - int(higher_ranked.size) if remaining <= 0: return higher_ranked[:requested_count] diff --git a/tests/test_ci_workflow.py b/tests/test_ci_workflow.py index a6dcf68..b912560 100644 --- a/tests/test_ci_workflow.py +++ b/tests/test_ci_workflow.py @@ -210,10 +210,10 @@ def test_ci_workflow_keeps_minimal_and_packaging_smoke_guards() -> None: assert "python -m pip install -e . --no-deps" in minimal_install for requirement in ( - "matplotlib==3.11.1", + "matplotlib==3.11.2", "networkx==3.6.1", - "numpy==2.4.6", - "pytest==9.1.1", + "numpy==2.4.5", + "pytest==9.2.0", "quimb==1.14.0", ): assert requirement in minimal_install diff --git a/tests/test_engineering_baseline.py b/tests/test_engineering_baseline.py index e2eae32..5abc16c 100644 --- a/tests/test_engineering_baseline.py +++ b/tests/test_engineering_baseline.py @@ -144,19 +144,21 @@ def test_dev_requirements_pin_verification_tools_and_use_editable_install() -> N assert "-e ." in lines assert { - "build==1.5.0", + "build==1.6.1", "bandit==1.9.4", - "ipython==9.15.0", - "matplotlib==3.11.1", + "ipython==9.18.1", + "matplotlib==3.11.2", "networkx==3.6.1", - "numpy==2.4.6", + "networkx==3.7", + "numpy==2.4.5", + "numpy==2.5.5", "pip-audit==2.10.1", "physics-tenpy==1.1.0", - "pyright==1.1.411", - "pytest==9.1.1", + "pyright==1.1.414", + "pytest==9.2.0", "quimb==1.14.0", - "ruff==0.15.22", - "setuptools==84.1.0", + "ruff==0.17.5", + "setuptools==84.2.1", "tensorkrowch==1.1.6", "tensornetwork==0.4.6", "twine==7.0.0", diff --git a/tests/test_packaging_metadata.py b/tests/test_packaging_metadata.py index fa36ea2..b441eca 100644 --- a/tests/test_packaging_metadata.py +++ b/tests/test_packaging_metadata.py @@ -20,7 +20,13 @@ def test_base_dependencies_are_declared_explicitly() -> None: dependencies = pyproject["project"]["dependencies"] - assert dependencies == ["matplotlib>=3.7", "networkx>=3.0", "numpy>=2.0"] + assert dependencies == [ + "matplotlib>=3.11.2", + "networkx>=3.6.1; python_version < '3.12'", + "networkx>=3.7; python_version >= '3.12'", + "numpy>=2.4.5; python_version < '3.12'", + "numpy>=2.5.5; python_version >= '3.12'", + ] def test_project_uses_spdx_license_metadata() -> None: diff --git a/tests/test_plotting.py b/tests/test_plotting.py index d68a2b8..c3094b9 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -3553,7 +3553,7 @@ def test_show_tensor_network_displays_selected_renderer(monkeypatch: pytest.Monk def fake_show() -> None: shown["value"] = True - monkeypatch.setattr(viewer_module.plt, "show", fake_show) + monkeypatch.setattr(plt, "show", fake_show) fig, ax = show_tensor_network( DummyNetwork(nodes=[node]), engine="tensorkrowch", @@ -3625,8 +3625,8 @@ def _fake_show() -> None: monkeypatch.setattr("IPython.core.getipython.get_ipython", _fake_get_ipython) monkeypatch.setattr("IPython.display.display", _fake_display) - monkeypatch.setattr(viewer_module.plt, "show", _fake_show) - monkeypatch.setattr(viewer_module.plt, "get_backend", lambda: backend_name) + monkeypatch.setattr(plt, "show", _fake_show) + monkeypatch.setattr(plt, "get_backend", lambda: backend_name) viewer_module._show_figure(fig)