-
Notifications
You must be signed in to change notification settings - Fork 347
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
Raise TypeError when .run() is called with non-compiled Program #799
Conversation
Couple things. 1. The test is currently performed in QuantumComputer.run(). Should the test be performed in QPU.run()? I chose QC.run() because that is where the `executable` is provided and will show up in the backtrace. 2. That test might not be the best it could be. Since we're not running on a QPU, we can't instantiate a true `QPU` object -- is the way I've mocked it appropriate and safe? Have a good day :}
89832d3
to
581a41c
Compare
pyquil/api/_quantum_computer.py
Outdated
@@ -144,6 +144,13 @@ def run(self, executable: Executable, | |||
are a list of floats or integers. | |||
:return: A numpy array of shape (trials, len(ro-register)) that contains 0s and 1s. | |||
""" | |||
# This prevents a common error where users expect QVM.run() | |||
# and QPU.run() to be interchangeable. QPU.run() needs the | |||
# supplied executable to have been compiled, QVM.run() does not. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some more color here: if you construct a qvm with a topology, the code will assume you care about realism and will error if you pass a program instead of an executable. However, we thought that would be annoying if you didn't really care about compiling/realism so if you construct a {n}q-qvm without a topology it will accept Program
s
>> get_qc('2q-qvm').run(program) # fine
>> get_qc('Aspen-1-2Q-A-qvm').run(program) # error! you need to compile
this might be more confusing than it's worth
pyquil/api/_quantum_computer.py
Outdated
# This prevents a common error where users expect QVM.run() | ||
# and QPU.run() to be interchangeable. QPU.run() needs the | ||
# supplied executable to have been compiled, QVM.run() does not. | ||
if isinstance(self.qam, QPU) and isinstance(executable, Program): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not put this check in the QPU
class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From above:
- The test is currently performed in QuantumComputer.run(). Should the test be performed in QPU.run()? I chose QC.run() because that is where the
executable
is provided and will show up in the backtrace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if you put it in QPU it will still show up in the backtrace, just one level up
# This test might need some more knowledgeable eyes. Not sure how | ||
# to best mock a qpu. | ||
qc = get_qc('1q-qvm') | ||
qc.qam = QPU(endpoint='tcp://not-needed:00000', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the legit way to mock this would be to mock out QPU.client.call
which is the rpcq thing that actually communicates with the quantum hardware. Maybe the rpcq repo has some useful test fixtures we could repurpose here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple minor comments you might want to address. Nice change :)
@@ -5,7 +5,7 @@ | |||
import pytest | |||
|
|||
from pyquil import Program, get_qc, list_quantum_computers | |||
from pyquil.api import QVM, QuantumComputer, local_qvm | |||
from pyquil.api import QVM, QPU, QuantumComputer, local_qvm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn't look like this is used anywhere
@@ -120,6 +121,13 @@ def run(self): | |||
|
|||
:return: The QPU object itself. | |||
""" | |||
# This prevents a common error where users expect QVM.run() | |||
# and QPU.run() to be interchangeable. QPU.run() needs the | |||
# supplied executable to have been compiled, QVM.run() does not. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good, I don't remember what the error would be otherwise, but this error message is certainly better.
Ideally, QPU and QVM should be interchangeable.
I think a warning is raised when running on QVM without calling .compile, or maybe only in some cases. Maybe we can consider rewording this comment to encourage users to call .compile even when targeting the QVM, to prevent people from running into this issue in the first place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the full story here: #799 (comment)
@@ -5,7 +5,7 @@ | |||
import pytest | |||
|
|||
from pyquil import Program, get_qc, list_quantum_computers | |||
from pyquil.api import QVM, QuantumComputer, local_qvm | |||
from pyquil.api import QVM, QPU, QuantumComputer, local_qvm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from pyquil.api import QVM, QPU, QuantumComputer, local_qvm | |
from pyquil.api import QVM, QuantumComputer, local_qvm |
Couple things.
the test be performed in QPU.run()? I chose QC.run() because that is
where the
executable
is provided and will show up in thebacktrace.
running on a QPU, we can't instantiate a true
QPU
object -- is theway I've mocked it appropriate and safe?
Closes #740.
Have a good day :}