amazon-braket / amazon-braket-sdk-python

A Python SDK for interacting with quantum devices on Amazon Braket
https://aws.amazon.com/braket/
Apache License 2.0
294 stars 118 forks source link

Use Tracker to track number of tasks in LocalSimulator #975

Open mbeach-aws opened 1 month ago

mbeach-aws commented 1 month ago

Describe the feature you'd like Currently, the Tracker counts the number of on-demand tasks, but not LocalSimulator tasks. For example

from braket.aws import AwsDevice
from braket.circuits import Circuit
from braket.tracking import Tracker

circ = Circuit().h(0).cnot(0,1)
device = AwsDevice("arn:aws:braket:::device/quantum-simulator/amazon/sv1")
with Tracker() as tracker:
    task = device.run(circ, shots=1000).result()

print(tracker.quantum_tasks_statistics())
>> {'arn:aws:braket:::device/quantum-simulator/amazon/sv1':
 {'shots': 1000,
  'tasks': {'COMPLETED': 1},
  'execution_duration': datetime.timedelta(microseconds=4000),
  'billed_execution_duration': datetime.timedelta(seconds=3)}}

print(tracker.simulator_tasks_cost())
>> $0.00375

The proposal is to add this functionality to track task counts on local simulator like this:

from braket.aws import AwsDevice
from braket.circuits import Circuit
from braket.tracking import Tracker
from braket.devices import LocalSimulator

circ = Circuit().h(0).cnot(0,1)
device = LocalSimulator()
with Tracker() as tracker:
    task = device.run(circ, shots=1000).result()

print(tracker.quantum_tasks_statistics())
>> {'braket:local/simulator':
 {'shots': 1000,
  'tasks': {'COMPLETED': 1},
  'execution_duration': datetime.timedelta(microseconds=4000),
  'billed_execution_duration': None}}

print(tracker.simulator_tasks_cost())
>> $0
njones93531 commented 1 month ago

Hi! I would like to work on this task as part of unitaryhack.

rmshaffer commented 3 weeks ago

Hi! I would like to work on this task as part of unitaryhack.

Hi @njones93531, thanks for your interest! Feel free to create a PR with your changes and we will be happy to review it and provide feedback.