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

feature: Direct Reservation context manager #955

Closed mbeach-aws closed 2 months ago

mbeach-aws commented 2 months ago

Issue #, if available:

Description of changes: a new context manger to modify AwsQuantumTasks created within this context to run on a device with a reservation ARN.This is useful for ensuring that all quantum task

    Examples:
        As a context manager
        >>> with DirectReservation(device_arn, reservation_arn="<my_reservation_arn>"):
        ...     task1 = device.run(circuit, shots)
        ...     task2 = device.run(circuit, shots)

        or start the reservation
        >>> DirectReservation(device_arn, reservation_arn="<my_reservation_arn>").start()
        ... task1 = device.run(circuit, shots)
        ... task2 = device.run(circuit, shots)

Testing done:

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

General

Tests

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 100.00%. Comparing base (07d9e1e) to head (561c503).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #955 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 134 135 +1 Lines 8857 8903 +46 Branches 1989 1998 +9 ========================================= + Hits 8857 8903 +46 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

kshitijc commented 2 months ago

Context managers are typically used to allocate and release resources. If in the future we allow programmatic creation of reservations, will the proposed interface here make it hard to do that? Do we need to add in the context manager interface right now?

speller26 commented 2 months ago

The use case for reservations is booking a slot ahead of time, with enough room for cancellation if needed; creation of a reservation upon entering the context manager could be a very long blocking call. As well, the current implementation doesn't rule out the world where reservation creation gets fast and fine-grained enough that one could reserve a device for immediate use; the reservation_arn field could become optional, with extra optional parameters added for creation.