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

KeyError in threshold_distances in calculate_detunings #83

Closed
Misty-W opened this issue Jul 10, 2024 · 2 comments
Closed

KeyError in threshold_distances in calculate_detunings #83

Misty-W opened this issue Jul 10, 2024 · 2 comments
Assignees

Comments

@Misty-W
Copy link
Contributor

Misty-W commented Jul 10, 2024

When I run the automated script with each of the three cases in #78 (comment), etc, I get the following error:

File "/Users/mistywahl/Documents/GitHub/aquapointer/aquapointer/analog/qubo_solution.py", line 117, in run_qubo
detunings = canvas.calculate_detunings()
File "/Users/mistywahl/Documents/GitHub/aquapointer/aquapointer/density_canvas/DensityCanvas.py", line 701, in calculate_detunings
if d10 < threshold_distances[i]:
KeyError: 0

Originally I'd thought this was related to the force_lattice_size error, but it seems different. From what I can tell, the update to calculate_detunings in #81 didn't account for the possibility that threshold_distances could be empty at line 701. I could just fix it as suggested below but wanted to check first if there's a reason threshold_distances should not be empty by line 701, which would indicate another problem.

Suggested solution:
Replace threshold_distances = {} with

from collections import defaultdict
threshold_distances = defaultdict(float)
@darcangelomauro
Copy link
Collaborator

The function of the variable threshold_distance is to set a distance such that the interaction between a qubit and its neighbours that are closer than that distance is ignored. Sometimes, however, no interaction has to be ignored, and in this case threshold_distance should be the smallest possible distance.
The issue was solved in #84 by initializing threshold_distance with the smallest distance with:

threshold_distances[i] = distances[i][-1][1]

The remaining code will modify this value if a different threshold is needed, otherwise it will leave it unchanged.

@Misty-W
Copy link
Contributor Author

Misty-W commented Jul 16, 2024

Same solution as #82.

@Misty-W Misty-W closed this as completed Jul 16, 2024
Misty-W added a commit that referenced this issue Jul 16, 2024
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

No branches or pull requests

2 participants