Skip to content
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

Row-ify atom positions. #84

Open
weinbe58 opened this issue May 15, 2023 · 8 comments
Open

Row-ify atom positions. #84

weinbe58 opened this issue May 15, 2023 · 8 comments
Labels
enhancement New feature or request mod:location issues related to atoms module
Milestone

Comments

@weinbe58
Copy link
Member

Issue

One complaint we commonly see is that the row constraints of the lattice makes it difficult to create a task.

Proposed solution

One method to get around this is to create a function that automatically generates a new set of positions that fits the constraints of the lattice.

The implementation of how to do this is pretty tricky. Ideally, the algorithm should modify the atom positions as little as possible while also working within the constraints of the device.

One thought I had is to come up with a generic algorithm that forces the atom positions into rows of fixed y-values, but as a layer on top, we have a first pass that will try every valid rotation of the atom positions.

What is a valid rotation is taking any two pairs of atoms and making that the x-axis of your system. Then you can rotate the current coordinates and check to see if those rotated positions fit the length and width constraints of the device.

If that rotation fits that constraint it next goes into the "rowify" calculation, after which, the average displacement is calculated for all the atoms.

The final transformation chosen is the rotation that is valid and has the minimum displacement of atoms.

Row-ify lattice

To "rowify" the atoms, the idea would be to calculate all groups of positions that fall within the minimum row spacing and then replace those values with their average y-value to get the new positions.

Finally the x-positions need to be changed so that the atoms do not violate the minimum distance constraint.

Here is a code snippet to do the first part:

import numpy as np


def rowify(positions, min_row_spacing = 0.01, positions_resolution=1e-5):
    y_sorted_indices = np.argsort(positions[:,1])
    
    rounded_positions = np.around(
        np.round(positions[y_sorted_indices,:]/positions_resolution) * positions_resolution, 13
    )
    
    ys = rounded_positions[:,1]
    inds = np.arange(ys.size)
    groups = set([])
    for i,y in enumerate(ys):
        mask = np.abs(y-ys) < min_row_spacing
        group = tuple(inds[mask])
        groups.add(group)
    
    for group in groups:
        ind = list(group)
        new_y = np.mean(ys[ind])
        
        ys[ind] = np.around(
            np.round(new_y/positions_resolution) * positions_resolution, 13
        )

    print(rounded_positions)
        
    
np.random.seed(0)
positions = np.random.uniform(0,1,(100,2))

rowify(positions, min_row_spacing=0.01)
@weinbe58 weinbe58 added enhancement New feature or request mod:location issues related to atoms module labels May 15, 2023
@weinbe58 weinbe58 added this to the internal-alpha milestone May 15, 2023
@Wang-Shengtao
Copy link
Member

Two quick comments:

  1. Does it make sense to give warnings on this first before implementing a solution? Or maybe that's already there.
  2. Since embedded sorting may remove the constraint of the rows, perhaps would be great to check the physical constraints of the improved sorting and the timeline for rolling them out on the hardware.

@weinbe58
Copy link
Member Author

  1. Yes of course it doesn't make sense to automatically apply it I would make it optional and put a validation error in the case where it doesn't work.
  2. We will have to support multiple devices with multiple capabilities so it's still useful to have this if people use Aquila vs. Gemini.

@jon-wurtz
Copy link

I have a piece of code that starts to do this already. Its messy but works ish by greedily adding rows.
image

@jon-wurtz
Copy link

The same except rowifying [] in [] for the [***] project

image

@weinbe58
Copy link
Member Author

weinbe58 commented May 15, 2023

Can you link your implementation? @jon-wurtz

@weinbe58
Copy link
Member Author

Also for some graphs you are showing it looks like there are multiple length scales.

Have you thought about the two length scales separately? One could treat the larger length scale with a weighted MIS problem with nodes tightly clustered together being treated as a node with a different weights.

Then run a weighted MIS on the effective nodes with a background value determined by the larger scale solution.

@jon-wurtz
Copy link

Yes, this is actually one idea for the BP project-- identify cliques and squish them into one effective node. I believe the giant blob is Springfield MA. I don't like the above implementation (it is slightly unpredictable) and am currently working on a more stable method based on tree/forest aggregation

@weinbe58
Copy link
Member Author

Experimental implementations will be here https://github.com/QuEra-AnA/rowify

@weinbe58 weinbe58 modified the milestones: internal-alpha, internal-alpha-2 May 16, 2023
@weinbe58 weinbe58 added this to the public-beta-1 milestone Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request mod:location issues related to atoms module
Projects
None yet
Development

No branches or pull requests

3 participants