Skip to content

Instantly share code, notes, and snippets.

@hariby
Last active January 4, 2022 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hariby/baa5f564f14310ccb3032604aba6a7b4 to your computer and use it in GitHub Desktop.
Save hariby/baa5f564f14310ccb3032604aba6a7b4 to your computer and use it in GitHub Desktop.
IAM Policy to explicitly deny Braket Tasks which are Untagged or have large (>1000) shots.
from braket.circuits import Circuit
from braket.aws import AwsDevice
my_bucket = "amazon-braket-Your-Bucket-Name"
my_prefix = "Your-Folder-Name"
s3_folder = (my_bucket, my_prefix)
device = AwsDevice("arn:aws:braket:::device/quantum-simulator/amazon/sv1")
bell = Circuit().h(0).cnot(0, 1)
# specify the number of shots
shots = 1000
task_result = device.run(
bell,
s3_folder,
shots=shots, # do not hardcode here
tags = {'shots': str(shots)} # specify the number of shots in the tag
).result()
task_result.measurement_counts
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyUntaggedTasksAndJobs",
"Effect": "Deny",
"Action": [
"braket:CreateQuantumTask"
],
"Resource": "*",
"Condition": {
"Null": {
"aws:RequestTag/shots": "true"
}
}
},
{
"Sid": "DenyTasksAndJobsWithLargeShots",
"Effect": "Deny",
"Action": [
"braket:CreateQuantumTask"
],
"Resource": "*",
"Condition": {
"NumericGreaterThan": {
"aws:RequestTag/shots": "1000"
}
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment