Skip to content

Commit

Permalink
fix swap bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Kahsolt committed Aug 2, 2024
1 parent 018926f commit 15dfa12
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions server/app/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,14 @@ def handle_game_put(self, idx:int, target_qubit:int, control_qubit:int=None) ->
if isSWAP: # swap location of two single-qubit gate
if not isSWAP_give_up:
gates = self.circuit.gates
idx_A = gates.index(igate_A)
idx_B = gates.index(igate_B)
tmp = gates[idx_A]
gates[idx_A] = gates[idx_B]
gates[idx_B] = tmp
# 先交换指令位序
tmp = gates[target_qubit]
gates[target_qubit] = gates[control_qubit]
gates[control_qubit] = tmp
# 再交换所在线缆
tmp = gates[target_qubit].target_qubit
gates[target_qubit].target_qubit = gates[control_qubit].target_qubit
gates[control_qubit].target_qubit = tmp
else: # append to circuit
igate = IGate(xgate.name, target_qubit, xgate.param, control_qubit)
assert check_gate_can_put(self.circuit, igate, self.n_qubit, self.n_depth)
Expand Down
2 changes: 1 addition & 1 deletion server/app/sdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class GameConst:
'CNOT': 15,
'CZ': 15,
# ↓ this is NOT a gate, but an virtual action
'SWAP': 3,
'SWAP': 5,
}
gate_pool_names = list(gate_pool.keys())
gate_pool_weights = np.asarray(list(gate_pool.values()))
Expand Down

0 comments on commit 15dfa12

Please sign in to comment.