[Feature] PyO3 bindings for Preprocessor

Open
#1,431 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
76/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python, rust
Domain
api

Research direction

Start with qdp-core/src/preprocessing.rs to review the existing Preprocessor methods, then inspect the qdp-python crate's PyO3 entry points and current error mapping. Bind the four existing f64 methods without changing preprocessing algorithms, map validation failures to Python exceptions while preserving their messages, and verify the exposed Python calls and error behavior.

Written by the indexing model from the issue text.

Description

bug docs enhancement question
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.

Dominant language
Rust
Stars
2.3k
Forks
1k
Avg merge
2d 20h
Merged PRs (30d)
7

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/mahout

All issues in apache/mahout

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.