rigetti / pyquil

A Python library for quantum programming using Quil.
http://docs.rigetti.com
Apache License 2.0
1.4k stars 341 forks source link

Error when using is_done() with JobConnection #102

Closed schuylerfried closed 6 years ago

schuylerfried commented 7 years ago

Error indicates that 'jobId' key is not found in self.result dictionary. My beta key for the api works, as I've tested and ran several programs using api.SyncConnection() Here's the traceback:

File "test.py", line 17, in main while not res.is_done(): File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyquil/job_results.py", line 47, in is_done self.get() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyquil/job_results.py", line 63, in get return self.qpu.get_job(self) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyquil/api.py", line 296, in get_job url = self.endpoint + ("/job/%s" % (job_result.job_id())) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyquil/job_results.py", line 55, in job_id return self.result['jobId'] KeyError: 'jobId'

My source code was basically copied from the tutorial for testing purposes:

import pyquil.quil as pq from pyquil.quil import Program import pyquil.api as api from pyquil.gates import * from numpy import * import sys sys.path.append('/usr/local/lib/python2.7/site-packages') import nlopt from pyquil.api import JobConnection import time

job_qvm = JobConnection(endpoint="https://job.rigetti.com/beta") #qvm = api.SyncConnection()

def main():     res = job_qvm.run(Program(X(0)).measure(0, 0), [0])     while not res.is_done():         time.sleep(1)      print(res.get())     return 0

main()

stevenheidel commented 6 years ago

Hi @schuylerfried , is this still broken for you? If so I will look into it

schuylerfried commented 6 years ago

Unfortunately, it is.

My python2 and gcc versions are:

Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 12:39:47) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin

stevenheidel commented 6 years ago

I think I know what's happening: we recently changed to require a user_id for the job.rigetti.com endpoint. That means your .pyquil_config file should look like this:

[Rigetti Forest] url: https://job.rigetti.com/beta key: user_id:

If you don't have a user_id you will have to sign up again at http://www.rigetti.com/index.php/forest . Signing up only takes a few seconds now in our new system.

We will work on improving the error message.

schuylerfried commented 6 years ago

Worked - thank you! And yeah, a better error message would definitely be helpful.