Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 59 additions & 7 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ jobs:
- name: Install uv
run: pip install uv

- name: Install pytest-pyvista with test dependencies
# The core builds here; the gallery examples call write() and read().
run: uv pip install --system .[docs]
- name: Install with documentation dependencies
run: |
uv pip install --system .[docs] &&
python -m pip install pyvista vtk &&
uv pip check --system

- name: Setup headless display
uses: pyvista/setup-headless-display-action@v5.1
Expand Down Expand Up @@ -109,10 +111,13 @@ jobs:
run: pip install uv

- name: Install with test dependencies
# Pin vtk in the same resolve so the dependencies cannot replace it.
# pip supplies stock VTK; resolve PyVista with it to respect its VTK bounds.
env:
PVZSTD_BUILD_CORE: "1"
run: uv pip install --system .[tests] ${{ matrix.vtk-version != 'latest' && format('vtk=={0}', matrix.vtk-version) || '' }}
run: |
uv pip install --system .[tests] &&
python -m pip install pyvista ${{ matrix.vtk-version != 'latest' && format('vtk=={0}', matrix.vtk-version) || 'vtk' }} &&
uv pip check --system

- name: Confirm the VTK version
run: python -c "import importlib.metadata as m, sys; v = m.version('vtk'); print('vtk', v); sys.exit(0 if '${{ matrix.vtk-version }}' in ('latest', v) else 1)"
Expand Down Expand Up @@ -155,14 +160,61 @@ jobs:
- name: Install with test dependencies at the declared floors
env:
PVZSTD_BUILD_CORE: "1"
run: uv pip install --system .[tests] $(uv run .github/scripts/runtime_floors.py)
# Keep the runtime floors pinned when pip supplies the stock VTK binding.
run: |
uv pip install --system .[tests] $(uv run .github/scripts/runtime_floors.py) &&
python -m pip install $(uv run .github/scripts/runtime_floors.py) vtk==9.3.1 &&
uv pip check --system

- name: Show the installed runtime dependencies
run: uv pip list --system | grep -iE '^(pyvista|vtk) '

- name: Unit Testing
run: pytest -vv

cvista:
name: cvista without stock VTK
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7

- name: Set up Python 3.13
uses: actions/setup-python@v7
with:
python-version: "3.13"
cache: "pip"
cache-dependency-path: pyproject.toml

- name: Install uv
run: pip install uv

- name: Install with cvista and test dependencies
env:
PVZSTD_BUILD_CORE: "1"
run: |
uv pip install --system .[tests] 'pyvista[cvista]>=0.49'
uv pip uninstall --system vtk

- name: Confirm cvista is the only VTK binding
run: |
python - <<'PY'
from importlib.metadata import requires
import importlib.util
from packaging.requirements import Requirement
import pyvista as pv

assert all(Requirement(req).name != "vtk" for req in requires("pyvista-zstd"))
assert importlib.util.find_spec("vtkmodules") is None
assert pv.vtk_backend() == "cvista"
print("PyVista backend:", pv.vtk_backend())
PY

- name: Setup headless display
uses: pyvista/setup-headless-display-action@v5.1

- name: Unit Testing
run: pytest -vv

# The distributions the release publishes. They live here, in the same
# workflow as the release job, so that job can reach their artifacts through
# `needs` and `download-artifact`; artifacts do not cross workflow runs.
Expand Down Expand Up @@ -258,7 +310,7 @@ jobs:
# The wheel jobs are in the needs list because the release is what they are
# for: without them the only artefact published is an sdist, and every
# install on a machine with no C++ compiler fails.
needs: [doc, unit_testing, dependency_floor, wheels, sdist]
needs: [doc, unit_testing, dependency_floor, cvista, wheels, sdist]
runs-on: ubuntu-latest
environment:
name: pypi
Expand Down
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ producing a package that imports and cannot read anything.
Compatible with all VTK dataset types. Uses
`PyVista <https://docs.pyvista.org/>`__ under the hood.

The VTK binding is supplied by PyVista. Both stock VTK and PyVista's
``cvista`` backend are supported; ``pyvista-zstd`` does not require the stock
``vtk`` distribution itself. For cvista, install a PyVista version with
backend support:

.. code:: bash

pip install 'pyvista[cvista]>=0.49' pyvista-zstd

.. code:: py

