-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Preserve i->i initial layout when coupling_map satisfied #527
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
Conversation
qiskit/_compiler.py
Outdated
graphs are equal to backend qubits coupling graph. | ||
|
||
Parameters: | ||
instructions (List): List of circuit instructions. Noy all instructions |
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.
'Noy' -> 'Not
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def compile(circuits, backend, | ||
config=None, basis_gates=None, coupling_map=None, initial_layout=None, | ||
shots=1024, max_credits=10, seed=None, qobj_id=None, hpc=None, | ||
skip_translation=False): |
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.
Do we really want to remove this kwarg? For backward compatibility, should it not implicitly set skip_transpiler
and raise a depreciation warning saying that it will be removed in the future?
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, good point.
""" | ||
for instruction in instructions: | ||
if isinstance(instruction, Gate) and instruction.is_multi_qubit(): | ||
if instruction.get_qubit_coupling() not in coupling_map: |
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.
For a two qubit gate between qubits i
and j
, I thought the check would be if j
is in coupling_map[i]
or if i
in coupling_map[j]
. Is that what is going on here, or (more likely) am I missing something?
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 checks for exact match, meaning if there is a CX(q[i], q[j]) in the circuit, it checks that the device also has CX(q[i], q[j]) in it. The reason is that I want to keep already-matching circuits untouched, but pass any other ones through the mapper. A good mapper may actually find a more compact circuit, but usually a user that writes an already-matching circuit wants to use those exact qubits.
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.
Yeah, I found this confusing at first, because I thought that the coupling_map
was an adjacency list, but it's not. It more a list of coupled pairs: coupling_map = [[1, 0], [2, 0], [2, 1], [3, 2], [3, 4], [4, 2]]
.
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.
Yes, your right. This is what we want.
b98f728
to
ee466d3
Compare
8e6feca
to
9ae25f8
Compare
* Preserve i->i initial layout when already satisfied. * skip_translation deprecated in favor of skip_transpiler.
When a circuit already satisfies the coupling_map on the backend, the swap_mapper should not insert any swaps. This means passing an
initial_layout
ofq[i]->q[i]
.PR #478 optimizes the initial layout, but that creates unexpected behavior when the coupling map is already satisfied. Here, I only apply the optimization of #478 if swaps are indeed needed.
The other thing that this PR does is a slight name change:
skip_translation
->skip_transpiler
, to get ready for the transpiler PR.Motivation and Context
Issue was raised here:
https://quantumexperience.ng.bluemix.net/qx/community/question?questionId=5b0d17f943fb6e0038a623bf
Screenshots (if appropriate):
Types of changes
Checklist: