unitaryfund / aquapointer

Package applying quantum algorithms to find locations of water molecules in a protein cavity
GNU General Public License v3.0
8 stars 1 forks source link

KeyError in `threshold_distances` in `calculate_detunings` #83

Closed Misty-W closed 4 months ago

Misty-W commented 4 months ago

When I run the automated script with each of the three cases in https://github.com/unitaryfund/aquapointer/pull/78#issuecomment-2195124326, 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 commented 4 months ago

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 commented 4 months ago

Same solution as #82.