-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Error in extracting qasm code from a controlled UnitaryGate #4623
Comments
UnitaryGate.control() returns an instance of ControlledGate (not UnitaryGate), which doesn't override a qasm() function. thus qasm() reverts back to instruction.qasm() which assumes that self.param is an array of qarg. while UnitaryGate.control() stores the matrix representation in params I think the solution is either to:
either way this shouldn't change the qasm code generated for the standard controlled gates (cx,ccx.. etc) I'm trying to implement option 2. But if anyone wants to give it a shot, no problem. |
Can I give this a try? |
sure no problem. |
Any progress @rochisha0 ? |
@rochisha0 is not responsive. Do you mid PRing your solution @faisaldebouni ? |
Sure, I will work on this right away. |
I need some guidance with this. I see many problems with how qasm is being generated in general. Directly fixing this issue will not give the correct qasm code. Mainly, generating qasm definition for circuits with custom gates is not done recursively.
will give:
However, UnitaryGate definition is pretty flat, so the gate will be correctly defined. But One "temporary" solution is to make So My questions are, Do I:
|
This is mock implementation that adopts how qasm generation currently works regardless.
|
It seems to me that an arbitrary matrix should be synthesised to create a QASM definition. (Sorry this answer this late. This felt between the cracks) |
Still valid |
Information
What is the current behavior?
When I run the following code, I get the corresponding error:
It looks like
gate.params
returns the unitary matrixU
, and thenpi_check
tries to applycomplex(U)
, which results in the error.Steps to reproduce the problem
Run the code above.
What is the expected behavior?
No error should occur.
Suggested solutions
This looks like the same error as reported in #4447. It looks like the problem arises because
gate.params
is simply the numpy unitary matrix, but the.qasm()
method assumes that the parameters are all floats and callspi_check
on the unitary matrix. I'm not sure if this is an issue with the.qasm()
method, or with the way parameters are stored for the controlledgate
object. (When you remove the.control()
call from the definition ofgate
, the code runs as expected.)The text was updated successfully, but these errors were encountered: