Skip to content

[Feature] PyO3 bindings for Preprocessor #1431

Description

@0lai0

What

Expose the existing Rust Preprocessor (qdp-core/src/preprocessing.rs) to Python via PyO3, so Python users can call its validation and L2-norm helpers directly instead of reimplementing them.

Why

Preprocessor already exists and is tested in Rust, but it is invisible from Python — qumat_qdp users currently have no supported way to validate or compute norms on input before handing it to the encoder, so they either skip validation or duplicate the logic in Python. Binding the existing API closes that gap with no new core logic.

How

  • Add a PyO3 wrapper (in the qdp-python crate) exposing Preprocessor and its four current methods:
    • validate_input(host_data: &[f64], num_qubits: usize) -> Result<()>
    • calculate_l2_norm(host_data: &[f64]) -> Result<f64>
    • validate_batch(...)
    • calculate_batch_l2_norms(...) -> Result<Vec<f64>>
  • Bind f64 — the current Rust API is f64-only. Leave any f32 variant as a follow-up rather than widening the core here.
  • Map Rust validation errors to Python exceptions (e.g. ValueError) preserving the original message, so a failed validate_input raises cleanly in Python.
  • Keep method names and signatures aligned with the Rust API to minimize surprise; defer public re-export and docs to C2.

Note: Preprocessor currently has no normalize/standardize method (its struct doc mentions "normalization" aspirationally, but only the four methods above exist). This issue binds what exists; do not invent normalize/standardize here.

Out of scope: Public-API export from __init__.py and docstrings (C2), f32 variants, any change to the preprocessing algorithms, adding new normalize/standardize methods.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions