Skip to content

Commit 6e6cf02

Browse files
committed
add support for braket, pytket, qsharp, xacc
1 parent 701a3f3 commit 6e6cf02

File tree

10 files changed

+354
-0
lines changed

10 files changed

+354
-0
lines changed

braket/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Braket
2+
3+
[![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)

braket/main.ipynb

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "151d6c64",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"%%capture\n",
11+
"\n",
12+
"!pip install amazon-braket-sdk"
13+
]
14+
},
15+
{
16+
"cell_type": "code",
17+
"execution_count": 2,
18+
"id": "ff988bb3",
19+
"metadata": {},
20+
"outputs": [],
21+
"source": [
22+
"from braket.circuits import Circuit"
23+
]
24+
},
25+
{
26+
"cell_type": "code",
27+
"execution_count": 3,
28+
"id": "b7dd4b92",
29+
"metadata": {},
30+
"outputs": [
31+
{
32+
"name": "stdout",
33+
"output_type": "stream",
34+
"text": [
35+
"T : |0|1|\n",
36+
" \n",
37+
"q0 : -H-C-\n",
38+
" | \n",
39+
"q1 : ---X-\n",
40+
"\n",
41+
"T : |0|1|\n"
42+
]
43+
}
44+
],
45+
"source": [
46+
"qc = Circuit()\n",
47+
"qc.h(0)\n",
48+
"qc.cnot(control=0, target=1)\n",
49+
"\n",
50+
"print(qc)"
51+
]
52+
},
53+
{
54+
"cell_type": "code",
55+
"execution_count": null,
56+
"id": "7c83f913",
57+
"metadata": {},
58+
"outputs": [],
59+
"source": [
60+
"device = AwsDevice(\"arn:aws:braket:::device/qpu/ionq/ionQdevice\")\n",
61+
"\n",
62+
"# Enter the name of S3 bucket you created earlier\n",
63+
"my_bucket = \"amazon-braket-Your-Bucket-Name\" # the name of the bucket\n",
64+
"my_prefix = \"Your-Folder-Name\" # the name of the folder in the bucket\n",
65+
"s3_folder = (my_bucket, my_prefix)"
66+
]
67+
},
68+
{
69+
"cell_type": "code",
70+
"execution_count": null,
71+
"id": "4e02b63e",
72+
"metadata": {},
73+
"outputs": [],
74+
"source": [
75+
"result = device.run(qc, s3_folder, shots=1000).result()\n",
76+
"\n",
77+
"# Get measurement counts\n",
78+
"counts = result.measurement_counts\n",
79+
"print(counts)"
80+
]
81+
}
82+
],
83+
"metadata": {
84+
"kernelspec": {
85+
"display_name": "Python 3 (ipykernel)",
86+
"language": "python",
87+
"name": "python3"
88+
},
89+
"language_info": {
90+
"codemirror_mode": {
91+
"name": "ipython",
92+
"version": 3
93+
},
94+
"file_extension": ".py",
95+
"mimetype": "text/x-python",
96+
"name": "python",
97+
"nbconvert_exporter": "python",
98+
"pygments_lexer": "ipython3",
99+
"version": "3.11.3"
100+
}
101+
},
102+
"nbformat": 4,
103+
"nbformat_minor": 5
104+
}

pytket/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Pytket
2+
3+
[![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)

pytket/main.ipynb

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "151d6c64",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"%%capture\n",
11+
"\n",
12+
"!pip install pytket"
13+
]
14+
},
15+
{
16+
"cell_type": "code",
17+
"execution_count": null,
18+
"id": "f3042105",
19+
"metadata": {},
20+
"outputs": [],
21+
"source": [
22+
"from pytket import Circuit\n",
23+
"from pytket.extensions.ionq import IonQBackend\n",
24+
"\n",
25+
"import os\n",
26+
"from getpass import getpass\n",
27+
"\n",
28+
"# Get your API key from https://cloud.ionq.com/settings/keys\n",
29+
"api_key = os.getenv('IONQ_API_KEY') or getpass('Enter your IonQ API key: ')\n",
30+
"backend = IonQBackend(api_key=api_key, device_name=\"qpu\")"
31+
]
32+
},
33+
{
34+
"cell_type": "code",
35+
"execution_count": null,
36+
"id": "bd2c2829",
37+
"metadata": {},
38+
"outputs": [],
39+
"source": [
40+
"qc = Circuit(2, 2)\n",
41+
"qc.H(0)\n",
42+
"qc.CX(0, 1)\n",
43+
"qc.measure_all()"
44+
]
45+
},
46+
{
47+
"cell_type": "code",
48+
"execution_count": null,
49+
"id": "6aa9658d",
50+
"metadata": {},
51+
"outputs": [],
52+
"source": [
53+
"backend.compile_circuit(qc)\n",
54+
"handle = backend.process_circuit(qc, 100)\n",
55+
"counts = backend.get_result(handle).get_counts()\n",
56+
"print(counts)"
57+
]
58+
}
59+
],
60+
"metadata": {
61+
"kernelspec": {
62+
"display_name": "Python 3 (ipykernel)",
63+
"language": "python",
64+
"name": "python3"
65+
},
66+
"language_info": {
67+
"codemirror_mode": {
68+
"name": "ipython",
69+
"version": 3
70+
},
71+
"file_extension": ".py",
72+
"mimetype": "text/x-python",
73+
"name": "python",
74+
"nbconvert_exporter": "python",
75+
"pygments_lexer": "ipython3",
76+
"version": "3.11.3"
77+
}
78+
},
79+
"nbformat": 4,
80+
"nbformat_minor": 5
81+
}

