Skip to content
Merged
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
17 changes: 15 additions & 2 deletions qdp/qdp-python/qumat_qdp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def __init__(self, device_id: int = 0) -> None:
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.
Expand Down Expand Up @@ -151,6 +152,18 @@ def backend(self, name: str) -> 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(
Expand Down Expand Up @@ -183,7 +196,7 @@ def _run_throughput_rust(self) -> ThroughputResult:
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
Expand All @@ -199,7 +212,7 @@ def _run_latency_rust(self) -> LatencyResult:
encoding_method=self._encoding_method,
warmup_batches=self._warmup_batches,
seed=None,
dtype="f32",
dtype=self._dtype,
)
return LatencyResult(
duration_sec=duration_sec,
Expand Down
Loading