-
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
Fix UnitaryGate.repeat()
method
#12986
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the following people are relevant to this code:
|
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 a lot @timmintam! The PR looks pretty good, I just added a small suggestion
This would also happen for a set of other gates that have special These would fail because the custom |
UnitaryGate.repeat()
medthodUnitaryGate.repeat()
method
You are right @Cryoris, this would fail for other gates as well actually. Do you mean something along these lines this in the def _return_repeat(self, exponent: float) -> "Gate":
gate = Gate(name=f"{self.name}*{exponent}", num_qubits=self.num_qubits, params=[])
gate.validate_parameter = self.validate_parameter
gate.params = self.params
return gate It seems to do the trick. |
Yeah exactly! 🙂 An alternative solution would be to extend the Could you also add tests for these other gate types that fail? |
Pull Request Test Coverage Report for Build 10525187951Details
💛 - Coveralls |
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 a lot timmintam, just to err on the side of caution, could you also add a test for the PermutationGate
case in test/python/circuit/library/test_permutation.py
?
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.
Nice! The changes look good to me, but let's wait to see if @Cryoris has any final comment before merging.
fixes: | ||
- | | ||
Fixes an error when calling the method :meth:`.UnitaryGate.repeat`. | ||
Refer to `#11990 <https://github.com/Qiskit/qiskit/issues/11990>` for more |
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 this needs a trailing underscore (but @ElePT might know this better than me 🙂)
Refer to `#11990 <https://github.com/Qiskit/qiskit/issues/11990>` for more | |
Refer to `#11990 <https://github.com/Qiskit/qiskit/issues/11990>`__ for more |
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.
Nice, thanks for the update! Sorry I wasn't explicit about all gates that would need this kind of testing, this should be the complete list:
Initialize
(though this is anInstruction
so this might need the same fix on theInstruction
class)StatePreparation
DiagonalGate
LinearFunction
(not called gate but is a gate 🙂 )PauliGate
UCPauliRotGate
HamiltonianGate
Could you add a small test for these as well? They can all also be on 1 or 2 qubits max like what you already have 🙂
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.
LGTM thanks for the updates 🙂
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.
LGTM to me too!
Summary
Closes #11990 : error when calling the
UnitaryGate.repeat()
method (inherited from theGate
class).Details and comments
The method
repeat()
internally calls the private method_return_repeat()
which is inherited from theGate
class.It creates a new
Gate
object with argumentsparams=self.params
, which is expected to be of typeParameterExpression
orfloat
. However the parameters are of typenumpy.ndarray
for aUnitaryGate
.A simple fix is to omit these parameters (
params=[]
) as they are not directly used by the returnedGate
. Actually these parameters are still stored in therepeat()
method and used only there.