Skip to content

Preserve i->i initial layout when coupling_map satisfied#527

Merged
atilag merged 6 commits into
Qiskit:masterfrom
ajavadia:fix/initial_layout
Jun 11, 2018
Merged

Preserve i->i initial layout when coupling_map satisfied#527
atilag merged 6 commits into
Qiskit:masterfrom
ajavadia:fix/initial_layout

Conversation

@ajavadia
Copy link
Copy Markdown
Member

@ajavadia ajavadia commented May 30, 2018

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 of q[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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Comment thread qiskit/_compiler.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Noy' -> 'Not

Comment thread qiskit/_compiler.py Outdated
Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, good point.

Comment thread qiskit/_compiler.py Outdated
Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown
Member

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]].

Copy link
Copy Markdown
Contributor

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.

@ajavadia ajavadia force-pushed the fix/initial_layout branch from b98f728 to ee466d3 Compare June 7, 2018 21:09
atilag
atilag previously approved these changes Jun 8, 2018
atilag
atilag previously approved these changes Jun 8, 2018
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jun 8, 2018

CLA assistant check
All committers have signed the CLA.

@atilag atilag merged commit ae01c90 into Qiskit:master Jun 11, 2018
@ajavadia ajavadia deleted the fix/initial_layout branch July 21, 2018 00:02
lia-approves pushed a commit to edasgupta/qiskit-terra that referenced this pull request Jul 30, 2019
* Preserve i->i initial layout when already satisfied.
* skip_translation deprecated in favor of skip_transpiler.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants