8000 Fix Issue #469, Mapper error by nonhermitian · Pull Request #478 · Qiskit/qiskit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix Issue #469, Mapper error #478

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

Merged
merged 10 commits into from
May 16, 2018
Merged

Fix Issue #469, Mapper error #478

merged 10 commits into from
May 16, 2018

Conversation

nonhermitian
Copy link
Contributor
@nonhermitian nonhermitian commented May 16, 2018

Description

Picks a better initial layout for register to physical qubits if none is given.

This is a stopgap fix, as the values should be cached as they need only be computed once.

Motivation and Context

Multiple issues with swap mapper, as reported in #469.

How Has This Been Tested?

Seems to solve all mapper issues.

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.

@nonhermitian
Copy link
Contributor Author

Waiting for @rraymondhp to confirm that his issues have also been resolved by this PR.

@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
# pylint: disable=redefined-builtin
# pylint: disable=C0103
# pylint: disable=W9006
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove this pylint exceptions and take care of the warning themselves instead? In general, disabling a linter check (specially in qiskit/*) should only be used as a last resort, not as a convenience, in order to maintain the consistency of the codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed the raising exception issue. Not going to worry about how my iterator constants are defined.

@@ -279,6 +294,54 @@ def load_unroll_qasm_file(filename, basis_gates='u1,u2,u3,cx,id'):
return circuit_unrolled


def best_subset(backend, n_qubits):
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to have a couple of tests that exercise this function (or that invoke it trough compile())? Probably using the values that were reported in the initial issue or some edge cases would be a good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am trying to find a short test that raises an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@diego-plan9 diego-plan9 changed the title BUG: Fix Issue #469, Mapper error Fix Issue #469, Mapper error May 16, 2018
Copy link
Member
@atilag atilag left a comment

Choose a reason for hiding this comment

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

Overall good!
Just some comments regarding readability.

cmap = np.asarray(backend.configuration['coupling_map'])

if n_qubits > device_qubits:
raise ValueError('Number of qubits greater than device.')
Copy link
Member

Choose a reason for hiding this comment

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

For exceptions raised because of a Qiskit logical error, we better use: QISKitError('text')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

10000
if n_qubits > device_qubits:
raise ValueError('Number of qubits greater than device.')
elif n_qubits <= 0:
raise ValueError('Number of qubits <= 0.')
Copy link
Member

Choose a reason for hiding this comment

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

Same as above: ValueError() => QISKitError()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

connectivity mapping.
"""
device_qubits = backend.configuration['n_qubits']
cmap = np.asarray(backend.configuration['coupling_map'])
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this line after all the initial checks? ... so if some of the checks fail, there's no need for this computation.

raise ValueError('Number of qubits greater than device.')
elif n_qubits <= 0:
raise ValueError('Number of qubits <= 0.')
if n_qubits == 1:
Copy link
Member

Choose a reason for hiding this comment

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

I would put this check as the first line of the method. So if it's true we are returning fast.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

best = 0
best_map = None
# do bfs with each node as starting point
for kk in range(sp_cmap.shape[0]):
Copy link
Member

Choose a reason for hiding this comment

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

Index variables are the only exception for one letter naming, doesn't hurt the readability though, but I'd encourage to rename it to just: k

bfs = cs.breadth_first_order(sp_cmap, i_start=kk, directed=False,
return_predecessors=False)

con = 0
Copy link
Member

Choose a reason for hiding this comment

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

This is some kind of match counter, right? Can we change the name to something more verbose/explanatory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


con = 0
for ii in range(n_qubits):
ss = bfs[ii]
Copy link
Member

Choose a reason for hiding this comment

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

Can we have a better naming for ss? bfs_node? (to distinguish from the node of the sparse matrix index)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

ValueError: Wrong number of qubits given.
"""
device_qubits = backend.configuration['n_qubits']
cmap = np.asarray(backend.configuration['coupling_map'])
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this line before all the checks? so if something is failing in the preconditions there's no need to compute this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member
@diego-plan9 diego-plan9 left a comment

Choose a reason for hiding this comment

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

Fixed the raising exception issue. Not going to worry about how my iterator constants are defined.

Please refer to the contributor document and the code of conduct of the project - it is not about a single contributor having to worry, it is about maintaining the consistency and adhering to the conventions, in order to help the team as a whole. Again - can you remove the:

pylint: disable = C010

line, and take care of the linter issues in the proper way? They should be easier to fix after the latest round of renaming the variables to human-readable names, which is also in line with the rationale behind the linter and code style conventions.

@atilag atilag merged commit 64896d0 into Qiskit:master May 16, 2018
lia-approves pushed a commit to edasgupta/qiskit-terra that referenced this pull request Jul 30, 2019
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.

3 participants
0