-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
Waiting for @rraymondhp to confirm that his issues have also been resolved by this PR. |
qiskit/_compiler.py
Outdated
@@ -1,5 +1,7 @@ | |||
# -*- coding: utf-8 -*- | |||
# pylint: disable=redefined-builtin | |||
# pylint: disable=C0103 | |||
# pylint: disable=W9006 |
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 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.
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.
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): |
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.
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.
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.
I am trying to find a short test that raises an error.
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.
Done.
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.
Overall good!
Just some comments regarding readability.
qiskit/_compiler.py
Outdated
cmap = np.asarray(backend.configuration['coupling_map']) | ||
|
||
if n_qubits > device_qubits: | ||
raise ValueError('Number of qubits greater than device.') |
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 exceptions raised because of a Qiskit logical error, we better use: QISKitError('text')
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.
Done.
qiskit/_compiler.py
Outdated
if n_qubits > device_qubits: | ||
raise ValueError('Number of qubits greater than device.') | ||
elif n_qubits <= 0: | ||
raise ValueError('Number of qubits <= 0.') |
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.
Same as above: ValueError() => QISKitError()
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.
Done.
qiskit/_compiler.py
Outdated
connectivity mapping. | ||
""" | ||
device_qubits = backend.configuration['n_qubits'] | ||
cmap = np.asarray(backend.configuration['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.
Can we move this line after all the initial checks? ... so if some of the checks fail, there's no need for this computation.
qiskit/_compiler.py
Outdated
raise ValueError('Number of qubits greater than device.') | ||
elif n_qubits <= 0: | ||
raise ValueError('Number of qubits <= 0.') | ||
if n_qubits == 1: |
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.
I would put this check as the first line of the method. So if it's true we are returning fast.
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.
Done.
qiskit/_compiler.py
Outdated
best = 0 | ||
best_map = None | ||
# do bfs with each node as starting point | ||
for kk in range(sp_cmap.shape[0]): |
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.
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
qiskit/_compiler.py
Outdated
bfs = cs.breadth_first_order(sp_cmap, i_start=kk, directed=False, | ||
return_predecessors=False) | ||
|
||
con = 0 |
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 some kind of match counter, right? Can we change the name to something more verbose/explanatory?
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.
Done.
qiskit/_compiler.py
Outdated
|
||
con = 0 | ||
for ii in range(n_qubits): | ||
ss = bfs[ii] |
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 have a better naming for ss
? bfs_node
? (to distinguish from the node
of the sparse matrix index)
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.
Done.
qiskit/_compiler.py
Outdated
ValueError: Wrong number of qubits given. | ||
""" | ||
device_qubits = backend.configuration['n_qubits'] | ||
cmap = np.asarray(backend.configuration['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.
Can we move this line before all the checks? so if something is failing in the preconditions there's no need to compute this.
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.
Done.
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.
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.
* Fix mapper issue
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
Checklist: