Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for braket, pytket, qsharp, xacc #40

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions braket/README.md
Original file line number Diff line number Diff line change
@@ -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)
75 changes: 75 additions & 0 deletions braket/main.ipynb
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 3 additions & 0 deletions pytket/README.md
Original file line number Diff line number Diff line change
@@ -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)
100 changes: 100 additions & 0 deletions pytket/main.ipynb
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 10 additions & 0 deletions qsharp/Operation.qs
Original file line number Diff line number Diff line change
@@ -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);
}
}
3 changes: 3 additions & 0 deletions qsharp/README.md
Original file line number Diff line number Diff line change
@@ -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)
66 changes: 66 additions & 0 deletions qsharp/main.ipynb
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ pennylane
pennylane-ionq
projectq
cuda-quantum
amazon-braket-sdk
qsharp
pytket
pytket-ionq
xacc
matplotlib
pylatexenc
jupyter
3 changes: 3 additions & 0 deletions xacc/README.md
Original file line number Diff line number Diff line change
@@ -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)
77 changes: 77 additions & 0 deletions xacc/main.ipynb
Original file line number Diff line number Diff line change
@@ -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
}