-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Allow mcrx, mcry and mcrz gate methods to accept angles of ParameterValueType #13507
Conversation
One or more of the following people are relevant to this code:
|
The failing tests were added as part of #12752. |
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 looks great, I'm glad that we can support parameterized multicontrolled rotations!
I'm wondering whether we can consolidate the method you added with the existing _mcsu2_real_diagonal
to ensure we don't duplicate the logic. One option could be to take the unitary as Gate
instead of np.ndarray
:
def _mcsu2(gate: Gate, num_controls: int, use_basis_gates: bool) -> QuantumCircuit:
if isinstance(gate, RYGate):
s_gate = # ...
elif # the other Pauli rotation cases, RX and RZ
else:
unitary = gate.to_matrix()
s_gate = # compute s_gate
# common logic here
do you think that might work?
qiskit/circuit/library/standard_gates/multi_control_rotation_gates.py
Outdated
Show resolved
Hide resolved
qiskit/circuit/library/standard_gates/multi_control_rotation_gates.py
Outdated
Show resolved
Hide resolved
You refer to |
These are the failing tests, but all of them are failing (not only for RX / RY / RZ) |
Pull Request Test Coverage Report for Build 12653458685Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
qiskit/circuit/library/standard_gates/multi_control_rotation_gates.py
Outdated
Show resolved
Hide resolved
releasenotes/notes/fix-multi-controlled-rotation-gates-with-parameter-12a04701d0cd095b.yaml
Outdated
Show resolved
Hide resolved
qiskit/synthesis/multi_controlled/multi_control_rotation_gates.py
Outdated
Show resolved
Hide resolved
else: | ||
mode = "noancilla" | ||
|
||
if mode == "basic": |
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 not something to fix in this PR: but do you know why we have this special case only for MCRY
and not for the others? If it's more efficient we could also use it there.
This is something we can fix very cleanly if we synthesize controlled gates via HLS, which knows the number of free auxiliaries.
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.
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.
after checking it seems that adding ancillas can improve mcry in certain cases (num_controls >= 7). This is an optimization that should be explored in a follow-up work.
qiskit/synthesis/multi_controlled/multi_control_rotation_gates.py
Outdated
Show resolved
Hide resolved
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.
One small comment on the docs and one question that doesn't need to be resolved in this PR, otherwise LGTM 👍🏻
self._check_dups(all_qubits) | ||
|
||
n_c = len(control_qubits) | ||
if n_c == 1: # cu |
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.
With @alexanderivrii's PR on the annotated gate plugins, could we change this method in future to just append an annotated Pauli rotation? It would be nice if we can move this logic to the plugin so it doesn't need to be duplicated for the annotated rotation.
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.
Indeed. I think this could be done in a follow-up PR.
qiskit/synthesis/multi_controlled/multi_control_rotation_gates.py
Outdated
Show resolved
Hide resolved
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 for the improvement! I'm not 100% sure whether this should be a bugfix or a new feature -- do you remember whether parameterized rotations were supported before the changes to mcsu2_real_diag
etc. ?
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 looks good on my side as well. For posteriority, could you please add the number of 2-qubit gates we get for multiply-controlled parametric p gates before and after this PR (since we now use the same presumably better algorithm both for parametric and non-parametric gates)? It would be also nice to record somewhere further follow-ups discussed in this PR.
Summary
Address #12863
There are currently several open issues that fail with errors like:
QiskitError: 'Cannot synthesize MCRY with unbound parameter:
#7975
#11142
#13192
This PR aims to fix them
Details and comments