From 15dfa12f82d9c1e70b0af98b5f58694946470620 Mon Sep 17 00:00:00 2001 From: Kahsolt Date: Fri, 2 Aug 2024 16:34:29 +0800 Subject: [PATCH] fix swap bug --- server/app/game.py | 13 ++++++++----- server/app/sdata.py | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/server/app/game.py b/server/app/game.py index 3962090..8421a8c 100644 --- a/server/app/game.py +++ b/server/app/game.py @@ -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) diff --git a/server/app/sdata.py b/server/app/sdata.py index af91070..7d5426e 100644 --- a/server/app/sdata.py +++ b/server/app/sdata.py @@ -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()))