import pyvista_zstd
Expand Down
35 changes: 30 additions & 5 deletions cpp/tools/pvzstd_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,43 @@
// spec one per commit; each line is
// name <TAB> dtype <TAB> dtype_name <TAB> shape_csv <TAB> raw_path
//
// Each commit reports "commit <i> <seconds> <bytes_read>" to stderr. The byte
// Each commit reports "commit <i> <cpu_seconds> <bytes_read>" to stderr. The byte
// count is this process's rchar delta (-1 where unavailable): a wrongly re-read
// container is served from page cache and too cheap to catch on wall time.

#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif

#include "pvzstd/pvzstd.h"

namespace {

double ProcessCpuSeconds() {
#if defined(_WIN32)
FILETIME created, exited, kernel, user;
if (!GetProcessTimes(GetCurrentProcess(), &created, &exited, &kernel, &user)) return -1;
const uint64_t kernel_ticks =
(static_cast<uint64_t>(kernel.dwHighDateTime) << 32) | kernel.dwLowDateTime;
const uint64_t user_ticks =
(static_cast<uint64_t>(user.dwHighDateTime) << 32) | user.dwLowDateTime;
return static_cast<double>(kernel_ticks + user_ticks) * 1e-7;
#else
const std::clock_t ticks = std::clock();
return ticks == static_cast<std::clock_t>(-1) ? -1 : static_cast<double>(ticks) / CLOCKS_PER_SEC;
#endif
}

struct Spec {
std::string name;
std::string dtype;
Expand Down Expand Up @@ -212,12 +232,17 @@ int main(int argc, char **argv) {
}
// Around the commit, not the process, whose start-up would swamp it.
const long long read0 = BytesRead();
const auto t0 = std::chrono::steady_clock::now();
const double t0 = ProcessCpuSeconds();
st = pvzstd_stream_append(stream, arrays.data(), arrays.size(),
static_cast<pvzstd_shuffle_mode>(shuffle_code));
const auto t1 = std::chrono::steady_clock::now();
const double t1 = ProcessCpuSeconds();
const long long read1 = BytesRead();
std::fprintf(stderr, "commit %d %.6f %lld\n", c, std::chrono::duration<double>(t1 - t0).count(),
if (t0 < 0 || t1 < t0) {
std::cerr << "process CPU time is unavailable\n";
pvzstd_stream_free(stream);
return 1;
}
std::fprintf(stderr, "commit %d %.9f %lld\n", c, t1 - t0,
(read0 < 0 || read1 < 0) ? -1 : read1 - read0);
if (st != PVZSTD_OK) {
std::cerr << "pvzstd_stream_append: " << pvzstd_status_message(st) << "\n";
Expand Down
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ classifiers = [
]
# The core links zstd itself; nothing under ``src/`` imports the ``zstandard``
# Python bindings, so they are a test dependency, not a runtime one.
dependencies = ["pyvista>=0.45.0", "vtk>=9.3.1"]
# PyVista supplies the active VTK binding. A direct vtk requirement would force
# the stock wheel into applications that use cvista instead.
dependencies = ["pyvista>=0.45.0"]
description = "VTK zstandard compression library."
dynamic = ["version"]
license = "MIT"
Expand Down Expand Up @@ -60,6 +62,9 @@ tests = [
[tool.setuptools.packages.find]
where = ["src"]

[tool.uv]
exclude-dependencies = ["vtk"]

[tool.setuptools_scm]
fallback_version = "0.0.0.dev0"
git_describe_command = "git describe --dirty --tags --long --match v*"
Expand Down
3 changes: 1 addition & 2 deletions tests/conformance/test_cpp_reader_roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import numpy as np
import pytest
import pyvista as pv
import vtk

import pyvista_zstd as pz
from pyvista_zstd import _capi
Expand Down Expand Up @@ -81,7 +80,7 @@ def _mixed() -> pv.DataSet:
dtype=float,
)
cells = np.hstack([[HEX, 0, 1, 2, 3, 4, 5, 6, 7], [TET, 1, 8, 9, 10]])
ctypes_ = np.array([vtk.VTK_HEXAHEDRON, vtk.VTK_TETRA], dtype=np.uint8)
ctypes_ = np.array([pv.CellType.HEXAHEDRON, pv.CellType.TETRA], dtype=np.uint8)
ds = pv.UnstructuredGrid(cells, ctypes_, pts)
ds.point_data["p_f64"] = np.arange(ds.n_points, dtype=np.float64)
return ds
Expand Down
14 changes: 7 additions & 7 deletions tests/conformance/test_stream_parity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Streaming commits against the append path.

Both arms end at the same C entry points, so agreement pins the streaming
driver rather than the format. The timing arms below bound the FLAT arm
only: a bound on the control measures the machine, not the code.
driver rather than the format. CPU time measures work in both arms without
charging scheduler waits to the streaming implementation.
"""

from __future__ import annotations
Expand Down Expand Up @@ -92,7 +92,7 @@ def _write_spec(tmp_path: Path, tag: str, arrays: dict[str, np.ndarray]) -> str:


def _run_stream(container: Path, specs: list[str], *, shuffle) -> list[tuple[float, int]]:
"""Run the stream, returning (seconds, bytes_read) per commit from stderr."""
"""Run the stream, returning (CPU seconds, bytes_read) per commit from stderr."""
result = subprocess.run( # noqa: S603
[STREAM, str(container), SHUFFLE_CODE[shuffle], *specs],
capture_output=True,
Expand Down Expand Up @@ -181,8 +181,8 @@ def test_stream_cost_does_not_grow_with_what_is_already_committed(tmp_path) -> N
"""
Streaming cost does not grow with what is already committed.

Asserted against a control measured in the same run; absolute numbers are
not stable across machines. The container must keep growing, or the
Asserted against CPU time for a control measured in the same run; scheduler
waits do not contribute to either arm. The container must keep growing, or the
copying path never repeats work and this measures nothing -- checked on
file size, which is arithmetic, not on the control's wall time.
"""
Expand All @@ -198,9 +198,9 @@ def test_stream_cost_does_not_grow_with_what_is_already_committed(tmp_path) -> N
control_times = []
control_sizes = []
for i in range(N_COMMITS):
start = time.perf_counter()
start = time.process_time()
pz.append_arrays(control, {f"step_{i}_u": block}, shuffle=False)
control_times.append(time.perf_counter() - start)
control_times.append(time.process_time() - start)
control_sizes.append(control.stat().st_size)

streamed = tmp_path / "streamed.pv"
Expand Down
3 changes: 1 addition & 2 deletions tests/conformance/test_writer_parity.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import pytest
import pyvista as pv
import ref_reader
import vtk

import pyvista_zstd as pz

Expand Down Expand Up @@ -82,7 +81,7 @@ def _mixed() -> pv.DataSet:
dtype=float,
)
cells = np.hstack([[HEX, 0, 1, 2, 3, 4, 5, 6, 7], [TET, 1, 8, 9, 10]])
ctypes = np.array([vtk.VTK_HEXAHEDRON, vtk.VTK_TETRA], dtype=np.uint8)
ctypes = np.array([pv.CellType.HEXAHEDRON, pv.CellType.TETRA], dtype=np.uint8)
return pv.UnstructuredGrid(cells, ctypes, pts)


Expand Down
9 changes: 7 additions & 2 deletions tests/test_pyvista_zstd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ def test_esgrid_deselected_blocking_arrays(tmp_path: Path) -> None:

@pytest.mark.parametrize("id_type_width", [True, False])
def test_vtk_esgrid_needs_id_type_cell_storage(id_type_width: bool) -> None: # noqa: FBT001
"""Pin VTK issue 20126, why the reader widens ESG cells; failing here means VTK fixed it."""
"""Pin stock VTK issue 20126 while checking cvista's corrected connectivity."""
esgrid = _make_esgrid("cast")
cells = impl.vtkCellArray()
cells.DeepCopy(esgrid.GetCells())
Expand All @@ -1346,7 +1346,12 @@ def test_vtk_esgrid_needs_id_type_cell_storage(id_type_width: bool) -> None: #

# Every cell of this grid has a neighbour, so correct flags are all nonzero.
flags = grid.compute_connectivity().cell_data["ConnectivityFlags"]
assert flags.all() if id_type_width else not flags.any()
uses_cvista = hasattr(pv, "vtk_backend") and pv.vtk_backend() == "cvista"
if id_type_width or uses_cvista:
assert flags.all()
np.testing.assert_array_equal(flags, esgrid.compute_connectivity().cell_data["ConnectivityFlags"])
else:
assert not flags.any()


# DataSetMetadata fields pyvista-zstd 0.5.0 accepts; it rejects any other key.
Expand Down
Loading