-
Notifications
You must be signed in to change notification settings - Fork 945
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/apache/mahout
- Loading branch information
Showing
10 changed files
with
273 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,265 @@ | ||
{ | ||
"nbformat": 4, | ||
"nbformat_minor": 0, | ||
"metadata": { | ||
"colab": { | ||
"provenance": [], | ||
"authorship_tag": "ABX9TyNiuKjMe3+6/4/lQ29BvXn0", | ||
"include_colab_link": true | ||
}, | ||
"kernelspec": { | ||
"name": "python3", | ||
"display_name": "Python 3" | ||
}, | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "view-in-github", | ||
"colab_type": "text" | ||
}, | ||
"source": [ | ||
"<a href=\"https://colab.research.google.com/github/rawkintrevo/mahout/blob/mahout-2198/examples/Simple_Example.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"!pip install git+https://github.com/apache/mahout.git@main\n" | ||
], | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"id": "lNDTZhztd2dp", | ||
"outputId": "ea3b9e41-43a8-44e7-9daf-e62e71d93143" | ||
}, | ||
"execution_count": 1, | ||
"outputs": [ | ||
{ | ||
"output_type": "stream", | ||
"name": "stdout", | ||
"text": [ | ||
"Collecting git+https://github.com/apache/mahout.git@main\n", | ||
" Cloning https://github.com/apache/mahout.git (to revision main) to /tmp/pip-req-build-hjfu63k9\n", | ||
" Running command git clone --filter=blob:none --quiet https://github.com/apache/mahout.git /tmp/pip-req-build-hjfu63k9\n", | ||
" Resolved https://github.com/apache/mahout.git to commit 9ca93e01bf6ad9e87ef302917c740412ed6428b2\n", | ||
" Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", | ||
" Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n", | ||
" Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", | ||
"Collecting qiskit<0.46.0,>=0.45.1 (from qumat==0.0.1)\n", | ||
" Downloading qiskit-0.45.3-py3-none-any.whl (9.6 kB)\n", | ||
"Collecting qiskit-aer<0.14.0,>=0.13.2 (from qumat==0.0.1)\n", | ||
" Downloading qiskit_aer-0.13.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.3 MB)\n", | ||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m12.3/12.3 MB\u001b[0m \u001b[31m26.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | ||
"\u001b[?25hCollecting qiskit-terra==0.45.3 (from qiskit<0.46.0,>=0.45.1->qumat==0.0.1)\n", | ||
" Downloading qiskit_terra-0.45.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.3 MB)\n", | ||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m6.3/6.3 MB\u001b[0m \u001b[31m47.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | ||
"\u001b[?25hCollecting rustworkx>=0.13.0 (from qiskit-terra==0.45.3->qiskit<0.46.0,>=0.45.1->qumat==0.0.1)\n", | ||
" Downloading rustworkx-0.14.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB)\n", | ||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.1/2.1 MB\u001b[0m \u001b[31m55.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | ||
"\u001b[?25hRequirement already satisfied: numpy<2,>=1.17 in /usr/local/lib/python3.10/dist-packages (from qiskit-terra==0.45.3->qiskit<0.46.0,>=0.45.1->qumat==0.0.1) (1.25.2)\n", | ||
"Collecting ply>=3.10 (from qiskit-terra==0.45.3->qiskit<0.46.0,>=0.45.1->qumat==0.0.1)\n", | ||
" Downloading ply-3.11-py2.py3-none-any.whl (49 kB)\n", | ||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.6/49.6 kB\u001b[0m \u001b[31m4.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | ||
"\u001b[?25hRequirement already satisfied: psutil>=5 in /usr/local/lib/python3.10/dist-packages (from qiskit-terra==0.45.3->qiskit<0.46.0,>=0.45.1->qumat==0.0.1) (5.9.5)\n", | ||
"Requirement already satisfied: scipy>=1.5 in /usr/local/lib/python3.10/dist-packages (from qiskit-terra==0.45.3->qiskit<0.46.0,>=0.45.1->qumat==0.0.1) (1.11.4)\n", | ||
"Requirement already satisfied: sympy>=1.3 in /usr/local/lib/python3.10/dist-packages (from qiskit-terra==0.45.3->qiskit<0.46.0,>=0.45.1->qumat==0.0.1) (1.12)\n", | ||
"Collecting dill>=0.3 (from qiskit-terra==0.45.3->qiskit<0.46.0,>=0.45.1->qumat==0.0.1)\n", | ||
" Downloading dill-0.3.8-py3-none-any.whl (116 kB)\n", | ||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m116.3/116.3 kB\u001b[0m \u001b[31m12.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | ||
"\u001b[?25hRequirement already satisfied: python-dateutil>=2.8.0 in /usr/local/lib/python3.10/dist-packages (from qiskit-terra==0.45.3->qiskit<0.46.0,>=0.45.1->qumat==0.0.1) (2.8.2)\n", | ||
"Collecting stevedore>=3.0.0 (from qiskit-terra==0.45.3->qiskit<0.46.0,>=0.45.1->qumat==0.0.1)\n", | ||
" Downloading stevedore-5.2.0-py3-none-any.whl (49 kB)\n", | ||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.7/49.7 kB\u001b[0m \u001b[31m5.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | ||
"\u001b[?25hCollecting symengine!=0.10.0,>=0.9 (from qiskit-terra==0.45.3->qiskit<0.46.0,>=0.45.1->qumat==0.0.1)\n", | ||
" Downloading symengine-0.11.0-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (39.4 MB)\n", | ||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m39.4/39.4 MB\u001b[0m \u001b[31m14.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | ||
"\u001b[?25hRequirement already satisfied: typing-extensions in /usr/local/lib/python3.10/dist-packages (from qiskit-terra==0.45.3->qiskit<0.46.0,>=0.45.1->qumat==0.0.1) (4.10.0)\n", | ||
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.0->qiskit-terra==0.45.3->qiskit<0.46.0,>=0.45.1->qumat==0.0.1) (1.16.0)\n", | ||
"Collecting pbr!=2.1.0,>=2.0.0 (from stevedore>=3.0.0->qiskit-terra==0.45.3->qiskit<0.46.0,>=0.45.1->qumat==0.0.1)\n", | ||
" Downloading pbr-6.0.0-py2.py3-none-any.whl (107 kB)\n", | ||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m107.5/107.5 kB\u001b[0m \u001b[31m10.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | ||
"\u001b[?25hRequirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.10/dist-packages (from sympy>=1.3->qiskit-terra==0.45.3->qiskit<0.46.0,>=0.45.1->qumat==0.0.1) (1.3.0)\n", | ||
"Building wheels for collected packages: qumat\n", | ||
" Building wheel for qumat (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", | ||
" Created wheel for qumat: filename=qumat-0.0.1-py3-none-any.whl size=9957 sha256=a7ffe71a3aecd914a49905829bec86f9691eafac6af8500a110b1ee5257d4bbd\n", | ||
" Stored in directory: /tmp/pip-ephem-wheel-cache-fy8zfa_b/wheels/5a/92/df/8057f1db19a8a1d231017beafd367b718fa3be68bf0ef9cb70\n", | ||
"Successfully built qumat\n", | ||
"Installing collected packages: ply, symengine, rustworkx, pbr, dill, stevedore, qiskit-terra, qiskit, qiskit-aer, qumat\n", | ||
"Successfully installed dill-0.3.8 pbr-6.0.0 ply-3.11 qiskit-0.45.3 qiskit-aer-0.13.3 qiskit-terra-0.45.3 qumat-0.0.1 rustworkx-0.14.1 stevedore-5.2.0 symengine-0.11.0\n" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": { | ||
"id": "M3O-QEdbd1Y2" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# Import the QuantumComputer class from your package\n", | ||
"from qumat.qumat import QuMat\n", | ||
"\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"# Create an instance of QuantumComputer with a specific backend configuration\n", | ||
"backend_config = {\n", | ||
" 'backend_name': 'qiskit_simulator', # Replace with the actual backend you want to use\n", | ||
" 'backend_options': {\n", | ||
" 'simulator_type': 'aer_simulator',\n", | ||
" 'shots': 1024 # Number of shots for measurement\n", | ||
" }\n", | ||
"}\n", | ||
"qumat = QuMat(backend_config)\n", | ||
"\n", | ||
"# Create a quantum circuit\n", | ||
"qumat.create_empty_circuit(num_qubits=2)\n", | ||
"\n", | ||
"# Apply quantum gates to the circuit\n", | ||
"qumat.apply_hadamard_gate(qubit_index=0)\n", | ||
"qumat.apply_cnot_gate(control_qubit_index=0, target_qubit_index=1)\n", | ||
"qumat.apply_pauli_x_gate(qubit_index=0)\n" | ||
], | ||
"metadata": { | ||
"id": "56zR0RS4eNuY" | ||
}, | ||
"execution_count": 9, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"\n", | ||
"# Measure the quantum circuit\n", | ||
"measurement_results = qumat.circuit.measure_all()" | ||
], | ||
"metadata": { | ||
"id": "1FaC7deljh5I" | ||
}, | ||
"execution_count": 10, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"# Display the measurement results\n", | ||
"print(\"Measurement Results:\", measurement_results)" | ||
], | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"id": "YEOzZJzXjPsU", | ||
"outputId": "6ffd7923-f93e-4858-a280-8f40a79ab468" | ||
}, | ||
"execution_count": 14, | ||
"outputs": [ | ||
{ | ||
"output_type": "stream", | ||
"name": "stdout", | ||
"text": [ | ||
"Measurement Results: None\n" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"#qiskit object method\n", | ||
"qumat.circuit.draw()" | ||
], | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/", | ||
"height": 156 | ||
}, | ||
"id": "Mz8gUmf3etu7", | ||
"outputId": "917d37bb-10bc-443b-9b7d-ff83ee8e16ac" | ||
}, | ||
"execution_count": 15, | ||
"outputs": [ | ||
{ | ||
"output_type": "execute_result", | ||
"data": { | ||
"text/plain": [ | ||
" ┌───┐ ┌───┐ ░ ┌─┐ ░ ┌─┐ \n", | ||
" q_0: ┤ H ├──■──┤ X ├─░─┤M├────░─┤M├───\n", | ||
" └───┘┌─┴─┐└───┘ ░ └╥┘┌─┐ ░ └╥┘┌─┐\n", | ||
" q_1: ─────┤ X ├──────░──╫─┤M├─░──╫─┤M├\n", | ||
" └───┘ ░ ║ └╥┘ ░ ║ └╥┘\n", | ||
" meas: 2/═══════════════════╩══╩═════╬══╬═\n", | ||
" 0 1 ║ ║ \n", | ||
"meas0: 2/════════════════════════════╩══╩═\n", | ||
" 0 1 " | ||
], | ||
"text/html": [ | ||
"<pre style=\"word-wrap: normal;white-space: pre;background: #fff0;line-height: 1.1;font-family: "Courier New",Courier,monospace\"> ┌───┐ ┌───┐ ░ ┌─┐ ░ ┌─┐ \n", | ||
" q_0: ┤ H ├──■──┤ X ├─░─┤M├────░─┤M├───\n", | ||
" └───┘┌─┴─┐└───┘ ░ └╥┘┌─┐ ░ └╥┘┌─┐\n", | ||
" q_1: ─────┤ X ├──────░──╫─┤M├─░──╫─┤M├\n", | ||
" └───┘ ░ ║ └╥┘ ░ ║ └╥┘\n", | ||
" meas: 2/═══════════════════╩══╩═════╬══╬═\n", | ||
" 0 1 ║ ║ \n", | ||
"meas0: 2/════════════════════════════╩══╩═\n", | ||
" 0 1 </pre>" | ||
] | ||
}, | ||
"metadata": {}, | ||
"execution_count": 15 | ||
} | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"# Also requires qiskit\n", | ||
"from qiskit import execute\n", | ||
"# needs to be added as a method...\n", | ||
"job = execute(qumat.circuit, qumat.backend, shots=1024) # Simulate the circuit 1024 times\n", | ||
"\n", | ||
"\n", | ||
"result = job.result()\n", | ||
"counts = result.get_counts()\n", | ||
"\n", | ||
"print(\"Measurement Results:\", counts)" | ||
], | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"id": "HrhrQVIEjrzz", | ||
"outputId": "25c993a7-b894-4a9b-96a3-7fe9aead9422" | ||
}, | ||
"execution_count": 16, | ||
"outputs": [ | ||
{ | ||
"output_type": "stream", | ||
"name": "stdout", | ||
"text": [ | ||
"Measurement Results: {'10 10': 503, '01 01': 521}\n" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [], | ||
"metadata": { | ||
"id": "jVBuEr2EleH1" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.