Skip to content

Commit

Permalink
feat: env var method
Browse files Browse the repository at this point in the history
  • Loading branch information
mbeach-aws committed Apr 16, 2024
1 parent 4b1a676 commit df50f40
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
repos:
- repo: local
hooks:
- id: tox_linters
name: linters
entry: tox -e linters_check
language: system
types: [python]
16 changes: 4 additions & 12 deletions examples/reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,18 @@
from braket.aws import AwsDevice
from braket.circuits import Circuit
from braket.devices import Devices
from braket.reservations import reservation
from braket.reservations import DirectReservation

bell = Circuit().h(0).cnot(0, 1)
device = AwsDevice(Devices.IonQ.Aria1)

# To run a task in a device reservation, change the device to the one you reserved
# and fill in your reservation ARN.
with reservation(device, reservation_arn="reservation ARN"):
with DirectReservation(device, reservation_arn="reservation ARN"):
task = device.run(bell, shots=100)

print(task.result().measurement_counts)

# Alternatively, you may directly pass the reservation ARN to all quantum tasks.
# Alternatively, you may start the reservation globally
DirectReservation(device, reservation_arn="reservation ARN").start()
task = device.run(bell, shots=100, reservation_arn="reservation ARN")
print(task.result().measurement_counts)


# A third option to run a reservation is by decorating a function.
# All tasks created within the function will use the reservation.
@reservation(device, reservation_arn="reservation ARN")
def my_function():
task = device.run(bell, shots=100)
print(task.result().measurement_counts)
2 changes: 1 addition & 1 deletion src/braket/reservations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# language governing permissions and limitations under the License.


from braket.reservations.reservations import reservation # noqa: F401
from braket.reservations.reservations import DirectReservation # noqa: F401
3 changes: 0 additions & 3 deletions test/unit_tests/braket/aws/test_aws_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1415,10 +1415,8 @@ def test_create_quantum_task_with_correct_device_and_reservation():

# Expected boto3 parameters
boto3_params = {"deviceArn": "device_arn_example"}

expected_arn = "example_quantum_task_arn"

# Mock boto3 client and its response
with patch("boto3.client") as mock_boto3_client:
mock_client = MagicMock()
mock_client.create_quantum_task.return_value = {"quantumTaskArn": expected_arn}
Expand All @@ -1430,7 +1428,6 @@ def test_create_quantum_task_with_correct_device_and_reservation():
# Assertions
mock_client.create_quantum_task.assert_called_once_with(
deviceArn="device_arn_example",
someOtherParam="value",
reservationArn="reservation_arn_example",
)
assert arn == expected_arn
Expand Down

0 comments on commit df50f40

Please sign in to comment.