-
Notifications
You must be signed in to change notification settings - Fork 73
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
PRINT-INSTRUCTION-GENERIC fails to print gate applications with complex-valued parameters #313
Comments
Woof. Seems like a similar issue #257. |
Quil tried to get a little more rigid about its typing last summer (cf. https://github.com/rigetti/quil/blob/master/spec/typed-memory.md ), and I think parameter values are forbidden from being complex numbers. However, the Quilt RFC ( https://github.com/rigetti/quil/tree/master/rfcs/analog ) wants complex parameter values in some of its new constructs. This isn't to say you shouldn't work on this issue (especially since it might become more relevant when Quilt gets under way), but rather to explain why no user has reported the bug in the wild. |
Good to know, thank you. I will take a look in any case. If the fix to support complex params seems simple, maybe we go ahead and do it in anticipation of Quilt support (or maybe not yet). If it looks like a bigger can of worms requiring medium-to-large changes, perhaps it makes sense to shelve it for now and maybe just update quilc to provide a better error message. We'll see! |
So it turns out that this instruction is actually failing to print in the guts of
I was not paying close enough attention to the backtrace in my above example and incorrectly assumed that the program had made it through Given that this will require compiler changes (as opposed to a Note that this error is tangentially related to a code-review comment from earlier today, namely passing a complex param to (defun build-gate (operator params &rest qubits)
"Shorthand function for constructing a GATE-APPLICATION object from QUIL-like input. OPERATOR must be a standard gate name."
(check-type params list)
(check-type qubits list)
(assert (not (null qubits)))
(flet ((capture-param (param)
(typecase param
(double-float
(constant param))
(memory-ref
(make-delayed-expression nil nil param))
(otherwise
param)))
... If I modify
|
:) This is a cascade of sloppy typechecking. The parser didn't stop you from passing |
(j/k Robert also wrote the parser) |
This is why I like excessively checking types everywhere like some kind of paranoiac :-) Were complex params previously supported? What has me confused is that these are explicitly tested and permitted in the parser tests (presumably with complex params that at least result in unitary matrices, unlike my silly Perhaps the way to go would be to update the parser to complain early, then move these tests cases from |
They were previously supported, but it was never a good idea: it's definitely possible to pick parameters in
so that the the resulting gate is unitary, but (1) the pattern of legal values is quite nonobvious and (2) an illegal choice of parameters was blamed on the user and resulted in undefined behavior. What happens in practice is more like
where the pattern is obvious—
but you really have to go out of your way to do such a silly thing. I'd strongly prefer that we stick with this ^ and remove support for complex parameters in the parser (and the associated tests), but it ought to be (re-)sanctioned by @stylewarning. |
I would be happy if we constrained parameters to just be real as a matter of practicality. |
Closing this as resolved by #608. Attempting to pass complex-valued gate parameters now raises a more readable error:
|
Minimal reproduction case:
The following files from the parser tests also tickle the bug:
For example:
Note that these Quil programs can be parsed and printed just fine, as long as they don't pass through
compiler-hook
.The text was updated successfully, but these errors were encountered: