Skip to content

Commit

Permalink
Use diff_method="device" to reduce cost of BYOC example (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmshaffer authored Aug 15, 2023
1 parent 2a4fb53 commit 53b5a92
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def q_circuit(self):
s3_destination_folder=None,
)

@qml.qnode(dev, interface="autograd")
@qml.qnode(dev, diff_method="device", interface="autograd")
def circuit(*weights, features=np.zeros(2**nwires)):
AmplitudeEmbedding(features=features, wires=range(nwires), normalize=True, pad_with=0.0)
w_layer1, w_layer2, rotation = weights
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,35 +322,25 @@
"Now that we have prepared an algorithm script and the container for the job, we can submit the hybrid job to AWS using <code>AwsQuantumJob.create</code>. Remember to provide the container we just created via the <code>image_uri</code> keyword."
]
},
{
"cell_type": "markdown",
"id": "d2ba127a",
"metadata": {},
"source": [
"<div class=\"alert alert-block alert-warning\">\n",
"<b>Caution:</b> The job that is created below will take a long time to run (roughly 90 minutes) and will incur simulation costs up to $40 for running tasks on the SV1 on-demand simulator. Please uncomment and run the job only if you are comfortable with the time and cost.\n",
"</div>"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "f38b86d5",
"metadata": {},
"outputs": [],
"source": [
"# from braket.aws import AwsQuantumJob\n",
"from braket.aws import AwsQuantumJob\n",
"\n",
"# image_uri = \"<aws_account_id>.dkr.ecr.<your_region>.amazonaws.com/amazon-braket-my-qtc:latest\"\n",
"image_uri = \"<aws_account_id>.dkr.ecr.<your_region>.amazonaws.com/amazon-braket-my-qtc:latest\"\n",
"\n",
"# job = AwsQuantumJob.create(\n",
"# device=\"arn:aws:braket:::device/quantum-simulator/amazon/sv1\",\n",
"# source_module=\"algorithm_script.py\",\n",
"# entry_point=\"algorithm_script:main\",\n",
"# wait_until_complete=False,\n",
"# job_name=\"my-aws-job\",\n",
"# image_uri=image_uri,\n",
"# )"
"job = AwsQuantumJob.create(\n",
" device=\"arn:aws:braket:::device/quantum-simulator/amazon/sv1\",\n",
" source_module=\"algorithm_script.py\",\n",
" entry_point=\"algorithm_script:main\",\n",
" wait_until_complete=False,\n",
" job_name=\"my-aws-job\",\n",
" image_uri=image_uri,\n",
")"
]
},
{
Expand All @@ -364,9 +354,9 @@
"output_type": "stream",
"text": [
"Task Summary\n",
"{'arn:aws:braket:::device/quantum-simulator/amazon/sv1': {'shots': 0, 'tasks': {'COMPLETED': 11800}, 'execution_duration': 1721.538, 'billed_execution_duration': 35400.0}}\n",
"{'arn:aws:braket:::device/quantum-simulator/amazon/sv1': {'shots': 0, 'tasks': {'COMPLETED': 40}, 'execution_duration': 13.689, 'billed_execution_duration': 120.0}}\n",
"Note: Charges shown are estimates based on your Amazon Braket simulator and quantum processing unit (QPU) task usage. Estimated charges shown may differ from your actual charges. Estimated charges do not factor in any discounts or credits, and you may experience additional charges based on your use of other services such as Amazon Elastic Compute Cloud (Amazon EC2).\n",
"Estimated cost to run tasks in this job: 44.25 USD\n"
"Estimated cost to run tasks in this job: 0.15 USD\n"
]
}
],
Expand Down Expand Up @@ -414,7 +404,6 @@
"metadata": {},
"outputs": [],
"source": [
"# The cell completes when the job finishes. It may take 90 minutes.\n",
"weights = job.result()['weights']"
]
},
Expand Down Expand Up @@ -522,7 +511,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8.10 ('venv': venv)",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -536,7 +525,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.9.15"
},
"vscode": {
"interpreter": {
Expand Down

0 comments on commit 53b5a92

Please sign in to comment.