qsharp/Operation.qs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Bell {
2+
open Microsoft.Quantum.Intrinsic;
3+
open Microsoft.Quantum.Measurement;
4+
operation MeasureEntanglement() : Result[] {
5+
use qubits = Qubit[2];
6+
H(qubits[0]);
7+
CNOT(qubits[0], qubits[1]);
8+
return MultiM(qubits);
9+
}
10+
}

qsharp/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Q#
2+
3+
[![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)

qsharp/main.ipynb

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "151d6c64",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"%%capture\n",
11+
"\n",
12+
"!pip install qsharp"
13+
]
14+
},
15+
{
16+
"cell_type": "code",
17+
"execution_count": 2,
18+
"id": "f3042105",
19+
"metadata": {},
20+
"outputs": [],
21+
"source": [
22+
"import qsharp\n",
23+
"import qsharp.azure\n",
24+
"from Bell import MeasureEntanglement\n",
25+
"\n",
26+
"qsharp.azure.connect(\n",
27+
" resourceId=\"the name of your quantum resource\",\n",
28+
" location=\"East US\",\n",
29+
")\n",
30+
"qsharp.azure.target(\"ionq.qpu\")"
31+
]
32+
},
33+
{
34+
"cell_type": "code",
35+
"execution_count": null,
36+
"id": "19020254",
37+
"metadata": {},
38+
"outputs": [],
39+
"source": [
40+
"result = qsharp.azure.execute(MeasureEntanglement, shots=1000, jobName=\"Bell\")\n",
41+
"print(result)"
42+
]
43+
}
44+
],
45+
"metadata": {
46+
"kernelspec": {
47+
"display_name": "Python 3 (ipykernel)",
48+
"language": "python",
49+
"name": "python3"
50+
},
51+
"language_info": {
52+
"codemirror_mode": {
53+
"name": "ipython",
54+
"version": 3
55+
},
56+
"file_extension": ".py",
57+
"mimetype": "text/x-python",
58+
"name": "python",
59+
"nbconvert_exporter": "python",
60+
"pygments_lexer": "ipython3",
61+
"version": "3.11.3"
62+
}
63+
},
64+
"nbformat": 4,
65+
"nbformat_minor": 5
66+
}

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ pennylane
66
pennylane-ionq
77
projectq
88
cuda-quantum
9+
amazon-braket-sdk
10+
qsharp
11+
pytket
12+
xacc
913
matplotlib
1014
pylatexenc
1115
jupyter

xacc/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# XACC
2+
3+
[![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)

xacc/main.ipynb

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "151d6c64",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"%%capture\n",
11+
"\n",
12+
"!pip install xacc"
13+
]
14+
},
15+
{
16+
"cell_type": "code",
17+
"execution_count": null,
18+
"id": "f3042105",
19+
"metadata": {},
20+
"outputs": [],
21+
"source": [
22+
"import xacc"
23+
]
24+
},
25+
{
26+
"cell_type": "code",
27+
"execution_count": null,
28+
"id": "66dba273",
29+
"metadata": {},
30+
"outputs": [],
31+
"source": [
32+
"ionq = xacc.getAccelerator(\"ionq:qpu\")\n",
33+
"compiler = xacc.getCompiler(\"xasm\")\n",
34+
"ir = compiler.compile(r\"\"\"__qpu__ void bell(qbit q) {\n",
35+
" H(q[0]);\n",
36+
" CX(q[0], q[1]);\n",
37+
" Measure(q[0]);\n",
38+
" Measure(q[1]);\n",
39+
"}\"\"\", ionq)"
40+
]
41+
},
42+
{
43+
"cell_type": "code",
44+
"execution_count": null,
45+
"id": "7a58565e",
46+
"metadata": {},
47+
"outputs": [],
48+
"source": [
49+
"buffer = xacc.qalloc(2)\n",
50+
"r = ionq.execute(buffer, ir.getComposite(\"bell\"))\n",
51+
"results = buffer.getMeasurementCounts()\n",
52+
"print(results)"
53+
]
54+
}
55+
],
56+
"metadata": {
57+
"kernelspec": {
58+
"display_name": "Python 3 (ipykernel)",
59+
"language": "python",
60+
"name": "python3"
61+
},
62+
"language_info": {
63+
"codemirror_mode": {
64+
"name": "ipython",
65+
"version": 3
66+
},
67+
"file_extension": ".py",
68+
"mimetype": "text/x-python",
69+
"name": "python",
70+
"nbconvert_exporter": "python",
71+
"pygments_lexer": "ipython3",
72+
"version": "3.11.3"
73+
}
74+
},
75+
"nbformat": 4,
76+
"nbformat_minor": 5
77+
}

0 commit comments

Comments
 (0)