-
Notifications
You must be signed in to change notification settings - Fork 61
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
SABRE + CircuitMap Optimization #1419
Conversation
for more information, see https://pre-commit.ci
SABRE + CircuitMap OptimizationPrevious Implementation
New ImplementationThe code has been updated in three key areas: 1. Qubit Mapping
1-1. Layout Relabel
qibo/src/qibo/transpiler/router.py Lines 731 to 739 in 0111a6e
qibo/src/qibo/transpiler/router.py Lines 702 to 707 in 0111a6e
1-2 Physical-Logical Mapping
qibo/src/qibo/transpiler/router.py Lines 183 to 192 in 0111a6e
qibo/src/qibo/transpiler/router.py Lines 280 to 284 in 0111a6e
2. Temporary CircuitMap
qibo/src/qibo/transpiler/router.py Lines 194 to 196 in 0111a6e
qibo/src/qibo/transpiler/router.py Lines 843 to 849 in 0111a6e
3. Blocks in the
|
dag = nx.DiGraph() | |
dag.add_nodes_from(range(len(gates_qubits_pairs))) | |
# 3# additionally store target qubits of the gates | |
for i in range(len(gates_qubits_pairs)): | |
dag.nodes[i]["qubits"] = gates_qubits_pairs[i] |
- For example,
self._dag = [(0, {'qubits': (0, 9), 'layer': 0}), (1, {'qubits': (5, 9), 'layer': 1}), (2, {'qubits': (2, 8), 'layer': 0})]
- The function
_get_dag_layer(n, qubits=True)
returns a list of target qubits for the gates in layern
. - This allows retrieval of target qubits in
$O(1)$ time.
qibo/src/qibo/transpiler/router.py
Lines 807 to 815 in 0111a6e
# 3# depend on the 'qubits' flag, return the block number or target qubits | |
# 3# return target qubits -> to avoid using get_physical_qubits(block_num) | |
if qubits: | |
layer_qubits = [] | |
nodes = self._dag.nodes(data=True) | |
for node in nodes: | |
if node[1]["layer"] == n_layer: | |
# return target qubits | |
layer_qubits.append(node[1]["qubits"]) |
4. Additional Improvements
- Use shallow copy when copying integer lists.
Evaluation
- Test: 100 random 50-CZ gates on 20 qubits.
- Line connectivity
- Qibo SABRE is 6x faster than before.
- The reason for the reduction in the number of SWAP gates is unknown.
Mean Std
Qiskit Sabre Time 0.0439 0.0075
Qibo Sabre Time 0.0625 0.0179
Qibo Sabre Old Time 0.4252 0.106
Qiskit Sabre Swaps 189.97 21.7295
Qibo Sabre Swaps 196.54 21.8712
Qibo Sabre Old Swaps 279.96 35.739
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 @csookim, I looked into the new CircuitMap
and it seems better, I just have a handful of comments.
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.
Thank you for this improvement, I had a first look at the changes and I agree on the corrections proposed by @BrunoLiegiBastonLiegi
Regarding the performance improvement (number of swaps) I beliave that refactoring the circuit_map probaly solved some bug that we were not able to identify.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1419 +/- ##
=======================================
Coverage 97.10% 97.11%
=======================================
Files 81 81
Lines 11653 11679 +26
=======================================
+ Hits 11316 11342 +26
Misses 337 337
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Co-authored-by: BrunoLiegiBastonLiegi <[email protected]>
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
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 @csookim, this looks almost perfect to me now, I just made some further minor comments.
Regarding the coverage, there are 4 lines missing, some are related to the error of the circuit
not being passed to the CircuitMap
, which as I pointed out previously it would better to drop by making the argument mandatory. Some others to one of the two new properties setter that it's probably never used.
Co-authored-by: BrunoLiegiBastonLiegi <[email protected]>
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Custom qubit names can be used in Sabre. But the node names in the
|
:math:`{\\textup{"q0"}: 1, \\textup{"q1"}: 2, \\textup{"q2"}:0}` | |
to assign the physical qubits :math:`\\{0, 1, 2\\}` | |
to the logical qubits :math:`[1, 2, 0]`. |
I believe some parts of the code in Placer
need to be updated, and the test files should be updated after resolving issue #1429.
Thanks @csookim for the insight about the |
At the moment it is not an important requirement but it may become fundamental for qibolab in the future when it will support hardware qubit names different from integers. |
@csookim there are a few tests failing in the pipeline and router. If you can fix them then i will proceed with the review |
This comment was marked as resolved.
This comment was marked as resolved.
I just did, there are some open comments that were not addressed and did not receive any answer |
@csookim I don't see any new updates or answers to the points that are still open, could you please double check those and the tests that are failing? |
This comment was marked as resolved.
This comment was marked as resolved.
I cannot see any answer to those comments, did you answer them? Please double check, because if you click the button "start a review" instead of "Add a single comment", your answers are going to be pending until you finish the review, and they are going to be visible for you only. |
This comment was marked as resolved.
This comment was marked as resolved.
@BrunoLiegiBastonLiegi I've updated the code handling these issues and modified the test functions.
Currently, the |
for more information, see https://pre-commit.ci
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.
Co-authored-by: BrunoLiegiBastonLiegi <[email protected]>
Co-authored-by: BrunoLiegiBastonLiegi <[email protected]>
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
I agree with the PR, However after the latest merge with master there is an error occurring. Can you fix it before I approve? |
There is a bug in drawer #1438. I will update it as soon as the issue is resolved. Please approve it after the update. |
@Simone-Bordoni Please review this PR. Thanks. |
To improve Sabre's performance, several implementations have been updated. I’ve added comments to the code and each comment number corresponds to the explanation numbers provided below. Please let me know if any clarifications are needed. Below is the code explanation.
Checklist:
After the code review:
_swap_candidates(), _check_execution(), _shortest_path_routing()
(removeget_physical_qubits(block_num)
).ShortestPaths
.