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

Add quilc_client property to QVMCompiler, improve timeout documentation #1273

Merged
merged 15 commits into from
Nov 17, 2020

Conversation

notmgsk
Copy link
Contributor

@notmgsk notmgsk commented Nov 16, 2020

Add a client property to QPUCompiler so that it has better feature
parity with QVMCompiler. Generally we tell folks that

  1. QVMCompiler and QPUCompiler should be largely interchangeable,
    meaning that you can swap qc = get_qc("Aspen-8", as_qvm=True) with
    qc = get_qc("Aspen-8", as_qvm=False), and things should Just
    Work. And

  2. To set the timeout on a QVMCompiler one does
    qc.compiler.client.rpc_timeout = ... but on a QPUCompiler
    qc.compiler.quilc_client.rpc_timeout = ....

This change brings 1 and 2 into alignment, so that the method for
configuring the compiler timeout is the same between the compiler
classes.

Further, it adds a set_timeout method for both classes, and updates
the documentation.

Add a client property to QPUCompiler so that it has better feature
parity with QVMCompiler. Generally we tell folks that

 1. QVMCompiler and QPUCompiler should be largely interchangeable,
 meaning that you can swap `qc = get_qc("Aspen-8", as_qvm=True)` with
 `qc = get_qc("Aspen-8", as_qvm=False)`, and things should Just
 Work. And

 2. To set the timeout on a QVMCompiler one does
 `qc.compiler.client.rpc_timeout = ...` but on a QPUCompiler
 `qc.compiler.quilc_client.rpc_timeout = ...`.

This change brings 1 and 2 into alignment, so that the method for
configuring the compiler timeout is the same between the compiler
classes.
@notmgsk notmgsk marked this pull request as ready for review November 16, 2020 21:06
@notmgsk notmgsk requested a review from a team as a code owner November 16, 2020 21:06

.. code:: python
qc = get_qc(..., as_qvm=False)
qc.compiler.quilc_client.rpc_timeout = 100 # 100 seconds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it? The instructions I've always used / given is:

On QVM, you need "qc.compiler.client.timeout";
On QPU it is just "qc.compiler.timeout".

Copy link
Contributor Author

@notmgsk notmgsk Nov 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timeout is most relevant to the Client object that is created. In both QVMCompiler and QPUCompiler the (quilc) client is instantiated in __init__ and so immediately uses the timeout arg given to __init__ (this is the same value that is assigned to self.timeout in both classes). Therefore if you want to modify the timeout that is used specifically in quilc, then you have to change qc.compiler.{client,quilc_client}.rpc_timeout. QPUCompiler has a second client to the translation service, which also uses self.timeout but is deferred until the client is requested. I think that means that you probably got it to work by using qc.compiler.timeout because the client hadn't yet been created, and so used the new timeout value.

All that to say, this PR doesn't modify the translation service timeout. Should it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, unless there was a separate well-documented path for the translation service, I'd apply this one timeout in both locations (and say that it applies to both the compiler timeout for quil_to_native_quil, and translation timeout for native_quil_to_executable).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that a commit I just added now does modify the translation service timeout. That one is set on a per-call basis to the current value of QPUCompiler#timeout.

pyquil/api/_compiler.py Outdated Show resolved Hide resolved
docs/source/compiler.rst Outdated Show resolved Hide resolved
docs/source/compiler.rst Outdated Show resolved Hide resolved
@property
def client(self) -> Client:
"""Return the `Client` for the compiler (i.e. quilc, not translation service)."""
# TODO(notmgsk): This was introduced around 2.25 to provide
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in the docstring, and not version-specific. While that seems like important information within the context of the PR, it becomes irrelevant as more information comes out.

Also, this might be worth having as an @abstractmethod on the AbstractCompiler with the documentation note there instead. That's the intent behind abstract methods in any case - parity among subclasses.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the comment entirely, and have chosen to not take the abstract method route just because at this point I'm not sure how much it gives us, but if you feel strongly about it I will add it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, now that the methods are identical, I think it's wise to make it a non-abstract method on the parent class for de-duplication

@@ -182,7 +182,7 @@ def __init__(
quilc_endpoint: Optional[str],
qpu_compiler_endpoint: Optional[str],
device: AbstractDevice,
timeout: int = 10,
timeout: float = 10,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also support this in get_qc, maybe as compiler_timeout? That's the "tutorial" way of constructing this in any case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Donezo. I have refrained from adding a timeout option to QuantumComputer#compile, because (1) I think the options available now are sufficient, and (2) we could probably find a million places to add a timeout flag to (gotta draw the line somewhere).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

pyquil/api/_compiler.py Show resolved Hide resolved
docs/source/compiler.rst Outdated Show resolved Hide resolved
@@ -338,7 +338,9 @@ def native_quil_to_executable(self, nq_program: Program) -> Optional[BinaryExecu
)
response: BinaryExecutableResponse = cast(
BinaryExecutableResponse,
self.qpu_compiler_client.call("native_quil_to_binary", request),
self.qpu_compiler_client.call(
"native_quil_to_binary", request, rpc_timeout=self.timeout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I flubbed this in #1246 , should have been included there


.. code:: python
qc = get_qc(..., as_qvm=False)
qc.compiler.quilc_client.rpc_timeout = 100 # 100 seconds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that a commit I just added now does modify the translation service timeout. That one is set on a per-call basis to the current value of QPUCompiler#timeout.

@kalzoo
Copy link
Contributor

kalzoo commented Nov 17, 2020

Needs a changelog entry also.

@notmgsk
Copy link
Contributor Author

notmgsk commented Nov 17, 2020

Hopefully all comments are addressed. Please take another look

@notmgsk notmgsk changed the title Add client property to QPUCompiler, improve timeout documentation Add quilc_client property to QVMCompiler, improve timeout documentation Nov 17, 2020
Copy link
Contributor

@kalzoo kalzoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since set_timeout is now identical between the two compilers, it should be hoisted to a concrete method on the parent class. Otherwise, lgtm

@notmgsk notmgsk merged commit 30f33b8 into master Nov 17, 2020
@notmgsk notmgsk mentioned this pull request Nov 17, 2020
@dbanty dbanty deleted the document-timeout-configuration branch February 14, 2022 17:03
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

Successfully merging this pull request may close these issues.

4 participants