amazon-braket/amazon-braket-examples

Issue loading SV1 and TN1

jstankowicz opened this issue · 6 comments

While attempting to run the notebook 1_Running_quantum_circuits_on_simulators.ipynb, I'm unable to load either the SV1 or TN1 devices. I receive the error:

>>> device = AwsDevice("arn:aws:braket:::device/quantum-simulator/amazon/sv1")
# ...
# lots of error message that I can post if useful
# ...
EndpointConnectionError: Could not connect to the endpoint URL: "https://braket.us-east-2.amazonaws.com/device/arn%3Aaws%3Abraket%3A%3A%3Adevice%2Fquantum-simulator%2Famazon%2Fsv1"

and

>>> device = AwsDevice("arn:aws:braket:::device/quantum-simulator/amazon/tn1")
# ...
# lots of error message that I can post if useful
# ...
EndpointConnectionError: Could not connect to the endpoint URL: "https://braket.us-east-2.amazonaws.com/device/arn%3Aaws%3Abraket%3A%3A%3Adevice%2Fquantum-simulator%2Famazon%2Ftn1"

I notice the error URL is pointing to us-east-2 even though both the SV1 and TN1 devices are on us-east-1 and I'm running the notebook on an EC2 instance on us-east-1.

Even though your EC2 instance is in us-east-1, can you double-check what region appears in .aws/config? Aternatively, run

from braket.aws import AwsSession
print(AwsSession().boto_session.region_name)

and make sure it isn't us-west-2.

So confusingly my aws config is set to us-east-1:

$more ~/.aws/config 
[default]
region = us-east-1
output = json

but the in-notebook call returns us-east-2:

>>> from braket.aws import AwsSession
>>> print(AwsSession().boto_session.region_name)
% us-east-2

I could load all devices by specifying an AwsSession with the correct region in the AwsDevice call:

>>> import boto3
>>> from braket.aws.aws_session import AwsSession
>>> from braket.aws import AwsDevice

>>> bs = boto3.session.Session(region_name="us-east-1")
>>> aws_session = AwsSession(boto_session=bs)
>>> device = AwsDevice("arn:aws:braket:::device/quantum-simulator/amazon/sv1",aws_session=aws_session)
>>> device.status
% 'ONLINE'

For what it's worth, I also checked the issue is the same on the IonQ and Rigetti devices.

That's really weird. One more thing to check:

import boto3
print(boto3.Session().region_name)

If this is still us-east-2, then boto3 might be pulling config from some other place; in that case, it might be worth running aws configure from within the notebook to change the actual config being used.

Ah, I was checking the aws config on the wrong EC2 instance. The instance on which I was running the tutorials indeed had the wrong region in the config. I corrected the config and everything works correctly.

But there is a note in the AwsDevices docs (https://amazon-braket-sdk-python.readthedocs.io/en/latest/_apidoc/braket.aws.aws_device.html#braket.aws.aws_device.AwsDevice):

Some devices (QPUs) are physically located in specific AWS Regions. In some cases, the current aws_session connects to a Region other than the Region in which the QPU is physically located. When this occurs, a cloned aws_session is created for the Region the QPU is located in.

See braket.aws.aws_device.AwsDevice.DEVICE_REGIONS for the AWS Regions provider devices are located in.

Did I end up in an unlikely corner case because I was using an EC2 instance on us-east-1, but had it misconfigured for us-east-2? Or should AwsDevice be able to handle that type of misconfiguration?

Right now, QPUs will redirect to their respective regions. The devices you failed to instantiate were both simulators, which do not redirect; instantiating, say, the Rigetti Aspen-11 (arn:aws:braket:::device/qpu/rigetti/Aspen-11), will work, even from us-east-2.

Got it, I didn't read the note carefully enough. Thanks for the help, and it looks like I've got this resolved at least on the Braket end.