|
1 | | -# qdp-python |
| 1 | +# qumat-qdp |
2 | 2 |
|
3 | | -PyO3 Python bindings for Apache Mahout QDP. |
| 3 | +GPU-accelerated quantum state encoding for [Apache Mahout Qumat](https://github.com/apache/mahout). |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +pip install qumat[qdp] |
| 9 | +``` |
| 10 | + |
| 11 | +Requires CUDA-capable GPU. |
4 | 12 |
|
5 | 13 | ## Usage |
6 | 14 |
|
7 | 15 | ```python |
8 | | -from _qdp import QdpEngine |
9 | | - |
10 | | -# Initialize on GPU 0 (defaults to float32 output) |
11 | | -engine = QdpEngine(0) |
| 16 | +import qumat.qdp as qdp |
| 17 | +import torch |
12 | 18 |
|
13 | | -# Optional: request float64 output if you need higher precision |
14 | | -# engine = QdpEngine(0, precision="float64") |
| 19 | +# Initialize engine on GPU 0 |
| 20 | +engine = qdp.QdpEngine(device_id=0) |
15 | 21 |
|
16 | | -# Encode data from Python list |
17 | | -data = [0.5, 0.5, 0.5, 0.5] |
18 | | -qtensor = engine.encode(data, num_qubits=2, encoding_method="amplitude") |
| 22 | +# Encode data into quantum state |
| 23 | +qtensor = engine.encode([1.0, 2.0, 3.0, 4.0], num_qubits=2, encoding_method="amplitude") |
19 | 24 |
|
20 | | -# Or encode from file formats |
21 | | -tensor_parquet = engine.encode("data.parquet", 10, "amplitude") |
22 | | -tensor_arrow = engine.encode("data.arrow", 10, "amplitude") |
| 25 | +# Zero-copy transfer to PyTorch |
| 26 | +tensor = torch.from_dlpack(qtensor) |
| 27 | +print(tensor) # Complex tensor on CUDA |
23 | 28 | ``` |
24 | 29 |
|
25 | | -## Build from source |
26 | | -```bash |
27 | | -# add a uv python 3.11 environment |
28 | | -uv venv -p python3.11 |
29 | | -source .venv/bin/activate |
30 | | -``` |
31 | | -```bash |
32 | | -uv sync --group dev |
33 | | -uv run maturin develop |
34 | | -``` |
| 30 | +## Encoding Methods |
35 | 31 |
|
36 | | -## Encoding methods |
| 32 | +| Method | Description | |
| 33 | +|--------|-------------| |
| 34 | +| `amplitude` | Normalize input as quantum amplitudes | |
| 35 | +| `angle` | Map values to rotation angles (one per qubit) | |
| 36 | +| `basis` | Encode integer as computational basis state | |
| 37 | +| `iqp` | IQP-style encoding with entanglement | |
37 | 38 |
|
38 | | -- `"amplitude"` - Amplitude encoding |
39 | | -- `"angle"` - Angle encoding |
40 | | -- `"basis"` - Basis encoding |
| 39 | +## Input Sources |
41 | 40 |
|
42 | | -## File format support |
| 41 | +```python |
| 42 | +# Python list |
| 43 | +qtensor = engine.encode([1.0, 2.0, 3.0, 4.0], 2, "amplitude") |
43 | 44 |
|
44 | | -- **Parquet** - `.parquet` files |
45 | | -- **Arrow IPC** - `.arrow` or `.feather` files |
46 | | -- **NumPy** - `.npy` files |
47 | | -- **PyTorch** - `.pt` or `.pth` files |
48 | | -- **TensorFlow** - `.pb` files (TensorProto format) |
| 45 | +# NumPy array |
| 46 | +qtensor = engine.encode(np.array([[1, 2, 3, 4], [4, 3, 2, 1]]), 2, "amplitude") |
49 | 47 |
|
50 | | -## Adding new bindings |
| 48 | +# PyTorch tensor (CPU or CUDA) |
| 49 | +qtensor = engine.encode(torch.tensor([1.0, 2.0, 3.0, 4.0]), 2, "amplitude") |
51 | 50 |
|
52 | | -1. Add method to `#[pymethods]` in `src/lib.rs`: |
53 | | -```rust |
54 | | -#[pymethods] |
55 | | -impl QdpEngine { |
56 | | - fn my_method(&self, arg: f64) -> PyResult<String> { |
57 | | - Ok(format!("Result: {}", arg)) |
58 | | - } |
59 | | -} |
| 51 | +# File formats |
| 52 | +qtensor = engine.encode("data.parquet", 10, "amplitude") |
| 53 | +qtensor = engine.encode("data.arrow", 10, "amplitude") |
| 54 | +qtensor = engine.encode("data.npy", 10, "amplitude") |
| 55 | +qtensor = engine.encode("data.pt", 10, "amplitude") |
60 | 56 | ``` |
61 | 57 |
|
62 | | -2. Rebuild: `uv run maturin develop` |
| 58 | +## Links |
63 | 59 |
|
64 | | -3. Use in Python: |
65 | | -```python |
66 | | -engine = QdpEngine(0) |
67 | | -result = engine.my_method(42.0) |
68 | | -``` |
| 60 | +- [Documentation](https://mahout.apache.org/) |
| 61 | +- [GitHub](https://github.com/apache/mahout) |
| 62 | +- [Qumat Package](https://pypi.org/project/qumat/) |
| 63 | + |
| 64 | +## License |
| 65 | + |
| 66 | +Apache License 2.0 |
0 commit comments