Suppose I have the simple circuit

bell = Circuit().h(0).cnot(control=0, target=1)

and I am running it in a notebook inside AWS. How can I download the results to my local pc when

  1. I use the LocalSimulator().

  2. An IonQ or a Rigetti device?


1 Answer 1


When you run on an IonQ or Rigetti device (or any other QPU or AWS-managed simulator) your results are stored in the S3 bucket/folder you specified at runtime:

# the name of the bucket
my_bucket = "example-bucket"
# the name of the folder in the bucket
my_prefix = "simulation-output"
s3_folder = (my_bucket, my_prefix)

# cloud-based managed simulator/QPU to run your circuit
device = AwsDevice('arn:aws:braket:::device/qpu/ionq/ionQdevice')

# execute the circuit
task = device.run(bell, s3_folder, shots=100)

To download your results, navigate to that S3 bucket/folder, click on results.json, and then in the upper right corner, you will see a Download button.

The results of runs using the local simulator are not stored in S3, or written to any file:

device = LocalSimulator()
task = device.run(bell, shots=100)

However, if you were so inclined, you could recreate the same behavior by doing a json.dump of the local quantum task result into a local file, and then use the upload_to_s3 or upload_local_data method from the braket.aws.AwsSession module.

For example, if you run

result = task.result()

followed by

import json

with open('result.json', 'w', encoding='utf-8') as f:
    json.dump(str(result), f, ensure_ascii=False, indent=4)

a file result.json would be created in your working directory. In the AWS Braket notebook filesystem, the full path would be /home/ec2-user/SageMaker/result.json. Clicking the jupyter icon in the top left corner will take you back to the filesystem GUI, where you will see the results file present. Back in the notebook, you can then use the previously mentioned functions from the AwsSession module to upload this file to S3.

To reiterate, the results of circuits run using the LocalSimulator are not automatically sent to S3. The procedure that I've described is just one of many ways that you can explicitly write the results into a file, and manually upload to S3. This is possible both from jupyter on your local computer, and from inside of your AWS Braket notebook instance, and works effectively the same way.

  • $\begingroup$ I don't understand the last part, but I think I had in mind something different. If you run in LocalSimulator in the cloud (not in e.g. in a laptop), how do you do to send the results to the s3 bucket? $\endgroup$ Feb 22, 2022 at 12:48
  • $\begingroup$ @user2820579 Let me know if the edits I made help, or if it's still unclear $\endgroup$
    – ryanhill1
    Feb 22, 2022 at 16:18
  • 1
    $\begingroup$ @user2820579 Why would you want to run the LocalSimulator in the cloud when you can use aws_sv1_simulator, which will send results to the bucket? $\endgroup$ Feb 22, 2022 at 16:18
  • $\begingroup$ SIMPLE, sv1 is not free! $\endgroup$ Feb 23, 2022 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.