This is an automated email from the ASF dual-hosted git repository.

guan404ming pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/mahout.git


The following commit(s) were added to refs/heads/main by this push:
     new cf043a253 fix(qdp): add dtype support to QdpBenchmark; default f64 
(#1366)
cf043a253 is described below

commit cf043a2535e04a369baa7730e873bf2e659375aa
Author: Ryan Huang <[email protected]>
AuthorDate: Thu Jun 4 12:34:28 2026 +0800

    fix(qdp): add dtype support to QdpBenchmark; default f64 (#1366)
    
    The Rust binding run_throughput_pipeline_py already accepts a dtype
    parameter (defaulting to 'f64') but QdpBenchmark in api.py never
    exposed it — the field was missing from __init__ and there was no
    builder method. A stale attempt at passing dtype='f32' unconditionally
    caused a TypeError on any QdpBenchmark call against a built extension
    that predated the dtype parameter.
    
    Changes:
    - Add _dtype='f64' field to QdpBenchmark.__init__
    - Add .dtype('f32'|'f64') builder method with validation and docstring
    - Pass self._dtype to both Rust call sites (_run_throughput_rust and
      _run_latency_rust); f32 activates the zero-copy batch path where the
      encoding supports it, falling back to f64 inside Rust otherwise
---
 qdp/qdp-python/qumat_qdp/api.py | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/qdp/qdp-python/qumat_qdp/api.py b/qdp/qdp-python/qumat_qdp/api.py
index a872a5547..98042b250 100644
--- a/qdp/qdp-python/qumat_qdp/api.py
+++ b/qdp/qdp-python/qumat_qdp/api.py
@@ -110,6 +110,7 @@ class QdpBenchmark:
         self._batch_size: int = 64
         self._warmup_batches: int = 0
         self._backend_name: str = "rust"
+        self._dtype: str = "f64"
 
     def qubits(self, n: int) -> QdpBenchmark:
         """Set the number of qubits for benchmarked encodings.
@@ -179,6 +180,18 @@ class QdpBenchmark:
         self._backend_name = name
         return self
 
+    def dtype(self, dtype: str) -> QdpBenchmark:
+        """Set pipeline element dtype: ``'f64'`` (default) or ``'f32'``.
+
+        ``'f32'`` activates the zero-copy float32 batch path where the encoding
+        supports it; encodings without an f32 kernel automatically fall back to
+        f64 inside the Rust pipeline.
+        """
+        if dtype not in ("f32", "f64"):
+            raise ValueError(f"dtype must be 'f32' or 'f64', got {dtype!r}")
+        self._dtype = dtype
+        return self
+
     def _validate(self) -> None:
         if self._num_qubits is None or self._total_batches is None:
             raise ValueError(
@@ -232,7 +245,7 @@ class QdpBenchmark:
             encoding_method=self._encoding_method,
             warmup_batches=self._warmup_batches,
             seed=None,
-            dtype="f32",
+            dtype=self._dtype,
         )
         return ThroughputResult(
             duration_sec=duration_sec, vectors_per_sec=vectors_per_sec
@@ -248,7 +261,7 @@ class QdpBenchmark:
             encoding_method=self._encoding_method,
             warmup_batches=self._warmup_batches,
             seed=None,
-            dtype="f32",
+            dtype=self._dtype,
         )
         return LatencyResult(
             duration_sec=duration_sec,

Reply via email to