From 41643f9d5f286d3963129ef1740f72134db5c12f Mon Sep 17 00:00:00 2001 From: Cheyu Wu Date: Thu, 1 Jan 2026 18:39:07 +0800 Subject: [PATCH 1/5] feat: [QDP] PyTorch Tensor Detection and CPU Path Signed-off-by: Cheyu Wu --- qdp/qdp-python/src/lib.rs | 65 +++++++++++++++++++++++++++ qdp/qdp-python/tests/test_bindings.py | 42 +++++++++++++++++ 2 files changed, 107 insertions(+) diff --git a/qdp/qdp-python/src/lib.rs b/qdp/qdp-python/src/lib.rs index df68be1bc1..227d60cd3f 100644 --- a/qdp/qdp-python/src/lib.rs +++ b/qdp/qdp-python/src/lib.rs @@ -139,6 +139,37 @@ impl Drop for QuantumTensor { unsafe impl Send for QuantumTensor {} unsafe impl Sync for QuantumTensor {} +/// Helper to detect PyTorch tensor +fn is_pytorch_tensor(obj: &Bound<'_, PyAny>) -> PyResult { + let type_obj = obj.get_type(); + let name = type_obj.name()?; + if name != "Tensor" { + return Ok(false); + } + let module = type_obj.module()?; + let module_name = module.to_str()?; + Ok(module_name == "torch") +} + +/// Helper to validate tensor +fn validate_tensor(tensor: &Bound<'_, PyAny>) -> PyResult<()> { + if !is_pytorch_tensor(tensor)? { + return Err(PyRuntimeError::new_err("Object is not a PyTorch Tensor")); + } + + let device = tensor.getattr("device")?; + let device_type: String = device.getattr("type")?.extract()?; + + if device_type != "cpu" { + return Err(PyRuntimeError::new_err(format!( + "Only CPU tensors are currently supported for this path. Got device: {}", + device_type + ))); + } + + Ok(()) +} + /// PyO3 wrapper for QdpEngine /// /// Provides Python bindings for GPU-accelerated quantum state encoding. @@ -215,6 +246,40 @@ impl QdpEngine { }) } + /// Encode from PyTorch Tensor + /// + /// Args: + /// tensor: PyTorch Tensor (must be on CPU) + /// num_qubits: Number of qubits for encoding + /// encoding_method: Encoding strategy + /// + /// Returns: + /// QuantumTensor: DLPack-compatible tensor + fn encode_tensor( + &self, + tensor: &Bound<'_, PyAny>, + num_qubits: usize, + encoding_method: &str, + ) -> PyResult { + validate_tensor(tensor)?; + + // Convert to flat list for encoding + let data: Vec = tensor + .call_method0("flatten")? + .call_method0("tolist")? + .extract()?; + + let ptr = self + .engine + .encode(&data, num_qubits, encoding_method) + .map_err(|e| PyRuntimeError::new_err(format!("Encoding failed: {}", e)))?; + + Ok(QuantumTensor { + ptr, + consumed: false, + }) + } + /// Encode from Parquet file /// /// Args: diff --git a/qdp/qdp-python/tests/test_bindings.py b/qdp/qdp-python/tests/test_bindings.py index 7808abc8c9..b6cefc83fe 100644 --- a/qdp/qdp-python/tests/test_bindings.py +++ b/qdp/qdp-python/tests/test_bindings.py @@ -143,3 +143,45 @@ def test_pytorch_precision_float64(): torch_tensor = torch.from_dlpack(qtensor) assert torch_tensor.dtype == torch.complex128 + +@pytest.mark.gpu +def test_encode_tensor_cpu(): + """Test encoding from CPU PyTorch tensor.""" + pytest.importorskip("torch") + import torch + from mahout_qdp import QdpEngine + + if not torch.cuda.is_available(): + pytest.skip("GPU required for QdpEngine") + + engine = QdpEngine(0) + data = torch.tensor([1.0, 2.0, 3.0, 4.0], dtype=torch.float64) + qtensor = engine.encode_tensor(data, 2, "amplitude") + + # Verify result + torch_tensor = torch.from_dlpack(qtensor) + assert torch_tensor.is_cuda + assert torch_tensor.shape == (1, 4) + + +@pytest.mark.gpu +def test_encode_tensor_errors(): + """Test error handling for encode_tensor.""" + pytest.importorskip("torch") + import torch + from mahout_qdp import QdpEngine + + if not torch.cuda.is_available(): + pytest.skip("GPU required for QdpEngine") + + engine = QdpEngine(0) + + # Test non-tensor input + with pytest.raises(RuntimeError, match="Object is not a PyTorch Tensor"): + engine.encode_tensor([1.0, 2.0], 1, "amplitude") + + # Test GPU tensor input (should fail as only CPU is supported for this path) + if torch.cuda.is_available(): + gpu_tensor = torch.tensor([1.0, 2.0], device="cuda:0") + with pytest.raises(RuntimeError, match="Only CPU tensors are currently supported"): + engine.encode_tensor(gpu_tensor, 1, "amplitude") From 968336274c068d4b96bfa2f8e20821efbc06ed9d Mon Sep 17 00:00:00 2001 From: Cheyu Wu Date: Sat, 3 Jan 2026 21:50:22 +0800 Subject: [PATCH 2/5] style: fix linter issue Signed-off-by: Cheyu Wu --- qdp/qdp-python/tests/test_bindings.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/qdp/qdp-python/tests/test_bindings.py b/qdp/qdp-python/tests/test_bindings.py index b6cefc83fe..8b39a2fc36 100644 --- a/qdp/qdp-python/tests/test_bindings.py +++ b/qdp/qdp-python/tests/test_bindings.py @@ -77,16 +77,17 @@ def test_dlpack_device_id_non_zero(): qtensor = engine.encode(data, 2, "amplitude") device_info = qtensor.__dlpack_device__() - assert device_info == (2, device_id), ( - f"Expected (2, {device_id}) for CUDA device {device_id}" - ) + assert device_info == ( + 2, + device_id, + ), f"Expected (2, {device_id}) for CUDA device {device_id}" # Verify PyTorch integration works with non-zero device_id torch_tensor = torch.from_dlpack(qtensor) assert torch_tensor.is_cuda - assert torch_tensor.device.index == device_id, ( - f"PyTorch tensor should be on device {device_id}" - ) + assert ( + torch_tensor.device.index == device_id + ), f"PyTorch tensor should be on device {device_id}" @pytest.mark.gpu @@ -144,6 +145,7 @@ def test_pytorch_precision_float64(): torch_tensor = torch.from_dlpack(qtensor) assert torch_tensor.dtype == torch.complex128 + @pytest.mark.gpu def test_encode_tensor_cpu(): """Test encoding from CPU PyTorch tensor.""" @@ -157,7 +159,7 @@ def test_encode_tensor_cpu(): engine = QdpEngine(0) data = torch.tensor([1.0, 2.0, 3.0, 4.0], dtype=torch.float64) qtensor = engine.encode_tensor(data, 2, "amplitude") - + # Verify result torch_tensor = torch.from_dlpack(qtensor) assert torch_tensor.is_cuda @@ -170,18 +172,20 @@ def test_encode_tensor_errors(): pytest.importorskip("torch") import torch from mahout_qdp import QdpEngine - + if not torch.cuda.is_available(): pytest.skip("GPU required for QdpEngine") engine = QdpEngine(0) - + # Test non-tensor input with pytest.raises(RuntimeError, match="Object is not a PyTorch Tensor"): engine.encode_tensor([1.0, 2.0], 1, "amplitude") - + # Test GPU tensor input (should fail as only CPU is supported for this path) if torch.cuda.is_available(): gpu_tensor = torch.tensor([1.0, 2.0], device="cuda:0") - with pytest.raises(RuntimeError, match="Only CPU tensors are currently supported"): + with pytest.raises( + RuntimeError, match="Only CPU tensors are currently supported" + ): engine.encode_tensor(gpu_tensor, 1, "amplitude") From 648ccf7826f2e68d9c4960fe1f1974ab16caa03c Mon Sep 17 00:00:00 2001 From: Cheyu Wu Date: Sat, 3 Jan 2026 22:14:37 +0800 Subject: [PATCH 3/5] style: linter err Signed-off-by: Cheyu Wu --- .../notebooks/mahout_benchmark.ipynb | 367 +++++++++--------- qdp/qdp-python/tests/test_bindings.py | 6 +- 2 files changed, 187 insertions(+), 186 deletions(-) diff --git a/qdp/qdp-python/benchmark/notebooks/mahout_benchmark.ipynb b/qdp/qdp-python/benchmark/notebooks/mahout_benchmark.ipynb index 8b0786aced..3730f65d45 100644 --- a/qdp/qdp-python/benchmark/notebooks/mahout_benchmark.ipynb +++ b/qdp/qdp-python/benchmark/notebooks/mahout_benchmark.ipynb @@ -1,195 +1,196 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "pjstUzDHQHad" - }, - "source": [ - "## Install environments" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "collapsed": true, - "id": "-hkLubLFXs_8", - "outputId": "35d2da5a-3b86-4340-fe96-8329b0f63fbb" - }, - "outputs": [], - "source": [ - "!sudo apt-get update -y > /dev/null\n", - "!sudo apt-get install python3.11 python3.11-dev python3.11-distutils libpython3.11-dev > /dev/null\n", - "!sudo apt-get install python3.11-venv binfmt-support > /dev/null\n", - "!sudo apt-get install python3-pip > /dev/null\n", - "!python3 -m pip install --upgrade pip > /dev/null\n", - "!python3 -m pip install ipykernel" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "collapsed": true, - "id": "_HEpQ4F3C4gV", - "outputId": "5dc64f8a-88b5-40da-b72b-145ee2034262" - }, - "outputs": [], - "source": [ - "# 1. Install Rust Toolchain\n", - "!curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y\n", - "import os\n", - "os.environ['PATH'] += \":/root/.cargo/bin\"\n", - "\n", - "# 2. Verify Installation\n", - "!rustc --version\n", - "!cargo --version" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "collapsed": true, - "id": "ljkluVL5ES4S", - "outputId": "aced063f-5dae-471d-a1b6-3cac437fe074" - }, - "outputs": [], - "source": [ - "!curl -LsSf https://astral.sh/uv/install.sh | sh" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "9cgMNKOoEgYm", - "outputId": "1cfd677c-2858-4e75-a949-5752d61fc6bb" - }, - "outputs": [], - "source": [ - "!nvcc --version" - ] + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "pjstUzDHQHad" + }, + "source": [ + "## Install environments" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" }, - { - "cell_type": "markdown", - "metadata": { - "id": "rOja7HAaQL1h" - }, - "source": [ - "## Install Mahout" - ] + "collapsed": true, + "id": "-hkLubLFXs_8", + "outputId": "35d2da5a-3b86-4340-fe96-8329b0f63fbb" + }, + "outputs": [], + "source": [ + "!sudo apt-get update -y > /dev/null\n", + "!sudo apt-get install python3.11 python3.11-dev python3.11-distutils libpython3.11-dev > /dev/null\n", + "!sudo apt-get install python3.11-venv binfmt-support > /dev/null\n", + "!sudo apt-get install python3-pip > /dev/null\n", + "!python3 -m pip install --upgrade pip > /dev/null\n", + "!python3 -m pip install ipykernel" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "collapsed": true, - "id": "u7Skxs7lDBlq", - "outputId": "8ef09700-8551-4d19-cb9e-1ba05f2641c5" - }, - "outputs": [], - "source": [ - "# 1. Clone the repository\n", - "!git clone -b dev-qdp https://github.com/apache/mahout.git\n", - "\n", - "# 2. Install Python Dependencies\n", - "# We use the requirements file provided in the benchmark folder\n", - "%cd /content/mahout/qdp/qdp-python\n", - "!uv venv -p python3.11\n", - "\n", - "!uv sync --group dev\n", - "!uv sync --group benchmark" - ] + "collapsed": true, + "id": "_HEpQ4F3C4gV", + "outputId": "5dc64f8a-88b5-40da-b72b-145ee2034262" + }, + "outputs": [], + "source": [ + "# 1. Install Rust Toolchain\n", + "!curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y\n", + "import os\n", + "\n", + "os.environ[\"PATH\"] += \":/root/.cargo/bin\"\n", + "\n", + "# 2. Verify Installation\n", + "!rustc --version\n", + "!cargo --version" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "fVUL1wnBp6X1", - "outputId": "a7f7b66c-e2f2-4e6c-b633-ffea4e7ca840" - }, - "outputs": [], - "source": [ - "!rm -rf /content/mahout/qdp/target/wheels/*\n", - "!uv run maturin build --interpreter .venv/bin/python\n", - "!uv pip install /content/mahout/qdp/target/wheels/*.whl --python .venv/bin/python --force-reinstall" - ] + "collapsed": true, + "id": "ljkluVL5ES4S", + "outputId": "aced063f-5dae-471d-a1b6-3cac437fe074" + }, + "outputs": [], + "source": [ + "!curl -LsSf https://astral.sh/uv/install.sh | sh" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "collapsed": true, - "id": "qqmfUHGsGm8m", - "outputId": "2e49ecce-1b3d-4954-bc4e-b823106b3839" - }, - "outputs": [], - "source": [ - "!uv pip install matplotlib-inline --python .venv/bin/python" - ] + "id": "9cgMNKOoEgYm", + "outputId": "1cfd677c-2858-4e75-a949-5752d61fc6bb" + }, + "outputs": [], + "source": [ + "!nvcc --version" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "rOja7HAaQL1h" + }, + "source": [ + "## Install Mahout" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" }, - { - "cell_type": "markdown", - "metadata": { - "id": "hj7sU3yJQeMj" - }, - "source": [ - "## Run Benchmarks" - ] + "collapsed": true, + "id": "u7Skxs7lDBlq", + "outputId": "8ef09700-8551-4d19-cb9e-1ba05f2641c5" + }, + "outputs": [], + "source": [ + "# 1. Clone the repository\n", + "!git clone -b dev-qdp https://github.com/apache/mahout.git\n", + "\n", + "# 2. Install Python Dependencies\n", + "# We use the requirements file provided in the benchmark folder\n", + "%cd /content/mahout/qdp/qdp-python\n", + "!uv venv -p python3.11\n", + "\n", + "!uv sync --group dev\n", + "!uv sync --group benchmark" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "iuP5BdI3E-oR", - "outputId": "e60bfe3c-145d-4962-fbbc-25f39f1ca69f" - }, - "outputs": [], - "source": [ - "!./.venv/bin/python /content/mahout/qdp/qdp-python/benchmark/benchmark_e2e.py --frameworks all --qubits 18 --samples 500" - ] - } - ], - "metadata": { - "accelerator": "GPU", + "id": "fVUL1wnBp6X1", + "outputId": "a7f7b66c-e2f2-4e6c-b633-ffea4e7ca840" + }, + "outputs": [], + "source": [ + "!rm -rf /content/mahout/qdp/target/wheels/*\n", + "!uv run maturin build --interpreter .venv/bin/python\n", + "!uv pip install /content/mahout/qdp/target/wheels/*.whl --python .venv/bin/python --force-reinstall" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { "colab": { - "gpuType": "T4", - "provenance": [] + "base_uri": "https://localhost:8080/" }, - "kernelspec": { - "display_name": "Python 3", - "name": "python3" + "collapsed": true, + "id": "qqmfUHGsGm8m", + "outputId": "2e49ecce-1b3d-4954-bc4e-b823106b3839" + }, + "outputs": [], + "source": [ + "!uv pip install matplotlib-inline --python .venv/bin/python" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "hj7sU3yJQeMj" + }, + "source": [ + "## Run Benchmarks" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" }, - "language_info": { - "name": "python" - } + "id": "iuP5BdI3E-oR", + "outputId": "e60bfe3c-145d-4962-fbbc-25f39f1ca69f" + }, + "outputs": [], + "source": [ + "!./.venv/bin/python /content/mahout/qdp/qdp-python/benchmark/benchmark_e2e.py --frameworks all --qubits 18 --samples 500" + ] + } + ], + "metadata": { + "accelerator": "GPU", + "colab": { + "gpuType": "T4", + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" }, - "nbformat": 4, - "nbformat_minor": 0 + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 } diff --git a/qdp/qdp-python/tests/test_bindings.py b/qdp/qdp-python/tests/test_bindings.py index 8b39a2fc36..ea23aceb76 100644 --- a/qdp/qdp-python/tests/test_bindings.py +++ b/qdp/qdp-python/tests/test_bindings.py @@ -85,9 +85,9 @@ def test_dlpack_device_id_non_zero(): # Verify PyTorch integration works with non-zero device_id torch_tensor = torch.from_dlpack(qtensor) assert torch_tensor.is_cuda - assert ( - torch_tensor.device.index == device_id - ), f"PyTorch tensor should be on device {device_id}" + assert torch_tensor.device.index == device_id, ( + f"PyTorch tensor should be on device {device_id}" + ) @pytest.mark.gpu From 03b698c2497d8050f4d037ae9d6fba9a0cfa97bc Mon Sep 17 00:00:00 2001 From: Cheyu Wu Date: Sat, 3 Jan 2026 22:17:50 +0800 Subject: [PATCH 4/5] doc: add comment for followup pr Signed-off-by: Cheyu Wu --- qdp/qdp-python/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/qdp/qdp-python/src/lib.rs b/qdp/qdp-python/src/lib.rs index 227d60cd3f..d06ce3d5d1 100644 --- a/qdp/qdp-python/src/lib.rs +++ b/qdp/qdp-python/src/lib.rs @@ -263,7 +263,9 @@ impl QdpEngine { ) -> PyResult { validate_tensor(tensor)?; - // Convert to flat list for encoding + // NOTE(perf): `tolist()` + `extract()` makes extra copies (Tensor -> Python list -> Vec). + // TODO: follow-up PR can use `numpy()`/buffer protocol (and possibly pinned host memory) + // to reduce copy overhead. let data: Vec = tensor .call_method0("flatten")? .call_method0("tolist")? From cfd2abb7fcd5a3eacd8d2b2ad5508ce8e70ef66b Mon Sep 17 00:00:00 2001 From: Cheyu Wu Date: Sat, 3 Jan 2026 22:34:03 +0800 Subject: [PATCH 5/5] revert: ipynb linter fix Signed-off-by: Cheyu Wu --- .../notebooks/mahout_benchmark.ipynb | 367 +++++++++--------- 1 file changed, 183 insertions(+), 184 deletions(-) diff --git a/qdp/qdp-python/benchmark/notebooks/mahout_benchmark.ipynb b/qdp/qdp-python/benchmark/notebooks/mahout_benchmark.ipynb index 3730f65d45..8b0786aced 100644 --- a/qdp/qdp-python/benchmark/notebooks/mahout_benchmark.ipynb +++ b/qdp/qdp-python/benchmark/notebooks/mahout_benchmark.ipynb @@ -1,196 +1,195 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "pjstUzDHQHad" - }, - "source": [ - "## Install environments" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "pjstUzDHQHad" + }, + "source": [ + "## Install environments" + ] }, - "collapsed": true, - "id": "-hkLubLFXs_8", - "outputId": "35d2da5a-3b86-4340-fe96-8329b0f63fbb" - }, - "outputs": [], - "source": [ - "!sudo apt-get update -y > /dev/null\n", - "!sudo apt-get install python3.11 python3.11-dev python3.11-distutils libpython3.11-dev > /dev/null\n", - "!sudo apt-get install python3.11-venv binfmt-support > /dev/null\n", - "!sudo apt-get install python3-pip > /dev/null\n", - "!python3 -m pip install --upgrade pip > /dev/null\n", - "!python3 -m pip install ipykernel" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "collapsed": true, + "id": "-hkLubLFXs_8", + "outputId": "35d2da5a-3b86-4340-fe96-8329b0f63fbb" + }, + "outputs": [], + "source": [ + "!sudo apt-get update -y > /dev/null\n", + "!sudo apt-get install python3.11 python3.11-dev python3.11-distutils libpython3.11-dev > /dev/null\n", + "!sudo apt-get install python3.11-venv binfmt-support > /dev/null\n", + "!sudo apt-get install python3-pip > /dev/null\n", + "!python3 -m pip install --upgrade pip > /dev/null\n", + "!python3 -m pip install ipykernel" + ] }, - "collapsed": true, - "id": "_HEpQ4F3C4gV", - "outputId": "5dc64f8a-88b5-40da-b72b-145ee2034262" - }, - "outputs": [], - "source": [ - "# 1. Install Rust Toolchain\n", - "!curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y\n", - "import os\n", - "\n", - "os.environ[\"PATH\"] += \":/root/.cargo/bin\"\n", - "\n", - "# 2. Verify Installation\n", - "!rustc --version\n", - "!cargo --version" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "collapsed": true, + "id": "_HEpQ4F3C4gV", + "outputId": "5dc64f8a-88b5-40da-b72b-145ee2034262" + }, + "outputs": [], + "source": [ + "# 1. Install Rust Toolchain\n", + "!curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y\n", + "import os\n", + "os.environ['PATH'] += \":/root/.cargo/bin\"\n", + "\n", + "# 2. Verify Installation\n", + "!rustc --version\n", + "!cargo --version" + ] }, - "collapsed": true, - "id": "ljkluVL5ES4S", - "outputId": "aced063f-5dae-471d-a1b6-3cac437fe074" - }, - "outputs": [], - "source": [ - "!curl -LsSf https://astral.sh/uv/install.sh | sh" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "collapsed": true, + "id": "ljkluVL5ES4S", + "outputId": "aced063f-5dae-471d-a1b6-3cac437fe074" + }, + "outputs": [], + "source": [ + "!curl -LsSf https://astral.sh/uv/install.sh | sh" + ] }, - "id": "9cgMNKOoEgYm", - "outputId": "1cfd677c-2858-4e75-a949-5752d61fc6bb" - }, - "outputs": [], - "source": [ - "!nvcc --version" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "rOja7HAaQL1h" - }, - "source": [ - "## Install Mahout" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "9cgMNKOoEgYm", + "outputId": "1cfd677c-2858-4e75-a949-5752d61fc6bb" + }, + "outputs": [], + "source": [ + "!nvcc --version" + ] }, - "collapsed": true, - "id": "u7Skxs7lDBlq", - "outputId": "8ef09700-8551-4d19-cb9e-1ba05f2641c5" - }, - "outputs": [], - "source": [ - "# 1. Clone the repository\n", - "!git clone -b dev-qdp https://github.com/apache/mahout.git\n", - "\n", - "# 2. Install Python Dependencies\n", - "# We use the requirements file provided in the benchmark folder\n", - "%cd /content/mahout/qdp/qdp-python\n", - "!uv venv -p python3.11\n", - "\n", - "!uv sync --group dev\n", - "!uv sync --group benchmark" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" + { + "cell_type": "markdown", + "metadata": { + "id": "rOja7HAaQL1h" + }, + "source": [ + "## Install Mahout" + ] }, - "id": "fVUL1wnBp6X1", - "outputId": "a7f7b66c-e2f2-4e6c-b633-ffea4e7ca840" - }, - "outputs": [], - "source": [ - "!rm -rf /content/mahout/qdp/target/wheels/*\n", - "!uv run maturin build --interpreter .venv/bin/python\n", - "!uv pip install /content/mahout/qdp/target/wheels/*.whl --python .venv/bin/python --force-reinstall" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "collapsed": true, + "id": "u7Skxs7lDBlq", + "outputId": "8ef09700-8551-4d19-cb9e-1ba05f2641c5" + }, + "outputs": [], + "source": [ + "# 1. Clone the repository\n", + "!git clone -b dev-qdp https://github.com/apache/mahout.git\n", + "\n", + "# 2. Install Python Dependencies\n", + "# We use the requirements file provided in the benchmark folder\n", + "%cd /content/mahout/qdp/qdp-python\n", + "!uv venv -p python3.11\n", + "\n", + "!uv sync --group dev\n", + "!uv sync --group benchmark" + ] }, - "collapsed": true, - "id": "qqmfUHGsGm8m", - "outputId": "2e49ecce-1b3d-4954-bc4e-b823106b3839" - }, - "outputs": [], - "source": [ - "!uv pip install matplotlib-inline --python .venv/bin/python" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "hj7sU3yJQeMj" - }, - "source": [ - "## Run Benchmarks" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "fVUL1wnBp6X1", + "outputId": "a7f7b66c-e2f2-4e6c-b633-ffea4e7ca840" + }, + "outputs": [], + "source": [ + "!rm -rf /content/mahout/qdp/target/wheels/*\n", + "!uv run maturin build --interpreter .venv/bin/python\n", + "!uv pip install /content/mahout/qdp/target/wheels/*.whl --python .venv/bin/python --force-reinstall" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "collapsed": true, + "id": "qqmfUHGsGm8m", + "outputId": "2e49ecce-1b3d-4954-bc4e-b823106b3839" + }, + "outputs": [], + "source": [ + "!uv pip install matplotlib-inline --python .venv/bin/python" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "hj7sU3yJQeMj" + }, + "source": [ + "## Run Benchmarks" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "iuP5BdI3E-oR", + "outputId": "e60bfe3c-145d-4962-fbbc-25f39f1ca69f" + }, + "outputs": [], + "source": [ + "!./.venv/bin/python /content/mahout/qdp/qdp-python/benchmark/benchmark_e2e.py --frameworks all --qubits 18 --samples 500" + ] + } + ], + "metadata": { + "accelerator": "GPU", "colab": { - "base_uri": "https://localhost:8080/" + "gpuType": "T4", + "provenance": [] }, - "id": "iuP5BdI3E-oR", - "outputId": "e60bfe3c-145d-4962-fbbc-25f39f1ca69f" - }, - "outputs": [], - "source": [ - "!./.venv/bin/python /content/mahout/qdp/qdp-python/benchmark/benchmark_e2e.py --frameworks all --qubits 18 --samples 500" - ] - } - ], - "metadata": { - "accelerator": "GPU", - "colab": { - "gpuType": "T4", - "provenance": [] - }, - "kernelspec": { - "display_name": "Python 3", - "name": "python3" + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } }, - "language_info": { - "name": "python" - } - }, - "nbformat": 4, - "nbformat_minor": 0 + "nbformat": 4, + "nbformat_minor": 0 }