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

Sdk version updates #42

Merged
merged 5 commits into from
Nov 6, 2024
Merged
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
53 changes: 19 additions & 34 deletions qbraid_lab/quantum_jobs/aws_iqm_quantum_jobs.ipynb

Large diffs are not rendered by default.

578 changes: 578 additions & 0 deletions qbraid_lab/quantum_jobs/aws_oqc_quantum_jobs.ipynb

Large diffs are not rendered by default.

218 changes: 106 additions & 112 deletions qbraid_lab/quantum_jobs/aws_quantum_jobs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,94 +11,150 @@
{
"cell_type": "code",
"execution_count": 1,
"id": "ece364ef-f49e-4a56-b32c-77aee1f1912f",
"id": "de7f060e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[0;35mSuccessfully enabled qBraid Quantum Jobs in the \u001b[1;35mamazon_braket\u001b[0m\u001b[0;35m environment.\u001b[0m\n",
"\u001b[0;35mEvery \u001b[1;35mAWS\u001b[0m\u001b[0;35m job you run will now be submitted through the qBraid API, so no access keys/tokens are necessary. \u001b[0m\n",
"\n",
"\u001b[0;35mTo disable, run:\u001b[0m `qbraid jobs disable amazon_braket`\n"
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"# enable qBraid Quantum Jobs\n",
"!qbraid jobs enable amazon_braket"
"%pip install -q amazon-braket-sdk"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "e668cc2b-2107-4f2a-bc65-1aa6da9b72cf",
"metadata": {},
"outputs": [],
"source": [
"# !qbraid configure magic"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "829a72b8",
"metadata": {},
"outputs": [],
"source": [
"%load_ext qbraid_magic"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "c962fcc4-6e09-43b9-af3f-13b8bd36bc3e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"qbraid-cli/0.9.0a0\n"
]
}
],
"source": [
"%qbraid --version"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "1635d207-9650-4bb5-9f72-9a386021858c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"qBraid quantum jobs already \u001b[1;32menabled\u001b[0m for \u001b[35mbraket\u001b[0m.\n",
"\n",
"Check the state of all quantum jobs libraries in this environment with: \n",
"\n",
" $ qbraid jobs state\n",
"\n"
]
}
],
"source": [
"%qbraid jobs enable braket -y"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "c2faa670-1fe9-47f2-9cfe-d488517914a3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"# installed environments:\n",
"#\n",
"qsharp /opt/.qbraid/environments/qsharp_b54crn\n",
"default \u001b[0;31mjobs\u001b[0m /opt/.qbraid/environments/qbraid_000000\n",
"qiskit \u001b[0;31mjobs\u001b[0m /home/jovyan/.qbraid/environments/qiskit_9y9siy\n",
"amazon_braket \u001b[0;32mjobs\u001b[0m /home/jovyan/.qbraid/environments/aws_braket_kwx6dl\n",
"intel /opt/.qbraid/environments/intel_zr7hfq\n",
"qbraid_sdk \u001b[0;31mjobs\u001b[0m /home/jovyan/.qbraid/environments/qbraid_sdk_9j9sjy\n",
"Executable: \u001b[35m/opt/.qbraid/environments/qbraid_000000/pyenv/bin/\u001b[0m\u001b[95mpython\u001b[0m\n",
"\n",
"\u001b[1mLibrary State\u001b[0m\n",
"braket \u001b[32menabled\u001b[0m\n",
"\n"
]
}
],
"source": [
"# list installed environments, check jobs keyword is green for Amazon Braket\n",
"!qbraid envs list"
"%qbraid jobs state"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 7,
"id": "f17a39b3-74b6-4798-9d8c-164d884e1251",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[0;35mYou have \u001b[0m1000.00\u001b[0;35m remaining qBraid credits.\u001b[0m\n"
"\n",
"qBraid credits remaining: 1912.9763\n",
"\n",
"For more information, visit: \u001b[4;94mhttps://docs.qbraid.com/home/pricing#credits\u001b[0m\n"
]
}
],
"source": [
"# check qBraid credits\n",
"!qbraid jobs get-credits"
"%qbraid account credits"
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 8,
"id": "e7fb9ec2-0500-4fd7-b9a5-952805764efc",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"T : |0|1|\n",
" \n",
"q0 : -H-C-\n",
" | \n",
"q1 : ---X-\n",
"\n",
"T : |0|1|\n"
"T : │ 0 │ 1 │\n",
" ┌───┐ \n",
"q0 : ─┤ H ├───●───\n",
" └───┘ │ \n",
" ┌─┴─┐ \n",
"q1 : ───────┤ X ├─\n",
" └───┘ \n",
"T : │ 0 │ 1 │\n"
]
}
],
"source": [
"import boto3\n",
"from braket.aws import AwsDevice, AwsQuantumTask\n",
"from braket.aws import AwsDevice\n",
"from braket.circuits import Circuit\n",
"\n",
"# create the Amazon Braket circuit\n",
Expand All @@ -109,7 +165,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 9,
"id": "9319ff25-f872-4cf4-8943-8453aaaa3ada",
"metadata": {},
"outputs": [],
Expand All @@ -123,134 +179,72 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 10,
"id": "d839f8db-0928-464f-9b26-06d89741bd05",
"metadata": {},
"outputs": [],
"source": [
"# execute the circuit\n",
"task = device.run(bell, shots=10)"
"task = device.run(bell, shots=100)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 11,
"id": "602ae9e2-675f-4a7d-8ad2-8dded3c19ca4",
"metadata": {},
"outputs": [],
"source": [
"# display the results\n",
"print(task.result().measurement_counts)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "fb323eeb-2f53-4fa1-b8e4-d915caf57981",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Fri Apr 21 2023 15:57:10 GMT+0000 (Coordinated Universal Time) arn:aws:braket:::device/quantum-simulator/amazon/sv1 arn:aws:braket:us-east-1:592242689881:quantum-task/ca33820b-987b-42e1-bac5-8b382324fe12\n",
"\n"
]
}
],
"source": [
"# list submitted jobs\n",
"!qbraid jobs list"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "2b0a87d2-865b-4d52-a01b-ccc1cf01c707",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[0;35mYou have \u001b[0m999.60\u001b[0;35m remaining qBraid credits.\u001b[0m\n"
"Counter({'00': 56, '11': 44})\n"
]
}
],
"source": [
"# check remaining qBraid credits\n",
"!qbraid jobs get-credits"
"# display the results\n",
"print(task.result().measurement_counts)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "36e52a6b-35dc-4ec4-8389-adda483fb92f",
"execution_count": 12,
"id": "fb323eeb-2f53-4fa1-b8e4-d915caf57981",
"metadata": {},
"outputs": [],
"source": [
"client = boto3.client(\"braket\")"
"# %qbraid jobs list"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "5bf07028-5ea1-4776-9c05-7a2f8872a134",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"createdAt: 2023-04-21 15:57:09.862000+00:00\n",
"endedAt: 2023-04-21 15:57:11.556000+00:00\n",
"costEstimate: 0.4000012 credits ~ $0.004000012\n"
]
}
],
"source": [
"# retrieve job data from braket boto3\n",
"boto_data = client.search_quantum_tasks(\n",
" filters=[{\"name\": \"quantumTaskArn\", \"operator\": \"EQUAL\", \"values\": [task.id]}],\n",
")\n",
"\n",
"job_data = boto_data[\"quantumTasks\"][0]\n",
"created = job_data[\"createdAt\"]\n",
"ended = job_data[\"endedAt\"]\n",
"cost = float(job_data[\"tags\"][\"costEstimate\"])\n",
"\n",
"print(f\"createdAt: {created}\")\n",
"print(f\"endedAt: {ended}\")\n",
"print(f\"costEstimate: {cost} credits ~ ${cost/100}\")"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "6470f22f-9a07-4c64-b02b-b268d54b80b6",
"execution_count": 13,
"id": "2b0a87d2-865b-4d52-a01b-ccc1cf01c707",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[0;35mDisable successful. You are now submitting quantum jobs with your own AWS credentials.\u001b[0m\n",
"\n",
"\u001b[0;35mTo re-enable, run:\u001b[0m `qbraid jobs enable amazon_braket`\n"
"qBraid credits remaining: 1909.2263\n",
"\n",
"For more information, visit: \u001b[4;94mhttps://docs.qbraid.com/home/pricing#credits\u001b[0m\n"
]
}
],
"source": [
"# disable qBraid Quantum Jobs\n",
"!qbraid jobs disable amazon_braket"
"# check remaining qBraid credits\n",
"%qbraid account credits"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 [Braket]",
"display_name": "Python 3 [Default]",
"language": "python",
"name": "python3_aws_braket_kwx6dl"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -262,7 +256,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.10"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down
Loading