Skip to content

Commit

Permalink
update aws quantum jobs notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhill1 committed Nov 6, 2024
1 parent b6a210a commit c8cf71f
Showing 1 changed file with 68 additions and 124 deletions.
192 changes: 68 additions & 124 deletions qbraid_lab/quantum_jobs/aws_quantum_jobs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,69 +18,91 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.3.1\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython -m pip install --upgrade pip\u001b[0m\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"%pip install -q amazon-braket-sdk qbraid-cli"
"%pip install -q amazon-braket-sdk"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "ece364ef-f49e-4a56-b32c-77aee1f1912f",
"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": [
"ERROR:qbraid_core.services.environments.magic:Failed to apply magic config at path /opt/.qbraid/environments/qbraid_000000/pyenv/lib/python3.11/site-packages: Failed to write path to /opt/.qbraid/environments/qbraid_000000/pyenv/lib/python3.11/site-packages/qbraid_config.pth.\n",
"ERROR:qbraid_core.services.environments.magic:Failed to apply magic config at path /opt/.qbraid/environments/qbraid_000000/pyenv/lib/python3.11/site-packages: Failed to write path to /opt/conda/lib/python3.11/site-packages/qbraid_config.pth.\n",
"\n",
"Successfully configured qBraid IPython magic commands.\n",
"\n",
"You can now use the qBraid-CLI from inside a Jupyter notebook as follows:\n",
"\n",
" \u001b[32mIn \u001b[0m\u001b[1;32m[\u001b[0m\u001b[1;33m1\u001b[0m\u001b[1;32m]\u001b[0m\u001b[32m:\u001b[0m \u001b[34m%\u001b[0mload_ext qbraid_magic\n",
"\n",
" \u001b[32mIn \u001b[0m\u001b[1;32m[\u001b[0m\u001b[1;33m2\u001b[0m\u001b[1;32m]\u001b[0m\u001b[32m:\u001b[0m \u001b[34m%\u001b[0mqbraid\n",
"\n"
"qbraid-cli/0.9.0a0\n"
]
}
],
"source": [
"!qbraid configure magic"
"%qbraid --version"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "829a72b8",
"execution_count": 5,
"id": "1635d207-9650-4bb5-9f72-9a386021858c",
"metadata": {},
"outputs": [],
"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": [
"%load_ext qbraid_magic"
"%qbraid jobs enable braket -y"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 6,
"id": "c2faa670-1fe9-47f2-9cfe-d488517914a3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Executable: \u001b[35m/home/jovyan/.qbraid/environments/amazon_3kbp0j/pyenv/bin/\u001b[0m\u001b[95mpython\u001b[0m\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"
"braket \u001b[32menabled\u001b[0m\n",
"\n"
]
}
],
Expand All @@ -90,7 +112,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 7,
"id": "f17a39b3-74b6-4798-9d8c-164d884e1251",
"metadata": {},
"outputs": [
Expand All @@ -99,18 +121,19 @@
"output_type": "stream",
"text": [
"\n",
"qBraid credits remaining: 921.0480\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 credits value"
"%qbraid account credits"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 8,
"id": "e7fb9ec2-0500-4fd7-b9a5-952805764efc",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -142,7 +165,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 9,
"id": "9319ff25-f872-4cf4-8943-8453aaaa3ada",
"metadata": {},
"outputs": [],
Expand All @@ -156,26 +179,26 @@
},
{
"cell_type": "code",
"execution_count": 8,
"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": 9,
"execution_count": 11,
"id": "602ae9e2-675f-4a7d-8ad2-8dded3c19ca4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Counter({'00': 6, '11': 4})\n"
"Counter({'00': 56, '11': 44})\n"
]
}
],
Expand All @@ -186,121 +209,42 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 12,
"id": "fb323eeb-2f53-4fa1-b8e4-d915caf57981",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[2KFetching... \u001b[32m⠸\u001b[0m Donerogress\n",
"\u001b[?25h\n",
"\u001b[1mJob ID Submitted \u001b[0m\n",
"\u001b[1mStatus\u001b[0m\n",
"aws_sv_sim-tarini-qjob-ioy808aly0zznfhplq9p \u001b[1;36m2024\u001b[0m-\u001b[1;36m10\u001b[0m-30T\u001b[1;92m21:51:51\u001b[0m.844Z \n",
"\u001b[34mINITIALIZED\u001b[0m\n",
"aws_sv_sim-tarini-qjob-ksxmvsch612niyppv0fx \u001b[1;36m2024\u001b[0m-\u001b[1;36m10\u001b[0m-30T\u001b[1;92m21:35:35\u001b[0m.061Z \n",
"\u001b[32mCOMPLETED\u001b[0m\n",
"aws_sv_sim-tarini-qjob-1azaxqqwzihlee3lu1wc \u001b[1;36m2024\u001b[0m-\u001b[1;36m10\u001b[0m-30T\u001b[1;92m21:10:24\u001b[0m.593Z \n",
"\u001b[32mCOMPLETED\u001b[0m\n",
"aws_sv_sim-tarini-qjob-zzkxx4bigpbtnew5lox9 \u001b[1;36m2024\u001b[0m-\u001b[1;36m10\u001b[0m-30T\u001b[1;92m19:36:23\u001b[0m.010Z \n",
"\u001b[32mCOMPLETED\u001b[0m\n",
"aws_iqm_garnet-tarini-qjob-qh0ds4eu8h92o5aemg19 \u001b[1;36m2024\u001b[0m-\u001b[1;36m10\u001b[0m-30T\u001b[1;92m19:28:49\u001b[0m.876Z \n",
"\u001b[34mQUEUED\u001b[0m\n",
"aws_sv_sim-tarini-qjob-bptjf33r5gs2taweahzu \u001b[1;36m2024\u001b[0m-\u001b[1;36m10\u001b[0m-30T\u001b[1;92m17:59:51\u001b[0m.158Z \n",
"\u001b[32mCOMPLETED\u001b[0m\n",
"aws_sv_sim-tarini-qjob-vsybofsshtocytwdjucm \u001b[1;36m2024\u001b[0m-\u001b[1;36m10\u001b[0m-29T\u001b[1;92m23:34:52\u001b[0m.702Z \n",
"\u001b[32mCOMPLETED\u001b[0m\n",
"aws_quera_aquila-tarini-qjob-mjbyoyeg0wfh8xzukr6d \u001b[1;36m2024\u001b[0m-\u001b[1;36m10\u001b[0m-29T\u001b[1;92m22:19:55\u001b[0m.830Z \n",
"\u001b[32mCOMPLETED\u001b[0m\n",
"aws_quera_aquila-tarini-qjob-yz3jhyausycveespa3p7 \u001b[1;36m2024\u001b[0m-\u001b[1;36m10\u001b[0m-29T\u001b[1;92m22:19:54\u001b[0m.986Z \n",
"\u001b[32mCOMPLETED\u001b[0m\n",
"aws_quera_aquila-tarini-qjob-bxff53kx4fchzw7io06o \u001b[1;36m2024\u001b[0m-\u001b[1;36m10\u001b[0m-29T\u001b[1;92m22:19:54\u001b[0m.645Z \n",
"\u001b[32mCOMPLETED\u001b[0m\n",
"\u001b[3m \u001b[0m\u001b[3m \u001b[0m\n",
"\u001b[3mDisplaying \u001b[0m\u001b[1;36m10\u001b[0m\u001b[3m most recent jobs\u001b[0m\u001b[3m \u001b[0m\n"
]
}
],
"outputs": [],
"source": [
"# list submitted jobs\n",
"!qbraid jobs list"
"# %qbraid jobs list"
]
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 13,
"id": "2b0a87d2-865b-4d52-a01b-ccc1cf01c707",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[2KFetching... \u001b[32m⠧\u001b[0m Donerogress\n",
"\u001b[?25h\n",
"qBraid credits remaining:\u001b[0m \u001b[35m\u001b[1m917.2980\u001b[0m\u001b[0m\n"
"\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": [
"# check remaining qBraid credits\n",
"!qbraid credits value"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "36e52a6b-35dc-4ec4-8389-adda483fb92f",
"metadata": {},
"outputs": [],
"source": [
"client = boto3.client(\"braket\")"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "5bf07028-5ea1-4776-9c05-7a2f8872a134",
"metadata": {},
"outputs": [
{
"ename": "ClientError",
"evalue": "An error occurred (500) when calling the SearchQuantumTasks operation (reached max retries: 4): ",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mClientError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[17], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# retrieve job data from braket boto3\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m boto_data \u001b[38;5;241m=\u001b[39m \u001b[43mclient\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msearch_quantum_tasks\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 3\u001b[0m \u001b[43m \u001b[49m\u001b[43mfilters\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m[\u001b[49m\u001b[43m{\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mname\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mquantumTaskArn\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43moperator\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mEQUAL\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mvalues\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43m[\u001b[49m\u001b[43mtask\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mid\u001b[49m\u001b[43m]\u001b[49m\u001b[43m}\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 4\u001b[0m \u001b[43m)\u001b[49m\n\u001b[1;32m 6\u001b[0m job_data \u001b[38;5;241m=\u001b[39m boto_data[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mquantumTasks\u001b[39m\u001b[38;5;124m\"\u001b[39m][\u001b[38;5;241m0\u001b[39m]\n\u001b[1;32m 7\u001b[0m created \u001b[38;5;241m=\u001b[39m job_data[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcreatedAt\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n",
"File \u001b[0;32m~/.qbraid/environments/amazon_3kbp0j/pyenv/lib/python3.11/site-packages/botocore/client.py:569\u001b[0m, in \u001b[0;36mClientCreator._create_api_method.<locals>._api_call\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 565\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m(\n\u001b[1;32m 566\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mpy_operation_name\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m() only accepts keyword arguments.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 567\u001b[0m )\n\u001b[1;32m 568\u001b[0m \u001b[38;5;66;03m# The \"self\" in this scope is referring to the BaseClient.\u001b[39;00m\n\u001b[0;32m--> 569\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_make_api_call\u001b[49m\u001b[43m(\u001b[49m\u001b[43moperation_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/.qbraid/environments/amazon_3kbp0j/pyenv/lib/python3.11/site-packages/botocore/client.py:1023\u001b[0m, in \u001b[0;36mBaseClient._make_api_call\u001b[0;34m(self, operation_name, api_params)\u001b[0m\n\u001b[1;32m 1019\u001b[0m error_code \u001b[38;5;241m=\u001b[39m error_info\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mQueryErrorCode\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;129;01mor\u001b[39;00m error_info\u001b[38;5;241m.\u001b[39mget(\n\u001b[1;32m 1020\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCode\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 1021\u001b[0m )\n\u001b[1;32m 1022\u001b[0m error_class \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mexceptions\u001b[38;5;241m.\u001b[39mfrom_code(error_code)\n\u001b[0;32m-> 1023\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m error_class(parsed_response, operation_name)\n\u001b[1;32m 1024\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 1025\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m parsed_response\n",
"\u001b[0;31mClientError\u001b[0m: An error occurred (500) when calling the SearchQuantumTasks operation (reached max retries: 4): "
]
}
],
"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}\")"
"%qbraid account credits"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 [Braket v1.86]",
"display_name": "Python 3 [Default]",
"language": "python",
"name": "python3_amazon_3kbp0j"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand Down

0 comments on commit c8cf71f

Please sign in to comment.