diff --git a/braket/README.md b/braket/README.md new file mode 100644 index 0000000..d8e57fb --- /dev/null +++ b/braket/README.md @@ -0,0 +1,3 @@ +# Braket + +[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/ionq-samples/getting-started/blob/main/braket/main.ipynb) diff --git a/braket/main.ipynb b/braket/main.ipynb new file mode 100644 index 0000000..63a4c4a --- /dev/null +++ b/braket/main.ipynb @@ -0,0 +1,75 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "151d6c64", + "metadata": {}, + "outputs": [], + "source": [ + "%%capture\n", + "\n", + "!pip install amazon-braket-sdk" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ff988bb3", + "metadata": {}, + "outputs": [], + "source": [ + "from braket.circuits import Circuit\n", + "from braket.aws import AwsDevice\n", + "\n", + "device = AwsDevice(\"arn:aws:braket:::device/qpu/ionq/ionQdevice\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b7dd4b92", + "metadata": {}, + "outputs": [], + "source": [ + "qc = Circuit()\n", + "qc.h(0)\n", + "qc.cnot(0, 1)\n", + "\n", + "print(qc)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4e02b63e", + "metadata": {}, + "outputs": [], + "source": [ + "task = device.run(bell, shots=100)\n", + "print(task.result().measurement_counts)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/pytket/README.md b/pytket/README.md new file mode 100644 index 0000000..881e5ea --- /dev/null +++ b/pytket/README.md @@ -0,0 +1,3 @@ +# Pytket + +[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/ionq-samples/getting-started/blob/main/pytket/main.ipynb) diff --git a/pytket/main.ipynb b/pytket/main.ipynb new file mode 100644 index 0000000..f819a77 --- /dev/null +++ b/pytket/main.ipynb @@ -0,0 +1,100 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "id": "151d6c64", + "metadata": {}, + "outputs": [], + "source": [ + "%%capture\n", + "\n", + "!pip install pytket pytket-ionq" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "f3042105", + "metadata": {}, + "outputs": [], + "source": [ + "from pytket import Circuit\n", + "from pytket.extensions.ionq import IonQBackend\n", + "\n", + "import os\n", + "from getpass import getpass\n", + "\n", + "# Get your API key from https://cloud.ionq.com/settings/keys\n", + "api_key = os.getenv('IONQ_API_KEY') or getpass('Enter your IonQ API key: ')\n", + "backend = IonQBackend(api_key=api_key, device_name=\"simulator\")" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "bd2c2829", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[H q[0]; CX q[0], q[1]; Measure q[0] --> c[0]; Measure q[1] --> c[1]; ]" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "qc = Circuit(2, 2)\n", + "qc.H(0)\n", + "qc.CX(0, 1)\n", + "qc.measure_all()" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "6aa9658d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Counter({(0, 0): 55, (1, 1): 45})\n" + ] + } + ], + "source": [ + "backend.get_compiled_circuit(qc)\n", + "handle = backend.process_circuit(qc, 100)\n", + "counts = backend.get_result(handle).get_counts()\n", + "print(counts)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/qsharp/Operation.qs b/qsharp/Operation.qs new file mode 100644 index 0000000..af8a8bd --- /dev/null +++ b/qsharp/Operation.qs @@ -0,0 +1,10 @@ +namespace Bell { + open Microsoft.Quantum.Intrinsic; + open Microsoft.Quantum.Measurement; + operation MeasureEntanglement() : Result[] { + use qubits = Qubit[2]; + H(qubits[0]); + CNOT(qubits[0], qubits[1]); + return MultiM(qubits); + } +} \ No newline at end of file diff --git a/qsharp/README.md b/qsharp/README.md new file mode 100644 index 0000000..dc2e60e --- /dev/null +++ b/qsharp/README.md @@ -0,0 +1,3 @@ +# Q# + +[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/ionq-samples/getting-started/blob/main/qsharp/main.ipynb) diff --git a/qsharp/main.ipynb b/qsharp/main.ipynb new file mode 100644 index 0000000..97ba70b --- /dev/null +++ b/qsharp/main.ipynb @@ -0,0 +1,66 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "151d6c64", + "metadata": {}, + "outputs": [], + "source": [ + "%%capture\n", + "\n", + "!pip install qsharp" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "f3042105", + "metadata": {}, + "outputs": [], + "source": [ + "import qsharp\n", + "import qsharp.azure\n", + "from Bell import MeasureEntanglement\n", + "\n", + "qsharp.azure.connect(\n", + " resourceId=\"the name of your quantum resource\",\n", + " location=\"East US\",\n", + ")\n", + "qsharp.azure.target(\"ionq.harmony\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "19020254", + "metadata": {}, + "outputs": [], + "source": [ + "result = qsharp.azure.execute(MeasureEntanglement, shots=100, jobName=\"Bell\")\n", + "print(result)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/requirements.txt b/requirements.txt index dadf6d4..eeacf6f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,6 +6,11 @@ pennylane pennylane-ionq projectq cuda-quantum +amazon-braket-sdk +qsharp +pytket +pytket-ionq +xacc matplotlib pylatexenc jupyter diff --git a/xacc/README.md b/xacc/README.md new file mode 100644 index 0000000..cedb3cf --- /dev/null +++ b/xacc/README.md @@ -0,0 +1,3 @@ +# XACC + +[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/ionq-samples/getting-started/blob/main/xacc/main.ipynb) diff --git a/xacc/main.ipynb b/xacc/main.ipynb new file mode 100644 index 0000000..85eb38f --- /dev/null +++ b/xacc/main.ipynb @@ -0,0 +1,77 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "151d6c64", + "metadata": {}, + "outputs": [], + "source": [ + "%%capture\n", + "\n", + "!pip install xacc" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f3042105", + "metadata": {}, + "outputs": [], + "source": [ + "import xacc" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "66dba273", + "metadata": {}, + "outputs": [], + "source": [ + "ionq = xacc.getAccelerator(\"ionq:simulator\")\n", + "compiler = xacc.getCompiler(\"xasm\")\n", + "ir = compiler.compile(r\"\"\"__qpu__ void bell(qbit q) {\n", + " H(q[0]);\n", + " CX(q[0], q[1]);\n", + " Measure(q[0]);\n", + " Measure(q[1]);\n", + "}\"\"\", ionq)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7a58565e", + "metadata": {}, + "outputs": [], + "source": [ + "buffer = xacc.qalloc(2)\n", + "r = ionq.execute(buffer, ir.getComposite(\"bell\"))\n", + "results = buffer.getMeasurementCounts()\n", + "print(results)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}