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

'Braket' object has no attribute 'get_device' #146

Closed NicoSchwaller closed 4 years ago

NicoSchwaller commented 4 years ago

Describe the bug When executing the example bell.py, the following error appears:


AttributeError Traceback (most recent call last)

in 19 aws_account_id = boto3.client("sts").get_caller_identity()["Account"] 20 ---> 21 device = AwsDevice("arn:aws:braket:::device/quantum-simulator/amazon/sv1") 22 s3_folder = (f"amazon-braket-output-{aws_account_id}", "folder-name") 23 ~/braketvirtenv/lib/python3.7/site-packages/braket/aws/aws_device.py in __init__(self, arn, aws_session) 74 self._provider_name = None 75 self._type = None ---> 76 self.refresh_metadata() 77 78 def run( ~/braketvirtenv/lib/python3.7/site-packages/braket/aws/aws_device.py in refresh_metadata(self) 153 Refresh the `AwsDevice` object with the most recent Device metadata. 154 """ --> 155 metadata = self._aws_session.get_device(self._arn) 156 self._name = metadata.get("deviceName") 157 self._status = metadata.get("deviceStatus") ~/braketvirtenv/lib/python3.7/site-packages/braket/aws/aws_session.py in get_device(self, arn) 116 Dict[str, Any]: Device metadata 117 """ --> 118 return self.braket_client.get_device(deviceArn=arn) ~/braketvirtenv/lib/python3.7/site-packages/botocore/client.py in __getattr__(self, item) 573 raise AttributeError( 574 "'%s' object has no attribute '%s'" % ( --> 575 self.__class__.__name__, item) 576 ) 577 AttributeError: 'Braket' object has no attribute 'get_device' **To reproduce** Execute bell.py **Expected behavior** Get the result of the experiment **System information** A description of your system. Please provide: - **Amazon Braket Python SDK version**: v1.0.0.post1 - **Amazon Braket Python Schemas version**: v1.0.0.post1 - **Amazon Braket Python Default Simulator version**: v1.0.0.post1 - **Python version**: 3.7.5
avawang1 commented 4 years ago

Thanks for reaching out. This probably has something to do with upgrading boto3 to have the braket client. Please run pip install boto3 --upgrade To troubleshoot further, please make sure that you can call get_device in boto3: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/braket.html#Braket.Client.get_device

Let us know if this has solved your problem.

NicoSchwaller commented 4 years ago

Thank you for the answer. I upgraded boto3 and this did not solve the problem, I have the same error when I call the get_device() method. My version of boto3 is 1.14.46.

jmp-aws commented 4 years ago

steps to reproduce

virtualenv braket
cd braket
source bin/activate
git clone https://github.com/aws/amazon-braket-sdk-python.git
pip install -e amazon-braket-sdk-python
python amazon-braket-sdk-python/examples/bell.py

error

Traceback (most recent call last):
  File "amazon-braket-sdk-python/examples/bell.py", line 21, in <module>
    device = AwsDevice("arn:aws:braket:::device/quantum-simulator/amazon/sv1")
  File "/Users/$(whoami)/git/braket/amazon-braket-sdk-python/src/braket/aws/aws_device.py", line 76, in __init__
    self.refresh_metadata()
  File "/Users/$(whoami)/git/braket/amazon-braket-sdk-python/src/braket/aws/aws_device.py", line 155, in refresh_metadata
    metadata = self._aws_session.get_device(self._arn)
  File "/Users/$(whoami)/git/braket/amazon-braket-sdk-python/src/braket/aws/aws_session.py", line 118, in get_device
    return self.braket_client.get_device(deviceArn=arn)
  File "/Users/$(whoami)/git/braket/lib/python3.7/site-packages/botocore/client.py", line 575, in __getattr__
    self.__class__.__name__, item)
AttributeError: 'Braket' object has no attribute 'get_device'

version info

pip freeze | grep boto3

avawang1 commented 4 years ago

Thanks @jmp-aws, I'm still unable to reproduce the error. I think it's due to the AWS CLI not being up to date, because the get_device API isn't able to be called.

Another option is to uninstall and re-install boto3.

Or, to start from a new virtualenv and run: pip install amazon-braket-sdk

jmp-aws commented 4 years ago

commands executed

python3 -m venv braket
cd braket
source bin/activate
pip install amazon-braket-sdk

# created bell.py file from copying and pasting from the repo
python bell.py

output

Traceback (most recent call last):
  File "bell.py", line 8, in <module>
    device = AwsDevice("arn:aws:braket:::device/quantum-simulator/amazon/sv1")
  File "/Users/$(whoami)/git/braket/lib/python3.8/site-packages/braket/aws/aws_device.py", line 76, in __init__
    self.refresh_metadata()
  File "/Users/$(whoami)/git/braket/lib/python3.8/site-packages/braket/aws/aws_device.py", line 155, in refresh_metadata
    metadata = self._aws_session.get_device(self._arn)
  File "/Users/$(whoami)/git/braket/lib/python3.8/site-packages/braket/aws/aws_session.py", line 118, in get_device
    return self.braket_client.get_device(deviceArn=arn)
  File "/Users/$(whoami)/git/braket/lib/python3.8/site-packages/botocore/client.py", line 573, in __getattr__
    raise AttributeError(
AttributeError: 'Braket' object has no attribute 'get_device'

pip freeze

amazon-braket-default-simulator==1.0.0.post1
amazon-braket-schemas==1.0.0.post1
amazon-braket-sdk==1.0.0.post1
backoff==1.10.0
boltons==20.2.1
boto3==1.14.46
botocore==1.17.46
decorator==4.4.2
docutils==0.15.2
jmespath==0.10.0
nest-asyncio==1.4.0
networkx==2.4
numpy==1.19.1
opt-einsum==3.3.0
pydantic==1.6.1
python-dateutil==2.8.1
s3transfer==0.3.3
six==1.15.0
urllib3==1.25.10
avawang1 commented 4 years ago

Still unable to reproduce the error.

Have you tried running: aws braket help in the command line and seeing if get-device appears in the list of available commands? If not, the version of the AWS CLI you have needs to be updated.

jmp-aws commented 4 years ago

commands executed

aws braket help

output

AVAILABLE COMMANDS
       o cancel-quantum-task

       o create-quantum-job

       o create-quantum-task

       o describe-qpus

       o describe-quantum-simulators

       o get-quantum-job

       o get-quantum-task

       o help

       o list-quantum-jobs

       o list-quantum-tasks

       o stop-quantum-job

working on trying to remove braket definition of aws cli installation

commands executed

brew uninstall awscli
rm -rf ~/.aws/models/aqx
rm -rf ~/.aws/models/braket
brew install awscli
aws braket help

output

AVAILABLE COMMANDS
       o cancel-quantum-task

       o create-quantum-task

       o get-device

       o get-quantum-task

       o help

       o search-devices

       o search-quantum-tasks

commands executed

python bell.py

output

Counter({'11': 56, '00': 44})
jmp-aws commented 4 years ago

@NicoSchwaller does removal of any aws cli models, uninstallation, and re-installation help resolve the issue? These are the commands that solved the issue for myself

brew uninstall awscli
rm -rf ~/.aws/models/aqx
rm -rf ~/.aws/models/braket
brew install awscli
aws braket help
NicoSchwaller commented 4 years ago

@NicoSchwaller does removal of any aws cli models, uninstallation, and re-installation help resolve the issue? These are the commands that solved the issue for myself

brew uninstall awscli
rm -rf ~/.aws/models/aqx
rm -rf ~/.aws/models/braket
brew install awscli
aws braket help

Yes, this did solve the problem, thanks a lot!