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

Make compiler connection check timeout user-configurable #1246

Merged
merged 7 commits into from
Sep 5, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
Changelog
=========

[v2.22.0](https://github.com/rigetti/pyquil/compare/v2.22.0..master) (in development)
[v2.23.0](https://github.com/rigetti/pyquil/compare/v2.22.0..master) (In development)
------------------------------------------------------------------------------------

### Announcements

### Improvements and Changes

- Compiler connection timeouts are now entirely user-configurable (@kalzoo, gh-1246)

### Bugfixes

[v2.21.1](https://github.com/rigetti/pyquil/compare/v2.21.0..v2.22.0) (July 30, 2020)
[v2.22.0](https://github.com/rigetti/pyquil/compare/v2.21.1..v2.22.0) (August 3, 2020)
------------------------------------------------------------------------------------

### Announcements
Expand All @@ -27,7 +29,7 @@ Changelog

### Announcements

- This is just a cosmetic updated, to trigger a new docker build.
- This is just a cosmetic update, to trigger a new docker build.

### Improvements and Changes

Expand Down
33 changes: 20 additions & 13 deletions pyquil/api/_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,26 +281,30 @@ def connect(self) -> None:

def _connect_quilc(self) -> None:
try:
quilc_version_dict = self.quilc_client.call("get_version_info", rpc_timeout=1)
quilc_version_dict = self.quilc_client.call("get_version_info")
check_quilc_version(quilc_version_dict)
except TimeoutError:
raise QuilcNotRunning(f"No quilc server reachable at {self.quilc_client.endpoint}")
raise QuilcNotRunning(
f"Request to quilc at {self.quilc_client.endpoint} timed out. "
"This could mean that quilc is not running, is not reachable, or is "
"responding slowly."
)

def _connect_qpu_compiler(self) -> None:
assert self.qpu_compiler_client is not None
try:
self.qpu_compiler_client.call("get_version_info", rpc_timeout=1)
self.qpu_compiler_client.call("get_version_info")
except TimeoutError:
raise QPUCompilerNotRunning(
f"No QPU compiler server reachable at {self.qpu_compiler_client.endpoint}"
f"Request to the QPU Compiler at {self.qpu_compiler_client.endpoint} "
"timed out. "
"This could mean that the service is not reachable or is responding slowly."
)

def get_version_info(self) -> Dict[str, Any]:
quilc_version_info = self.quilc_client.call("get_version_info", rpc_timeout=1)
quilc_version_info = self.quilc_client.call("get_version_info")
if self.qpu_compiler_client:
qpu_compiler_version_info = self.qpu_compiler_client.call(
"get_version_info", rpc_timeout=1
)
qpu_compiler_version_info = self.qpu_compiler_client.call("get_version_info")
return {"quilc": quilc_version_info, "qpu_compiler": qpu_compiler_version_info}
return {"quilc": quilc_version_info}

Expand Down Expand Up @@ -397,10 +401,14 @@ def connect(self) -> None:
version_dict = self.get_version_info()
check_quilc_version(version_dict)
except TimeoutError:
raise QuilcNotRunning(f"No quilc server running at {self.client.endpoint}")
raise QuilcNotRunning(
f"Request to quilc at {self.client.endpoint} timed out. "
"This could mean that quilc is not running, is not reachable, or is "
"responding slowly."
)

def get_version_info(self) -> Dict[str, Any]:
return cast(Dict[str, Any], self.client.call("get_version_info", rpc_timeout=1))
return cast(Dict[str, Any], self.client.call("get_version_info"))

@_record_call
def quil_to_native_quil(self, program: Program, *, protoquil: Optional[bool] = None) -> Program:
Expand Down Expand Up @@ -462,8 +470,7 @@ def call(
indicating the cause of the failure. If present, that message is delivered to the user.

:param payload: The rpcq message body.
:param rpc_timeout: The number of seconds to wait to read data back from the service
after connection.
:param rpc_timeout: The number of seconds to wait for each of 'connection' and 'response'.
@see https://requests.readthedocs.io/en/master/user/advanced/#timeouts
"""
url = urljoin(self.endpoint, method)
Expand All @@ -473,7 +480,7 @@ def call(
else:
body = None

response = self.session.post(url, json=body, timeout=(1, rpc_timeout))
response = self.session.post(url, json=body, timeout=rpc_timeout)

try:
response.raise_for_status()
Expand Down
3 changes: 1 addition & 2 deletions pyquil/api/tests/data/user_auth_token_invalid.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"access_token": "ok",
"refresh_token": "ok",
"scopish": "notwhatwe'relookingfor"
"refresh_token_invalid": "invalid"
}
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ rpcq >= 3.0.0
ipython

# test deps
black
black==19.10b0
coveralls
flake8
flake8-bugbear
Expand Down