Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update: default no longer returning RETIRED devices from get_devices #796

Merged
merged 4 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/braket/aws/aws_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,13 +564,15 @@ def get_devices(
>>> AwsDevice.get_devices(types=['SIMULATOR'])

Args:
arns (Optional[list[str]]): device ARN list, default is `None`
names (Optional[list[str]]): device name list, default is `None`
types (Optional[list[AwsDeviceType]]): device type list, default is `None`
arns (Optional[list[str]]): device ARN filter, default is `None`
names (Optional[list[str]]): device name filter, default is `None`
types (Optional[list[AwsDeviceType]]): device type filter, default is `None`
QPUs will be searched for all regions and simulators will only be
searched for the region of the current session.
statuses (Optional[list[str]]): device status list, default is `None`
provider_names (Optional[list[str]]): provider name list, default is `None`
statuses (Optional[list[str]]): device status filter, default is `None`. When `None`
is used, RETIRED devices will not be returned. To include RETIRED devices in
the results, use a filter that includes `RETIRED` for this parameter.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smallest nit: in this context we mean the string "RETIRED", unless we have an enum somewhere defining RETIRED

provider_names (Optional[list[str]]): provider name filter, default is `None`
order_by (str): field to order result by, default is `name`.
Accepted values are ['arn', 'name', 'type', 'provider_name', 'status']
aws_session (Optional[AwsSession]): An AWS session object.
Expand Down
12 changes: 8 additions & 4 deletions src/braket/aws/aws_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,12 @@ def search_devices(
all the filters `arns`, `names`, `types`, `statuses`, `provider_names`.

Args:
arns (Optional[list[str]]): device ARN list, default is `None`.
names (Optional[list[str]]): device name list, default is `None`.
types (Optional[list[str]]): device type list, default is `None`.
statuses (Optional[list[str]]): device status list, default is `None`.
arns (Optional[list[str]]): device ARN filter, default is `None`.
names (Optional[list[str]]): device name filter, default is `None`.
types (Optional[list[str]]): device type filter, default is `None`.
statuses (Optional[list[str]]): device status filter, default is `None`. When `None`
is used, RETIRED devices will not be returned. To include RETIRED devices in
the results, use a filter that includes `RETIRED` for this parameter.
provider_names (Optional[list[str]]): provider name list, default is `None`.

Returns:
Expand All @@ -645,6 +647,8 @@ def search_devices(
continue
if statuses and result["deviceStatus"] not in statuses:
continue
if statuses is None and result["deviceStatus"] == "RETIRED":
continue
Comment on lines +650 to +651
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I missing something, or does this not actually impact the search_devices call? Does this fix our time issue? It looks like it still gets every device but then filters after; is this a limitation of the search devices api?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does fix our time issue. Even though the API returns all values, we will filter our the retired ones. This means that when we actually do get_device for all returned devices, we will be doing many fewer calls.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that's the piece I was missing, that makes sense if get_device is what's taking a long time

if provider_names and result["providerName"] not in provider_names:
continue
results.append(result)
Expand Down
2 changes: 1 addition & 1 deletion test/integ_tests/test_device_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from braket.aws import AwsDevice
from braket.devices import Devices

RIGETTI_ARN = "arn:aws:braket:::device/qpu/rigetti/Aspen-10"
RIGETTI_ARN = "arn:aws:braket:us-west-1::device/qpu/rigetti/Aspen-M-3"
IONQ_ARN = "arn:aws:braket:us-east-1::device/qpu/ionq/Harmony"
SIMULATOR_ARN = "arn:aws:braket:::device/quantum-simulator/amazon/sv1"
OQC_ARN = "arn:aws:braket:eu-west-2::device/qpu/oqc/Lucy"
Expand Down
19 changes: 19 additions & 0 deletions test/unit_tests/braket/aws/test_aws_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,18 @@ def test_cancel_job_surfaces_errors(exception_type, aws_session):
},
],
),
(
{"statuses": ["RETIRED"]},
[
{
"deviceArn": "arn4",
"deviceName": "name4",
"deviceType": "QPU",
"deviceStatus": "RETIRED",
"providerName": "pname3",
},
],
),
(
{"provider_names": ["pname2"]},
[
Expand Down Expand Up @@ -745,6 +757,13 @@ def test_search_devices(input, output, aws_session):
"deviceStatus": "ONLINE",
"providerName": "pname2",
},
{
"deviceArn": "arn4",
"deviceName": "name4",
"deviceType": "QPU",
"deviceStatus": "RETIRED",
"providerName": "pname3",
},
]
}
]
Expand Down