File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
qubitverse/simulator/gates Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -193,7 +193,11 @@ namespace simulator
193193 if ((i & (1 << q_control)) != 0 )
194194 { // If control qubit is 1
195195 std::size_t target_bit_flipped_index = i ^ (1 << q_target);
196- std::swap (__s[i], __s[target_bit_flipped_index]);
196+ // Only swap once per pair.
197+ if (i < target_bit_flipped_index)
198+ {
199+ std::swap (__s[i], __s[target_bit_flipped_index]);
200+ }
197201 }
198202 }
199203 }
@@ -211,14 +215,14 @@ namespace simulator
211215 {
212216 for (std::size_t i = 0 ; i < (1 << n_qubits); ++i)
213217 {
214- // Extract the bits at positions q1 and q2 .
218+ // Extract the bits at positions q_control and q_target .
215219 std::size_t bit_q1 = (i >> q_control) & 1 ;
216220 std::size_t bit_q2 = (i >> q_target) & 1 ;
217221
218222 // Only need to swap if the bits differ.
219223 if (bit_q1 != bit_q2)
220224 {
221- // Flip the bits at q1 and q2 .
225+ // Flip the bits at q_control and q_target .
222226 std::size_t j = i ^ ((1 << q_control) | (1 << q_target));
223227 // To avoid double swapping, swap only if i < j.
224228 if (i < j)
You can’t perform that action at this time.
0 commit comments