-
Notifications
You must be signed in to change notification settings - Fork 342
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
Recursively expand defcals #1270
Conversation
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.
Thanks! As per our chat, just a couple tweaks:
- Regenerate with ANTLR 4.8
- account for and guard on expansion recursion depth. Use a module constant for maximum depth probably
Done.
Also done, though by a different method. Instead of testing that calibration isn't going too deep, I test that there's no cycle in the calibrations which I think is the more likely issue (i.e. user erroneously supplies a bad |
There's a strange build error happening on travis-ci. Looks like |
ce0c82d
to
ff62fb6
Compare
ff62fb6
to
beb6b16
Compare
beb6b16
to
ed2a596
Compare
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.
Should the grammar rely on the submodule now?
pyquil/quil.py
Outdated
expanded_instructions = expand_calibration(match) | ||
for expanded_instruction in expanded_instructions: | ||
if expanded_instruction in seen_instructions: | ||
raise RuntimeError( |
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.
Is there a more-expressive error class to use? Is it worth adding a CalibrationError
for this and other errors in calibration?
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 have defined that exception class. There already exists a CalibrationDoesntMatch
class, which now has CalibrationError
as its parent. Should we define a new child class CyclicalCalibrationError
? or is that going too far?
pyquil/tests/test_quilt.py
Outdated
assert calibrated == Program("RY(pi) 0").instructions | ||
|
||
|
||
def test_program_calibrate_cyclic_error(): |
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.
would prefer separate or parametrized test cases for these independent programs, i.e.
@pytest.mark.parametrize('program_text', ('DEFCAL RZ(%theta) q:\n\tRZ(%theta) q', ...))
def test_program_calibrate_cyclic_error(program_text):
...
Restored the grammar symlink. Must've gotten lost in a rebase. |
- recursively expand defcals - allow formal qubits in top-level gates
This PR does two things:
Recursively expand calibrations, meaning that if a calibration expansion introduces new instructions that have an associated calibration then those instructions will also be expanded (and so on).
Extends the grammar to permit "formal" arguments to
Gate
outside ofDEFCIRCUIT
. This is required because the above change (calibration expansion) is motivated by calibration bodies possibly including gates, and since a calibration can be specified on a qubit variable (e.g.q
rather than0
) then the body of the calibration needs to support qubit variables. Previously this was only allowed within a circuit definition, but to make life simpler, it is now possible anywhere a gate is permitted.