Skip to content

Commit 96ab5c4

Browse files
authored
Correct XY Hamiltonian interaction term (#744)
* Correct XY interaction term calculation * Adapt tutorial
1 parent 32fbbb0 commit 96ab5c4

File tree

3 files changed

+46
-51
lines changed

3 files changed

+46
-51
lines changed

pulser-simulation/pulser_simulation/hamiltonian.py

+12-14
Original file line numberDiff line numberDiff line change
@@ -457,22 +457,20 @@ def make_xy_term(q1: QubitId, q2: QubitId) -> qutip.Qobj:
457457
The units are given so that the coefficient
458458
includes a 1/hbar factor.
459459
"""
460-
dist = np.linalg.norm(self._qdict[q1] - self._qdict[q2])
461-
coords_dim = len(self._qdict[q1])
462-
mag_field = cast(np.ndarray, self.samples_obj._magnetic_field)[
463-
:coords_dim
464-
]
460+
diff_vector = np.zeros(3, dtype=float)
461+
diff_vector[: len(self._qdict[q1])] = (
462+
self._qdict[q1] - self._qdict[q2]
463+
)
464+
dist = np.linalg.norm(diff_vector)
465+
mag_field = cast(np.ndarray, self.samples_obj._magnetic_field)
465466
mag_norm = np.linalg.norm(mag_field)
466-
if mag_norm < 1e-8:
467-
cosine = 0.0
468-
else:
469-
cosine = np.dot(
470-
(self._qdict[q1] - self._qdict[q2]),
471-
mag_field,
472-
) / (dist * mag_norm)
467+
assert mag_norm > 0, "There must be a magnetic field in XY mode."
468+
cosine = np.dot(
469+
diff_vector,
470+
mag_field,
471+
) / (dist * mag_norm)
473472
U = (
474-
0.5
475-
* cast(float, self._device.interaction_coeff_xy)
473+
cast(float, self._device.interaction_coeff_xy)
476474
* (1 - 3 * cosine**2)
477475
/ dist**3
478476
)

tests/test_simulation.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -1189,11 +1189,10 @@ def test_get_xy_hamiltonian():
11891189
simple_sim.get_hamiltonian(-10)
11901190
# Constant detuning, so |ud><du| term is C_3/r^3 - 2*detuning for any time
11911191
simple_ham = simple_sim.get_hamiltonian(143)
1192-
assert simple_ham[1, 2] == 0.5 * MockDevice.interaction_coeff_xy / 10**3
1192+
assert simple_ham[1, 2] == MockDevice.interaction_coeff_xy / 10**3
11931193
assert (
11941194
np.abs(
1195-
simple_ham[1, 4]
1196-
- (-2 * 0.5 * MockDevice.interaction_coeff_xy / 10**3)
1195+
simple_ham[1, 4] - (-2 * MockDevice.interaction_coeff_xy / 10**3)
11971196
)
11981197
< 1e-10
11991198
)
@@ -1236,10 +1235,10 @@ def test_run_xy():
12361235
assert sim.samples_obj._measurement == "XY"
12371236

12381237

1239-
res1 = {"0000": 892, "1000": 47, "0100": 25, "0001": 19, "0010": 17}
1240-
res2 = {"0000": 962, "0010": 13, "1000": 13, "0100": 12}
1241-
res3 = {"0000": 904, "0100": 43, "0010": 24, "1000": 19, "0001": 10}
1242-
res4 = {"0000": 969, "0001": 18, "1000": 13}
1238+
res1 = {"0000": 950, "0100": 19, "0001": 21, "0010": 10}
1239+
res2 = {"0000": 944, "0010": 15, "1000": 33, "0100": 8}
1240+
res3 = {"0000": 950, "0100": 19, "0010": 10, "0001": 21}
1241+
res4 = {"0000": 951, "0100": 19, "1000": 30}
12431242

12441243

12451244
@pytest.mark.parametrize(

tutorials/quantum_simulation/Microwave-engineering of programmable XXZ Hamiltonians in arrays of Rydberg atoms.ipynb

+28-30
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)