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

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

Closed
NicoSchwaller opened this issue Aug 19, 2020 · 9 comments
Closed

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

NicoSchwaller opened this issue Aug 19, 2020 · 9 comments

Comments

@NicoSchwaller
Copy link
Collaborator

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
Copy link
Contributor

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
Copy link
Collaborator Author

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
Copy link

jmp-aws commented Aug 19, 2020

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

  • boto3==1.14.46

@avawang1
Copy link
Contributor

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
Copy link

jmp-aws commented Aug 19, 2020

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
Copy link
Contributor

avawang1 commented Aug 19, 2020

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
Copy link

jmp-aws commented Aug 19, 2020

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
Copy link

jmp-aws commented Aug 19, 2020

@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
Copy link
Collaborator Author

@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!

kshitijc pushed a commit that referenced this issue Nov 29, 2021
* make copy_aws_session public

* Add docstring, make func non-static

* change function name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants