-
Notifications
You must be signed in to change notification settings - Fork 12
feat(templates): Add greedy algorithm for gate layering #24
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
feat(templates): Add greedy algorithm for gate layering #24
Conversation
Introduces the `get_nn_gate_layers` utility function. This function takes a lattice object and partitions its nearest-neighbor pairs into the minimum number of compatible layers for parallel two-qubit gate application. This implementation uses a greedy edge-coloring algorithm to ensure that no two gates within the same layer act on the same qubit. The output is deterministic, with both layers and the edges within them being sorted. This functionality is essential for efficiently scheduling gates in algorithms like Trotterized Hamiltonian evolution and directly addresses Task 2 of the lattice API follow-up plan.
|
Hi @refraction-ray, I've just opened this Pull Request for Task 2, which implements the This should be ready for your review when you have a moment. Please let me know if you have any suggestions or if any changes are needed. Thanks again for your guidance! |
|
some general suggestions:
|
|
Sorry, I pushed the wrong version |
d7578f1 to
ebdebc9
Compare
|
@refraction-ray |
examples/vqe2d_lattice.py
Outdated
| K = tc.set_backend("jax") | ||
| tc.set_dtype("complex64") | ||
| # On Windows, cotengra's multiprocessing can cause issues. | ||
| tc.set_contractor("cotengra-8192-8192", parallel=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.
parallel=False is subtle (very slow), maybe you can try other parallel options to see whether they work in windows? https://cotengra.readthedocs.io/en/latest/advanced.html#parallelization
tests/test_lattice.py
Outdated
| @@ -1,5 +1,6 @@ | |||
| from unittest.mock import patch | |||
| import logging | |||
| from typing import List, Set, Tuple | |||
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.
we dont need to add type annotation for test functions, though it is okay to have them
examples/vqe2d_lattice.py
Outdated
| for i in range(nlayers): | ||
| for layer in gate_layers: | ||
| for j, k in layer: | ||
| c.rzz(int(j), int(k), theta=param[i, 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.
we should make each parameter different for each gate, a naive and also bruteforce way is to use a one-dimensional tensor for param, and for each use of param, we call param[count] then count+=1
tests/test_lattice.py
Outdated
| # ) | ||
|
|
||
|
|
||
| class MockLattice(AbstractLattice): |
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.
what is this class for, I dont see it being used, maybe deleted?
|
overall, very nice. Leave some minor comments to be fixed. |
|
for the slow speed a better way is to try the script with n=4, m=2, and no |
|
@refraction-ray |
Introduces the
get_nn_gate_layersutility function. This function takes a lattice object and partitions its nearest-neighbor pairs into the minimum number of compatible layers for parallel two-qubit gate application.This implementation uses a greedy edge-coloring algorithm to ensure that no two gates within the same layer act on the same qubit. The output is deterministic, with both layers and the edges within them being sorted.
This functionality is essential for efficiently scheduling gates in algorithms like Trotterized Hamiltonian evolution and directly addresses Task 2 of the lattice API follow-up plan.