Skip to content

Commit eba4511

Browse files
[v0.5-stable] update qdp readme to make it up-to-date (#980) (#985)
(cherry picked from commit 15037cf) Co-authored-by: Ryan Huang <hcr@apache.org>
1 parent b218f86 commit eba4511

File tree

1 file changed

+47
-49
lines changed

1 file changed

+47
-49
lines changed

qdp/qdp-python/README.md

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,66 @@
1-
# qdp-python
1+
# qumat-qdp
22

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.
412

513
## Usage
614

715
```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
1218

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)
1521

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")
1924

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
2328
```
2429

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
3531

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 |
3738

38-
- `"amplitude"` - Amplitude encoding
39-
- `"angle"` - Angle encoding
40-
- `"basis"` - Basis encoding
39+
## Input Sources
4140

42-
## File format support
41+
```python
42+
# Python list
43+
qtensor = engine.encode([1.0, 2.0, 3.0, 4.0], 2, "amplitude")
4344

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")
4947

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")
5150

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")
6056
```
6157

62-
2. Rebuild: `uv run maturin develop`
58+
## Links
6359

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

Comments
 (0)