-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Change switch_to_new condition in TwoQubitCompilationTargetGateset to switch only when it's optimal in terms of 2q gate counts
#5405
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,10 +170,24 @@ def decompose_to_target_gateset(self, op: 'cirq.Operation', moment_idx: int) -> | |
| old_2q_gate_count = sum(1 for o in ops.flatten_to_ops(old_optree) if len(o.qubits) == 2) | ||
| new_2q_gate_count = sum(1 for o in ops.flatten_to_ops(new_optree) if len(o.qubits) == 2) | ||
| switch_to_new = ( | ||
| any(op not in self for op in ops.flatten_to_ops(old_optree)) | ||
| any( | ||
| protocols.num_qubits(op) == 2 and op not in self | ||
| for op in ops.flatten_to_ops(old_optree) | ||
| ) | ||
| or new_2q_gate_count < old_2q_gate_count | ||
| ) | ||
| return new_optree if switch_to_new else old_optree | ||
| if switch_to_new: | ||
| return new_optree | ||
| mapped_old_optree: List['cirq.OP_TREE'] = [] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is different from the old behavior: if all old ops (1q or 2q) are in the target gateset and (If gateset behavior would prevent this case from occurring, a comment explaining this would be helpful)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The behavior is unchanged, i.e., if all old ops (1q or 2q) are in the target gateset and Notice that the |
||
| for old_op in ops.flatten_to_ops(old_optree): | ||
| if old_op in self: | ||
| mapped_old_optree.append(old_op) | ||
| else: | ||
| decomposed_op = self._decompose_single_qubit_operation(old_op, moment_idx) | ||
| if decomposed_op is None or decomposed_op is NotImplemented: | ||
| return NotImplemented | ||
| mapped_old_optree.append(decomposed_op) | ||
| return mapped_old_optree | ||
|
|
||
| def _decompose_single_qubit_operation( | ||
| self, op: 'cirq.Operation', moment_idx: int | ||
|
|
||
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.
Can we do this part of the check before constructing
new_optreeso we don't waste time on it if it's not needed?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.
We will have to construct the
new_optreeirrespective of whether this check returns a True or False.We will not switch to the
new_optreeonly if both the checks are false (i.e. all 2q operations inold_optreeare inselfandold_2q_gate_count <= new_2q_gate_count.